2015-12-23 15:20:26 -05:00
|
|
|
package WayofTime.bloodmagic.tile;
|
|
|
|
|
2016-06-29 07:43:04 -04:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2016-06-28 13:35:42 -04:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.Entity;
|
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;
|
2016-06-29 07:43:04 -04:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-12-23 18:45:47 -05:00
|
|
|
import net.minecraft.util.ITickable;
|
2016-06-29 07:43:04 -04:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-06-27 11:21:37 -04:00
|
|
|
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
|
2016-06-29 07:43:04 -04:00
|
|
|
import WayofTime.bloodmagic.api.iface.IAlchemyArray;
|
2016-06-27 11:21:37 -04:00
|
|
|
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
|
2015-12-23 15:20:26 -05:00
|
|
|
|
2016-06-29 07:43:04 -04:00
|
|
|
public class TileAlchemyArray extends TileInventory implements ITickable, IAlchemyArray
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
public boolean isActive = false;
|
|
|
|
public int activeCounter = 0;
|
2015-12-23 18:45:47 -05:00
|
|
|
|
2016-06-29 07:43:04 -04:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
public EnumFacing rotation = EnumFacing.HORIZONTALS[0];;
|
|
|
|
|
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
|
|
|
|
2016-06-28 13:35:42 -04:00
|
|
|
public void onEntityCollidedWithBlock(IBlockState state, Entity entity)
|
|
|
|
{
|
|
|
|
if (arrayEffect != null)
|
|
|
|
{
|
2016-06-29 07:43:04 -04:00
|
|
|
arrayEffect.onEntityCollidedWithBlock(this, worldObj, pos, state, entity);
|
2016-06-28 13:35:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
2016-09-07 17:46:06 -07:00
|
|
|
public void deserialize(NBTTagCompound tagCompound)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-09-07 17:46:06 -07:00
|
|
|
super.deserialize(tagCompound);
|
2015-12-30 15:34:40 -05:00
|
|
|
this.isActive = tagCompound.getBoolean("isActive");
|
|
|
|
this.activeCounter = tagCompound.getInteger("activeCounter");
|
2016-06-27 11:21:37 -04:00
|
|
|
this.key = tagCompound.getString("key");
|
2016-06-29 07:43:04 -04:00
|
|
|
this.rotation = EnumFacing.HORIZONTALS[tagCompound.getInteger(Constants.NBT.DIRECTION)];
|
2016-06-27 11:21:37 -04:00
|
|
|
|
|
|
|
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-09-07 17:46:06 -07:00
|
|
|
public NBTTagCompound serialize(NBTTagCompound tagCompound)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-09-07 17:46:06 -07:00
|
|
|
super.serialize(tagCompound);
|
2015-12-30 15:34:40 -05:00
|
|
|
tagCompound.setBoolean("isActive", isActive);
|
|
|
|
tagCompound.setInteger("activeCounter", activeCounter);
|
2016-06-28 07:26:16 -04:00
|
|
|
tagCompound.setString("key", "".equals(key) ? "empty" : key);
|
2016-06-29 07:43:04 -04:00
|
|
|
tagCompound.setInteger(Constants.NBT.DIRECTION, rotation.getHorizontalIndex());
|
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 15:20:26 -05:00
|
|
|
}
|