2015-12-23 15:20:26 -05:00
|
|
|
package WayofTime.bloodmagic.tile;
|
|
|
|
|
2015-12-23 18:45:47 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
|
|
import net.minecraft.util.ITickable;
|
2015-12-23 20:19:06 -05:00
|
|
|
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
|
|
|
|
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
|
2015-12-23 15:20:26 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class TileAlchemyArray extends TileInventory implements ITickable
|
|
|
|
{
|
|
|
|
public boolean isActive = false;
|
|
|
|
public int activeCounter = 0;
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public TileAlchemyArray()
|
|
|
|
{
|
|
|
|
super(2, "alchemyArray");
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
this.isActive = tagCompound.getBoolean("isActive");
|
|
|
|
this.activeCounter = tagCompound.getInteger("activeCounter");
|
|
|
|
}
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
tagCompound.setBoolean("isActive", isActive);
|
|
|
|
tagCompound.setInteger("activeCounter", activeCounter);
|
|
|
|
}
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
if (isActive && attemptCraft())
|
|
|
|
{
|
|
|
|
activeCounter++;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
isActive = false;
|
|
|
|
activeCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public boolean attemptCraft()
|
|
|
|
{
|
|
|
|
AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
|
|
|
|
if (effect != null)
|
|
|
|
{
|
|
|
|
isActive = true;
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (effect.update(this, this.activeCounter))
|
|
|
|
{
|
|
|
|
this.decrStackSize(0, 1);
|
|
|
|
this.decrStackSize(1, 1);
|
|
|
|
this.worldObj.setBlockToAir(getPos());
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public Packet getDescriptionPacket()
|
|
|
|
{
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
writeToNBT(nbttagcompound);
|
|
|
|
return new S35PacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
|
|
|
|
{
|
|
|
|
super.onDataPacket(net, packet);
|
|
|
|
readFromNBT(packet.getNbtCompound());
|
|
|
|
}
|
2015-12-23 15:20:26 -05:00
|
|
|
}
|