Misc recipe system fixes
- A bit of refactoring - Fixed critical issues with recipe matching - Restored recipe cache system
This commit is contained in:
parent
cf88b71d62
commit
07d21771da
18 changed files with 326 additions and 394 deletions
|
@ -82,14 +82,14 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
|
|||
|
||||
public int getFuelValue(ItemStack aStack) {
|
||||
if (GT_Utility.isStackInvalid(aStack)) return 0;
|
||||
Recipe tFuel = Recipe.findEqualRecipe(true, false, recipeMap, aStack);
|
||||
Recipe tFuel = Recipe.findEqualRecipe(true, recipeMap, aStack);
|
||||
if (tFuel != null) return (int)((tFuel.mStartEU * 1000L * efficiency) / 100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ItemStack getEmptyContainer(ItemStack aStack) {
|
||||
if (GT_Utility.isStackInvalid(aStack)) return null;
|
||||
Recipe tFuel = Recipe.findEqualRecipe(true, false, recipeMap, aStack);
|
||||
Recipe tFuel = Recipe.findEqualRecipe(true, recipeMap, aStack);
|
||||
if (tFuel != null) return GT_Utility.copy(tFuel.getOutputs()[0]);
|
||||
return GT_Utility.getContainerItem(aStack);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import gregtechmod.api.recipe.RecipeLogic;
|
|||
import gregtechmod.api.util.GT_OreDictUnificator;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
import gregtechmod.api.util.InfoBuilder;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -131,12 +132,21 @@ public abstract class GT_MetaTileEntity_BasicMachine extends MetaTileEntity impl
|
|||
|
||||
@Override
|
||||
public boolean spaceForOutput(Recipe recipe) {
|
||||
ItemStack aOutput1 = recipe.getOutputs()[0], aOutput2 = recipe.getOutputs().length > 1 ? recipe.getOutputs()[1] : null;
|
||||
if (mInventory[3] == null || aOutput1 == null || (mInventory[3].stackSize + aOutput1.stackSize <= mInventory[3].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[3], aOutput1)))
|
||||
if (mInventory[4] == null || aOutput2 == null || (mInventory[4].stackSize + aOutput2.stackSize <= mInventory[4].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[4], aOutput2)))
|
||||
return true;
|
||||
ItemStack[] output = recipe.getOutputs();
|
||||
int[] mOutput = getOutputSlots();
|
||||
|
||||
if (output.length <= mOutput.length) {
|
||||
for (ItemStack recOut : output) {
|
||||
for (int i : mOutput) {
|
||||
if (mInventory[i] != null && recOut != null && (!GT_Utility.areStacksEqual(mInventory[i], recOut) || mInventory[i].stackSize + recOut.stackSize > recOut.getMaxStackSize())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasTwoSeperateInputs() {
|
||||
return false;
|
||||
|
|
|
@ -3,6 +3,7 @@ package gregtechmod.api.metatileentity.implementations;
|
|||
import gregtechmod.api.enums.GT_Items;
|
||||
import gregtechmod.api.metatileentity.MetaTileEntity;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
|
@ -75,7 +76,12 @@ public abstract class GT_MetaTileEntity_BasicTank extends MetaTileEntity {
|
|||
|
||||
if (displaysItemStack()) {
|
||||
if (getDrainableStack() != null) {
|
||||
mInventory[getStackDisplaySlot()] = GT_Items.Display_Fluid.getWithDamage(displaysStackSize()?Math.max(1, Math.min(getDrainableStack().amount/1000, 64)):1, getDrainableStack().getFluidID());
|
||||
ItemStack fluidDisplay = GT_Items.Display_Fluid.getWithDamage(displaysStackSize()?Math.max(1, Math.min(getDrainableStack().amount/1000, 64)):1, getDrainableStack().getFluidID());;
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("amount", mFluid.amount);
|
||||
fluidDisplay.setTagCompound(data);
|
||||
mInventory[getStackDisplaySlot()] = fluidDisplay;
|
||||
|
||||
} else {
|
||||
if (GT_Items.Display_Fluid.isStackEqual(mInventory[getStackDisplaySlot()], true, true)) mInventory[getStackDisplaySlot()] = null;
|
||||
}
|
||||
|
|
|
@ -6,14 +6,22 @@ import gregtechmod.api.enums.Materials;
|
|||
import gregtechmod.api.interfaces.IGregTechTileEntity;
|
||||
import gregtechmod.api.util.GT_Log;
|
||||
import gregtechmod.api.util.GT_ModHandler;
|
||||
import gregtechmod.api.util.GT_OreDictUnificator;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
import gregtechmod.api.util.ItemStackKey;
|
||||
|
||||
import static gregtechmod.api.recipe.RecipeMaps.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -34,7 +42,7 @@ public class Recipe {
|
|||
public static volatile int VERSION = 408;
|
||||
|
||||
/** It is an IdentityHashMap, because it uses a List as Key, and since that List changes (and therefore the Result of the equals Method), the Key is not secure, while the Identity is. */
|
||||
private static final IdentityHashMap<List<Recipe>, HashMap<Integer, List<Recipe>>> sRecipeMappings = new IdentityHashMap<List<Recipe>, HashMap<Integer, List<Recipe>>>();
|
||||
private static final IdentityHashMap<List<Recipe>, Map<Integer, List<Recipe>>> RECIPE_MAPPINGS = new IdentityHashMap<>();
|
||||
|
||||
public static void reInit() {
|
||||
// GT_Log.log.info("GT_Mod: Re-Unificating Recipes.");
|
||||
|
@ -80,18 +88,60 @@ public class Recipe {
|
|||
public boolean match(ItemStack...machineInputs) {
|
||||
assert machineInputs != null : "Recipe check failed, machineInputs = null";
|
||||
assert machineInputs.length > 0 : "Recipe check failed, machineInputs size < 1";
|
||||
List<ItemStack> inputs = Arrays.stream(machineInputs)
|
||||
.filter(stack -> GT_Utility.isStackValid(stack))
|
||||
.collect(Collectors.toList());
|
||||
return match(null, inputs);
|
||||
}
|
||||
|
||||
if (machineInputs.length >= mInputs.length) {
|
||||
public boolean match(boolean decrease, IGregTechTileEntity tile, int[] inputSlots) {
|
||||
assert tile != null : "Recipe check failed, tile = null";
|
||||
assert inputSlots != null : "Recipe check failed, inputSlots = null";
|
||||
assert inputSlots.length > 0 : "Recipe check failed, inputSlots size < 1";
|
||||
|
||||
List<ItemStackKey> decreaseList = new ArrayList<>();
|
||||
Map<ItemStack, Integer> slotStacks = new HashMap<>();
|
||||
for (int i : inputSlots) {
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
if (stack != null) slotStacks.put(stack.copy(), i);
|
||||
}
|
||||
|
||||
|
||||
boolean success = this.match(key -> decreaseList.add(key), slotStacks.keySet());
|
||||
if (success && decrease) {
|
||||
Map<ItemStackKey, Integer> slotAligment = slotStacks.entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> ItemStackKey.from(e.getKey()), e -> e.getValue()));
|
||||
for (ItemStackKey item : decreaseList) {
|
||||
int slotIdx = slotAligment.get(item);
|
||||
tile.decrStackSize(slotIdx, item.getStackSize());
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matching recipe to following input, in case of successfully found item in recipe input map will execute actionPerfomer
|
||||
*/
|
||||
private boolean match(Consumer<ItemStackKey> actionPerfomer, Collection<ItemStack> inputs) {
|
||||
if (inputs.size() >= mInputs.length) {
|
||||
start:
|
||||
for (ItemStack input : Arrays.stream(machineInputs).filter(s -> GT_Utility.isStackValid(s)).collect(Collectors.toList())) {
|
||||
for (ItemStack[] slot : mInputs) {
|
||||
List<ItemStackKey> variants = Arrays.stream(slot)
|
||||
for (ItemStack input : inputs) {
|
||||
Iterator<ItemStack[]> recipeInputIter = new ArrayList<>(Arrays.asList(mInputs)).iterator(); // Creating instance of normal not connected
|
||||
while (recipeInputIter.hasNext()) { // array list to avoid damaging of recipe
|
||||
int idx = -1;
|
||||
List<ItemStackKey> variants = Arrays.stream(recipeInputIter.next())
|
||||
.map(s -> ItemStackKey.from(s))
|
||||
.collect(Collectors.toList());
|
||||
if (variants.contains(ItemStackKey.from(input))) {
|
||||
if ((idx = variants.indexOf(ItemStackKey.from(input))) >= 0) {
|
||||
if (variants.get(idx).get().stackSize <= input.stackSize) {
|
||||
if (actionPerfomer != null)
|
||||
actionPerfomer.accept(variants.get(idx));
|
||||
recipeInputIter.remove();
|
||||
continue start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -100,69 +150,30 @@ public class Recipe {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean match(boolean decrease, IGregTechTileEntity tile, int[] inputSlots) {
|
||||
assert tile != null : "Recipe check failed, tile = null";
|
||||
assert inputSlots != null : "Recipe check failed, inputSlots = null";
|
||||
assert inputSlots.length > 0 : "Recipe check failed, inputSlots size < 1";
|
||||
|
||||
Map<Integer, ItemStack> decreaseMap = new HashMap<>();
|
||||
Map<Integer, ItemStack> slotStacks = new HashMap<>();
|
||||
for (int i : inputSlots) {
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
if (stack != null)
|
||||
slotStacks.put(i, stack);
|
||||
}
|
||||
|
||||
for (ItemStack[] slot : mInputs) {
|
||||
Map<ItemStackKey, Integer> variants = Arrays.stream(slot)
|
||||
.collect(Collectors.toMap(stack -> ItemStackKey.from(stack), stack -> stack.stackSize));
|
||||
Iterator<Entry<Integer, ItemStack>> iter = slotStacks.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<Integer, ItemStack> value = iter.next();
|
||||
ItemStackKey temp = ItemStackKey.from(value.getValue());
|
||||
if ((variants.keySet().contains(temp))) {
|
||||
ItemStack recipeItem = temp.get();
|
||||
recipeItem.stackSize = variants.get(temp);
|
||||
ItemStack slotItem = value.getValue();
|
||||
if (recipeItem.stackSize <= slotItem.stackSize) {
|
||||
decreaseMap.put(value.getKey(), recipeItem);
|
||||
iter.remove();
|
||||
break;
|
||||
} else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (decrease && decreaseMap.size() == mInputs.length) for (Entry<Integer, ItemStack> e : decreaseMap.entrySet()) {
|
||||
tile.decrStackSize(e.getKey(), e.getValue().stackSize);
|
||||
}
|
||||
|
||||
return decreaseMap.size() == mInputs.length;
|
||||
}
|
||||
|
||||
private final void addToMap(HashMap<Integer, List<Recipe>> aMap) {
|
||||
private final void addToMap(Map<Integer, List<Recipe>> aMap) {
|
||||
for (ItemStack[] tStacks : mInputs) {
|
||||
for (ItemStack tStack : tStacks) if (tStack != null) {
|
||||
Integer tIntStack = GT_Utility.stackToInt(tStack);
|
||||
List<Recipe> tList = aMap.get(tIntStack);
|
||||
if (tList == null) aMap.put(tIntStack, tList = new ArrayList<Recipe>(2));
|
||||
if (tList == null) aMap.put(tIntStack, tList = new ArrayList<>(2));
|
||||
tList.add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void addToLists(List<Recipe> aList) {
|
||||
HashMap<Integer, List<Recipe>> aMap = sRecipeMappings.get(aList);
|
||||
if (aMap == null) sRecipeMappings.put(aList, aMap = new HashMap<Integer, List<Recipe>>());
|
||||
aList.add(this);
|
||||
addToMap(aMap);
|
||||
Map<Integer, List<Recipe>> aMap = RECIPE_MAPPINGS.get(aList);
|
||||
if (aMap == null) {
|
||||
RECIPE_MAPPINGS.put(aList, aMap = new HashMap<>());
|
||||
}
|
||||
|
||||
public static Recipe findEqualRecipe(boolean aShapeless, boolean aNotUnificated, List<Recipe> aList, ItemStack...aInputs) {
|
||||
addToMap(aMap);
|
||||
aList.add(this);
|
||||
}
|
||||
|
||||
public static Recipe findEqualRecipe(boolean aShapeless, List<Recipe> aList, ItemStack...aInputs) {
|
||||
if (aInputs.length < 1) return null;
|
||||
HashMap<Integer, List<Recipe>> tMap = sRecipeMappings.get(aList);
|
||||
if (aNotUnificated) GT_OreDictUnificator.setStackArray(true, aInputs);
|
||||
Map<Integer, List<Recipe>> tMap = RECIPE_MAPPINGS.get(aList);
|
||||
if (tMap == null) {
|
||||
for (Recipe tRecipe : aList) if (tRecipe.match(aInputs)) return tRecipe.mEnabled?tRecipe:null;
|
||||
} else {
|
||||
|
@ -176,6 +187,18 @@ public class Recipe {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Recipe findEqualRecipe(boolean shapeless, List<Recipe> recipeMap, IGregTechTileEntity tile, int[] inputSlots) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
for (int i : inputSlots) {
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
if (GT_Utility.isStackValid(stack)) {
|
||||
stacks.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return findEqualRecipe(shapeless, recipeMap, stacks.toArray(new ItemStack[0]));
|
||||
}
|
||||
|
||||
public void checkCellBalance() {
|
||||
if (!GregTech_API.SECONDARY_DEBUG_MODE || mInputs.length < 1) return;
|
||||
|
||||
|
@ -228,12 +251,6 @@ public class Recipe {
|
|||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
// NBTTagCompound tag = new NBTTagCompound();
|
||||
// tag.setInteger("duration", mDuration);
|
||||
// tag.setInteger("startEU", mStartEU);
|
||||
// tag.setInteger("EUt", mEUt);
|
||||
// tag.setInteger("duration", mDuration);
|
||||
// NBTTagCompound output
|
||||
data.setInteger("recipeHash", this.hashCode());
|
||||
}
|
||||
|
||||
|
@ -251,105 +268,99 @@ public class Recipe {
|
|||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aDuration, int aEUt, int aStartEU) {
|
||||
// aInput1 = GT_OreDictUnificator.get(true, aInput1);
|
||||
// aInput2 = GT_OreDictUnificator.get(true, aInput2);
|
||||
// aOutput1 = GT_OreDictUnificator.get(true, aOutput1);
|
||||
// aOutput2 = GT_OreDictUnificator.get(true, aOutput2);
|
||||
// aOutput3 = GT_OreDictUnificator.get(true, aOutput3);
|
||||
// aOutput4 = GT_OreDictUnificator.get(true, aOutput4);
|
||||
// /*
|
||||
// * Wtf gregorious, what the purpose of this?
|
||||
// */
|
||||
// if (aInput1 != null && aInput1.getItemDamage() != GregTech_API.ITEM_WILDCARD_DAMAGE) {
|
||||
// if (GT_Utility.areStacksEqual(aInput1, aOutput1)) {
|
||||
// if (aInput1.stackSize >= aOutput1.stackSize) {
|
||||
// aInput1.stackSize -= aOutput1.stackSize;
|
||||
// aOutput1 = null;
|
||||
// } else {
|
||||
// aOutput1.stackSize -= aInput1.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput1, aOutput2)) {
|
||||
// if (aInput1.stackSize >= aOutput2.stackSize) {
|
||||
// aInput1.stackSize -= aOutput2.stackSize;
|
||||
// aOutput2 = null;
|
||||
// } else {
|
||||
// aOutput2.stackSize -= aInput1.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput1, aOutput3)) {
|
||||
// if (aInput1.stackSize >= aOutput3.stackSize) {
|
||||
// aInput1.stackSize -= aOutput3.stackSize;
|
||||
// aOutput3 = null;
|
||||
// } else {
|
||||
// aOutput3.stackSize -= aInput1.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput1, aOutput4)) {
|
||||
// if (aInput1.stackSize >= aOutput4.stackSize) {
|
||||
// aInput1.stackSize -= aOutput4.stackSize;
|
||||
// aOutput4 = null;
|
||||
// } else {
|
||||
// aOutput4.stackSize -= aInput1.stackSize;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (aInput2 != null && aInput2.getItemDamage() != GregTech_API.ITEM_WILDCARD_DAMAGE) {
|
||||
// if (GT_Utility.areStacksEqual(aInput2, aOutput1)) {
|
||||
// assert aOutput1 != null;
|
||||
// if (aInput2.stackSize >= aOutput1.stackSize) {
|
||||
// aInput2.stackSize -= aOutput1.stackSize;
|
||||
// aOutput1 = null;
|
||||
// } else {
|
||||
// aOutput1.stackSize -= aInput2.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput2, aOutput2)) {
|
||||
// assert aOutput2 != null;
|
||||
// if (aInput2.stackSize >= aOutput2.stackSize) {
|
||||
// aInput2.stackSize -= aOutput2.stackSize;
|
||||
// aOutput2 = null;
|
||||
// } else {
|
||||
// aOutput2.stackSize -= aInput2.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput2, aOutput3)) {
|
||||
// assert aOutput3 != null;
|
||||
// if (aInput2.stackSize >= aOutput3.stackSize) {
|
||||
// aInput2.stackSize -= aOutput3.stackSize;
|
||||
// aOutput3 = null;
|
||||
// } else {
|
||||
// aOutput3.stackSize -= aInput2.stackSize;
|
||||
// }
|
||||
// }
|
||||
// if (GT_Utility.areStacksEqual(aInput2, aOutput4)) {
|
||||
// assert aOutput4 != null;
|
||||
// if (aInput2.stackSize >= aOutput4.stackSize) {
|
||||
// aInput2.stackSize -= aOutput4.stackSize;
|
||||
// aOutput4 = null;
|
||||
// } else {
|
||||
// aOutput4.stackSize -= aInput2.stackSize;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (byte i = 64; i > 1; i--) if (aDuration / i > 0) {
|
||||
// if (aInput1 == null || aInput1 .stackSize % i == 0)
|
||||
// if (aInput2 == null || aInput2 .stackSize % i == 0)
|
||||
// if (aOutput1 == null || aOutput1.stackSize % i == 0)
|
||||
// if (aOutput2 == null || aOutput2.stackSize % i == 0)
|
||||
// if (aOutput3 == null || aOutput3.stackSize % i == 0)
|
||||
// if (aOutput4 == null || aOutput4.stackSize % i == 0) {
|
||||
// if (aInput1 != null) aInput1 .stackSize /= i;
|
||||
// if (aInput2 != null) aInput2 .stackSize /= i;
|
||||
// if (aOutput1 != null) aOutput1.stackSize /= i;
|
||||
// if (aOutput2 != null) aOutput2.stackSize /= i;
|
||||
// if (aOutput3 != null) aOutput3.stackSize /= i;
|
||||
// if (aOutput4 != null) aOutput4.stackSize /= i;
|
||||
// aDuration /= i;
|
||||
// }
|
||||
// }
|
||||
/*
|
||||
* Wtf gregorious, what the purpose of this?
|
||||
*/
|
||||
if (aInput1 != null && aInput1.getItemDamage() != GregTech_API.ITEM_WILDCARD_DAMAGE) {
|
||||
if (GT_Utility.areStacksEqual(aInput1, aOutput1)) {
|
||||
if (aInput1.stackSize >= aOutput1.stackSize) {
|
||||
aInput1.stackSize -= aOutput1.stackSize;
|
||||
aOutput1 = null;
|
||||
} else {
|
||||
aOutput1.stackSize -= aInput1.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput1, aOutput2)) {
|
||||
if (aInput1.stackSize >= aOutput2.stackSize) {
|
||||
aInput1.stackSize -= aOutput2.stackSize;
|
||||
aOutput2 = null;
|
||||
} else {
|
||||
aOutput2.stackSize -= aInput1.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput1, aOutput3)) {
|
||||
if (aInput1.stackSize >= aOutput3.stackSize) {
|
||||
aInput1.stackSize -= aOutput3.stackSize;
|
||||
aOutput3 = null;
|
||||
} else {
|
||||
aOutput3.stackSize -= aInput1.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput1, aOutput4)) {
|
||||
if (aInput1.stackSize >= aOutput4.stackSize) {
|
||||
aInput1.stackSize -= aOutput4.stackSize;
|
||||
aOutput4 = null;
|
||||
} else {
|
||||
aOutput4.stackSize -= aInput1.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aInput2 != null && aInput2.getItemDamage() != GregTech_API.ITEM_WILDCARD_DAMAGE) {
|
||||
if (GT_Utility.areStacksEqual(aInput2, aOutput1)) {
|
||||
assert aOutput1 != null;
|
||||
if (aInput2.stackSize >= aOutput1.stackSize) {
|
||||
aInput2.stackSize -= aOutput1.stackSize;
|
||||
aOutput1 = null;
|
||||
} else {
|
||||
aOutput1.stackSize -= aInput2.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput2, aOutput2)) {
|
||||
assert aOutput2 != null;
|
||||
if (aInput2.stackSize >= aOutput2.stackSize) {
|
||||
aInput2.stackSize -= aOutput2.stackSize;
|
||||
aOutput2 = null;
|
||||
} else {
|
||||
aOutput2.stackSize -= aInput2.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput2, aOutput3)) {
|
||||
assert aOutput3 != null;
|
||||
if (aInput2.stackSize >= aOutput3.stackSize) {
|
||||
aInput2.stackSize -= aOutput3.stackSize;
|
||||
aOutput3 = null;
|
||||
} else {
|
||||
aOutput3.stackSize -= aInput2.stackSize;
|
||||
}
|
||||
}
|
||||
if (GT_Utility.areStacksEqual(aInput2, aOutput4)) {
|
||||
assert aOutput4 != null;
|
||||
if (aInput2.stackSize >= aOutput4.stackSize) {
|
||||
aInput2.stackSize -= aOutput4.stackSize;
|
||||
aOutput4 = null;
|
||||
} else {
|
||||
aOutput4.stackSize -= aInput2.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (byte i = 64; i > 1; i--) if (aDuration / i > 0) {
|
||||
if (aInput1 == null || aInput1 .stackSize % i == 0)
|
||||
if (aInput2 == null || aInput2 .stackSize % i == 0)
|
||||
if (aOutput1 == null || aOutput1.stackSize % i == 0)
|
||||
if (aOutput2 == null || aOutput2.stackSize % i == 0)
|
||||
if (aOutput3 == null || aOutput3.stackSize % i == 0)
|
||||
if (aOutput4 == null || aOutput4.stackSize % i == 0) {
|
||||
if (aInput1 != null) aInput1 .stackSize /= i;
|
||||
if (aInput2 != null) aInput2 .stackSize /= i;
|
||||
if (aOutput1 != null) aOutput1.stackSize /= i;
|
||||
if (aOutput2 != null) aOutput2.stackSize /= i;
|
||||
if (aOutput3 != null) aOutput3.stackSize /= i;
|
||||
if (aOutput4 != null) aOutput4.stackSize /= i;
|
||||
aDuration /= i;
|
||||
}
|
||||
}
|
||||
|
||||
if (aInput1 == null) {
|
||||
mInputs = new ItemStack [0][];
|
||||
|
@ -407,126 +418,126 @@ public class Recipe {
|
|||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, int aDuration, int aEUt, int aStartEU) {
|
||||
this(aInput1, aInput2, aOutput1, null, null, null, Math.max(aDuration, 1), aEUt, Math.max(Math.min(aStartEU, 160000000), 0));
|
||||
if (mInputs.length > 1 && findEqualRecipe(true, false, sFusionRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 1 && findEqualRecipe(true, sFusionRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sFusionRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aDuration) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, aOutput3, aOutput4, Math.max(aDuration, 1), 5, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sCentrifugeRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sCentrifugeRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sCentrifugeRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aDuration, int aEUt) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, aOutput3, aOutput4, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sElectrolyzerRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sElectrolyzerRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sElectrolyzerRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, int aDuration, int aEUt) {
|
||||
this(aInput1, null, aOutput1, aOutput2, null, null, aDuration, aEUt, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sLatheRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sLatheRecipes, aInput1) == null) {
|
||||
addToLists(sLatheRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aDuration, ItemStack aOutput1, int aEUt) {
|
||||
this(aInput1, null, aOutput1, null, null, null, aDuration, aEUt, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sCutterRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sCutterRecipes, aInput1) == null) {
|
||||
addToLists(sCutterRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, aOutput3, null, 200*aInput1.stackSize, 30, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sSawmillRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sSawmillRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sSawmillRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, aOutput3, aOutput4, 100*aInput1.stackSize, 120, 0);
|
||||
if (mInputs.length > 0 && aInput2 != null && mOutputs[0] != null && findEqualRecipe(false, false, sGrinderRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && aInput2 != null && mOutputs[0] != null && findEqualRecipe(false, sGrinderRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sGrinderRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aCellAmount, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aDuration, int aEUt) {
|
||||
this(aInput1, aCellAmount>0?GT_Items.Cell_Empty.get(Math.min(64, Math.max(1, aCellAmount))):null, aOutput1, aOutput2, aOutput3, aOutput4, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sDistillationRecipes, aInput1, aCellAmount>0?GT_Items.Cell_Empty.get(Math.min(64, Math.max(1, aCellAmount))):null) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sDistillationRecipes, aInput1, aCellAmount>0?GT_Items.Cell_Empty.get(Math.min(64, Math.max(1, aCellAmount))):null) == null) {
|
||||
addToLists(sDistillationRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, int aDuration, int aEUt, int aLevel) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), aLevel > 0 ? aLevel : 100);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sBlastRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sBlastRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sBlastRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aInput2, ItemStack aOutput1, ItemStack aOutput2) {
|
||||
this(aInput1, GT_ModHandler.getIC2Item("industrialTnt", aInput2>0?aInput2<64?aInput2:64:1, new ItemStack(Blocks.tnt, aInput2>0?aInput2<64?aInput2:64:1)), aOutput1, aOutput2, null, null, 20, 30, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sImplosionRecipes, aInput1, GT_ModHandler.getIC2Item("industrialTnt", aInput2>0?aInput2<64?aInput2:64:1, new ItemStack(Blocks.tnt, aInput2>0?aInput2<64?aInput2:64:1))) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sImplosionRecipes, aInput1, GT_ModHandler.getIC2Item("industrialTnt", aInput2>0?aInput2<64?aInput2:64:1, new ItemStack(Blocks.tnt, aInput2>0?aInput2<64?aInput2:64:1))) == null) {
|
||||
addToLists(sImplosionRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aEUt, int aDuration, ItemStack aOutput1) {
|
||||
this(aInput1, null, aOutput1, null, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sWiremillRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sWiremillRecipes, aInput1) == null) {
|
||||
addToLists(sWiremillRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(int aEUt, int aDuration, ItemStack aInput1, ItemStack aOutput1) {
|
||||
this(aInput1, GT_Items.Circuit_Integrated.getWithDamage(0, aInput1.stackSize), aOutput1, null, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, false, sBenderRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(false, sBenderRecipes, aInput1) == null) {
|
||||
addToLists(sBenderRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(int aEUt, int aDuration, ItemStack aInput1, ItemStack aShape, ItemStack aOutput1) {
|
||||
this(aInput1, aShape, aOutput1, null, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 1 && mOutputs[0] != null && findEqualRecipe(false, false, sExtruderRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 1 && mOutputs[0] != null && findEqualRecipe(false, sExtruderRecipes, aInput1) == null) {
|
||||
addToLists(sExtruderRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aEUt, ItemStack aInput2, int aDuration, ItemStack aOutput1) {
|
||||
this(aInput1, aInput2, aOutput1, null, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sAssemblerRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sAssemblerRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sAssemblerRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, int aEUt, int aDuration, ItemStack aOutput1) {
|
||||
this(aInput1, aInput2, aOutput1, null, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sAlloySmelterRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sAlloySmelterRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sAlloySmelterRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, int aEUt, ItemStack aInput2, int aDuration, ItemStack aOutput1, ItemStack aOutput2) {
|
||||
this(aInput1, aInput2, aOutput1, aOutput2, null, null, Math.max(aDuration, 1), Math.max(aEUt, 1), 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sCannerRecipes, aInput1, aInput2) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sCannerRecipes, aInput1, aInput2) == null) {
|
||||
addToLists(sCannerRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aOutput1, int aDuration) {
|
||||
this(aInput1, null, aOutput1, null, null, null, Math.max(aDuration, 1), 120, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sVacuumRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sVacuumRecipes, aInput1) == null) {
|
||||
addToLists(sVacuumRecipes);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, int aDuration) {
|
||||
this(aInput1, aInput2, aOutput1, null, null, null, Math.max(aDuration, 1), 30, 0);
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, false, sChemicalRecipes, aInput1) == null) {
|
||||
if (mInputs.length > 0 && mOutputs[0] != null && findEqualRecipe(true, sChemicalRecipes, aInput1) == null) {
|
||||
addToLists(sChemicalRecipes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import gregtechmod.api.interfaces.IGregTechTileEntity;
|
|||
import gregtechmod.api.interfaces.IRecipeWorkable;
|
||||
import gregtechmod.api.util.GT_Log;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -113,16 +114,19 @@ public class RecipeLogic {
|
|||
}
|
||||
} else {
|
||||
// find new recipe
|
||||
Recipe resRec = customRecipeProvider != null ? customRecipeProvider.get() :
|
||||
recipeMap.stream()
|
||||
.filter(rec -> match(rec))
|
||||
.findFirst().orElse(null);
|
||||
Recipe resRec = findRecipe();
|
||||
if (resRec != null)
|
||||
startRecipe(resRec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Recipe findRecipe() {
|
||||
if (customRecipeProvider == null) {
|
||||
return Recipe.findEqualRecipe(true, recipeMap, getMachine().getBaseMetaTileEntity(), getMachine().getInputSlots());
|
||||
} else return customRecipeProvider.get();
|
||||
}
|
||||
|
||||
protected boolean match(Recipe recipe) {
|
||||
return recipe.match(false, getMachine().getBaseMetaTileEntity(), getMachine().getInputSlots());
|
||||
}
|
||||
|
|
|
@ -32,16 +32,20 @@ public final class ItemStackKey {
|
|||
|
||||
public ItemStack get() {
|
||||
ItemStack copy = this.stack.copy();
|
||||
stack.stackSize = this.stackSize;
|
||||
copy.stackSize = this.stackSize;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public int getStackSize() {
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
public boolean isStackEquals(ItemStack stack) {
|
||||
if (GT_Utility.isStackValid(stack)) {
|
||||
if (isWildcard) {
|
||||
return this.stack.getItem() == stack.getItem();
|
||||
} else {
|
||||
return ItemStack.areItemStacksEqual(get(), stack) && ItemStack.areItemStackTagsEqual(get(), stack);
|
||||
return ItemStack.areItemStacksEqual(this.stack, stack) && ItemStack.areItemStackTagsEqual(this.stack, stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +54,7 @@ public final class ItemStackKey {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ItemStackKey[stack=%s, wildcard=%s]", stack.toString(), isWildcard);
|
||||
return String.format("ItemStackKey[stack=%s, wildcard=%s, amount=%s]", stack.toString(), isWildcard, stackSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,15 +3,9 @@ package gregtechmod.common.containers;
|
|||
import gregtechmod.api.gui.GT_ContainerMetaTile_Machine;
|
||||
import gregtechmod.api.gui.GT_Slot_Output;
|
||||
import gregtechmod.api.interfaces.IGregTechTileEntity;
|
||||
import gregtechmod.common.tileentities.machines.GT_MetaTileEntity_ChemicalReactor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class GT_Container_ChemicalReactor extends GT_ContainerMetaTile_Machine {
|
||||
|
||||
|
@ -25,35 +19,6 @@ public class GT_Container_ChemicalReactor extends GT_ContainerMetaTile_Machine {
|
|||
addSlotToContainer(new GT_Slot_Output (mTileEntity, 2, 80, 46));
|
||||
}
|
||||
|
||||
public int mProgress, mMaxProgress, mProgressScale;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return;
|
||||
mProgress = ((GT_MetaTileEntity_ChemicalReactor)mTileEntity.getMetaTileEntity()).getProgresstime();
|
||||
mMaxProgress = ((GT_MetaTileEntity_ChemicalReactor)mTileEntity.getMetaTileEntity()).maxProgresstime();
|
||||
mProgressScale = Math.max(0, Math.min(10, (mProgress>0?1:0) + (mProgress * 10) / (mMaxProgress<1?1:mMaxProgress)));
|
||||
|
||||
Iterator var2 = this.crafters.iterator();
|
||||
while (var2.hasNext()) {
|
||||
ICrafting var1 = (ICrafting)var2.next();
|
||||
var1.sendProgressBarUpdate(this, 100, mProgress);
|
||||
var1.sendProgressBarUpdate(this, 101, mMaxProgress);
|
||||
var1.sendProgressBarUpdate(this, 102, mProgressScale);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateProgressBar(int par1, int par2) {
|
||||
super.updateProgressBar(par1, par2);
|
||||
switch (par1) {
|
||||
case 100: mProgress = par2; break;
|
||||
case 101: mMaxProgress = par2; break;
|
||||
case 102: mProgressScale = par2; break;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSlotCount() {
|
||||
return 3;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class GT_GUIContainer_ChemicalReactor extends GT_GUIContainerMetaTile_Mac
|
|||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||
|
||||
if (mContainer != null && mContainer.mProgressTime>0) {
|
||||
int tScale = ((GT_Container_ChemicalReactor)mContainer).mProgressScale;
|
||||
int tScale = Math.max(0, Math.min(10, (mContainer.mProgressTime>0?1:0) + (mContainer.mProgressTime * 10) / (mContainer.mMaxProgressTime<1?1:mContainer.mMaxProgressTime)));
|
||||
drawTexturedModalRect(x + 73, y + 34, 183, 34, 30, tScale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,17 @@ package gregtechmod.common.items;
|
|||
|
||||
import gregtechmod.api.GregTech_API;
|
||||
import gregtechmod.api.items.GT_Generic_Item;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
@ -57,6 +62,17 @@ public class GT_FluidDisplayItem extends GT_Generic_Item {
|
|||
return StatCollector.translateToLocal(getUnlocalizedName(aStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List strs, boolean advMode) {
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
if (tag != null && tag.hasKey("amount")) {
|
||||
int amount = tag.getInteger("amount");
|
||||
strs.add(I18n.format("metatileentity.fluid.amount", GT_Utility.parseNumberToString(amount)));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
|
|
|
@ -120,6 +120,8 @@ public class GT_SensorCard_Item extends GT_Generic_Item implements IRemoteSensor
|
|||
public List<PanelString> getStringData(int displaySettings, ICardWrapper aCard, boolean showLabels) {
|
||||
List<PanelString> rList = new ArrayList<>();
|
||||
String jsonData = aCard.getString("aData");
|
||||
|
||||
try {
|
||||
JsonObject data = new JsonParser().parse(jsonData).getAsJsonObject();
|
||||
|
||||
int i = 0;
|
||||
|
@ -155,6 +157,7 @@ public class GT_SensorCard_Item extends GT_Generic_Item implements IRemoteSensor
|
|||
if ((displaySettings & 1 << i) != 0) rList.add(str);
|
||||
i++;
|
||||
}
|
||||
} catch (Throwable e) {}
|
||||
|
||||
return rList;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class GT_MetaTileEntity_ElectricTypeSorter extends GT_MetaTileEntity_Elec
|
|||
|
||||
OrePrefixes tPrefix = OrePrefixes.getPrefix(sTypeList[mMode]);
|
||||
|
||||
if (((mMode == 11 && mInventory[0].getItem() instanceof ItemFood) || (mMode == 12 && Recipe.findEqualRecipe(false, false, RecipeMaps.sGrinderRecipes, mInventory[0], GT_ModHandler.getWaterCell(1)) != null) || (tPrefix != null && tPrefix.contains(mInventory[0])) || GT_OreDictUnificator.isItemStackInstanceOf(mInventory[0], sTypeList[mMode]))) {
|
||||
if (((mMode == 11 && mInventory[0].getItem() instanceof ItemFood) || (mMode == 12 && Recipe.findEqualRecipe(false, RecipeMaps.sGrinderRecipes, mInventory[0], GT_ModHandler.getWaterCell(1)) != null) || (tPrefix != null && tPrefix.contains(mInventory[0])) || GT_OreDictUnificator.isItemStackInstanceOf(mInventory[0], sTypeList[mMode]))) {
|
||||
getBaseMetaTileEntity().decreaseStoredEnergyUnits(tPrice = GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), getBaseMetaTileEntity().getIInventoryAtSide(mTargetDirection), getBaseMetaTileEntity().getBackFacing(), GT_Utility.getOppositeSide(mTargetDirection), null, false, mTargetStackSize!=0?(byte)mTargetStackSize:64, mTargetStackSize!=0?(byte)mTargetStackSize:1, (byte)64, (byte)1)*3, true);
|
||||
}
|
||||
if (tPrice <= 0) {
|
||||
|
|
|
@ -147,7 +147,7 @@ public class GT_MetaTileEntity_Centrifuge extends GT_MetaTileEntity_BasicTank im
|
|||
ItemStack fluidItem = findFluidItem(recipe);
|
||||
FluidStack fluid = null;
|
||||
|
||||
if ((fluid = GT_Utility.getFluidForFilledItem(fluidItem)) != null) {
|
||||
if (mFluid != null && (fluid = GT_Utility.getFluidForFilledItem(fluidItem)) != null) {
|
||||
fluid.amount = 1000 * fluidItem.stackSize;
|
||||
if (fluid.getFluidID() == mFluid.getFluidID() && mFluid.amount >= fluid.amount) {
|
||||
if (consume) mFluid.amount -= fluid.amount;
|
||||
|
|
|
@ -1,136 +1,61 @@
|
|||
package gregtechmod.common.tileentities.machines;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import gregtechmod.api.GregTech_API;
|
||||
import gregtechmod.api.interfaces.IGregTechTileEntity;
|
||||
import gregtechmod.api.metatileentity.MetaTileEntity;
|
||||
import gregtechmod.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
|
||||
import gregtechmod.api.recipe.Recipe;
|
||||
import gregtechmod.api.util.GT_Utility;
|
||||
import gregtechmod.api.util.InfoBuilder;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class GT_MetaTileEntity_ChemicalReactor extends MetaTileEntity {
|
||||
public class GT_MetaTileEntity_ChemicalReactor extends GT_MetaTileEntity_BasicMachine {
|
||||
|
||||
private int mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0;
|
||||
private ItemStack mOutputItem1;
|
||||
|
||||
public GT_MetaTileEntity_ChemicalReactor(int aID, String mName) {
|
||||
super(aID, mName);
|
||||
public GT_MetaTileEntity_ChemicalReactor(int aID, String mName, List<Recipe> recipeMap) {
|
||||
super(aID, mName, recipeMap);
|
||||
recipeLogic.moveItems = false;
|
||||
}
|
||||
|
||||
public GT_MetaTileEntity_ChemicalReactor() {
|
||||
|
||||
public GT_MetaTileEntity_ChemicalReactor(List<Recipe> recipeMap) {
|
||||
super(recipeMap);
|
||||
recipeLogic.moveItems = false;
|
||||
}
|
||||
|
||||
@Override public boolean isTransformerUpgradable() {return true;}
|
||||
@Override public boolean isOverclockerUpgradable() {return true;}
|
||||
@Override public boolean isBatteryUpgradable() {return true;}
|
||||
@Override public boolean isSimpleMachine() {return false;}
|
||||
@Override public boolean isFacingValid(byte aFacing) {return false;}
|
||||
@Override public boolean isEnetInput() {return true;}
|
||||
@Override public boolean isInputFacing(byte aSide) {return true;}
|
||||
@Override public int maxEUInput() {return 32;}
|
||||
@Override public int maxEUStore() {return 10000;}
|
||||
@Override public int maxRFStore() {return maxEUStore();}
|
||||
@Override public int maxSteamStore() {return maxEUStore();}
|
||||
@Override public int getInvSize() {return 3;}
|
||||
@Override public void onRightclick(EntityPlayer aPlayer) {getBaseMetaTileEntity().openGUI(aPlayer, 124);}
|
||||
@Override public boolean isAccessAllowed(EntityPlayer aPlayer) {return true;}
|
||||
@Override public int getProgresstime() {return mProgresstime;}
|
||||
@Override public int maxProgresstime() {return mMaxProgresstime;}
|
||||
@Override public int increaseProgress(int aProgress) {mProgresstime += aProgress; return mMaxProgresstime-mProgresstime;}
|
||||
@Override public int dechargerSlotCount() {return 0;}
|
||||
|
||||
@Override
|
||||
public void onRightclick(EntityPlayer aPlayer) {
|
||||
getBaseMetaTileEntity().openGUI(aPlayer, 124);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
|
||||
return new GT_MetaTileEntity_ChemicalReactor();
|
||||
return new GT_MetaTileEntity_ChemicalReactor(recipeLogic.recipeMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveNBTData(NBTTagCompound aNBT) {
|
||||
aNBT.setInteger("mEUt", mEUt);
|
||||
aNBT.setInteger("mProgresstime", mProgresstime);
|
||||
aNBT.setInteger("mMaxProgresstime", mMaxProgresstime);
|
||||
|
||||
if (mOutputItem1 != null) {
|
||||
NBTTagCompound tNBT = new NBTTagCompound();
|
||||
mOutputItem1.writeToNBT(tNBT);
|
||||
aNBT.setTag("mOutputItem1", tNBT);
|
||||
}
|
||||
public int[] getInputSlots() {
|
||||
return new int[] {0, 1};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadNBTData(NBTTagCompound aNBT) {
|
||||
mEUt = aNBT.getInteger("mEUt");
|
||||
mProgresstime = aNBT.getInteger("mProgresstime");
|
||||
mMaxProgresstime = aNBT.getInteger("mMaxProgresstime");
|
||||
|
||||
NBTTagCompound tNBT1 = (NBTTagCompound)aNBT.getTag("mOutputItem1");
|
||||
if (tNBT1 != null) {
|
||||
mOutputItem1 = GT_Utility.loadItem(tNBT1);
|
||||
}
|
||||
public int[] getOutputSlots() {
|
||||
return new int[] {2};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostTick() {
|
||||
if (getBaseMetaTileEntity().isServerSide()) {
|
||||
if (mMaxProgresstime > 0) {
|
||||
getBaseMetaTileEntity().setActive(true);
|
||||
if (mProgresstime < 0 || getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt*(int)Math.pow(4, getBaseMetaTileEntity().getOverclockerUpgradeCount()), false)) {
|
||||
if ((mProgresstime+=(int)Math.pow(2, getBaseMetaTileEntity().getOverclockerUpgradeCount()))>=mMaxProgresstime) {
|
||||
addOutputProducts();
|
||||
mOutputItem1 = null;
|
||||
mProgresstime = 0;
|
||||
mMaxProgresstime = 0;
|
||||
public void startProcess() {
|
||||
getBaseMetaTileEntity().setErrorDisplayID(0);
|
||||
}
|
||||
} else {
|
||||
getBaseMetaTileEntity().setActive(false);
|
||||
if (GregTech_API.sConstantEnergy) {
|
||||
mProgresstime = -10;
|
||||
|
||||
@Override
|
||||
public void stutterProcess() {
|
||||
getBaseMetaTileEntity().setErrorDisplayID(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getBaseMetaTileEntity().setActive(false);
|
||||
if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().getUniversalEnergyStored() > 100) checkRecipe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addOutputProducts() {
|
||||
if (mOutputItem1 != null)
|
||||
if (mInventory[2] == null)
|
||||
mInventory[2] = GT_Utility.copy(mOutputItem1);
|
||||
else if (GT_Utility.areStacksEqual(mInventory[2], mOutputItem1))
|
||||
mInventory[2].stackSize = Math.min(mOutputItem1.getMaxStackSize(), mOutputItem1.stackSize + mInventory[2].stackSize);
|
||||
}
|
||||
|
||||
private boolean spaceForOutput(Recipe aRecipe) {
|
||||
if (mInventory[2] == null || aRecipe.getOutput(0) == null || (mInventory[2].stackSize + aRecipe.getOutput(0).stackSize <= mInventory[2].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[2], aRecipe.getOutput(0))))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkRecipe() {
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sChemicalRecipes, mInventory[0], mInventory[1]);
|
||||
|
||||
if (tRecipe != null) {
|
||||
if (spaceForOutput(tRecipe) && tRecipe.isRecipeInputEqual(true, true, mInventory[0], mInventory[1])) {
|
||||
if (mInventory[0] != null) if (mInventory[0].stackSize == 0) mInventory[0] = null;
|
||||
if (mInventory[1] != null) if (mInventory[1].stackSize == 0) mInventory[1] = null;
|
||||
|
||||
mMaxProgresstime = tRecipe.mDuration;
|
||||
mEUt = tRecipe.mEUt;
|
||||
mOutputItem1 = GT_Utility.copy(tRecipe.getOutput(0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) {
|
||||
|
@ -141,19 +66,6 @@ public class GT_MetaTileEntity_ChemicalReactor extends MetaTileEntity {
|
|||
return aActive?67:66;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Object>> getInfoData() {
|
||||
return InfoBuilder.create()
|
||||
.newKey("sensor.progress.percentage", mProgresstime * 100.0D / mMaxProgresstime)
|
||||
.newKey("sensor.progress.secs", mProgresstime / 20)
|
||||
.newKey("sensor.progress.secs", mMaxProgresstime / 20)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGivingInformation() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "metatileentity.GT_ChemicalReactor.tooltip";
|
||||
|
|
|
@ -36,7 +36,7 @@ public class GT_MetaTileEntity_Extruder extends GT_MetaTileEntity_BasicMachine {
|
|||
public void checkRecipe() {
|
||||
GT_Utility.moveStackFromSlotAToSlotB(this.getBaseMetaTileEntity(), this.getBaseMetaTileEntity(), 3, 4, (byte)64, (byte)1, (byte)64, (byte)1);
|
||||
if(super.mInventory[1] != null && super.mInventory[1].stackSize > 0 && super.mInventory[2] != null && super.mInventory[2].stackSize > 0) {
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sExtruderRecipes, new ItemStack[]{super.mInventory[1], super.mInventory[2]});
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, Recipe.sExtruderRecipes, new ItemStack[]{super.mInventory[1], super.mInventory[2]});
|
||||
if(tRecipe != null && this.spaceForOutput(tRecipe.getOutput(0), (ItemStack)null) && tRecipe.isRecipeInputEqual(false, true, new ItemStack[]{super.mInventory[1], super.mInventory[2]})) {
|
||||
super.mEUt = tRecipe.mEUt;
|
||||
super.mMaxProgresstime = tRecipe.mDuration;
|
||||
|
@ -60,7 +60,7 @@ public class GT_MetaTileEntity_Extruder extends GT_MetaTileEntity_BasicMachine {
|
|||
}
|
||||
|
||||
public boolean allowPutStack(int aIndex, byte aSide, ItemStack aStack) {
|
||||
return aIndex == 1 && super.allowPutStack(aIndex, aSide, aStack) && Recipe.findEqualRecipe(false, true, Recipe.sExtruderRecipes, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), super.mInventory[2]}) != null;
|
||||
return aIndex == 1 && super.allowPutStack(aIndex, aSide, aStack) && Recipe.findEqualRecipe(false, Recipe.sExtruderRecipes, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), super.mInventory[2]}) != null;
|
||||
}
|
||||
|
||||
public int getTopFacingInactive() {
|
||||
|
|
|
@ -30,7 +30,7 @@ public class GT_MetaTileEntity_Lathe extends GT_MetaTileEntity_BasicMachine {
|
|||
public void checkRecipe() {
|
||||
GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), 1, 2, (byte)64, (byte)1, (byte)64, (byte)1);
|
||||
if (mInventory[2] != null && mInventory[2].stackSize > 0) {
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sLatheRecipes, mInventory[2]);
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, Recipe.sLatheRecipes, mInventory[2]);
|
||||
if (tRecipe != null && spaceForOutput(tRecipe.getOutput(0), tRecipe.getOutput(1)) && tRecipe.isRecipeInputEqual(true, true, mInventory[2], null)) {
|
||||
mEUt = tRecipe.mEUt;
|
||||
mMaxProgresstime = tRecipe.mDuration;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class GT_MetaTileEntity_PlateCutter extends GT_MetaTileEntity_BasicMachin
|
|||
public void checkRecipe() {
|
||||
GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), 1, 2, (byte)64, (byte)1, (byte)64, (byte)1);
|
||||
if (mInventory[2] != null && mInventory[2].stackSize > 0) {
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sCutterRecipes, mInventory[2]);
|
||||
Recipe tRecipe = Recipe.findEqualRecipe(false, Recipe.sCutterRecipes, mInventory[2]);
|
||||
if (tRecipe != null && spaceForOutput(tRecipe.getOutput(0), null) && tRecipe.isRecipeInputEqual(true, true, mInventory[2], null)) {
|
||||
mEUt = tRecipe.mEUt;
|
||||
mMaxProgresstime = tRecipe.mDuration;
|
||||
|
|
|
@ -52,7 +52,7 @@ public class GT_MetaTileEntityLoader implements Runnable {
|
|||
new GT_MetaTileEntity_VacuumFreezer ( 38, "GT_VacuumFreezer");
|
||||
new GT_MetaTileEntity_ElectricRegulatorAdvanced ( 39, "GT_RegulatorAdvanced");
|
||||
new GT_MetaTileEntity_DragonEggEnergySiphon ( 40, "GT_DragonEggEnergySiphon");
|
||||
new GT_MetaTileEntity_ChemicalReactor ( 41, "GT_ChemicalReactor");
|
||||
new GT_MetaTileEntity_ChemicalReactor ( 41, "GT_ChemicalReactor" , RecipeMaps.sChemicalRecipes);
|
||||
new GT_MetaTileEntity_MagicEnergyConverter ( 42, "GT_MagicConverter" , RecipeMaps.sMagicFuels , 100);
|
||||
new GT_MetaTileEntity_MagicEnergyAbsorber ( 43, "GT_MagicAbsorber");
|
||||
new GT_MetaTileEntity_DistillationTower ( 44, "GT_DistillationTower");
|
||||
|
|
|
@ -1388,6 +1388,7 @@ item.GT_SensorCard_Item.tooltip.info.missing=Missing Coodinates!
|
|||
metatileentity.GT_MetaTileEntity_BasicGenerator.tooltip=Generating: %d EU
|
||||
metatileentity.machines.input_allow=Input from Output Side allowed
|
||||
metatileentity.machines.input_deny=Input from Output Side forbidden
|
||||
metatileentity.fluid.amount=%s mb
|
||||
|
||||
pipes.fluid.capacity=Fluid Capacity: %s L/sec
|
||||
pipes.item.capacity=Item Capacity: %s Stacks/sec
|
||||
|
|
Loading…
Reference in a new issue