2015-02-25 06:03:59 +01:00
|
|
|
package com.pahimar.ee3.tileentity;
|
|
|
|
|
2015-05-07 19:45:06 +02:00
|
|
|
import com.pahimar.ee3.api.array.AlchemyArray;
|
2015-02-25 06:03:59 +01:00
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
|
|
|
import com.pahimar.ee3.network.message.MessageTileEntityAlchemyArray;
|
2015-04-14 04:27:11 +02:00
|
|
|
import cpw.mods.fml.common.Loader;
|
2015-02-25 06:03:59 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-03-05 05:31:43 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-02-25 06:03:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-03-05 20:01:11 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-03-23 16:07:47 +01:00
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2015-03-05 05:31:43 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-02-25 06:03:59 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-03-05 05:31:43 +01:00
|
|
|
import net.minecraft.world.Explosion;
|
2015-02-25 06:03:59 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public class TileEntityAlchemyArray extends TileEntityEE implements ISidedInventory {
|
2015-02-25 06:03:59 +01:00
|
|
|
private AlchemyArray alchemyArray;
|
|
|
|
private ForgeDirection rotation;
|
|
|
|
private int size;
|
2015-03-23 16:07:47 +01:00
|
|
|
private int tickCount;
|
2015-02-25 06:03:59 +01:00
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public TileEntityAlchemyArray() {
|
2015-02-25 06:03:59 +01:00
|
|
|
super();
|
|
|
|
rotation = ForgeDirection.UNKNOWN;
|
|
|
|
size = 0;
|
2015-03-11 21:34:37 +01:00
|
|
|
alchemyArray = null;
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public AlchemyArray getAlchemyArray() {
|
2015-02-25 06:03:59 +01:00
|
|
|
return alchemyArray;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setAlchemyArray(AlchemyArray alchemyArray) {
|
2015-02-25 06:03:59 +01:00
|
|
|
setAlchemyArray(alchemyArray, 1);
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setAlchemyArray(AlchemyArray alchemyArray, int size) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.alchemyArray = alchemyArray;
|
|
|
|
this.size = size;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public ForgeDirection getRotation() {
|
2015-02-25 06:03:59 +01:00
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setRotation(ForgeDirection rotation) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = rotation;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setRotation(int rotation, int facing) {
|
|
|
|
if (this.orientation == ForgeDirection.UP) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.orientation == ForgeDirection.DOWN) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.orientation == ForgeDirection.NORTH) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.orientation == ForgeDirection.SOUTH) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.EAST;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.WEST;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.orientation == ForgeDirection.EAST) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.UP;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.orientation == ForgeDirection.WEST) {
|
|
|
|
if ((rotation + facing) % 4 == 0) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.NORTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 1) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.DOWN;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 2) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.SOUTH;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if ((rotation + facing) % 4 == 3) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.rotation = ForgeDirection.UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public int getSize() {
|
2015-02-25 06:03:59 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setSize(int size) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2023-01-03 17:47:36 +01:00
|
|
|
public AxisAlignedBB getRenderBoundingBox() {
|
|
|
|
if (this.orientation == ForgeDirection.UP
|
|
|
|
|| this.orientation == ForgeDirection.DOWN) {
|
|
|
|
return AxisAlignedBB.getBoundingBox(
|
|
|
|
xCoord - size,
|
|
|
|
yCoord - 1,
|
|
|
|
zCoord - size,
|
|
|
|
xCoord + size,
|
|
|
|
yCoord + 1,
|
|
|
|
zCoord + size
|
|
|
|
);
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.NORTH || this.orientation == ForgeDirection.SOUTH)
|
|
|
|
{
|
2023-01-03 17:47:36 +01:00
|
|
|
return AxisAlignedBB.getBoundingBox(
|
|
|
|
xCoord - size,
|
|
|
|
yCoord - size,
|
|
|
|
zCoord - 1,
|
|
|
|
xCoord + size,
|
|
|
|
yCoord + size,
|
|
|
|
zCoord + 1
|
|
|
|
);
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.EAST || this.orientation == ForgeDirection.WEST)
|
|
|
|
{
|
2023-01-03 17:47:36 +01:00
|
|
|
return AxisAlignedBB.getBoundingBox(
|
|
|
|
xCoord - 1,
|
|
|
|
yCoord - size,
|
|
|
|
zCoord - size,
|
|
|
|
xCoord + 1,
|
|
|
|
yCoord + size,
|
|
|
|
zCoord + size
|
|
|
|
);
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.getRenderBoundingBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void updateEntity() {
|
2015-02-25 06:03:59 +01:00
|
|
|
super.updateEntity();
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (!worldObj.isRemote) {
|
2015-03-23 16:07:47 +01:00
|
|
|
++tickCount;
|
2023-01-03 17:47:36 +01:00
|
|
|
if (tickCount % 100 == 0) {
|
|
|
|
if (!areDummyBlocksValid()) {
|
2015-02-25 06:03:59 +01:00
|
|
|
this.invalidate();
|
|
|
|
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
}
|
2015-03-05 05:31:43 +01:00
|
|
|
|
2015-03-23 16:07:47 +01:00
|
|
|
onUpdate(worldObj, xCoord, yCoord, zCoord, tickCount);
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public int getLightLevel() {
|
|
|
|
if (alchemyArray != null) {
|
2015-03-11 21:34:37 +01:00
|
|
|
return alchemyArray.getLightLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public void onBlockPlacedBy(
|
|
|
|
World world,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z,
|
|
|
|
EntityLivingBase entityLiving,
|
|
|
|
ItemStack itemStack
|
|
|
|
) {
|
|
|
|
onBlockPlacedBy(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, entityLiving, itemStack
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockPlacedBy(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
EntityLivingBase entityLiving,
|
|
|
|
ItemStack itemStack
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayPlacedBy(
|
|
|
|
world,
|
|
|
|
eventX,
|
|
|
|
eventY,
|
|
|
|
eventZ,
|
|
|
|
arrayX,
|
|
|
|
arrayY,
|
|
|
|
arrayZ,
|
|
|
|
entityLiving,
|
|
|
|
itemStack
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockActivated(
|
|
|
|
World world,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z,
|
|
|
|
EntityPlayer entityPlayer,
|
|
|
|
int sideHit,
|
|
|
|
float hitX,
|
|
|
|
float hitY,
|
|
|
|
float hitZ
|
|
|
|
) {
|
|
|
|
onBlockActivated(
|
|
|
|
world,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
z,
|
|
|
|
this.xCoord,
|
|
|
|
this.yCoord,
|
|
|
|
this.zCoord,
|
|
|
|
entityPlayer,
|
|
|
|
sideHit,
|
|
|
|
hitX,
|
|
|
|
hitY,
|
|
|
|
hitZ
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockActivated(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
EntityPlayer entityPlayer,
|
|
|
|
int sideHit,
|
|
|
|
float hitX,
|
|
|
|
float hitY,
|
|
|
|
float hitZ
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayActivated(
|
|
|
|
world,
|
|
|
|
eventX,
|
|
|
|
eventY,
|
|
|
|
eventZ,
|
|
|
|
arrayX,
|
|
|
|
arrayY,
|
|
|
|
arrayZ,
|
|
|
|
entityPlayer,
|
|
|
|
sideHit,
|
|
|
|
hitX,
|
|
|
|
hitY,
|
|
|
|
hitZ
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
onBlockClicked(World world, int x, int y, int z, EntityPlayer entityPlayer) {
|
|
|
|
onBlockClicked(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, entityPlayer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockClicked(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
EntityPlayer entityPlayer
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayClicked(
|
|
|
|
world, eventX, eventY, eventZ, arrayX, arrayY, arrayZ, entityPlayer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) {
|
|
|
|
onBlockDestroyedByExplosion(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, explosion
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockDestroyedByExplosion(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
Explosion explosion
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayDestroyedByExplosion(
|
|
|
|
world, eventX, eventY, eventZ, arrayX, arrayY, arrayZ, explosion
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int metaData) {
|
|
|
|
onBlockDestroyedByPlayer(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, metaData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onBlockDestroyedByPlayer(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
int metaData
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayDestroyedByPlayer(
|
|
|
|
world, eventX, eventY, eventZ, arrayX, arrayY, arrayZ, metaData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
|
|
|
|
onEntityCollidedWithBlock(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, entity
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEntityCollidedWithBlock(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
Entity entity
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onEntityCollidedWithArray(
|
|
|
|
world, eventX, eventY, eventZ, arrayX, arrayY, arrayZ, entity
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
onFallenUpon(World world, int x, int y, int z, Entity entity, float fallDistance) {
|
|
|
|
onFallenUpon(
|
|
|
|
world, x, y, z, this.xCoord, this.yCoord, this.zCoord, entity, fallDistance
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onFallenUpon(
|
|
|
|
World world,
|
|
|
|
int eventX,
|
|
|
|
int eventY,
|
|
|
|
int eventZ,
|
|
|
|
int arrayX,
|
|
|
|
int arrayY,
|
|
|
|
int arrayZ,
|
|
|
|
Entity entity,
|
|
|
|
float fallDistance
|
|
|
|
) {
|
|
|
|
if (alchemyArray != null) {
|
|
|
|
alchemyArray.onArrayFallenUpon(
|
|
|
|
world,
|
|
|
|
eventX,
|
|
|
|
eventY,
|
|
|
|
eventZ,
|
|
|
|
arrayX,
|
|
|
|
arrayY,
|
|
|
|
arrayZ,
|
|
|
|
entity,
|
|
|
|
fallDistance
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onUpdate(World world, int x, int y, int z, int tickCount) {
|
|
|
|
if (alchemyArray != null) {
|
2015-03-23 16:07:47 +01:00
|
|
|
alchemyArray.onUpdate(world, x, y, z, tickCount);
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public Packet getDescriptionPacket() {
|
|
|
|
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityAlchemyArray(this
|
|
|
|
));
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
2015-02-25 06:03:59 +01:00
|
|
|
super.readFromNBT(nbtTagCompound);
|
|
|
|
rotation = ForgeDirection.getOrientation(nbtTagCompound.getInteger("rotation"));
|
|
|
|
size = nbtTagCompound.getInteger("size");
|
2023-01-03 17:47:36 +01:00
|
|
|
NBTTagCompound alchemyArrayTagCompound
|
|
|
|
= nbtTagCompound.getCompoundTag("alchemyArray");
|
2015-03-11 21:34:37 +01:00
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (!alchemyArrayTagCompound.hasNoTags()) {
|
2015-03-11 21:34:37 +01:00
|
|
|
alchemyArray = AlchemyArray.readArrayFromNBT(alchemyArrayTagCompound);
|
2023-01-03 17:47:36 +01:00
|
|
|
try {
|
|
|
|
Class clazz = Class.forName(
|
|
|
|
alchemyArray.getClassName(),
|
|
|
|
true,
|
|
|
|
Loader.instance().getModClassLoader()
|
|
|
|
);
|
2015-03-11 21:34:37 +01:00
|
|
|
alchemyArray = (AlchemyArray) clazz.getConstructor().newInstance();
|
2015-03-23 16:07:47 +01:00
|
|
|
alchemyArray.readFromNBT(alchemyArrayTagCompound);
|
2023-01-03 17:47:36 +01:00
|
|
|
} catch (Exception e) {
|
2015-03-11 21:34:37 +01:00
|
|
|
this.invalidate();
|
2023-01-03 17:47:36 +01:00
|
|
|
if (worldObj != null) {
|
2015-03-11 21:34:37 +01:00
|
|
|
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
|
|
|
}
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else {
|
2015-03-05 05:31:43 +01:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
2015-02-25 06:03:59 +01:00
|
|
|
super.writeToNBT(nbtTagCompound);
|
|
|
|
nbtTagCompound.setInteger("rotation", rotation.ordinal());
|
|
|
|
nbtTagCompound.setInteger("size", size);
|
|
|
|
NBTTagCompound alchemyArrayTagCompound = new NBTTagCompound();
|
2023-01-03 17:47:36 +01:00
|
|
|
if (alchemyArray != null) {
|
2015-03-11 21:34:37 +01:00
|
|
|
alchemyArray.writeToNBT(alchemyArrayTagCompound);
|
|
|
|
}
|
2015-02-25 06:03:59 +01:00
|
|
|
nbtTagCompound.setTag("alchemyArray", alchemyArrayTagCompound);
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
private boolean areDummyBlocksValid() {
|
2015-02-25 06:03:59 +01:00
|
|
|
boolean validDummyBlocks = true;
|
|
|
|
int coordOffset = this.size / 2;
|
|
|
|
|
2023-01-03 17:47:36 +01: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)) {
|
2015-02-25 06:03:59 +01:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.NORTH || this.orientation == ForgeDirection.SOUTH)
|
|
|
|
{
|
2023-01-03 17:47:36 +01:00
|
|
|
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)) {
|
2015-02-25 06:03:59 +01:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.orientation == ForgeDirection.EAST || this.orientation == ForgeDirection.WEST)
|
|
|
|
{
|
2023-01-03 17:47:36 +01:00
|
|
|
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)) {
|
2015-02-25 06:03:59 +01:00
|
|
|
validDummyBlocks = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return validDummyBlocks;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
private boolean isValidDummyBlock(int x, int y, int z) {
|
|
|
|
if (!this.worldObj.isRemote) {
|
|
|
|
if (this.worldObj.getTileEntity(x, y, z) instanceof TileEntityDummyArray) {
|
|
|
|
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;
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-05 20:01:11 +01:00
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public int getSizeInventory() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public ItemStack getStackInSlot(int slotIndex) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).getStackInSlot(slotIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public ItemStack decrStackSize(int slotIndex, int decrementAmount) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).decrStackSize(slotIndex, decrementAmount);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public ItemStack getStackInSlotOnClosing(int slotIndex) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).getStackInSlotOnClosing(slotIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
((IInventory) alchemyArray).setInventorySlotContents(slotIndex, itemStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public String getInventoryName() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).getInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean hasCustomInventoryName() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).hasCustomInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).isUseableByPlayer(entityplayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void openInventory() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
((IInventory) alchemyArray).openInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void closeInventory() {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
((IInventory) alchemyArray).closeInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) {
|
|
|
|
if (alchemyArray instanceof IInventory) {
|
2015-03-05 20:01:11 +01:00
|
|
|
return ((IInventory) alchemyArray).isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-23 16:07:47 +01:00
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public int[] getAccessibleSlotsFromSide(int slotIndex) {
|
2015-03-23 16:07:47 +01:00
|
|
|
return new int[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) {
|
2015-03-23 16:07:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) {
|
2015-03-23 16:07:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-25 06:03:59 +01:00
|
|
|
}
|