From 683249da92ebaa31d1ee0df058bb0d8a425cb01f Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Wed, 23 Dec 2015 14:31:04 +0100 Subject: [PATCH] make solderer save state, tweak duration for recipes and add sided inv --- .../java/storagecraft/gui/GuiSolderer.java | 2 +- .../java/storagecraft/tile/TileSolderer.java | 55 ++++++++++++++++++- .../tile/solderer/SoldererRecipeDrive.java | 2 +- .../SoldererRecipePrintedProcessor.java | 14 ++++- .../solderer/SoldererRecipeProcessor.java | 12 +++- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/main/java/storagecraft/gui/GuiSolderer.java b/src/main/java/storagecraft/gui/GuiSolderer.java index ebeadf82b..b384b87b0 100644 --- a/src/main/java/storagecraft/gui/GuiSolderer.java +++ b/src/main/java/storagecraft/gui/GuiSolderer.java @@ -35,7 +35,7 @@ public class GuiSolderer extends GuiBase if (solderer.isWorking()) { - drawTexturedModalRect(x + 83, y + 40 - 1, 177, 0, solderer.getProgressScaled(21), 14); + drawTexturedModalRect(x + 83, y + 40 - 1, 177, 0, solderer.getProgressScaled(22), 15); } } diff --git a/src/main/java/storagecraft/tile/TileSolderer.java b/src/main/java/storagecraft/tile/TileSolderer.java index fd5d27992..8bc392632 100644 --- a/src/main/java/storagecraft/tile/TileSolderer.java +++ b/src/main/java/storagecraft/tile/TileSolderer.java @@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import storagecraft.inventory.InventorySimple; @@ -12,9 +13,11 @@ import storagecraft.tile.solderer.ISoldererRecipe; import storagecraft.tile.solderer.SoldererRegistry; import storagecraft.util.InventoryUtils; -// @TODO: Write working and progress to NBT -public class TileSolderer extends TileMachine implements IInventory +public class TileSolderer extends TileMachine implements IInventory, ISidedInventory { + public static final String NBT_WORKING = "Working"; + public static final String NBT_PROGRESS = "Progress"; + private InventorySimple inventory = new InventorySimple("solderer", 4); private ISoldererRecipe recipe; private boolean working = false; @@ -151,12 +154,57 @@ public class TileSolderer extends TileMachine implements IInventory return inventory.isItemValidForSlot(slot, stack); } + @Override + public int[] getAccessibleSlotsFromSide(int side) + { + // On all sides, but not the bottom we can reach the slots + if (side > 0) + { + return new int[] + { + 0, 1, 2 + }; + } + + // On the bottom we can only reach the output slot + return new int[] + { + 3 + }; + } + + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side) + { + // We can insert in all slots, but not the output slot or via the output side + return side != 0 && slot != 3; + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) + { + // We can only extract from the buttom in the last slot + return side == 0 && slot == 3; + } + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); InventoryUtils.restoreInventory(this, nbt); + + recipe = SoldererRegistry.getRecipe(inventory); + + if (nbt.hasKey(NBT_WORKING)) + { + working = nbt.getBoolean(NBT_WORKING); + } + + if (nbt.hasKey(NBT_PROGRESS)) + { + progress = nbt.getInteger(NBT_PROGRESS); + } } @Override @@ -165,6 +213,9 @@ public class TileSolderer extends TileMachine implements IInventory super.writeToNBT(nbt); InventoryUtils.saveInventory(this, nbt); + + nbt.setBoolean(NBT_WORKING, working); + nbt.setInteger(NBT_PROGRESS, progress); } @Override diff --git a/src/main/java/storagecraft/tile/solderer/SoldererRecipeDrive.java b/src/main/java/storagecraft/tile/solderer/SoldererRecipeDrive.java index a06a7d7f6..648681eae 100644 --- a/src/main/java/storagecraft/tile/solderer/SoldererRecipeDrive.java +++ b/src/main/java/storagecraft/tile/solderer/SoldererRecipeDrive.java @@ -36,6 +36,6 @@ public class SoldererRecipeDrive implements ISoldererRecipe @Override public int getDuration() { - return 400; + return 500; } } diff --git a/src/main/java/storagecraft/tile/solderer/SoldererRecipePrintedProcessor.java b/src/main/java/storagecraft/tile/solderer/SoldererRecipePrintedProcessor.java index 2b6da32c9..3f6f7a18f 100644 --- a/src/main/java/storagecraft/tile/solderer/SoldererRecipePrintedProcessor.java +++ b/src/main/java/storagecraft/tile/solderer/SoldererRecipePrintedProcessor.java @@ -44,6 +44,18 @@ public class SoldererRecipePrintedProcessor implements ISoldererRecipe @Override public int getDuration() { - return 100; + switch (type) + { + case ItemProcessor.TYPE_PRINTED_BASIC: + return 100; + case ItemProcessor.TYPE_PRINTED_IMPROVED: + return 150; + case ItemProcessor.TYPE_PRINTED_ADVANCED: + return 200; + case ItemProcessor.TYPE_PRINTED_SILICON: + return 90; + } + + return 0; } } diff --git a/src/main/java/storagecraft/tile/solderer/SoldererRecipeProcessor.java b/src/main/java/storagecraft/tile/solderer/SoldererRecipeProcessor.java index f3542dd6f..d36a42dcf 100644 --- a/src/main/java/storagecraft/tile/solderer/SoldererRecipeProcessor.java +++ b/src/main/java/storagecraft/tile/solderer/SoldererRecipeProcessor.java @@ -50,6 +50,16 @@ public class SoldererRecipeProcessor implements ISoldererRecipe @Override public int getDuration() { - return 200; + switch (type) + { + case ItemProcessor.TYPE_BASIC: + return 250; + case ItemProcessor.TYPE_IMPROVED: + return 300; + case ItemProcessor.TYPE_ADVANCED: + return 350; + } + + return 0; } }