2015-04-17 02:09:12 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import ic2.api.energy.prefab.BasicSink;
|
2015-05-08 20:42:52 +02:00
|
|
|
import ic2.api.energy.tile.IEnergyTile;
|
2015-04-17 02:09:12 +02:00
|
|
|
import ic2.api.tile.IWrenchable;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-04-28 19:23:48 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-06-08 23:39:07 +02:00
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2015-04-17 02:09:12 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-04-28 19:23:48 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
2015-04-26 17:22:26 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2015-06-25 21:17:14 +02:00
|
|
|
import techreborn.api.recipe.RecipeCrafter;
|
2015-04-26 17:22:26 +02:00
|
|
|
import techreborn.blocks.BlockMachineCasing;
|
2015-04-28 19:23:48 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
2015-04-17 18:42:57 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-04-26 17:22:26 +02:00
|
|
|
import techreborn.lib.Location;
|
2015-04-17 18:42:57 +02:00
|
|
|
import techreborn.util.Inventory;
|
2015-04-17 02:09:12 +02:00
|
|
|
|
2015-06-08 23:39:07 +02:00
|
|
|
public class TileBlastFurnace extends TileMachineBase implements IWrenchable, IInventory, IEnergyTile, ISidedInventory {
|
2015-04-17 02:09:12 +02:00
|
|
|
|
|
|
|
public int tickTime;
|
|
|
|
public BasicSink energy;
|
2015-04-28 19:23:48 +02:00
|
|
|
public Inventory inventory = new Inventory(4, "TileBlastFurnace", 64);
|
2015-06-25 21:17:14 +02:00
|
|
|
public RecipeCrafter crafter;
|
2015-04-28 22:04:28 +02:00
|
|
|
public static int euTick = 5;
|
2015-06-25 21:17:14 +02:00
|
|
|
|
2015-04-28 22:04:28 +02:00
|
|
|
public TileBlastFurnace() {
|
2015-04-28 19:23:48 +02:00
|
|
|
//TODO configs
|
2015-07-20 16:19:23 +02:00
|
|
|
energy = new BasicSink(this, 10000,ConfigTechReborn.CentrifugeTier);
|
2015-06-25 21:17:14 +02:00
|
|
|
int[] inputs = new int[2];
|
|
|
|
inputs[0] = 0;
|
|
|
|
inputs[1] = 1;
|
|
|
|
int[] outputs = new int[2];
|
|
|
|
outputs[0] = 2;
|
|
|
|
outputs[1] = 3;
|
|
|
|
crafter = new RecipeCrafter("blastFurnaceRecipe", this, energy, 2, 2, inventory, inputs, outputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity()
|
|
|
|
{
|
|
|
|
super.updateEntity();
|
|
|
|
energy.updateEntity();
|
|
|
|
crafter.updateEntity();
|
2015-04-28 19:23:48 +02:00
|
|
|
}
|
2015-04-17 18:42:57 +02:00
|
|
|
|
2015-04-17 02:09:12 +02:00
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
2015-04-17 02:09:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public short getFacing() {
|
2015-04-17 02:09:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void setFacing(short facing) {
|
2015-04-17 02:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-10 18:06:08 +02:00
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
|
|
|
|
{
|
|
|
|
if (entityPlayer.isSneaking())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-04-17 02:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public float getWrenchDropRate() {
|
2015-04-17 02:09:12 +02:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2015-04-17 02:09:12 +02:00
|
|
|
return new ItemStack(ModBlocks.BlastFurnace, 1);
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:04:28 +02:00
|
|
|
public int getHeat() {
|
|
|
|
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
|
|
|
|
TileEntity tileEntity = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
|
|
|
|
if (tileEntity instanceof TileMachineCasing) {
|
2015-07-20 16:19:23 +02:00
|
|
|
if(((TileMachineCasing) tileEntity).isConnected()){
|
|
|
|
if ((tileEntity.getBlockType() instanceof BlockMachineCasing)) {
|
|
|
|
int heat;
|
|
|
|
heat = BlockMachineCasing.getHeatFromMeta(tileEntity.getBlockMetadata());
|
|
|
|
Location location = new Location(xCoord, yCoord, zCoord, direction);
|
|
|
|
location.modifyPositionFromSide(direction, 1);
|
|
|
|
if (worldObj.getBlock(location.getX(), location.getY(), location.getZ()).getUnlocalizedName().equals("tile.lava")) {
|
|
|
|
heat += 500;
|
|
|
|
}
|
|
|
|
return heat;
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 22:04:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-25 21:17:14 +02:00
|
|
|
// @Override
|
|
|
|
// public void updateEntity(){
|
|
|
|
// super.updateEntity();
|
|
|
|
// energy.updateEntity();
|
|
|
|
// if (getStackInSlot(0) != null && getStackInSlot(1) != null) {
|
|
|
|
// if (recipe == null) {
|
|
|
|
// for (BlastFurnaceRecipe furnaceRecipe : TechRebornAPI.blastFurnaceRecipes) {
|
|
|
|
// if (ItemUtils.isItemEqual(getStackInSlot(0), furnaceRecipe.getInput1(), true, true) && ItemUtils.isItemEqual(getStackInSlot(1), furnaceRecipe.getInput2(), true, true)) {
|
|
|
|
// recipe = furnaceRecipe;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// if (!ItemUtils.isItemEqual(getStackInSlot(0), recipe.getInput1(), true, true) || !ItemUtils.isItemEqual(getStackInSlot(1), recipe.getInput2(), true, true)) {
|
|
|
|
// recipe = null;
|
|
|
|
// tickTime = 0;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// if (tickTime >= recipe.getTickTime()) {
|
|
|
|
// //When both slots are empty
|
|
|
|
// if (getStackInSlot(2) == null && getStackInSlot(3) == null) {
|
|
|
|
// setInventorySlotContents(2, recipe.getOutput1());
|
|
|
|
// setInventorySlotContents(3, recipe.getOutput2());
|
|
|
|
// tickTime = 0;
|
|
|
|
// recipe = null;
|
|
|
|
// } else
|
|
|
|
// //When both are the same as the recipe
|
|
|
|
// if (ItemUtils.isItemEqual(getStackInSlot(2), recipe.getOutput1(), true, true) && ItemUtils.isItemEqual(getStackInSlot(3), recipe.getOutput2(), true, true) && !areBothOutputsFull()) {
|
|
|
|
// decrStackSize(2, -recipe.getOutput1().stackSize);
|
|
|
|
// decrStackSize(3, -recipe.getOutput2().stackSize);
|
|
|
|
// tickTime = 0;
|
|
|
|
// recipe = null;
|
|
|
|
// } else
|
|
|
|
// //When slot one has stuff and slot 2 is empty
|
|
|
|
// if (ItemUtils.isItemEqual(getStackInSlot(2), recipe.getOutput1(), true, true) && getStackInSlot(3) == null) {
|
|
|
|
// //Stops if the first slot if full
|
|
|
|
// if (recipe.getOutput1() != null
|
|
|
|
// && getStackInSlot(2) != null
|
|
|
|
// && getStackInSlot(2).stackSize
|
|
|
|
// + recipe.getOutput1().stackSize > recipe
|
|
|
|
// .getOutput1().getMaxStackSize()) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// decrStackSize(2, recipe.getOutput1().stackSize);
|
|
|
|
// setInventorySlotContents(3, recipe.getOutput2());
|
|
|
|
// tickTime = 0;
|
|
|
|
// recipe = null;
|
|
|
|
// } else
|
|
|
|
// //When slot 2 has stuff and slot 1 is empty
|
|
|
|
// if (ItemUtils.isItemEqual(getStackInSlot(3), recipe.getInput2(), true, true) && getStackInSlot(2) == null) {
|
|
|
|
// if (recipe.getOutput2() != null
|
|
|
|
// && getStackInSlot(3) != null
|
|
|
|
// && getStackInSlot(3).stackSize
|
|
|
|
// + recipe.getOutput2().stackSize > recipe
|
|
|
|
// .getOutput1().getMaxStackSize()) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// decrStackSize(3, recipe.getOutput2().stackSize);
|
|
|
|
// setInventorySlotContents(2, recipe.getOutput1());
|
|
|
|
// tickTime = 0;
|
|
|
|
// recipe = null;
|
|
|
|
// }
|
|
|
|
// } else if (getHeat() >= recipe.getMinHeat()) {
|
|
|
|
// if (energy.canUseEnergy(5)) {
|
|
|
|
// tickTime++;
|
|
|
|
// energy.useEnergy(5);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// recipe = null;
|
|
|
|
// tickTime = 0;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public boolean areBothOutputsFull() {
|
|
|
|
// if (recipe.getOutput1() != null
|
|
|
|
// && getStackInSlot(2) != null
|
|
|
|
// && getStackInSlot(2).stackSize
|
|
|
|
// + recipe.getOutput1().stackSize > recipe
|
|
|
|
// .getOutput1().getMaxStackSize()) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// if (recipe.getOutput2() != null
|
|
|
|
// && getStackInSlot(3) != null
|
|
|
|
// && getStackInSlot(3).stackSize
|
|
|
|
// + recipe.getOutput2().stackSize > recipe
|
|
|
|
// .getOutput1().getMaxStackSize()) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
2015-04-28 22:04:28 +02:00
|
|
|
|
2015-04-28 19:23:48 +02:00
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public int getSizeInventory() {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public ItemStack getStackInSlot(int p_70301_1_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.getStackInSlot(p_70301_1_);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.decrStackSize(p_70298_1_, p_70298_2_);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.getStackInSlotOnClosing(p_70304_1_);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
inventory.setInventorySlotContents(p_70299_1_, p_70299_2_);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public String getInventoryName() {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.getInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public boolean hasCustomInventoryName() {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.hasCustomInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public int getInventoryStackLimit() {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.isUseableByPlayer(p_70300_1_);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void openInventory() {
|
2015-04-28 19:23:48 +02:00
|
|
|
inventory.openInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void closeInventory() {
|
2015-04-28 19:23:48 +02:00
|
|
|
inventory.closeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
2015-04-28 19:23:48 +02:00
|
|
|
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
|
|
|
|
}
|
|
|
|
|
2015-06-06 22:41:41 +02:00
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
energy.invalidate();
|
|
|
|
super.invalidate();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onChunkUnload()
|
|
|
|
{
|
|
|
|
energy.onChunkUnload();
|
|
|
|
super.onChunkUnload();
|
|
|
|
}
|
2015-04-28 19:23:48 +02:00
|
|
|
|
2015-04-28 22:04:28 +02:00
|
|
|
public Packet getDescriptionPacket() {
|
2015-04-28 19:23:48 +02:00
|
|
|
NBTTagCompound nbtTag = new NBTTagCompound();
|
|
|
|
writeToNBT(nbtTag);
|
|
|
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
|
|
|
|
this.zCoord, 1, nbtTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net,
|
2015-04-28 22:04:28 +02:00
|
|
|
S35PacketUpdateTileEntity packet) {
|
2015-04-28 19:23:48 +02:00
|
|
|
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
|
|
|
|
yCoord, zCoord);
|
|
|
|
readFromNBT(packet.func_148857_g());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
2015-04-28 19:23:48 +02:00
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
inventory.readFromNBT(tagCompound);
|
|
|
|
tickTime = tagCompound.getInteger("tickTime");
|
2015-05-08 19:42:12 +02:00
|
|
|
energy.readFromNBT(tagCompound);
|
2015-04-28 19:23:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-28 22:04:28 +02:00
|
|
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
2015-04-28 19:23:48 +02:00
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
2015-05-08 19:42:12 +02:00
|
|
|
energy.writeToNBT(tagCompound);
|
2015-04-28 19:23:48 +02:00
|
|
|
writeUpdateToNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:04:28 +02:00
|
|
|
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
|
2015-04-28 19:23:48 +02:00
|
|
|
tagCompound.setInteger("tickTime", tickTime);
|
|
|
|
}
|
2015-06-08 23:39:07 +02:00
|
|
|
|
|
|
|
// ISidedInventory
|
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side)
|
|
|
|
{
|
2015-06-09 00:11:48 +02:00
|
|
|
return side == ForgeDirection.DOWN.ordinal() ? new int[]{0, 1, 2, 3} : new int[]{0, 1, 2, 3};
|
2015-06-08 23:39:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side)
|
|
|
|
{
|
2015-06-09 00:11:48 +02:00
|
|
|
if (slotIndex >= 1)
|
|
|
|
return false;
|
2015-06-08 23:39:07 +02:00
|
|
|
return isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side)
|
|
|
|
{
|
|
|
|
return slotIndex == 2 || slotIndex == 3;
|
|
|
|
}
|
2015-04-28 19:23:48 +02:00
|
|
|
|
2015-07-20 16:19:23 +02:00
|
|
|
public int getProgressScaled(int scale) {
|
|
|
|
if(crafter.currentTickTime != 0) {
|
|
|
|
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getEnergyScaled(int scale) {
|
|
|
|
return (int)energy.getEnergyStored() * scale / energy.getCapacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-28 19:23:48 +02:00
|
|
|
|
2015-04-17 02:09:12 +02:00
|
|
|
}
|