2015-12-23 15:20:26 -05:00
|
|
|
package WayofTime.bloodmagic.tile;
|
|
|
|
|
2016-06-27 20:01:34 -04:00
|
|
|
import net.minecraft.inventory.InventoryHelper;
|
2015-12-23 18:45:47 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
2016-03-17 13:00:44 -07:00
|
|
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
2015-12-23 18:45:47 -05:00
|
|
|
import net.minecraft.util.ITickable;
|
2016-06-27 11:21:37 -04: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
|
|
|
|
2016-06-27 15:07:00 -04:00
|
|
|
private String key = "empty";
|
2016-06-27 11:21:37 -04:00
|
|
|
private AlchemyArrayEffect arrayEffect;
|
|
|
|
|
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");
|
2016-06-27 11:21:37 -04:00
|
|
|
this.key = tagCompound.getString("key");
|
|
|
|
|
|
|
|
NBTTagCompound arrayTag = tagCompound.getCompoundTag("arrayTag");
|
|
|
|
arrayEffect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(key);
|
|
|
|
if (arrayEffect != null)
|
|
|
|
{
|
|
|
|
arrayEffect.readFromNBT(arrayTag);
|
|
|
|
}
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
2016-05-19 17:43:33 -07:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
tagCompound.setBoolean("isActive", isActive);
|
|
|
|
tagCompound.setInteger("activeCounter", activeCounter);
|
2016-06-28 07:20:28 -04:00
|
|
|
tagCompound.setString("key", key == "" ? "empty" : key);
|
2016-06-27 11:21:37 -04:00
|
|
|
|
|
|
|
NBTTagCompound arrayTag = new NBTTagCompound();
|
|
|
|
if (arrayEffect != null)
|
|
|
|
{
|
|
|
|
arrayEffect.writeToNBT(arrayTag);
|
|
|
|
}
|
|
|
|
tagCompound.setTag("arrayTag", arrayTag);
|
|
|
|
|
2016-05-19 17:43:33 -07:00
|
|
|
return tagCompound;
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2016-02-08 14:41:58 -08:00
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
if (isActive && attemptCraft())
|
|
|
|
{
|
|
|
|
activeCounter++;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
isActive = false;
|
|
|
|
activeCounter = 0;
|
2016-06-27 11:21:37 -04:00
|
|
|
arrayEffect = null;
|
2016-06-27 15:07:00 -04:00
|
|
|
key = "empty";
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2016-06-27 20:01:34 -04:00
|
|
|
/**
|
|
|
|
* This occurs when the block is destroyed.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void dropItems()
|
|
|
|
{
|
|
|
|
super.dropItems();
|
|
|
|
if (arrayEffect != null)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public boolean attemptCraft()
|
|
|
|
{
|
|
|
|
AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
|
|
|
|
if (effect != null)
|
2016-06-27 11:21:37 -04:00
|
|
|
{
|
|
|
|
if (arrayEffect == null)
|
|
|
|
{
|
|
|
|
arrayEffect = effect;
|
|
|
|
key = effect.getKey();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
String effectKey = effect.getKey();
|
|
|
|
if (effectKey.equals(key))
|
|
|
|
{
|
|
|
|
//Good! Moving on.
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
//Something has changed, therefore we have to move our stuffs.
|
|
|
|
//TODO: Add an AlchemyArrayEffect.onBreak(); ?
|
|
|
|
arrayEffect = effect;
|
|
|
|
key = effect.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arrayEffect != null)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
isActive = true;
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2016-06-27 11:21:37 -04:00
|
|
|
if (arrayEffect.update(this, this.activeCounter))
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
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
|
2016-05-19 17:43:33 -07:00
|
|
|
public SPacketUpdateTileEntity getUpdatePacket()
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
writeToNBT(nbttagcompound);
|
2016-03-17 13:00:44 -07:00
|
|
|
return new SPacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
2015-12-23 20:19:06 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
2016-03-17 13:00:44 -07:00
|
|
|
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
super.onDataPacket(net, packet);
|
|
|
|
readFromNBT(packet.getNbtCompound());
|
|
|
|
}
|
2015-12-23 15:20:26 -05:00
|
|
|
}
|