TechReborn/src/main/java/techreborn/tiles/TileBlastFurnace.java

201 lines
6 KiB
Java
Raw Normal View History

package techreborn.tiles;
2016-05-12 20:16:40 +02:00
import reborncore.common.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
2015-06-08 23:39:07 +02:00
import net.minecraft.inventory.ISidedInventory;
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;
2016-03-13 17:08:30 +01:00
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
2015-04-26 17:22:26 +02:00
import net.minecraft.tileentity.TileEntity;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing;
2016-03-15 09:13:05 +01:00
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
2015-11-08 13:15:45 +01:00
import reborncore.common.misc.Location;
import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.tile.TilePowerAcceptor;
2015-11-08 13:15:45 +01:00
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
2016-04-03 15:25:46 +02:00
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.BlastFurnaceRecipe;
2015-04-26 17:22:26 +02:00
import techreborn.blocks.BlockMachineCasing;
2015-04-28 19:23:48 +02:00
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
2015-08-10 15:32:01 +02:00
import techreborn.multiblocks.MultiBlockCasing;
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,IInventoryProvider, ISidedInventory, ITileRecipeHandler<BlastFurnaceRecipe>, IRecipeCrafterProvider {
2016-03-25 10:47:34 +01:00
public static int euTick = 5;
public int tickTime;
public Inventory inventory = new Inventory(4, "TileBlastFurnace", 64, this);
public RecipeCrafter crafter;
public int capacity = 1000;
public TileBlastFurnace() {
2016-03-25 10:47:34 +01:00
// TODO configs
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(Reference.blastFurnaceRecipe, this, 2, 2, inventory, inputs, outputs);
}
@Override
public void update() {
super.update();
2016-03-25 10:47:34 +01:00
crafter.updateEntity();
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
public EnumFacing getFacing() {
2016-03-25 10:47:34 +01:00
return getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
2016-03-25 10:47:34 +01:00
}
@Override
public float getWrenchDropRate() {
2016-03-25 10:47:34 +01:00
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
2016-03-25 10:47:34 +01:00
return new ItemStack(ModBlocks.BlastFurnace, 1);
}
public int getHeat() {
for (EnumFacing direction : EnumFacing.values()) {
2016-03-25 10:47:34 +01:00
TileEntity tileEntity = worldObj.getTileEntity(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()));
if (tileEntity instanceof TileMachineCasing) {
2016-03-25 10:47:34 +01:00
if (((TileMachineCasing) tileEntity).isConnected()
&& ((TileMachineCasing) tileEntity).getMultiblockController().isAssembled()) {
2016-03-25 10:47:34 +01:00
MultiBlockCasing casing = ((TileMachineCasing) tileEntity).getMultiblockController();
Location location = new Location(getPos().getX(), getPos().getY(), getPos().getZ(), direction);
location.modifyPositionFromSide(direction, 1);
int heat = 0;
if (worldObj.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
.getBlock() == tileEntity.getBlockType()) {
2016-03-25 10:47:34 +01:00
return 0;
}
for (IMultiblockPart part : casing.connectedParts) {
2016-03-25 10:47:34 +01:00
BlockMachineCasing casing1 = (BlockMachineCasing) worldObj.getBlockState(part.getPos())
.getBlock();
heat += casing1
.getHeatFromState(part.getWorld().getBlockState(part.getWorldLocation().toBlockPos()));
// TODO meta fix
}
if (worldObj.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")
&& worldObj
.getBlockState(new BlockPos(location.getX(), location.getY() + 1, location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")) {
2016-03-25 10:47:34 +01:00
heat += 500;
}
return heat;
}
}
}
return 0;
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
2016-03-25 10:47:34 +01:00
worldObj.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
getPos().getY(), getPos().getZ());
readFromNBT(packet.getNbtCompound());
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
tickTime = tagCompound.getInteger("tickTime");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.writeToNBT(tagCompound);
writeUpdateToNBT(tagCompound);
2016-05-18 17:53:54 +02:00
return tagCompound;
2016-03-25 10:47:34 +01:00
}
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
tagCompound.setInteger("tickTime", tickTime);
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[]{0, 1, 2, 3} : new int[]{0, 1, 2, 3};
2016-03-25 10:47:34 +01:00
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
2016-03-25 10:47:34 +01:00
if (slotIndex >= 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return slotIndex == 2 || slotIndex == 3;
}
public int getProgressScaled(int scale) {
if (crafter.currentTickTime != 0) {
2016-03-25 10:47:34 +01:00
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
}
return 0;
}
@Override
public double getMaxPower() {
return 512000;
2016-03-25 10:47:34 +01:00
}
@Override
public EnumPowerTier getTier() {
2016-03-25 10:47:34 +01:00
return EnumPowerTier.HIGH;
}
2016-04-03 15:25:46 +02:00
@Override
public boolean canCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
if (tile instanceof TileBlastFurnace) {
TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
return blastFurnace.getHeat() >= recipe.neededHeat;
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
return true;
}
@Override
public Inventory getInventory() {
return inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
}
}