diff options
Diffstat (limited to 'src/main/java/gregtech/api')
7 files changed, 156 insertions, 112 deletions
diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java index a24c4acbcd..e1f3c3f0e0 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java @@ -73,7 +73,7 @@ public class NodeEnergyReceiver extends ConsumerNode { tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) if (GT_Mod.gregtechproxy.mPollution) - GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), 100000); + GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), GT_Mod.gregtechproxy.mPollutionOnExplosion); new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder() .setStrength(tStrength) diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 24d0576864..30a5230168 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -113,7 +113,7 @@ public interface IEnergyConnected extends IColoredTileEntity, IHasWorldObjectAnd tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) if (GT_Mod.gregtechproxy.mPollution) - GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), 100000); + GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), GT_Mod.gregtechproxy.mPollutionOnExplosion); new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder() .setStrength(tStrength) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 9176d063ce..a0a5e75b54 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1403,7 +1403,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } } - GT_Pollution.addPollution(this, 100000); + GT_Pollution.addPollution(this, GT_Mod.gregtechproxy.mPollutionOnExplosion); mMetaTileEntity.doExplosion(aAmount); } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index bb7b795c36..289a43fdd8 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -117,7 +117,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity @Override public boolean isFacingValid(byte aSide) { - return aSide > 1; + return true; } @Override @@ -214,7 +214,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity long tFluidAmountToUse = Math.min(mFluid.amount / tConsumed, (maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); //long tFluidAmountToUse = Math.min(mFluid.amount / tConsumed, (maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue);//TODO CHECK if (tFluidAmountToUse > 0 && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) { - GT_Pollution.addPollution(getBaseMetaTileEntity(),10 * getPollution()); + // divided by two because this is called every 10 ticks, not 20 + GT_Pollution.addPollution(getBaseMetaTileEntity(),getPollution()/2); mFluid.amount -= tFluidAmountToUse * tConsumed; } } @@ -229,7 +230,8 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) { aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); - GT_Pollution.addPollution(getBaseMetaTileEntity(),10 * getPollution()); + // divided by two because this is called every 10 ticks, not 20 + GT_Pollution.addPollution(getBaseMetaTileEntity(),getPollution()/2); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java index 7b99d78009..552d3d6587 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java @@ -16,7 +16,7 @@ import net.minecraftforge.fluids.FluidTankInfo; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - * <p/> + * * This is the main construct for my generic Tanks. Filling and emptying behavior have to be implemented manually */ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_TieredMachineBlock implements IHasFluidDisplayItem { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 6369c48f8e..8fe70c4f72 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -401,6 +401,13 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public abstract int getPollutionPerTick(ItemStack aStack); /** + * Gets the pollution produced per second by this multiblock + */ + public int getPollutionPerSecond(ItemStack aStack){ + return 20 * getPollutionPerTick(aStack); + } + + /** * Gets the damage to the ItemStack, usually 0 or 1. */ public abstract int getDamageToComponent(ItemStack aStack); @@ -539,7 +546,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { GT_Log.exp.println("MultiBlockExplosion at: " +this.getBaseMetaTileEntity().getXCoord()+" | "+this.getBaseMetaTileEntity().getYCoord()+" | "+this.getBaseMetaTileEntity().getZCoord()+" DIMID: "+ this.getBaseMetaTileEntity().getWorld().provider.dimensionId+"."); - GT_Pollution.addPollution(getBaseMetaTileEntity(), 300000); + GT_Pollution.addPollution(getBaseMetaTileEntity(), GT_Mod.gregtechproxy.mPollutionOnExplosion); mInventory[1] = null; for (MetaTileEntity tTileEntity : mInputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); for (MetaTileEntity tTileEntity : mOutputBusses) tTileEntity.getBaseMetaTileEntity().doExplosion(V[8]); diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 7b74f95a6b..6e12a3d36c 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -376,115 +376,131 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return isRecipeInputEqual(aDecreaseStacksizeBySuccess, false, aFluidInputs, aInputs); } + /** + * Okay, did some code archeology to figure out what's going on here. + * + * <p>This variable was added in + * <a href=https://github.com/GTNewHorizons/GT5-Unofficial/commit/9959ab7443982a19ad329bca424ab515493432e9>this commit,</a> + * in order to fix the issues mentioned in + * <a href=https://github.com/GTNewHorizons/GT5-Unofficial/pull/183>the PR</a>. + * + * <p>It looks like it controls checking NBT. At this point, since we are still using universal + * fluid cells which store their fluids in NBT, it probably will not be safe to disable the NBT + * checks in the near future. Data sticks may be another case. Anyway, we probably can't get rid + * of this without some significant changes to clean up recipe inputs. + */ public static boolean GTppRecipeHelper; + /** + * WARNING: Do not call this method with both {@code aDecreaseStacksizeBySuccess} and {@code aDontCheckStackSizes} set to {@code true}! + * You'll get weird behavior. + */ public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) { - if (mInputs.length > 0 && aInputs == null) return false; if (mFluidInputs.length > 0 && aFluidInputs == null) return false; - int amt; - for (FluidStack tFluid : mFluidInputs) - if (tFluid != null) { - boolean temp = true; - amt = tFluid.amount; - for (FluidStack aFluid : aFluidInputs) - if (aFluid != null && aFluid.isFluidEqual(tFluid)) { - if (aDontCheckStackSizes) { - temp = false; - break; - } - amt -= aFluid.amount; - if (amt < 1) { - temp = false; - break; + + // We need to handle 0-size recipe inputs. These are for inputs that don't get consumed. + boolean inputFound; + int remainingCost; + + // Array tracking modified fluid amounts. For efficiency, we will lazily initialize this array. + // We use Integer so that we can have null as the default value, meaning unchanged. + Integer[] newFluidAmounts = null; + if (aFluidInputs != null) { + newFluidAmounts = new Integer[aFluidInputs.length]; + + for (FluidStack recipeFluidCost : mFluidInputs) { + if (recipeFluidCost != null) { + inputFound = false; + remainingCost = recipeFluidCost.amount; + + for (int i = 0; i < aFluidInputs.length; i++) { + FluidStack providedFluid = aFluidInputs[i]; + if (providedFluid != null && providedFluid.isFluidEqual(recipeFluidCost)) { + inputFound = true; + if (newFluidAmounts[i] == null) { + newFluidAmounts[i] = providedFluid.amount; + } + + if (aDontCheckStackSizes || newFluidAmounts[i] >= remainingCost) { + newFluidAmounts[i] -= remainingCost; + remainingCost = 0; + break; + } else { + remainingCost -= newFluidAmounts[i]; + newFluidAmounts[i] = 0; + } } } - if (temp) return false; + + if (remainingCost > 0 || !inputFound) { + // Cost not satisfied, or for non-consumed inputs, input not found. + return false; + } + } } + } - HashSet<Integer> isVisited = new HashSet<>(); - - for (ItemStack tStack : mInputs) { - ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); - if (unified_tStack != null) { - amt = tStack.stackSize; - boolean temp = true; - int it = 0; - for (ItemStack aStack : aInputs) { - it ++; - if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isVisited.contains(it)) { - isVisited.add(it); - if (GTppRecipeHelper) {//remove once the fix is out - if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { - if (!GT_Utility.areStacksEqual(aStack, tStack, false)) - continue; + // Array tracking modified item stack sizes. For efficiency, we will lazily initialize this array. + // We use Integer so that we can have null as the default value, meaning unchanged. + Integer[] newItemAmounts = null; + if (aInputs != null) { + newItemAmounts = new Integer[aInputs.length]; + + for (ItemStack recipeItemCost : mInputs) { + ItemStack unifiedItemCost = GT_OreDictUnificator.get_nocopy(true, recipeItemCost); + if (unifiedItemCost != null) { + inputFound = false; + remainingCost = recipeItemCost.stackSize; + + for (int i = 0; i < aInputs.length; i++) { + ItemStack providedItem = aInputs[i]; + if (GT_OreDictUnificator.isInputStackEqual(providedItem, unifiedItemCost)) { + if (GTppRecipeHelper) { // Please see JavaDoc on GTppRecipeHelper for why this is here. + if (GT_Utility.areStacksEqual(providedItem, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(providedItem, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(providedItem, ItemList.Tool_DataOrb.get(1L), true)) { + if (!GT_Utility.areStacksEqual(providedItem, recipeItemCost, false)) + continue; + } + } + + inputFound = true; + if (newItemAmounts[i] == null) { + newItemAmounts[i] = providedItem.stackSize; + } + + if (aDontCheckStackSizes || newItemAmounts[i] >= remainingCost) { + newItemAmounts[i] -= remainingCost; + remainingCost = 0; + break; + } else { + remainingCost -= newItemAmounts[i]; + newItemAmounts[i] = 0; } } - if (aDontCheckStackSizes) { - temp = false; - break; - } - amt -= aStack.stackSize; - if (amt < 1) { - temp = false; - break; - } + } + + if (remainingCost > 0 || !inputFound) { + // Cost not satisfied, or for non-consumed inputs, input not found. + return false; } } - if (temp) return false; } } + if (aDecreaseStacksizeBySuccess) { + // Copy modified amounts into the input stacks. if (aFluidInputs != null) { - for (FluidStack tFluid : mFluidInputs) { - if (tFluid != null) { - amt = tFluid.amount; - for (FluidStack aFluid : aFluidInputs) { - if (aFluid != null && aFluid.isFluidEqual(tFluid)) { - if (aDontCheckStackSizes) { - aFluid.amount -= amt; - break; - } - if (aFluid.amount < amt) { - amt -= aFluid.amount; - aFluid.amount = 0; - } else { - aFluid.amount -= amt; - amt = 0; - break; - } - } - } + for (int i = 0; i < aFluidInputs.length; i++) { + if (newFluidAmounts[i] != null) { + aFluidInputs[i].amount = newFluidAmounts[i]; } } } if (aInputs != null) { - for (ItemStack tStack : mInputs) { - if (tStack != null) { - amt = tStack.stackSize; - for (ItemStack aStack : aInputs) { - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { - if (GTppRecipeHelper) { - if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { - if (!GT_Utility.areStacksEqual(aStack, tStack, false)) - continue; - } - } - if (aDontCheckStackSizes){ - aStack.stackSize -= amt; - break; - } - if (aStack.stackSize < amt){ - amt -= aStack.stackSize; - aStack.stackSize = 0; - }else{ - aStack.stackSize -= amt; - amt = 0; - break; - } - } - } + for (int i = 0; i < aInputs.length; i++) { + if (newItemAmounts[i] != null) { + aInputs[i].stackSize = newItemAmounts[i]; } } } @@ -1569,23 +1585,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { GT_Recipe rRecipe = super.findRecipe(aTileEntity, aRecipe, aNotUnificated, aVoltage, aFluids, aSpecialSlot, aInputs); if (aInputs == null || aInputs.length < 2 || aInputs[0] == null || aInputs[1] == null || !GregTech_API.sPostloadFinished) return rRecipe; - if (rRecipe == null) { - if (ItemList.Shape_Mold_Name.isStackEqual(aInputs[0], false, true)) { - ItemStack tOutput = GT_Utility.copyAmount(1, aInputs[1]); - tOutput.setStackDisplayName(aInputs[0].getDisplayName()); - rRecipe = new GT_Recipe(false, new ItemStack[]{ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, aInputs[1])}, new ItemStack[]{tOutput}, null, null, null, null, 128, 8, 0); - rRecipe.mCanBeBuffered = false; - return rRecipe; - } - if (ItemList.Shape_Mold_Name.isStackEqual(aInputs[1], false, true)) { - ItemStack tOutput = GT_Utility.copyAmount(1, aInputs[0]); - tOutput.setStackDisplayName(aInputs[1].getDisplayName()); - rRecipe = new GT_Recipe(false, new ItemStack[]{ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, aInputs[0])}, new ItemStack[]{tOutput}, null, null, null, null, 128, 8, 0); - rRecipe.mCanBeBuffered = false; - return rRecipe; - } - return null; - } + if (rRecipe == null) + return findRenamingRecipe(aInputs); for (ItemStack aMold : aInputs) { if (ItemList.Shape_Mold_Credit.isStackEqual(aMold, false, true)) { NBTTagCompound tNBT = aMold.getTagCompound(); @@ -1601,6 +1602,40 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } return rRecipe; } + + private ItemStack findNameMoldIndex(ItemStack[] inputs) { + for (ItemStack stack: inputs) { + if (ItemList.Shape_Mold_Name.isStackEqual(stack, false, true)) + return stack; + } + return null; + } + + private ItemStack findStackToRename(ItemStack[] inputs, ItemStack mold) { + for (ItemStack stack: inputs) { + if (stack == mold || stack == null) + continue; + return stack; + } + return null; + } + + private GT_Recipe findRenamingRecipe(ItemStack[] inputs) { + ItemStack mold = findNameMoldIndex(inputs); + if (mold == null) + return null; + ItemStack input = findStackToRename(inputs, mold); + if (input == null) + return null; + ItemStack output = GT_Utility.copyAmount(1, input); + output.setStackDisplayName(mold.getDisplayName()); + GT_Recipe recipe = new GT_Recipe(false, + new ItemStack[]{ ItemList.Shape_Mold_Name.get(0), GT_Utility.copyAmount(1, input) }, + new ItemStack[]{ output }, + null, null, null, null, 128, 8, 0); + recipe.mCanBeBuffered = false; + return recipe; + } } /** |