Revert "Add a config to lock the rolling machine recipe + some optimisations #1412"

This reverts commit 0b8f139
This commit is contained in:
modmuss50 2018-02-11 14:01:24 +00:00
parent 38933ca8a8
commit 3fe260b739
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
2 changed files with 17 additions and 43 deletions

View file

@ -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<ResourceLocation, IRecipe> getRecipeList() {
return recipes;
}

View file

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