From 3fe260b7397863427400c618826efdbfa9efb503 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 11 Feb 2018 14:01:24 +0000 Subject: [PATCH] Revert "Add a config to lock the rolling machine recipe + some optimisations #1412" This reverts commit 0b8f139 --- .../techreborn/api/RollingMachineRecipe.java | 10 ---- .../techreborn/tiles/TileRollingMachine.java | 50 +++++++------------ 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/main/java/techreborn/api/RollingMachineRecipe.java b/src/main/java/techreborn/api/RollingMachineRecipe.java index b5d2d141e..a7ca9ec7f 100644 --- a/src/main/java/techreborn/api/RollingMachineRecipe.java +++ b/src/main/java/techreborn/api/RollingMachineRecipe.java @@ -145,16 +145,6 @@ public class RollingMachineRecipe { return ItemStack.EMPTY; } - public IRecipe findMatchingRecipeObj(InventoryCrafting inv, World world) { - for (IRecipe irecipe : recipes.values()) { - if (irecipe.matches(inv, world)) { - return irecipe; - } - } - - return null; - } - public HashMap getRecipeList() { return recipes; } diff --git a/src/main/java/techreborn/tiles/TileRollingMachine.java b/src/main/java/techreborn/tiles/TileRollingMachine.java index cef7fe649..9305c4f27 100644 --- a/src/main/java/techreborn/tiles/TileRollingMachine.java +++ b/src/main/java/techreborn/tiles/TileRollingMachine.java @@ -28,7 +28,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import reborncore.api.IToolDrop; @@ -45,7 +44,7 @@ import techreborn.client.container.builder.ContainerBuilder; import techreborn.init.ModBlocks; import techreborn.lib.ModInfo; -import javax.annotation.Nullable; +import javax.annotation.Nonnull; //TODO add tick and power bars. @@ -68,15 +67,10 @@ public class TileRollingMachine extends TilePowerAcceptor public Inventory inventory = new Inventory(3, "TileRollingMachine", 64, this); public boolean isRunning; public int tickTime; - @Nullable - public IRecipe currentRecipe; + @Nonnull + public ItemStack currentRecipe; private int outputSlot; - //TODO make this per machine and set in the gui. - //Set this to true to lock the recipe - @ConfigRegistry(config = "machines", category = "rolling_machine", key = "lockRecipe", comment = "This locks 1 of each ingredient in the crafting matrix, this may allow for some automation.") - public static boolean lockRecipe = false; - public TileRollingMachine() { super(); outputSlot = 0; @@ -112,20 +106,21 @@ public class TileRollingMachine extends TilePowerAcceptor super.update(); this.charge(2); if (!this.world.isRemote) { - this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipeObj(this.craftMatrix, this.world); - if (!this.currentRecipe.getRecipeOutput().isEmpty() && this.canMake()) { + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (!this.currentRecipe.isEmpty() && this.canMake()) { if (this.tickTime >= TileRollingMachine.runTime) { - if (!this.currentRecipe.getRecipeOutput().isEmpty()) { + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (!this.currentRecipe.isEmpty()) { boolean hasCrafted = false; if (this.inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) { - this.inventory.setInventorySlotContents(outputSlot, this.currentRecipe.getRecipeOutput()); + this.inventory.setInventorySlotContents(outputSlot, this.currentRecipe); this.tickTime = 0; hasCrafted = true; } else { - if (this.inventory.getStackInSlot(outputSlot).getCount() + this.currentRecipe.getRecipeOutput().getCount() <= this.currentRecipe.getRecipeOutput() + if (this.inventory.getStackInSlot(outputSlot).getCount() + this.currentRecipe.getCount() <= this.currentRecipe .getMaxStackSize()) { final ItemStack stack = this.inventory.getStackInSlot(outputSlot); - stack.setCount(stack.getCount() + this.currentRecipe.getRecipeOutput().getCount()); + stack.setCount(stack.getCount() + this.currentRecipe.getCount()); this.inventory.setInventorySlotContents(outputSlot, stack); this.tickTime = 0; hasCrafted = true; @@ -135,24 +130,24 @@ public class TileRollingMachine extends TilePowerAcceptor for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { this.craftMatrix.decrStackSize(i, 1); } - this.currentRecipe = null; + this.currentRecipe = ItemStack.EMPTY; } } } } - if (this.currentRecipe != null) { + if (!this.currentRecipe.isEmpty()) { if (this.canUseEnergy(energyPerTick) && this.tickTime < TileRollingMachine.runTime && canMake()) { this.useEnergy(energyPerTick); this.tickTime++; } } - if (this.currentRecipe == null) { + if (this.currentRecipe.isEmpty()) { this.tickTime = 0; } } else { - this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipeObj(this.craftMatrix, this.world); - if (this.currentRecipe == null) { - this.inventory.setInventorySlotContents(1, this.currentRecipe.getRecipeOutput()); + this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); + if (!this.currentRecipe.isEmpty()) { + this.inventory.setInventorySlotContents(1, this.currentRecipe); } else { this.inventory.setInventorySlotContents(1, ItemStack.EMPTY); } @@ -160,20 +155,10 @@ public class TileRollingMachine extends TilePowerAcceptor } public boolean canMake() { - ItemStack stack = currentRecipe.getRecipeOutput(); + ItemStack stack = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world); if(stack.isEmpty()){ return false; } - if(lockRecipe){ - for (int i = 0; i < 9; i++) { - ItemStack ingredient = craftMatrix.getStackInSlot(i); - if(!ingredient.isEmpty()) { - if(ingredient.getCount() == 1){ - return false; - } - } - } - } ItemStack output = getStackInSlot(outputSlot); if(output.isEmpty()){ return true; @@ -256,5 +241,4 @@ public class TileRollingMachine extends TilePowerAcceptor } } - }