From ad890079ec37a64d40d232098494c00a868e9ec7 Mon Sep 17 00:00:00 2001 From: Ourten Date: Sun, 8 Jan 2017 14:00:19 +0100 Subject: [PATCH] Convert RollingMachine --- .../java/techreborn/client/GuiHandler.java | 13 +- .../container/ContainerRollingMachine.java | 111 ----------------- .../container/builder/BuiltContainer.java | 20 +++- .../container/builder/ContainerBuilder.java | 12 +- .../ContainerTileInventoryBuilder.java | 7 ++ .../client/gui/GuiRollingMachine.java | 44 ++++--- .../compat/jei/TechRebornJeiPlugin.java | 5 +- .../techreborn/tiles/TileRollingMachine.java | 113 ++++++++++-------- 8 files changed, 140 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/techreborn/client/container/ContainerRollingMachine.java diff --git a/src/main/java/techreborn/client/GuiHandler.java b/src/main/java/techreborn/client/GuiHandler.java index 1dc637443..869323f49 100644 --- a/src/main/java/techreborn/client/GuiHandler.java +++ b/src/main/java/techreborn/client/GuiHandler.java @@ -11,6 +11,7 @@ import reborncore.api.tile.IContainerLayout; import reborncore.common.container.RebornContainer; import reborncore.common.util.ItemUtils; +import techreborn.api.RollingMachineRecipe; import techreborn.api.recipe.machines.AlloySmelterRecipe; import techreborn.client.container.*; import techreborn.client.container.builder.ContainerBuilder; @@ -93,7 +94,17 @@ public class GuiHandler implements IGuiHandler { .upgradeSlot(9, 152, 44).upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue() .addInventory().create(); } else if (ID == GuiHandler.rollingMachineID) { - return new ContainerRollingMachine((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z)), player); + return new ContainerBuilder("rollingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142) + .addInventory().tile(((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z))).craftMatrix) + .slot(0, 30, 17).slot(1, 48, 17).slot(2, 66, 17).slot(3, 30, 35).slot(4, 48, 35).slot(5, 66, 35) + .slot(6, 30, 53).slot(7, 48, 53).slot(8, 66, 53) + .onCraft(inv -> ((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z))).inventory + .setInventorySlotContents(1, RollingMachineRecipe.instance.findMatchingRecipe(inv, world))) + .addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).outputSlot(0, 124, 35) + .energySlot(2, 8, 51).syncEnergyValue() + .syncIntegerValue(((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z)))::getBurnTime, + ((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z)))::setBurnTime) + .addInventory().create(); } else if (ID == GuiHandler.blastFurnaceID) { return new ContainerBlastFurnace((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)), player); } else if (ID == GuiHandler.alloySmelterID) { diff --git a/src/main/java/techreborn/client/container/ContainerRollingMachine.java b/src/main/java/techreborn/client/container/ContainerRollingMachine.java deleted file mode 100644 index 4162bb33e..000000000 --- a/src/main/java/techreborn/client/container/ContainerRollingMachine.java +++ /dev/null @@ -1,111 +0,0 @@ -package techreborn.client.container; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import reborncore.client.gui.slots.BaseSlot; -import reborncore.client.gui.slots.SlotOutput; -import reborncore.common.container.RebornContainer; -import techreborn.api.RollingMachineRecipe; -import techreborn.tiles.TileRollingMachine; - -public class ContainerRollingMachine extends RebornContainer { - - EntityPlayer player; - TileRollingMachine tile; - int currentItemBurnTime; - int burnTime; - int energy; - - public ContainerRollingMachine(TileRollingMachine tileRollingmachine, EntityPlayer player) { - tile = tileRollingmachine; - this.player = player; - - for (int l = 0; l < 3; l++) { - for (int k1 = 0; k1 < 3; k1++) { - this.addSlotToContainer( - new BaseSlot(tileRollingmachine.craftMatrix, k1 + l * 3, 30 + k1 * 18, 17 + l * 18)); - } - } - - // output - this.addSlotToContainer(new SlotOutput(tileRollingmachine.inventory, 0, 124, 35)); - // battery - this.addSlotToContainer(new BaseSlot(tileRollingmachine.inventory, 2, 8, 51)); - - int i; - - for (i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (i = 0; i < 9; ++i) { - this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142)); - } - } - - @Override - public boolean canInteractWith(EntityPlayer player) { - return true; - } - - @Override - public final void onCraftMatrixChanged(IInventory inv) { - ItemStack output = RollingMachineRecipe.instance.findMatchingRecipe(tile.craftMatrix, tile.getWorld()); - tile.inventory.setInventorySlotContents(1, output); - } - - @Override - public void addListener(IContainerListener crafting) { - super.addListener(crafting); - crafting.sendProgressBarUpdate(this, 0, tile.runTime); - crafting.sendProgressBarUpdate(this, 1, tile.tickTime); - crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy()); - } - - @Override - public void detectAndSendChanges() { - for (int i = 0; i < this.listeners.size(); i++) { - IContainerListener crafting = this.listeners.get(i); - if (this.currentItemBurnTime != tile.runTime) { - crafting.sendProgressBarUpdate(this, 0, tile.runTime); - } - if (this.burnTime != tile.tickTime || tile.tickTime == -1) { - crafting.sendProgressBarUpdate(this, 1, tile.tickTime); - } - if (this.energy != (int) tile.getEnergy()) { - crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy()); - } - } - super.detectAndSendChanges(); - } - - @Override - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - if (id == 0) { - this.currentItemBurnTime = value; - } else if (id == 1) { - this.burnTime = value; - } else if (id == 2) { - this.energy = value; - } - this.tile.runTime = this.currentItemBurnTime; - if (this.burnTime == -1) { - this.burnTime = 0; - } - this.tile.tickTime = this.burnTime; - this.tile.setEnergy(this.energy); - } - - public int getBurnTimeRemainingScaled(int scale) { - if (burnTime == 0 || this.currentItemBurnTime == 0) { - return 0; - } - return this.burnTime * scale / this.currentItemBurnTime; - } - -} diff --git a/src/main/java/techreborn/client/container/builder/BuiltContainer.java b/src/main/java/techreborn/client/container/builder/BuiltContainer.java index 3650c35ce..98ca202cb 100644 --- a/src/main/java/techreborn/client/container/builder/BuiltContainer.java +++ b/src/main/java/techreborn/client/container/builder/BuiltContainer.java @@ -5,9 +5,7 @@ import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -16,6 +14,7 @@ import reborncore.common.util.ItemUtils; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.Predicate; @@ -30,6 +29,7 @@ public class BuiltContainer extends Container { private final ArrayList> shortValues; private final ArrayList> integerValues; + private List> craftEvents; private Integer[] integerParts; public BuiltContainer(final String name, final Predicate canInteract, @@ -61,6 +61,10 @@ public class BuiltContainer extends Container { this.integerParts = new Integer[this.integerValues.size()]; } + public void addCraftEvents(final List> craftEvents) { + this.craftEvents = craftEvents; + } + public void addSlot(final Slot slot) { this.addSlotToContainer(slot); } @@ -70,6 +74,16 @@ public class BuiltContainer extends Container { return this.canInteract.test(playerIn); } + @Override + public final void onCraftMatrixChanged(final IInventory inv) { + if (!this.craftEvents.isEmpty()) + this.craftEvents.forEach(consumer -> consumer.accept((InventoryCrafting) inv)); + // final ItemStack output = + // RollingMachineRecipe.instance.findMatchingRecipe(this.tile.craftMatrix, + // this.tile.getWorld()); + // this.tile.inventory.setInventorySlotContents(1, output); + } + @Override public void detectAndSendChanges() { super.detectAndSendChanges(); diff --git a/src/main/java/techreborn/client/container/builder/ContainerBuilder.java b/src/main/java/techreborn/client/container/builder/ContainerBuilder.java index 161faf451..56ac35700 100644 --- a/src/main/java/techreborn/client/container/builder/ContainerBuilder.java +++ b/src/main/java/techreborn/client/container/builder/ContainerBuilder.java @@ -6,10 +6,12 @@ import org.apache.commons.lang3.tuple.Pair; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.Predicate; @@ -17,6 +19,7 @@ import java.util.function.Predicate; public class ContainerBuilder { private final String name; + private Predicate canInteract = player -> true; final List slots; @@ -25,6 +28,8 @@ public class ContainerBuilder { final List> shortValues; final List> integerValues; + final List> craftEvents; + public ContainerBuilder(final String name) { this.name = name; @@ -35,6 +40,8 @@ public class ContainerBuilder { this.shortValues = new ArrayList<>(); this.integerValues = new ArrayList<>(); + + this.craftEvents = new ArrayList<>(); } public ContainerBuilder interact(final Predicate canInteract) { @@ -59,12 +66,15 @@ public class ContainerBuilder { } public BuiltContainer create() { - final BuiltContainer built = new BuiltContainer(this.name, this.canInteract, this.playerInventoryRanges, + final BuiltContainer built = new BuiltContainer(this.name, this.canInteract, + this.playerInventoryRanges, this.tileInventoryRanges); if (!this.shortValues.isEmpty()) built.addShortSync(this.shortValues); if (!this.integerValues.isEmpty()) built.addIntegerSync(this.integerValues); + if (!this.craftEvents.isEmpty()) + built.addCraftEvents(this.craftEvents); this.slots.forEach(built::addSlot); diff --git a/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java b/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java index 15c976ba2..ba5e89f8e 100644 --- a/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java +++ b/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.Range; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.SlotFurnaceFuel; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; @@ -21,6 +22,7 @@ import techreborn.Core; import techreborn.client.container.builder.slot.FilteredSlot; import techreborn.utils.upgrade.IMachineUpgrade; +import java.util.function.Consumer; import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.Predicate; @@ -133,6 +135,11 @@ public class ContainerTileInventoryBuilder { return this; } + public ContainerTileInventoryBuilder onCraft(final Consumer onCraft) { + this.parent.craftEvents.add(onCraft); + return this; + } + public ContainerBuilder addInventory() { this.parent.tileInventoryRanges.add(Range.between(this.rangeStart, this.parent.slots.size() - 1)); return this.parent; diff --git a/src/main/java/techreborn/client/gui/GuiRollingMachine.java b/src/main/java/techreborn/client/gui/GuiRollingMachine.java index 318448c0a..4c27b7707 100644 --- a/src/main/java/techreborn/client/gui/GuiRollingMachine.java +++ b/src/main/java/techreborn/client/gui/GuiRollingMachine.java @@ -6,33 +6,40 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.translation.I18n; -import techreborn.client.container.ContainerRollingMachine; + +import techreborn.api.RollingMachineRecipe; +import techreborn.client.container.builder.ContainerBuilder; import techreborn.tiles.TileRollingMachine; public class GuiRollingMachine extends GuiContainer { public static final ResourceLocation texture = new ResourceLocation("techreborn", - "textures/gui/rolling_machine.png"); + "textures/gui/rolling_machine.png"); TileRollingMachine rollingMachine; - ContainerRollingMachine containerRollingMachine; - public GuiRollingMachine(EntityPlayer player, TileRollingMachine tileRollingmachine) { - super(new ContainerRollingMachine(tileRollingmachine, player)); + public GuiRollingMachine(final EntityPlayer player, final TileRollingMachine tileRollingmachine) { + super(new ContainerBuilder("rollingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142) + .addInventory().tile(tileRollingmachine.craftMatrix).slot(0, 30, 17).slot(1, 48, 17).slot(2, 66, 17) + .slot(3, 30, 35).slot(4, 48, 35).slot(5, 66, 35).slot(6, 30, 53).slot(7, 48, 53).slot(8, 66, 53) + .onCraft(inv -> tileRollingmachine.inventory.setInventorySlotContents(1, + RollingMachineRecipe.instance.findMatchingRecipe(inv, tileRollingmachine.getWorld()))) + .addInventory().tile(tileRollingmachine).outputSlot(0, 124, 35).energySlot(2, 8, 51).syncEnergyValue() + .syncIntegerValue(tileRollingmachine::getBurnTime, tileRollingmachine::setBurnTime).addInventory() + .create()); this.xSize = 176; this.ySize = 167; - rollingMachine = tileRollingmachine; - containerRollingMachine = (ContainerRollingMachine) this.inventorySlots; + this.rollingMachine = tileRollingmachine; } @Override - protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(texture); - int k = (this.width - this.xSize) / 2; - int l = (this.height - this.ySize) / 2; + this.mc.getTextureManager().bindTexture(GuiRollingMachine.texture); + final int k = (this.width - this.xSize) / 2; + final int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); - int j = this.containerRollingMachine.getBurnTimeRemainingScaled(24); + int j = this.rollingMachine.getBurnTimeRemainingScaled(24); this.drawTexturedModalRect(k + 91, l + 34, 176, 14, j + 1, 19); j = this.rollingMachine.getEnergyScaled(12); @@ -41,19 +48,20 @@ public class GuiRollingMachine extends GuiContainer { } } - protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { - String name = I18n.translateToLocal("tile.techreborn.rollingmachine.name"); + @Override + protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) { + final String name = I18n.translateToLocal("tile.techreborn.rollingmachine.name"); this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, - 4210752); + 4210752); this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8, - this.ySize - 96 + 2, 4210752); + this.ySize - 96 + 2, 4210752); } @Override public void initGui() { this.buttonList.clear(); - int k = (this.width - this.xSize) / 2; - int l = (this.height - this.ySize) / 2; + final int k = (this.width - this.xSize) / 2; + final int l = (this.height - this.ySize) / 2; this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R")); super.initGui(); } diff --git a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java index 0b7470baf..1d6b3aa5d 100644 --- a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java +++ b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java @@ -284,11 +284,10 @@ public class TechRebornJeiPlugin extends BlankModPlugin { recipeTransferRegistry.addRecipeTransferHandler(ContainerIndustrialElectrolyzer.class, RecipeCategoryUids.INDUSTRIAL_ELECTROLYZER, 0, 2, 7, 36); recipeTransferRegistry - .addRecipeTransferHandler(ContainerRollingMachine.class, RecipeCategoryUids.ROLLING_MACHINE, 0, 9, 11, - 36); - recipeTransferRegistry .addRecipeTransferHandler(ContainerVacuumFreezer.class, RecipeCategoryUids.VACUUM_FREEZER, 0, 1, 2, 36); + recipeTransferRegistry.addRecipeTransferHandler( + new BuiltContainerTransferInfo("rollingmachine", RecipeCategoryUids.ROLLING_MACHINE, 36, 9, 0, 36)); recipeTransferRegistry.addRecipeTransferHandler( new BuiltContainerTransferInfo("alloyfurnace", RecipeCategoryUids.ALLOY_SMELTER, 36, 2, 0, 36)); recipeTransferRegistry.addRecipeTransferHandler( diff --git a/src/main/java/techreborn/tiles/TileRollingMachine.java b/src/main/java/techreborn/tiles/TileRollingMachine.java index 8f14838d4..cb2ef6570 100644 --- a/src/main/java/techreborn/tiles/TileRollingMachine.java +++ b/src/main/java/techreborn/tiles/TileRollingMachine.java @@ -6,12 +6,14 @@ import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; + import reborncore.api.power.EnumPowerTier; import reborncore.api.tile.IInventoryProvider; import reborncore.common.IWrenchable; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.util.Inventory; import reborncore.common.util.ItemUtils; + import techreborn.api.RollingMachineRecipe; import techreborn.init.ModBlocks; @@ -37,12 +39,12 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable } @Override - public boolean canAcceptEnergy(EnumFacing direction) { + public boolean canAcceptEnergy(final EnumFacing direction) { return true; } @Override - public boolean canProvideEnergy(EnumFacing direction) { + public boolean canProvideEnergy(final EnumFacing direction) { return false; } @@ -64,72 +66,72 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable @Override public void updateEntity() { super.updateEntity(); - charge(2); - if (!world.isRemote) { - currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); - if (currentRecipe != null && canMake()) { - if (tickTime >= runTime) { - currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); - if (currentRecipe != null) { + this.charge(2); + if (!this.world.isRemote) { + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (this.currentRecipe != null && this.canMake()) { + if (this.tickTime >= this.runTime) { + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (this.currentRecipe != null) { boolean hasCrafted = false; - if (inventory.getStackInSlot(0) == ItemStack.EMPTY) { - inventory.setInventorySlotContents(0, currentRecipe); - tickTime = -1; + if (this.inventory.getStackInSlot(0) == ItemStack.EMPTY) { + this.inventory.setInventorySlotContents(0, this.currentRecipe); + this.tickTime = -1; hasCrafted = true; } else { - if (inventory.getStackInSlot(0).getCount() + currentRecipe.getCount() <= currentRecipe - .getMaxStackSize()) { - ItemStack stack = inventory.getStackInSlot(0); - stack.setCount(stack.getCount() + currentRecipe.getCount()); - inventory.setInventorySlotContents(0, stack); - tickTime = -1; + if (this.inventory.getStackInSlot(0).getCount() + this.currentRecipe.getCount() <= this.currentRecipe + .getMaxStackSize()) { + final ItemStack stack = this.inventory.getStackInSlot(0); + stack.setCount(stack.getCount() + this.currentRecipe.getCount()); + this.inventory.setInventorySlotContents(0, stack); + this.tickTime = -1; hasCrafted = true; } } if (hasCrafted) { - for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { - craftMatrix.decrStackSize(i, 1); + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + this.craftMatrix.decrStackSize(i, 1); } - currentRecipe = null; + this.currentRecipe = null; } } } } - if (currentRecipe != null) { - if (canUseEnergy(euTick) && tickTime < runTime) { - useEnergy(euTick); - tickTime++; + if (this.currentRecipe != null) { + if (this.canUseEnergy(this.euTick) && this.tickTime < this.runTime) { + this.useEnergy(this.euTick); + this.tickTime++; } } - if (currentRecipe == null) { - tickTime = -1; + if (this.currentRecipe == null) { + this.tickTime = -1; } } else { - currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); - if (currentRecipe != null) { - inventory.setInventorySlotContents(1, currentRecipe); + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (this.currentRecipe != null) { + this.inventory.setInventorySlotContents(1, this.currentRecipe); } else { - inventory.setInventorySlotContents(1, ItemStack.EMPTY); + this.inventory.setInventorySlotContents(1, ItemStack.EMPTY); } } } public boolean canMake() { - return RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world) != null; + return RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world) != null; } @Override - public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { + public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) { return false; } @Override public EnumFacing getFacing() { - return getFacingEnum(); + return this.getFacingEnum(); } @Override - public boolean wrenchCanRemove(EntityPlayer entityPlayer) { + public boolean wrenchCanRemove(final EntityPlayer entityPlayer) { return entityPlayer.isSneaking(); } @@ -139,29 +141,29 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable } @Override - public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { + public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) { return new ItemStack(ModBlocks.ROLLING_MACHINE, 1); } @Override - public void readFromNBT(NBTTagCompound tagCompound) { + public void readFromNBT(final NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound); - isRunning = tagCompound.getBoolean("isRunning"); - tickTime = tagCompound.getInteger("tickTime"); + ItemUtils.readInvFromNBT(this.craftMatrix, "Crafting", tagCompound); + this.isRunning = tagCompound.getBoolean("isRunning"); + this.tickTime = tagCompound.getInteger("tickTime"); } @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { + public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound); - writeUpdateToNBT(tagCompound); + ItemUtils.writeInvToNBT(this.craftMatrix, "Crafting", tagCompound); + this.writeUpdateToNBT(tagCompound); return tagCompound; } - public void writeUpdateToNBT(NBTTagCompound tagCompound) { - tagCompound.setBoolean("isRunning", isRunning); - tagCompound.setInteger("tickTime", tickTime); + public void writeUpdateToNBT(final NBTTagCompound tagCompound) { + tagCompound.setBoolean("isRunning", this.isRunning); + tagCompound.setInteger("tickTime", this.tickTime); } @Override @@ -176,15 +178,30 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable @Override public Inventory getInventory() { - return inventory; + return this.inventory; } private static class RollingTileContainer extends Container { @Override - public boolean canInteractWith(EntityPlayer entityplayer) { + public boolean canInteractWith(final EntityPlayer entityplayer) { return true; } } + + public int getBurnTime() { + return this.tickTime; + } + + public void setBurnTime(final int burnTime) { + this.tickTime = burnTime; + } + + public int getBurnTimeRemainingScaled(final int scale) { + if (this.tickTime == 0 || this.runTime == 0) { + return 0; + } + return this.tickTime * scale / this.runTime; + } }