Convert RollingMachine

This commit is contained in:
Ourten 2017-01-08 14:00:19 +01:00
parent 8a0a133e02
commit ad890079ec
8 changed files with 140 additions and 185 deletions

View file

@ -11,6 +11,7 @@ import reborncore.api.tile.IContainerLayout;
import reborncore.common.container.RebornContainer; import reborncore.common.container.RebornContainer;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import techreborn.api.RollingMachineRecipe;
import techreborn.api.recipe.machines.AlloySmelterRecipe; import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.client.container.*; import techreborn.client.container.*;
import techreborn.client.container.builder.ContainerBuilder; 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() .upgradeSlot(9, 152, 44).upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue()
.addInventory().create(); .addInventory().create();
} else if (ID == GuiHandler.rollingMachineID) { } 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) { } else if (ID == GuiHandler.blastFurnaceID) {
return new ContainerBlastFurnace((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)), player); return new ContainerBlastFurnace((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.alloySmelterID) { } else if (ID == GuiHandler.alloySmelterID) {

View file

@ -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;
}
}

View file

@ -5,9 +5,7 @@ import org.apache.commons.lang3.tuple.MutableTriple;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.*;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -16,6 +14,7 @@ import reborncore.common.util.ItemUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -30,6 +29,7 @@ public class BuiltContainer extends Container {
private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Short>> shortValues; private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Short>> shortValues;
private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Integer>> integerValues; private final ArrayList<MutableTriple<IntSupplier, IntConsumer, Integer>> integerValues;
private List<Consumer<InventoryCrafting>> craftEvents;
private Integer[] integerParts; private Integer[] integerParts;
public BuiltContainer(final String name, final Predicate<EntityPlayer> canInteract, public BuiltContainer(final String name, final Predicate<EntityPlayer> canInteract,
@ -61,6 +61,10 @@ public class BuiltContainer extends Container {
this.integerParts = new Integer[this.integerValues.size()]; this.integerParts = new Integer[this.integerValues.size()];
} }
public void addCraftEvents(final List<Consumer<InventoryCrafting>> craftEvents) {
this.craftEvents = craftEvents;
}
public void addSlot(final Slot slot) { public void addSlot(final Slot slot) {
this.addSlotToContainer(slot); this.addSlotToContainer(slot);
} }
@ -70,6 +74,16 @@ public class BuiltContainer extends Container {
return this.canInteract.test(playerIn); 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 @Override
public void detectAndSendChanges() { public void detectAndSendChanges() {
super.detectAndSendChanges(); super.detectAndSendChanges();

View file

@ -6,10 +6,12 @@ import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -17,6 +19,7 @@ import java.util.function.Predicate;
public class ContainerBuilder { public class ContainerBuilder {
private final String name; private final String name;
private Predicate<EntityPlayer> canInteract = player -> true; private Predicate<EntityPlayer> canInteract = player -> true;
final List<Slot> slots; final List<Slot> slots;
@ -25,6 +28,8 @@ public class ContainerBuilder {
final List<Pair<IntSupplier, IntConsumer>> shortValues; final List<Pair<IntSupplier, IntConsumer>> shortValues;
final List<Pair<IntSupplier, IntConsumer>> integerValues; final List<Pair<IntSupplier, IntConsumer>> integerValues;
final List<Consumer<InventoryCrafting>> craftEvents;
public ContainerBuilder(final String name) { public ContainerBuilder(final String name) {
this.name = name; this.name = name;
@ -35,6 +40,8 @@ public class ContainerBuilder {
this.shortValues = new ArrayList<>(); this.shortValues = new ArrayList<>();
this.integerValues = new ArrayList<>(); this.integerValues = new ArrayList<>();
this.craftEvents = new ArrayList<>();
} }
public ContainerBuilder interact(final Predicate<EntityPlayer> canInteract) { public ContainerBuilder interact(final Predicate<EntityPlayer> canInteract) {
@ -59,12 +66,15 @@ public class ContainerBuilder {
} }
public BuiltContainer create() { 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); this.tileInventoryRanges);
if (!this.shortValues.isEmpty()) if (!this.shortValues.isEmpty())
built.addShortSync(this.shortValues); built.addShortSync(this.shortValues);
if (!this.integerValues.isEmpty()) if (!this.integerValues.isEmpty())
built.addIntegerSync(this.integerValues); built.addIntegerSync(this.integerValues);
if (!this.craftEvents.isEmpty())
built.addCraftEvents(this.craftEvents);
this.slots.forEach(built::addSlot); this.slots.forEach(built::addSlot);

View file

@ -4,6 +4,7 @@ import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.SlotFurnaceFuel; import net.minecraft.inventory.SlotFurnaceFuel;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -21,6 +22,7 @@ import techreborn.Core;
import techreborn.client.container.builder.slot.FilteredSlot; import techreborn.client.container.builder.slot.FilteredSlot;
import techreborn.utils.upgrade.IMachineUpgrade; import techreborn.utils.upgrade.IMachineUpgrade;
import java.util.function.Consumer;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -133,6 +135,11 @@ public class ContainerTileInventoryBuilder {
return this; return this;
} }
public ContainerTileInventoryBuilder onCraft(final Consumer<InventoryCrafting> onCraft) {
this.parent.craftEvents.add(onCraft);
return this;
}
public ContainerBuilder addInventory() { public ContainerBuilder addInventory() {
this.parent.tileInventoryRanges.add(Range.between(this.rangeStart, this.parent.slots.size() - 1)); this.parent.tileInventoryRanges.add(Range.between(this.rangeStart, this.parent.slots.size() - 1));
return this.parent; return this.parent;

View file

@ -6,33 +6,40 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n; 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; import techreborn.tiles.TileRollingMachine;
public class GuiRollingMachine extends GuiContainer { public class GuiRollingMachine extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn", public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/rolling_machine.png"); "textures/gui/rolling_machine.png");
TileRollingMachine rollingMachine; TileRollingMachine rollingMachine;
ContainerRollingMachine containerRollingMachine;
public GuiRollingMachine(EntityPlayer player, TileRollingMachine tileRollingmachine) { public GuiRollingMachine(final EntityPlayer player, final TileRollingMachine tileRollingmachine) {
super(new ContainerRollingMachine(tileRollingmachine, player)); 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.xSize = 176;
this.ySize = 167; this.ySize = 167;
rollingMachine = tileRollingmachine; this.rollingMachine = tileRollingmachine;
containerRollingMachine = (ContainerRollingMachine) this.inventorySlots;
} }
@Override @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); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture); this.mc.getTextureManager().bindTexture(GuiRollingMachine.texture);
int k = (this.width - this.xSize) / 2; final int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2; final int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); 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); this.drawTexturedModalRect(k + 91, l + 34, 176, 14, j + 1, 19);
j = this.rollingMachine.getEnergyScaled(12); 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_) { @Override
String name = I18n.translateToLocal("tile.techreborn.rollingmachine.name"); 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, 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.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752); this.ySize - 96 + 2, 4210752);
} }
@Override @Override
public void initGui() { public void initGui() {
this.buttonList.clear(); this.buttonList.clear();
int k = (this.width - this.xSize) / 2; final int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2; final int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R")); this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R"));
super.initGui(); super.initGui();
} }

