Revert "Add a config to lock the rolling machine recipe + some optimisations #1412"
This reverts commit 0b8f139
This commit is contained in:
parent
38933ca8a8
commit
3fe260b739
2 changed files with 17 additions and 43 deletions
|
@ -145,16 +145,6 @@ public class RollingMachineRecipe {
|
||||||
return ItemStack.EMPTY;
|
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() {
|
public HashMap<ResourceLocation, IRecipe> getRecipeList() {
|
||||||
return recipes;
|
return recipes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import reborncore.api.IToolDrop;
|
import reborncore.api.IToolDrop;
|
||||||
|
@ -45,7 +44,7 @@ import techreborn.client.container.builder.ContainerBuilder;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
//TODO add tick and power bars.
|
//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 Inventory inventory = new Inventory(3, "TileRollingMachine", 64, this);
|
||||||
public boolean isRunning;
|
public boolean isRunning;
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
@Nullable
|
@Nonnull
|
||||||
public IRecipe currentRecipe;
|
public ItemStack currentRecipe;
|
||||||
private int outputSlot;
|
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() {
|
public TileRollingMachine() {
|
||||||
super();
|
super();
|
||||||
outputSlot = 0;
|
outputSlot = 0;
|
||||||
|
@ -112,20 +106,21 @@ public class TileRollingMachine extends TilePowerAcceptor
|
||||||
super.update();
|
super.update();
|
||||||
this.charge(2);
|
this.charge(2);
|
||||||
if (!this.world.isRemote) {
|
if (!this.world.isRemote) {
|
||||||
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipeObj(this.craftMatrix, this.world);
|
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
|
||||||
if (!this.currentRecipe.getRecipeOutput().isEmpty() && this.canMake()) {
|
if (!this.currentRecipe.isEmpty() && this.canMake()) {
|
||||||
if (this.tickTime >= TileRollingMachine.runTime) {
|
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;
|
boolean hasCrafted = false;
|
||||||
if (this.inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) {
|
if (this.inventory.getStackInSlot(outputSlot) == ItemStack.EMPTY) {
|
||||||
this.inventory.setInventorySlotContents(outputSlot, this.currentRecipe.getRecipeOutput());
|
this.inventory.setInventorySlotContents(outputSlot, this.currentRecipe);
|
||||||
this.tickTime = 0;
|
this.tickTime = 0;
|
||||||
hasCrafted = true;
|
hasCrafted = true;
|
||||||
} else {
|
} 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()) {
|
.getMaxStackSize()) {
|
||||||
final ItemStack stack = this.inventory.getStackInSlot(outputSlot);
|
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.inventory.setInventorySlotContents(outputSlot, stack);
|
||||||
this.tickTime = 0;
|
this.tickTime = 0;
|
||||||
hasCrafted = true;
|
hasCrafted = true;
|
||||||
|
@ -135,24 +130,24 @@ public class TileRollingMachine extends TilePowerAcceptor
|
||||||
for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) {
|
for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) {
|
||||||
this.craftMatrix.decrStackSize(i, 1);
|
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()) {
|
if (this.canUseEnergy(energyPerTick) && this.tickTime < TileRollingMachine.runTime && canMake()) {
|
||||||
this.useEnergy(energyPerTick);
|
this.useEnergy(energyPerTick);
|
||||||
this.tickTime++;
|
this.tickTime++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.currentRecipe == null) {
|
if (this.currentRecipe.isEmpty()) {
|
||||||
this.tickTime = 0;
|
this.tickTime = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipeObj(this.craftMatrix, this.world);
|
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
|
||||||
if (this.currentRecipe == null) {
|
if (!this.currentRecipe.isEmpty()) {
|
||||||
this.inventory.setInventorySlotContents(1, this.currentRecipe.getRecipeOutput());
|
this.inventory.setInventorySlotContents(1, this.currentRecipe);
|
||||||
} else {
|
} else {
|
||||||
this.inventory.setInventorySlotContents(1, ItemStack.EMPTY);
|
this.inventory.setInventorySlotContents(1, ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
|
@ -160,20 +155,10 @@ public class TileRollingMachine extends TilePowerAcceptor
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canMake() {
|
public boolean canMake() {
|
||||||
ItemStack stack = currentRecipe.getRecipeOutput();
|
ItemStack stack = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
|
||||||
if(stack.isEmpty()){
|
if(stack.isEmpty()){
|
||||||
return false;
|
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);
|
ItemStack output = getStackInSlot(outputSlot);
|
||||||
if(output.isEmpty()){
|
if(output.isEmpty()){
|
||||||
return true;
|
return true;
|
||||||
|
@ -256,5 +241,4 @@ public class TileRollingMachine extends TilePowerAcceptor
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue