BloodMagic/src/main/java/WayofTime/bloodmagic/tile/TilePurificationAltar.java

84 lines
2.8 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.iface.IPurificationAsh;
import WayofTime.bloodmagic.ritual.AreaDescriptor;
import WayofTime.bloodmagic.util.helper.PurificationHelper;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
2017-08-16 04:30:48 +00:00
import java.util.List;
public class TilePurificationAltar extends TileInventory implements ITickable {
public AreaDescriptor purityArea = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public double totalPurity = 0;
public double maxPurity = 0;
public double purityRate = 0;
2017-08-16 04:30:48 +00:00
public TilePurificationAltar() {
super(1, "purificationAltar");
}
@Override
2017-08-16 04:30:48 +00:00
public void update() {
if (totalPurity <= 0) {
ItemStack stack = this.getStackInSlot(0);
2017-08-16 04:30:48 +00:00
if (!stack.isEmpty() && stack.getItem() instanceof IPurificationAsh) {
totalPurity = ((IPurificationAsh) stack.getItem()).getTotalPurity(stack);
maxPurity = ((IPurificationAsh) stack.getItem()).getMaxPurity(stack);
purityRate = ((IPurificationAsh) stack.getItem()).getPurityRate(stack);
}
2017-08-16 04:30:48 +00:00
} else {
return;
}
AxisAlignedBB aabb = purityArea.getAABB(getPos());
2016-12-13 03:56:36 +00:00
List<EntityAnimal> animalList = getWorld().getEntitiesWithinAABB(EntityAnimal.class, aabb);
2017-08-16 04:30:48 +00:00
if (animalList.isEmpty()) {
return;
}
boolean hasPerformed = false;
2017-08-16 04:30:48 +00:00
for (EntityAnimal animal : animalList) {
double added = PurificationHelper.addPurity(animal, Math.min(purityRate, totalPurity), maxPurity);
2017-08-16 04:30:48 +00:00
if (added > 0) {
totalPurity -= purityRate;
hasPerformed = true;
}
}
2017-08-16 04:30:48 +00:00
if (hasPerformed) {
if (getWorld().rand.nextInt(4) == 0 && getWorld() instanceof WorldServer) {
2016-12-13 03:56:36 +00:00
WorldServer server = (WorldServer) getWorld();
server.spawnParticle(EnumParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 1, 0.02, 0.03, 0.02, 0);
}
}
}
@Override
2017-08-16 04:30:48 +00:00
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
totalPurity = tag.getDouble("totalPurity");
maxPurity = tag.getDouble("maxPurity");
purityRate = tag.getDouble("purityRate");
}
@Override
2017-08-16 04:30:48 +00:00
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setDouble("totalPurity", totalPurity);
tag.setDouble("maxPurity", maxPurity);
tag.setDouble("purityRate", purityRate);
return tag;
}
}