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

222 lines
6.3 KiB
Java
Raw Normal View History

package techreborn.tiles.multiblock;
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;
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;
2016-10-08 21:46:16 +02:00
import reborncore.common.IWrenchable;
2015-11-08 13:15:45 +01:00
import reborncore.common.misc.Location;
import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
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;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
2015-08-10 15:32:01 +02:00
import techreborn.multiblocks.MultiBlockCasing;
import techreborn.tiles.TileMachineCasing;
2016-10-08 21:46:16 +02:00
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;
2016-10-08 21:46:16 +02:00
public TileBlastFurnace() {
super(ConfigTechReborn.CentrifugeTier);
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
2016-10-08 21:46:16 +02:00
public void updateEntity() {
super.updateEntity();
2016-03-25 10:47:34 +01:00
crafter.updateEntity();
}
@Override
2016-10-08 21:46:16 +02:00
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public EnumFacing getFacing() {
2016-03-25 10:47:34 +01:00
return getFacingEnum();
}
@Override
2016-10-08 21:46:16 +02:00
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public float getWrenchDropRate() {
2016-03-25 10:47:34 +01:00
return 1.0F;
}
@Override
2016-10-08 21:46:16 +02:00
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
2016-03-25 10:47:34 +01:00
return new ItemStack(ModBlocks.BlastFurnace, 1);
}
2016-10-08 21:46:16 +02:00
public int getHeat() {
for (EnumFacing direction : EnumFacing.values()) {
2016-11-19 13:50:08 +01:00
TileEntity tileEntity = world.getTileEntity(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
2016-10-08 21:46:16 +02:00
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()));
if (tileEntity instanceof TileMachineCasing) {
2016-03-25 10:47:34 +01:00
if (((TileMachineCasing) tileEntity).isConnected()
2016-10-08 21:46:16 +02:00
&& ((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;
2016-11-19 13:50:08 +01:00
if (world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
2016-10-08 21:46:16 +02:00
.getBlock() == tileEntity.getBlockType()) {
2016-03-25 10:47:34 +01:00
return 0;
}
2016-10-08 21:46:16 +02:00
for (IMultiblockPart part : casing.connectedParts) {
2016-11-19 13:50:08 +01:00
BlockMachineCasing casing1 = (BlockMachineCasing) world.getBlockState(part.getPos())
2016-10-08 21:46:16 +02:00
.getBlock();
2016-03-25 10:47:34 +01:00
heat += casing1
2016-10-08 21:46:16 +02:00
.getHeatFromState(part.getWorld().getBlockState(part.getWorldLocation().toBlockPos()));
2016-03-25 10:47:34 +01:00
// TODO meta fix
}
2016-11-19 13:50:08 +01:00
if (world.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
2016-10-08 21:46:16 +02:00
.getBlock().getUnlocalizedName().equals("tile.lava")
2016-11-19 13:50:08 +01:00
&& world
2016-10-08 21:46:16 +02:00
.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
2016-10-08 21:46:16 +02:00
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
2016-11-19 13:50:08 +01:00
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
2016-10-08 21:46:16 +02:00
getPos().getY(), getPos().getZ());
2016-03-25 10:47:34 +01:00
readFromNBT(packet.getNbtCompound());
}
@Override
2016-10-08 21:46:16 +02:00
public void readFromNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
tickTime = tagCompound.getInteger("tickTime");
}
@Override
2016-10-08 21:46:16 +02:00
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
}
2016-10-08 21:46:16 +02:00
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
tagCompound.setInteger("tickTime", tickTime);
}
// ISidedInventory
@Override
2016-10-08 21:46:16 +02:00
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
if (slotIndex >= 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
return slotIndex == 2 || slotIndex == 3;
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
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
2016-10-08 21:46:16 +02:00
public double getMaxPower() {
return 10000;
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canAcceptEnergy(EnumFacing direction) {
return true;
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canProvideEnergy(EnumFacing direction) {
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxOutput() {
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxInput() {
return 128;
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
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;
}
}