2014-09-19 04:38:14 +02:00
|
|
|
package com.pahimar.ee3.tileentity;
|
|
|
|
|
2014-10-03 21:55:22 +02:00
|
|
|
import com.pahimar.ee3.api.AlchemyArray;
|
|
|
|
import com.pahimar.ee3.api.Glyph;
|
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
|
|
|
import com.pahimar.ee3.network.message.MessageTileEntityAlchemyArray;
|
2014-09-25 22:23:45 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-10-21 21:59:00 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-10-03 21:55:22 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.Packet;
|
2014-09-25 22:23:45 +02:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2014-10-21 21:59:00 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-10-15 03:11:54 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-09-24 22:02:45 +02:00
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public class TileEntityAlchemyArray extends TileEntityEE
|
|
|
|
{
|
2014-10-03 21:55:22 +02:00
|
|
|
private AlchemyArray alchemyArray;
|
2014-10-15 03:11:54 +02:00
|
|
|
private ForgeDirection rotation;
|
2014-10-17 22:16:14 +02:00
|
|
|
private int ticksSinceSync;
|
2014-09-24 22:02:45 +02:00
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public TileEntityAlchemyArray()
|
|
|
|
{
|
2014-09-24 22:02:45 +02:00
|
|
|
super();
|
2014-10-03 21:55:22 +02:00
|
|
|
alchemyArray = new AlchemyArray();
|
2014-10-15 03:11:54 +02:00
|
|
|
rotation = ForgeDirection.UNKNOWN;
|
2014-09-24 22:02:45 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public AlchemyArray getAlchemyArray()
|
|
|
|
{
|
2014-10-03 21:55:22 +02:00
|
|
|
return alchemyArray;
|
2014-09-25 22:23:45 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public boolean addGlyphToAlchemyArray(Glyph glyph)
|
|
|
|
{
|
2014-10-14 22:08:12 +02:00
|
|
|
return alchemyArray.addGlyph(glyph);
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public boolean addGlyphToAlchemyArray(Glyph glyph, int size)
|
|
|
|
{
|
2014-10-14 22:08:12 +02:00
|
|
|
return addGlyphToAlchemyArray(new Glyph(glyph, size));
|
2014-10-03 21:55:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public ForgeDirection getRotation()
|
|
|
|
{
|
2014-10-10 20:54:07 +02:00
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public void setRotation(int rotation, int facing)
|
|
|
|
{
|
|
|
|
if (this.orientation == ForgeDirection.UP)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.DOWN)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.NORTH)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.SOUTH)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.EAST)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.WEST)
|
|
|
|
{
|
|
|
|
if ((rotation + facing) % 4 == 0)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 1)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 2)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if ((rotation + facing) % 4 == 3)
|
|
|
|
{
|
2014-10-15 21:51:23 +02:00
|
|
|
this.rotation = ForgeDirection.UP;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 22:20:41 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:23:45 +02:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-10-21 21:59:00 +02:00
|
|
|
public AxisAlignedBB getRenderBoundingBox()
|
|
|
|
{
|
|
|
|
if (this.orientation == ForgeDirection.UP || this.orientation == ForgeDirection.DOWN)
|
|
|
|
{
|
2014-10-17 21:43:18 +02:00
|
|
|
return AxisAlignedBB.getBoundingBox(xCoord - alchemyArray.getLargestGlyphSize(), yCoord - 1, zCoord - alchemyArray.getLargestGlyphSize(), xCoord + alchemyArray.getLargestGlyphSize(), yCoord + 1, zCoord + alchemyArray.getLargestGlyphSize());
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.NORTH || this.orientation == ForgeDirection.SOUTH)
|
|
|
|
{
|
2014-10-17 21:43:18 +02:00
|
|
|
return AxisAlignedBB.getBoundingBox(xCoord - alchemyArray.getLargestGlyphSize(), yCoord - alchemyArray.getLargestGlyphSize(), zCoord - 1, xCoord + alchemyArray.getLargestGlyphSize(), yCoord + alchemyArray.getLargestGlyphSize(), zCoord + 1);
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.EAST || this.orientation == ForgeDirection.WEST)
|
|
|
|
{
|
2014-10-17 21:43:18 +02:00
|
|
|
return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord - alchemyArray.getLargestGlyphSize(), zCoord - alchemyArray.getLargestGlyphSize(), xCoord + 1, yCoord + alchemyArray.getLargestGlyphSize(), zCoord + alchemyArray.getLargestGlyphSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getRenderBoundingBox();
|
2014-10-03 21:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-21 21:59:00 +02:00
|
|
|
public Packet getDescriptionPacket()
|
|
|
|
{
|
2014-10-03 21:55:22 +02:00
|
|
|
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityAlchemyArray(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-21 21:59:00 +02:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
|
|
|
{
|
2014-10-03 21:55:22 +02:00
|
|
|
super.readFromNBT(nbtTagCompound);
|
|
|
|
|
|
|
|
NBTTagCompound alchemyArrayTagCompound = nbtTagCompound.getCompoundTag("alchemyArray");
|
|
|
|
alchemyArray = AlchemyArray.readAlchemyArrayFromNBT(alchemyArrayTagCompound);
|
2014-10-10 20:54:07 +02:00
|
|
|
|
2014-10-15 03:11:54 +02:00
|
|
|
rotation = ForgeDirection.getOrientation(nbtTagCompound.getInteger("rotation"));
|
2014-10-03 21:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-21 21:59:00 +02:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
|
|
|
{
|
2014-10-03 21:55:22 +02:00
|
|
|
super.writeToNBT(nbtTagCompound);
|
|
|
|
|
|
|
|
NBTTagCompound alchemyArrayTagCompound = new NBTTagCompound();
|
|
|
|
alchemyArray.writeToNBT(alchemyArrayTagCompound);
|
|
|
|
|
2014-10-15 03:11:54 +02:00
|
|
|
nbtTagCompound.setInteger("rotation", rotation.ordinal());
|
2014-10-10 20:54:07 +02:00
|
|
|
|
2014-10-03 21:55:22 +02:00
|
|
|
nbtTagCompound.setTag("alchemyArray", alchemyArrayTagCompound);
|
2014-09-24 22:02:45 +02:00
|
|
|
}
|
2014-10-16 22:26:11 +02:00
|
|
|
|
|
|
|
@Override
|
2014-10-21 21:59:00 +02:00
|
|
|
public void updateEntity()
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
super.updateEntity();
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
if (!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if (++ticksSinceSync % 100 == 0)
|
|
|
|
{
|
|
|
|
if (!areDummyBlocksValid())
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
this.invalidate();
|
|
|
|
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
public void onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int sideHit, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
// TODO: Perform the action for the registered alchemy array
|
|
|
|
this.alchemyArray.onAlchemyArrayActivated(world, x, y, z, entityPlayer, sideHit, hitX, hitY, hitZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean areDummyBlocksValid()
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
boolean validDummyBlocks = true;
|
|
|
|
int coordOffset = this.alchemyArray.getLargestGlyphSize() / 2;
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
if (this.orientation == ForgeDirection.UP || this.orientation == ForgeDirection.DOWN)
|
|
|
|
{
|
|
|
|
for (int i = this.xCoord - coordOffset; i <= this.xCoord + coordOffset; i++)
|
|
|
|
{
|
|
|
|
for (int j = this.zCoord - coordOffset; j <= this.zCoord + coordOffset; j++)
|
|
|
|
{
|
|
|
|
if ((i != this.xCoord || j != this.zCoord) && !isValidDummyBlock(i, this.yCoord, j))
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.NORTH || this.orientation == ForgeDirection.SOUTH)
|
|
|
|
{
|
|
|
|
for (int i = this.xCoord - coordOffset; i <= this.xCoord + coordOffset; i++)
|
|
|
|
{
|
|
|
|
for (int j = this.yCoord - coordOffset; j <= this.yCoord + coordOffset; j++)
|
|
|
|
{
|
|
|
|
if ((i != this.xCoord || j != this.yCoord) && !isValidDummyBlock(i, j, this.zCoord))
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 21:59:00 +02:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.EAST || this.orientation == ForgeDirection.WEST)
|
|
|
|
{
|
|
|
|
for (int i = this.yCoord - coordOffset; i <= this.yCoord + coordOffset; i++)
|
|
|
|
{
|
|
|
|
for (int j = this.zCoord - coordOffset; j <= this.zCoord + coordOffset; j++)
|
|
|
|
{
|
|
|
|
if ((i != this.yCoord || j != this.zCoord) && !isValidDummyBlock(this.xCoord, i, j))
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return validDummyBlocks;
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:59:00 +02:00
|
|
|
private boolean isValidDummyBlock(int x, int y, int z)
|
|
|
|
{
|
|
|
|
if (!this.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if (this.worldObj.getTileEntity(x, y, z) instanceof TileEntityDummyArray)
|
|
|
|
{
|
2014-10-17 22:16:14 +02:00
|
|
|
TileEntityDummyArray tileEntityDummyArray = (TileEntityDummyArray) this.worldObj.getTileEntity(x, y, z);
|
|
|
|
|
|
|
|
return tileEntityDummyArray.getOrientation() == this.orientation &&
|
|
|
|
tileEntityDummyArray.getTrueXCoord() == this.xCoord &&
|
|
|
|
tileEntityDummyArray.getTrueYCoord() == this.yCoord &&
|
|
|
|
tileEntityDummyArray.getTrueZCoord() == this.zCoord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-10-16 22:26:11 +02:00
|
|
|
}
|
2014-09-19 04:38:14 +02:00
|
|
|
}
|