View file

@ -284,11 +284,10 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
recipeTransferRegistry.addRecipeTransferHandler(ContainerIndustrialElectrolyzer.class, recipeTransferRegistry.addRecipeTransferHandler(ContainerIndustrialElectrolyzer.class,
RecipeCategoryUids.INDUSTRIAL_ELECTROLYZER, 0, 2, 7, 36); RecipeCategoryUids.INDUSTRIAL_ELECTROLYZER, 0, 2, 7, 36);
recipeTransferRegistry recipeTransferRegistry
.addRecipeTransferHandler(ContainerRollingMachine.class, RecipeCategoryUids.ROLLING_MACHINE, 0, 9, 11,
36);
recipeTransferRegistry
.addRecipeTransferHandler(ContainerVacuumFreezer.class, RecipeCategoryUids.VACUUM_FREEZER, 0, 1, 2, 36); .addRecipeTransferHandler(ContainerVacuumFreezer.class, RecipeCategoryUids.VACUUM_FREEZER, 0, 1, 2, 36);
recipeTransferRegistry.addRecipeTransferHandler(
new BuiltContainerTransferInfo("rollingmachine", RecipeCategoryUids.ROLLING_MACHINE, 36, 9, 0, 36));
recipeTransferRegistry.addRecipeTransferHandler( recipeTransferRegistry.addRecipeTransferHandler(
new BuiltContainerTransferInfo("alloyfurnace", RecipeCategoryUids.ALLOY_SMELTER, 36, 2, 0, 36)); new BuiltContainerTransferInfo("alloyfurnace", RecipeCategoryUids.ALLOY_SMELTER, 36, 2, 0, 36));
recipeTransferRegistry.addRecipeTransferHandler( recipeTransferRegistry.addRecipeTransferHandler(

View file

@ -6,12 +6,14 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier; import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider; import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable; import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import techreborn.api.RollingMachineRecipe; import techreborn.api.RollingMachineRecipe;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
@ -37,12 +39,12 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
} }
@Override @Override
public boolean canAcceptEnergy(EnumFacing direction) { public boolean canAcceptEnergy(final EnumFacing direction) {
return true; return true;
} }
@Override @Override
public boolean canProvideEnergy(EnumFacing direction) { public boolean canProvideEnergy(final EnumFacing direction) {
return false; return false;
} }
@ -64,72 +66,72 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
charge(2); this.charge(2);
if (!world.isRemote) { if (!this.world.isRemote) {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (currentRecipe != null && canMake()) { if (this.currentRecipe != null && this.canMake()) {
if (tickTime >= runTime) { if (this.tickTime >= this.runTime) {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (currentRecipe != null) { if (this.currentRecipe != null) {
boolean hasCrafted = false; boolean hasCrafted = false;
if (inventory.getStackInSlot(0) == ItemStack.EMPTY) { if (this.inventory.getStackInSlot(0) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(0, currentRecipe); this.inventory.setInventorySlotContents(0, this.currentRecipe);
tickTime = -1; this.tickTime = -1;
hasCrafted = true; hasCrafted = true;
} else { } else {
if (inventory.getStackInSlot(0).getCount() + currentRecipe.getCount() <= currentRecipe if (this.inventory.getStackInSlot(0).getCount() + this.currentRecipe.getCount() <= this.currentRecipe
.getMaxStackSize()) { .getMaxStackSize()) {
ItemStack stack = inventory.getStackInSlot(0); final ItemStack stack = this.inventory.getStackInSlot(0);
stack.setCount(stack.getCount() + currentRecipe.getCount()); stack.setCount(stack.getCount() + this.currentRecipe.getCount());
inventory.setInventorySlotContents(0, stack); this.inventory.setInventorySlotContents(0, stack);
tickTime = -1; this.tickTime = -1;
hasCrafted = true; hasCrafted = true;
} }
} }
if (hasCrafted) { if (hasCrafted) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) {
craftMatrix.decrStackSize(i, 1); this.craftMatrix.decrStackSize(i, 1);
} }
currentRecipe = null; this.currentRecipe = null;
} }
} }
} }
} }
if (currentRecipe != null) { if (this.currentRecipe != null) {
if (canUseEnergy(euTick) && tickTime < runTime) { if (this.canUseEnergy(this.euTick) && this.tickTime < this.runTime) {
useEnergy(euTick); this.useEnergy(this.euTick);
tickTime++; this.tickTime++;
} }
} }
if (currentRecipe == null) { if (this.currentRecipe == null) {
tickTime = -1; this.tickTime = -1;
} }
} else { } else {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world); this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (currentRecipe != null) { if (this.currentRecipe != null) {
inventory.setInventorySlotContents(1, currentRecipe); this.inventory.setInventorySlotContents(1, this.currentRecipe);
} else { } else {
inventory.setInventorySlotContents(1, ItemStack.EMPTY); this.inventory.setInventorySlotContents(1, ItemStack.EMPTY);
} }
} }
} }
public boolean canMake() { public boolean canMake() {
return RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world) != null; return RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world) != null;
} }
@Override @Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false; return false;
} }
@Override @Override
public EnumFacing getFacing() { public EnumFacing getFacing() {
return getFacingEnum(); return this.getFacingEnum();
} }
@Override @Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) { public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking(); return entityPlayer.isSneaking();
} }
@ -139,29 +141,29 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
} }
@Override @Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ROLLING_MACHINE, 1); return new ItemStack(ModBlocks.ROLLING_MACHINE, 1);
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) { public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound); ItemUtils.readInvFromNBT(this.craftMatrix, "Crafting", tagCompound);
isRunning = tagCompound.getBoolean("isRunning"); this.isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime"); this.tickTime = tagCompound.getInteger("tickTime");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound); ItemUtils.writeInvToNBT(this.craftMatrix, "Crafting", tagCompound);
writeUpdateToNBT(tagCompound); this.writeUpdateToNBT(tagCompound);
return tagCompound; return tagCompound;
} }
public void writeUpdateToNBT(NBTTagCompound tagCompound) { public void writeUpdateToNBT(final NBTTagCompound tagCompound) {
tagCompound.setBoolean("isRunning", isRunning); tagCompound.setBoolean("isRunning", this.isRunning);
tagCompound.setInteger("tickTime", tickTime); tagCompound.setInteger("tickTime", this.tickTime);
} }
@Override @Override
@ -176,15 +178,30 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return this.inventory;
} }
private static class RollingTileContainer extends Container { private static class RollingTileContainer extends Container {
@Override @Override
public boolean canInteractWith(EntityPlayer entityplayer) { public boolean canInteractWith(final EntityPlayer entityplayer) {
return true; 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;
}
} }