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

245 lines
7.4 KiB
Java
Raw Normal View History

package techreborn.tiles.multiblock;
import net.minecraft.entity.player.EntityPlayer;
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;
2017-01-08 15:45:05 +01:00
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;
2017-01-08 15:45:05 +01:00
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.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
2015-08-10 15:32:01 +02:00
import techreborn.multiblocks.MultiBlockCasing;
import techreborn.tiles.TileMachineCasing;
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider,
ITileRecipeHandler<BlastFurnaceRecipe>, IRecipeCrafterProvider, IContainerProvider {
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;
2017-01-08 15:45:05 +01:00
private int cachedHeat;
2016-10-08 21:46:16 +02:00
public TileBlastFurnace() {
super(ConfigTechReborn.CentrifugeTier);
2016-03-25 10:47:34 +01:00
// TODO configs
2017-01-08 15:45:05 +01:00
final int[] inputs = new int[2];
2016-03-25 10:47:34 +01:00
inputs[0] = 0;
inputs[1] = 1;
2017-01-08 15:45:05 +01:00
final int[] outputs = new int[2];
2016-03-25 10:47:34 +01:00
outputs[0] = 2;
outputs[1] = 3;
2017-01-08 15:45:05 +01:00
this.crafter = new RecipeCrafter(Reference.blastFurnaceRecipe, this, 2, 2, this.inventory, inputs, outputs);
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void updateEntity() {
super.updateEntity();
2017-01-08 15:45:05 +01:00
this.crafter.updateEntity();
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 15:45:05 +01:00
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public EnumFacing getFacing() {
2017-01-08 15:45:05 +01:00
return this.getFacingEnum();
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 15:45:05 +01:00
public boolean wrenchCanRemove(final 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
2017-01-08 15:45:05 +01:00
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_BLAST_FURNACE, 1);
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
public int getHeat() {
2017-01-08 15:45:05 +01:00
for (final EnumFacing direction : EnumFacing.values()) {
final TileEntity tileEntity = this.world.getTileEntity(new BlockPos(this.getPos().getX() + direction.getFrontOffsetX(),
this.getPos().getY() + direction.getFrontOffsetY(), this.getPos().getZ() + direction.getFrontOffsetZ()));
2016-10-08 21:46:16 +02:00
if (tileEntity instanceof TileMachineCasing) {
2016-03-25 10:47:34 +01:00
if (((TileMachineCasing) tileEntity).isConnected()
2017-01-08 15:45:05 +01:00
&& ((TileMachineCasing) tileEntity).getMultiblockController().isAssembled()) {
final MultiBlockCasing casing = ((TileMachineCasing) tileEntity).getMultiblockController();
final Location location = new Location(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), direction);
2016-03-25 10:47:34 +01:00
location.modifyPositionFromSide(direction, 1);
int heat = 0;
2017-01-08 15:45:05 +01:00
if (this.world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
.getBlock() == tileEntity.getBlockType()) {
2016-03-25 10:47:34 +01:00
return 0;
}
2017-01-08 15:45:05 +01:00
for (final IMultiblockPart part : casing.connectedParts) {
final BlockMachineCasing casing1 = (BlockMachineCasing) this.world.getBlockState(part.getPos())
.getBlock();
2016-03-25 10:47:34 +01:00
heat += casing1
2017-01-08 15:45:05 +01:00
.getHeatFromState(part.getWorld().getBlockState(part.getWorldLocation().toBlockPos()));
2016-03-25 10:47:34 +01:00
// TODO meta fix
}
2017-01-08 15:45:05 +01:00
if (this.world.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")
&& this.world
.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
2017-01-08 15:45:05 +01:00
public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) {
this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX(),
this.getPos().getY(), this.getPos().getZ());
this.readFromNBT(packet.getNbtCompound());
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 15:45:05 +01:00
public void readFromNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
2017-01-08 15:45:05 +01:00
this.tickTime = tagCompound.getInteger("tickTime");
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 15:45:05 +01:00
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.writeToNBT(tagCompound);
2017-01-08 15:45:05 +01:00
this.writeUpdateToNBT(tagCompound);
2016-05-18 17:53:54 +02:00
return tagCompound;
2016-03-25 10:47:34 +01:00
}
2017-01-08 15:45:05 +01:00
public void writeUpdateToNBT(final NBTTagCompound tagCompound) {
tagCompound.setInteger("tickTime", this.tickTime);
2016-03-25 10:47:34 +01:00
}
// ISidedInventory
@Override
2017-01-08 15:45:05 +01:00
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
}
@Override
2017-01-08 15:45:05 +01:00
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex >= 2)
return false;
2017-01-08 15:45:05 +01:00
return this.isItemValidForSlot(slotIndex, itemStack);
}
@Override
2017-01-08 15:45:05 +01:00
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex == 2 || slotIndex == 3;
}
2016-03-25 10:47:34 +01:00
2017-01-08 15:45:05 +01:00
public int getProgressScaled(final int scale) {
if (this.crafter.currentTickTime != 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
2016-03-25 10:47:34 +01:00
}
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxPower() {
return 10000;
}
@Override
2017-01-08 15:45:05 +01:00
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
2017-01-08 15:45:05 +01:00
public boolean canProvideEnergy(final 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
2017-01-08 15:45:05 +01:00
public boolean canCraft(final TileEntity tile, final BlastFurnaceRecipe recipe) {
2016-04-03 15:25:46 +02:00
if (tile instanceof TileBlastFurnace) {
2017-01-08 15:45:05 +01:00
final TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
2016-04-03 15:25:46 +02:00
return blastFurnace.getHeat() >= recipe.neededHeat;
}
return false;
}
@Override
2017-01-08 15:45:05 +01:00
public boolean onCraft(final TileEntity tile, final BlastFurnaceRecipe recipe) {
2016-04-03 15:25:46 +02:00
return true;
}
@Override
public Inventory getInventory() {
2017-01-08 15:45:05 +01:00
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
2017-01-08 15:45:05 +01:00
return this.crafter;
}
public void setHeat(final int heat) {
this.cachedHeat = heat;
}
public int getCachedHeat() {
return this.cachedHeat;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("blastfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 40, 25).slot(1, 40, 43).outputSlot(2, 100, 35).outputSlot(3, 118, 35)
.syncEnergyValue().syncCrafterValue().syncIntegerValue(this::getHeat, this::setHeat).addInventory()
.create();
}
}