aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorPrometheus0000 <prometheus0000000@gmail.com>2021-02-11 14:29:19 -0500
committerGitHub <noreply@github.com>2021-02-11 14:29:19 -0500
commit3a027e939e2c18e165b2f1405637c92f25736582 (patch)
tree1d75209cd6c074313f0e3f15bc989f7b258a57bd /src/main/java/gregtech/api
parentc6324633a4491296c0505e59aa7f8747af0c640a (diff)
parente0c1f654b17d901d018603912bf32c32bd136bad (diff)
downloadGT5-Unofficial-3a027e939e2c18e165b2f1405637c92f25736582.tar.gz
GT5-Unofficial-3a027e939e2c18e165b2f1405637c92f25736582.tar.bz2
GT5-Unofficial-3a027e939e2c18e165b2f1405637c92f25736582.zip
Merge pull request #23 from GTNewHorizons/experimental
update
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/GregTech_API.java4
-rw-r--r--src/main/java/gregtech/api/enums/GT_Values.java2
-rw-r--r--src/main/java/gregtech/api/enums/HeatingCoilLevel.java6
-rw-r--r--src/main/java/gregtech/api/enums/ItemList.java40
-rw-r--r--src/main/java/gregtech/api/enums/Materials.java2
-rw-r--r--src/main/java/gregtech/api/enums/Textures.java8
-rw-r--r--src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java155
-rw-r--r--src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java3
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java94
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaTileEntity.java25
-rw-r--r--src/main/java/gregtech/api/metatileentity/examples/GT_MetaTileEntity_E_Furnace.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java12
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java18
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java8
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java36
-rw-r--r--src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java2
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java18
-rw-r--r--src/main/java/gregtech/api/util/GT_LanguageManager.java8
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java345
-rw-r--r--src/main/java/gregtech/api/util/GT_OreDictUnificator.java50
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java230
24 files changed, 774 insertions, 304 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java
index 17f171a953..0fbb1cd745 100644
--- a/src/main/java/gregtech/api/GregTech_API.java
+++ b/src/main/java/gregtech/api/GregTech_API.java
@@ -221,7 +221,6 @@ public class GregTech_API {
sRecipeFile = null,
sMachineFile = null,
sWorldgenFile = null,
- sModularArmor = null,
sMaterialProperties = null,
sMaterialComponents = null,
sUnification = null,
@@ -296,7 +295,8 @@ public class GregTech_API {
mGTPlusPlus = false,
mTranslocator = false,
mTConstruct = false,
- mGalacticraft = false;
+ mGalacticraft = false,
+ mAE2 = false;
public static int
mEUtoRF = 360,
mRFtoEU = 20;
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java
index 8545f42bea..d2b391edcb 100644
--- a/src/main/java/gregtech/api/enums/GT_Values.java
+++ b/src/main/java/gregtech/api/enums/GT_Values.java
@@ -298,4 +298,6 @@ public class GT_Values {
public static boolean debugChunkloaders = false;
public static boolean cls_enabled;
+
+ public static boolean hideAssLineRecipes = false;
}
diff --git a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
index f4b28ede2b..2388a92cd3 100644
--- a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
+++ b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
@@ -50,14 +50,14 @@ public enum HeatingCoilLevel {
* @return the coil Level, used for Parallels in the Multi Furnace for example
*/
public byte getLevel() {
- return (byte) Math.min(16, 2 << (this.ordinal() - 2));
+ return (byte) (1 << Math.min(Math.max(0, this.ordinal() - 2), 4));
}
/**
* @return the coil Discount, used for discount in the Multi Furnace for example
*/
- public byte getCostDiscount() {
- return (byte) Math.max(1, 2 << (this.ordinal() - 1 - 6)); //-1 bcs. of none, -4 = offset
+ public int getCostDiscount() {
+ return 1 << Math.max(0, this.ordinal() - 5);
}
public static HeatingCoilLevel getFromTier(byte tier){
diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java
index 94efa0605f..5d6de01493 100644
--- a/src/main/java/gregtech/api/enums/ItemList.java
+++ b/src/main/java/gregtech/api/enums/ItemList.java
@@ -1,6 +1,7 @@
package gregtech.api.enums;
import gregtech.api.interfaces.IItemContainer;
+import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
@@ -9,6 +10,9 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
+import java.util.Locale;
+
+import static gregtech.api.enums.GT_Values.NI;
import static gregtech.api.enums.GT_Values.W;
/**
@@ -1405,6 +1409,8 @@ public enum ItemList implements IItemContainer {
Long_Distance_Pipeline_Fluid_Pipe,
Long_Distance_Pipeline_Item_Pipe,
+ Hatch_Output_Bus_ME,
+
NULL,
Cover_RedstoneTransmitterExternal,
Cover_RedstoneTransmitterInternal,
@@ -1553,20 +1559,6 @@ public enum ItemList implements IItemContainer {
Moxcell_2,
Moxcell_4,
- ModularBasicHelmet,
- ModularBasicChestplate,
- ModularBasicLeggings,
- ModularBasicBoots,
-
- ModularElectric1Helmet,
- ModularElectric1Chestplate,
- ModularElectric1Leggings,
- ModularElectric1Boots,
-
- ModularElectric2Helmet,
- ModularElectric2Chestplate,
- ModularElectric2Leggings,
- ModularElectric2Boots,
Block_Powderbarrel,
GelledToluene,
@@ -2021,8 +2013,24 @@ public enum ItemList implements IItemContainer {
public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements) {
ItemStack rStack = get(1, aReplacements);
if (GT_Utility.isStackInvalid(rStack))
- return null;
- rStack.setStackDisplayName(aDisplayName);
+ return NI;
+
+ // CamelCase alphanumeric words from aDisplayName
+ StringBuilder tCamelCasedDisplayNameBuilder = new StringBuilder();
+ final String[] tDisplayNameWords = aDisplayName.split("\\W");
+ for (String tWord : tDisplayNameWords){
+ if (tWord.length() > 0) tCamelCasedDisplayNameBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US));
+ if (tWord.length() > 1) tCamelCasedDisplayNameBuilder.append(tWord.substring(1).toLowerCase(Locale.US));
+ }
+ if (tCamelCasedDisplayNameBuilder.length() == 0) {
+ // CamelCased DisplayName is empty, so use hash of aDisplayName
+ tCamelCasedDisplayNameBuilder.append(((Long) (long)aDisplayName.hashCode()).toString());
+ }
+
+ // Construct a translation key from UnlocalizedName and CamelCased DisplayName
+ final String tKey = rStack.getUnlocalizedName() + ".with." + tCamelCasedDisplayNameBuilder.toString() + ".name";
+
+ rStack.setStackDisplayName(GT_LanguageManager.addStringLocalization(tKey, aDisplayName));
return GT_Utility.copyAmount(aAmount, rStack);
}
diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java
index b46d26e02d..d00c3bd8fc 100644
--- a/src/main/java/gregtech/api/enums/Materials.java
+++ b/src/main/java/gregtech/api/enums/Materials.java
@@ -649,7 +649,7 @@ public class Materials implements IColorModulationContainer, ISubTagContainer {
public static Materials Cryotheum = new Materials( 898, TextureSet.SET_SHINY , 1.0F, 0, 1, 1 , 0, 148, 203, 0, "Cryotheum" , "Cryotheum" , 2, 62, -1, 0, false, false, 2, 3, 1, Dyes.dyeLightBlue , 2, Arrays.asList(new MaterialStack(Saltpeter, 1), new MaterialStack(Redstone, 1), new MaterialStack(Snow, 1), new MaterialStack(Blizz, 1)), Arrays.asList(new TC_AspectStack(TC_Aspects.PRAECANTATIO, 2), new TC_AspectStack(TC_Aspects.ELECTRUM, 1), new TC_AspectStack(TC_Aspects.GELUM, 1)));
public static Materials HydratedCoal = new Materials( 818, TextureSet.SET_ROUGH , 1.0F, 0, 1, 1 , 70, 70, 100, 0, "HydratedCoal" , "Hydrated Coal" , 0, 0, -1, 0, false, false, 1, 9, 8, Dyes.dyeBlack , 2, Arrays.asList(new MaterialStack(Coal, 8), new MaterialStack(Water, 1)));
public static Materials Apatite = new Materials( 530, TextureSet.SET_DIAMOND , 1.0F, 0, 1, 1 |4|8 , 200, 200, 255, 0, "Apatite" , "Apatite" , 0, 0, -1, 0, false, false, 2, 1, 1, Dyes.dyeCyan , 1, Arrays.asList(new MaterialStack(Calcium, 5), new MaterialStack(Phosphate, 3), new MaterialStack(Chlorine, 1)), Arrays.asList(new TC_AspectStack(TC_Aspects.MESSIS, 2)));
- public static Materials Alumite = new Materials( 400, TextureSet.SET_METALLIC , 5.0F, 768, 2, 1|2 |128 , 255, 105, 180, 0, "Alumite" , "Alumite" , 0, 0, -1, 0, false, false, 1, 1, 1, Dyes.dyePink , 2, Arrays.asList(new MaterialStack(Aluminium, 5), new MaterialStack(Steel, 2), new MaterialStack(Obsidian, 2)), Arrays.asList(new TC_AspectStack(TC_Aspects.STRONTIO, 2)));
+ public static Materials Alumite = new Materials( 400, TextureSet.SET_METALLIC , 5.0F, 768, 2, 1|2 |64|128 , 255, 105, 180, 0, "Alumite" , "Alumite" , 0, 0, -1, 0, false, false, 1, 1, 1, Dyes.dyePink , 2, Arrays.asList(new MaterialStack(Aluminium, 5), new MaterialStack(Steel, 2), new MaterialStack(Obsidian, 2)), Arrays.asList(new TC_AspectStack(TC_Aspects.STRONTIO, 2)));
public static Materials Manyullyn = new Materials( 386, TextureSet.SET_SHINY , 25.0F, 2048, 5, 1|2 |8 |64|128 , 154, 76, 185, 0, "Manyullyn" , "Manyullyn" , 0, 0, 3600, 3600, true, false, 1, 1, 1, Dyes.dyePurple , 2, Arrays.asList(new MaterialStack(Cobalt, 1), new MaterialStack(Ardite, 1)), Arrays.asList(new TC_AspectStack(TC_Aspects.STRONTIO, 2))).disableAutoGeneratedBlastFurnaceRecipes();
public static Materials Steeleaf = new Materials( 339, TextureSet.SET_LEAF , 8.0F, 768, 3, 1|2 |64|128 , 50, 127, 50, 0, "Steeleaf" , "Steeleaf" , 5, 24, -1, 0, false, false, 4, 1, 1, Dyes.dyeGreen , 2, Arrays.asList(new MaterialStack(Steel, 1), new MaterialStack(Magic, 1)), Arrays.asList(new TC_AspectStack(TC_Aspects.HERBA, 2), new TC_AspectStack(TC_Aspects.METALLUM, 2), new TC_AspectStack(TC_Aspects.PRAECANTATIO, 1)));
public static Materials Knightmetal = new Materials( 362, TextureSet.SET_METALLIC , 8.0F, 1024, 3, 1|2 |64|128 , 210, 240, 200, 0, "Knightmetal" , "Knightmetal" , 5, 24, -1, 0, false, false, 4, 1, 1, Dyes.dyeLime , 2, Arrays.asList(new MaterialStack(Steel, 2), new MaterialStack(Magic, 1)), Arrays.asList(new TC_AspectStack(TC_Aspects.LUCRUM, 1), new TC_AspectStack(TC_Aspects.METALLUM, 2)));
diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java
index de2c0919e7..3a9af71aa2 100644
--- a/src/main/java/gregtech/api/enums/Textures.java
+++ b/src/main/java/gregtech/api/enums/Textures.java
@@ -80,6 +80,7 @@ public class Textures {
BLOCK_STEELEAF,
BLOCK_ICHORIUM,
BLOCK_FIRESTONE,
+ BLOCK_SHADOW,
OVERLAY_ENERGY_IN_POWER,
OVERLAY_ENERGY_OUT_POWER,
@@ -903,7 +904,9 @@ public class Textures {
PIPE_RESTRICTOR_UR,
PIPE_RESTRICTOR_DL,
PIPE_RESTRICTOR_DR,
- PIPE_RESTRICTOR_LR;
+ PIPE_RESTRICTOR_LR,
+
+ OVERLAY_ME_HATCH;
/**
* Icon for Fresh CFoam
@@ -1302,7 +1305,8 @@ public class Textures {
BLOCK_HSSS,
BLOCK_STEELEAF,
BLOCK_ICHORIUM,
- BLOCK_FIRESTONE
+ BLOCK_FIRESTONE,
+ BLOCK_SHADOW
},
STORAGE_BLOCKS9 = new IIconContainer[]{
BLOCK_AERCRYSTAL,
diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
index 7e14061d2f..38f8bd3b35 100644
--- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
+++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
@@ -4,11 +4,16 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
+import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidContainerItem;
+
+import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -179,17 +184,159 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank {
@Override
public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) {
+ GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity();
+ if (machine == null) return null;
+ ItemStack tResultStack;
switch (aSlotIndex) {
case 0:
- if (mTileEntity.getMetaTileEntity() == null) return null;
- ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mFluidTransfer = !((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mFluidTransfer;
+ machine.mFluidTransfer = !machine.mFluidTransfer;
return null;
case 1:
if (mTileEntity.getMetaTileEntity() == null) return null;
- ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer = !((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer;
+ machine.mItemTransfer = !machine.mItemTransfer;
return null;
+ case 2:
+ if (aMouseclick > 1)
+ return null;
+ tResultStack = pickupFluid(machine.getDrainableStack(), aPlayer, aMouseclick == 0);
+ if (machine.getDrainableStack() != null && machine.getDrainableStack().amount == 0)
+ machine.setDrainableStack(null);
+ return tResultStack;
default:
- return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
+ if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length) {
+ if (aMouseclick > 1)
+ return null;
+ // input fluid slot
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null;
+ FluidStack tInputFluid = machine.getFillableStack();
+ FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true);
+ if (tInputFluid == null) {
+ if (tFluidHeld == null)
+ // both null -> no op
+ return null;
+ return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0);
+ } else {
+ if (tFluidHeld != null) {
+ // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here
+ return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0);
+ } else {
+ tResultStack = pickupFluid(tInputFluid, aPlayer, aMouseclick == 0);
+ if (tInputFluid.amount == 0)
+ machine.setFillableStack(null);
+ return tResultStack;
+ }
+ }
+ } else {
+ return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
+ }
+ }
+ }
+
+ private ItemStack pickupFluid(FluidStack aTankStack, EntityPlayer aPlayer, boolean aProcessFullStack) {
+ if (aTankStack == null) return null;
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null;
+ int tOriginalFluidAmount = aTankStack.amount;
+ ItemStack tFilled = GT_Utility.fillFluidContainer(aTankStack, tStackSizedOne, true, false);
+ if (tFilled == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) {
+ IFluidContainerItem tContainerItem = (IFluidContainerItem) tStackSizedOne.getItem();
+ int tFilledAmount = tContainerItem.fill(tStackSizedOne, aTankStack, true);
+ if (tFilledAmount > 0) {
+ tFilled = tStackSizedOne;
+ aTankStack.amount -= tFilledAmount;
+ }
+ }
+ if (tFilled != null) {
+ if (aProcessFullStack) {
+ int tFilledAmount = tOriginalFluidAmount - aTankStack.amount;
+ /*
+ work out how many more items we can fill
+ one cell is already used, so account for that
+ the round down behavior will left over a fraction of a cell worth of fluid
+ the user then get to decide what to do with it
+ it will not be too fancy if it spills out partially filled cells
+ */
+ int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, aTankStack.amount / tFilledAmount);
+ aTankStack.amount -= tFilledAmount * tAdditionalParallel;
+ tFilled.stackSize += tAdditionalParallel;
+ }
+ replaceCursorItemStack(aPlayer, tFilled);
+ }
+ return tFilled;
+ }
+
+ private ItemStack fillFluid(GT_MetaTileEntity_BasicMachine aMachine, EntityPlayer aPlayer, FluidStack aFluidHeld, boolean aProcessFullStack) {
+ // we are not using aMachine.fill() here any more, so we need to check for fluid type here ourselves
+ if (aMachine.getFillableStack() != null && !aMachine.getFillableStack().isFluidEqual(aFluidHeld))
+ return null;
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null)
+ return null;
+
+ int tFreeSpace = aMachine.getCapacity() - (aMachine.getFillableStack() != null ? aMachine.getFillableStack().amount : 0);
+ if (tFreeSpace <= 0)
+ // no space left
+ return null;
+
+ // find out how much fluid can be taken
+ // some cells cannot be partially filled
+ ItemStack tStackEmptied = null;
+ int tAmountTaken = 0;
+ if (tFreeSpace >= aFluidHeld.amount) {
+ // fully accepted - try take it from item now
+ // IFluidContainerItem is intentionally not checked here. it will be checked later
+ tStackEmptied = GT_Utility.getContainerForFilledItem(tStackSizedOne, false);
+ tAmountTaken = aFluidHeld.amount;
+ }
+ if (tStackEmptied == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) {
+ // either partially accepted, or is IFluidContainerItem
+ IFluidContainerItem container = (IFluidContainerItem) tStackSizedOne.getItem();
+ FluidStack tDrained = container.drain(tStackSizedOne, tFreeSpace, true);
+ if (tDrained != null && tDrained.amount > 0) {
+ // something is actually drained - change the cell and drop it to player
+ tStackEmptied = tStackSizedOne;
+ tAmountTaken = tDrained.amount;
+ }
+ }
+ if (tStackEmptied == null)
+ // somehow the cell refuse to give out that amount of fluid, no op then
+ return null;
+
+ // find out how many fill can we do
+ // same round down behavior as above
+ // however here the fluid stack is not changed at all, so the exact code will slightly differ
+ int tParallel = aProcessFullStack ? Math.min(tFreeSpace / tAmountTaken, tStackHeld.stackSize) : 1;
+ if (aMachine.getFillableStack() == null) {
+ FluidStack tNewFillableStack = aFluidHeld.copy();
+ tNewFillableStack.amount = tAmountTaken * tParallel;
+ aMachine.setFillableStack(tNewFillableStack);
+ } else {
+ aMachine.getFillableStack().amount += tAmountTaken * tParallel;
+ }
+ tStackEmptied.stackSize = tParallel;
+ replaceCursorItemStack(aPlayer, tStackEmptied);
+ return tStackEmptied;
+ }
+
+ private void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) {
+ int tStackResultMaxStackSize = tStackResult.getMaxStackSize();
+ while (tStackResult.stackSize > tStackResultMaxStackSize) {
+ aPlayer.inventory.getItemStack().stackSize -= tStackResultMaxStackSize;
+ GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult.splitStack(tStackResultMaxStackSize));
+ }
+ if (aPlayer.inventory.getItemStack().stackSize == tStackResult.stackSize) {
+ // every cell is mutated. it could just stay on the cursor.
+ aPlayer.inventory.setItemStack(tStackResult);
+ } else {
+ // some cells not mutated. The mutated cells must go into the inventory
+ // or drop into the world if there isn't enough space.
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ tStackHeld.stackSize -= tStackResult.stackSize;
+ GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult);
}
}
diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java
index c7288cc26e..a9de87e751 100644
--- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java
+++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java
@@ -610,10 +610,13 @@ public interface IGT_RecipeAdder {
boolean addAutoclaveRecipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluid, ItemStack aOutput, int aChance, int aDuration, int aEUt, boolean aCleanroom);
+ boolean addAutoclaveRecipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluidIn, FluidStack aFluidOut, ItemStack aOutput, int aChance, int aDuration, int aEUt, boolean aCleanroom);
+
boolean addAutoclaveSpaceRecipe(ItemStack aInput, FluidStack aFluid, ItemStack aOutput, int aChance, int aDuration, int aEUt, boolean aCleanroom);
boolean addAutoclaveSpaceRecipe(ItemStack aInput, ItemStack aCircuit, FluidStack aFluid, ItemStack aOutput, int aChance, int aDuration, int aEUt, boolean aCleanroom);
+
/**
* Adds a Recipe for the Mixer
*/
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index f5bcf8bfbd..9fd8e75754 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -1,5 +1,15 @@
package gregtech.api.metatileentity;
+import appeng.api.networking.IGridNode;
+import appeng.api.networking.security.IActionHost;
+import appeng.api.util.AECableType;
+import appeng.api.util.DimensionalCoord;
+import appeng.me.helpers.AENetworkProxy;
+import appeng.me.helpers.IGridProxyable;
+import appeng.tile.TileEvent;
+import appeng.tile.events.TileEventType;
+import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.Optional;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ItemList;
@@ -51,7 +61,10 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
* <p/>
* This is the main TileEntity for EVERYTHING.
*/
-public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity {
+@Optional.InterfaceList(value = {
+ @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true),
+ @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)})
+public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable {
private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior};
protected MetaTileEntity mMetaTileEntity;
protected long mStoredEnergy = 0, mStoredSteam = 0;
@@ -918,11 +931,15 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
mMetaTileEntity.setBaseMetaTileEntity(null);
}
super.invalidate();
+ if (GregTech_API.mAE2)
+ invalidateAE();
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
+ if (GregTech_API.mAE2)
+ onChunkUnloadAE();
}
@Override
@@ -2210,5 +2227,78 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
}
return slotIndex + indexShift;
}
-}
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public IGridNode getGridNode(ForgeDirection forgeDirection) {
+ if (mFacing != forgeDirection.ordinal())
+ return null;
+ AENetworkProxy gp = getProxy();
+ return gp != null ? gp.getNode() : null;
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public AECableType getCableConnectionType(ForgeDirection forgeDirection) {
+ return mMetaTileEntity == null ? AECableType.NONE : mMetaTileEntity.getCableConnectionType(forgeDirection);
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public void securityBreak() {}
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public IGridNode getActionableNode() {
+ AENetworkProxy gp = getProxy();
+ return gp != null ? gp.getNode() : null;
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public AENetworkProxy getProxy() {
+ return mMetaTileEntity == null ? null : mMetaTileEntity.getProxy();
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public DimensionalCoord getLocation() { return new DimensionalCoord( this ); }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public void gridChanged() {
+ if (mMetaTileEntity != null)
+ mMetaTileEntity.gridChanged();
+ }
+
+ @TileEvent( TileEventType.WORLD_NBT_READ )
+ @Optional.Method(modid = "appliedenergistics2")
+ public void readFromNBT_AENetwork( final NBTTagCompound data )
+ {
+ AENetworkProxy gp = getProxy();
+ if (gp != null)
+ getProxy().readFromNBT( data );
+ }
+
+ @TileEvent( TileEventType.WORLD_NBT_WRITE )
+ @Optional.Method(modid = "appliedenergistics2")
+ public void writeToNBT_AENetwork( final NBTTagCompound data )
+ {
+ AENetworkProxy gp = getProxy();
+ if (gp != null)
+ gp.writeToNBT( data );
+ }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ void onChunkUnloadAE() {
+ AENetworkProxy gp = getProxy();
+ if (gp != null)
+ gp.onChunkUnload();
+ }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ void invalidateAE() {
+ AENetworkProxy gp = getProxy();
+ if (gp != null)
+ gp.invalidate();
+ }
+}
diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
index 9fa16b9890..31ec73d04b 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
@@ -130,6 +130,10 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
*/
public abstract boolean renderInside(byte aSide);
+ public boolean isDisplaySecondaryDescription() {
+ return false;
+ }
+
@Override
public IGregTechTileEntity getBaseMetaTileEntity() {
return mBaseMetaTileEntity;
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
index d873627e21..79447a96cb 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
@@ -1,5 +1,9 @@
package gregtech.api.metatileentity;
+import appeng.api.util.AECableType;
+import appeng.me.helpers.AENetworkProxy;
+import appeng.me.helpers.IGridProxyable;
+import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
@@ -95,6 +99,14 @@ public abstract class MetaTileEntity implements IMetaTileEntity {
mName = aName;
}
+ /**
+ * This method will only be called on client side
+ * @return whether the secondary description should be display. default is false
+ */
+ public boolean isDisplaySecondaryDescription() {
+ return false;
+ }
+
@Override
public IGregTechTileEntity getBaseMetaTileEntity() {
return mBaseMetaTileEntity;
@@ -935,4 +947,17 @@ public abstract class MetaTileEntity implements IMetaTileEntity {
public boolean shouldJoinIc2Enet() { return false; }
public boolean shouldTriggerBlockUpdate() { return false; }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ public AECableType getCableConnectionType(ForgeDirection forgeDirection) {
+ return AECableType.NONE;
+ }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ public AENetworkProxy getProxy() {
+ return null;
+ }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ public void gridChanged() {}
}
diff --git a/src/main/java/gregtech/api/metatileentity/examples/GT_MetaTileEntity_E_Furnace.java b/src/main/java/gregtech/api/metatileentity/examples/GT_MetaTileEntity_E_Furnace.java
index 4d54a142cd..d0f3074af1 100644
--- a/src/main/java/gregtech/api/metatileentity/examples/GT_MetaTileEntity_E_Furnace.java
+++ b/src/main/java/gregtech/api/metatileentity/examples/GT_MetaTileEntity_E_Furnace.java
@@ -44,7 +44,7 @@ public class GT_MetaTileEntity_E_Furnace extends GT_MetaTileEntity_BasicMachine
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
- return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && GT_ModHandler.getSmeltingOutput(GT_Utility.copyAmount(64, aStack), false, null) != null;
+ return super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack) && (mDisableFilter || GT_ModHandler.getSmeltingOutput(GT_Utility.copyAmount(64, aStack), false, null) != null);
}
@Override
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
index 4fc3b28dc9..e472305a36 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
@@ -675,4 +675,16 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
if (inputAABB.intersectsWith(aabb)) outputAABB.add(aabb);
}
}
+ @Override
+ public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) {
+ if (aFluid == null)
+ return null;
+ for (int i = 0; i < mFluids.length; ++i) {
+ final FluidStack f = mFluids[i];
+ if (f == null || !f.isFluidEqual(aFluid))
+ continue;
+ return drainFromIndex(aFluid.amount, doDrain, i);
+ }
+ return null;
+ }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
index 497e42b9aa..fa653df16f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
@@ -23,6 +23,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
@@ -53,6 +54,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
public final ItemStack[] mOutputItems;
public final int mInputSlotCount, mAmperage;
public boolean mAllowInputFromOutputSide = false, mFluidTransfer = false, mItemTransfer = false, mHasBeenUpdated = false, mStuttering = false, mCharge = false, mDecharge = false;
+ public boolean mDisableFilter = true;
public int mMainFacing = -1, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mOutputBlocked = 0;
public FluidStack mOutputFluid;
public String mGUIName, mNEIName;
@@ -418,6 +420,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
aNBT.setBoolean("mItemTransfer", mItemTransfer);
aNBT.setBoolean("mHasBeenUpdated", mHasBeenUpdated);
aNBT.setBoolean("mAllowInputFromOutputSide", mAllowInputFromOutputSide);
+ aNBT.setBoolean("mDisableFilter", mDisableFilter);
aNBT.setInteger("mEUt", mEUt);
aNBT.setInteger("mMainFacing", mMainFacing);
aNBT.setInteger("mProgresstime", mProgresstime);
@@ -437,6 +440,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
mItemTransfer = aNBT.getBoolean("mItemTransfer");
mHasBeenUpdated = aNBT.getBoolean("mHasBeenUpdated");
mAllowInputFromOutputSide = aNBT.getBoolean("mAllowInputFromOutputSide");
+ mDisableFilter = aNBT.getBoolean("mDisableFilter");
mEUt = aNBT.getInteger("mEUt");
mMainFacing = aNBT.getInteger("mMainFacing");
mProgresstime = aNBT.getInteger("mProgresstime");
@@ -791,8 +795,13 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
@Override
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (aSide == getBaseMetaTileEntity().getFrontFacing() || aSide == mMainFacing) {
- mAllowInputFromOutputSide = !mAllowInputFromOutputSide;
- GT_Utility.sendChatToPlayer(aPlayer, mAllowInputFromOutputSide ? trans("095","Input from Output Side allowed") : trans("096","Input from Output Side forbidden"));
+ if (aPlayer.isSneaking()){
+ mDisableFilter = !mDisableFilter;
+ GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter." + mDisableFilter));
+ } else {
+ mAllowInputFromOutputSide = !mAllowInputFromOutputSide;
+ GT_Utility.sendChatToPlayer(aPlayer, mAllowInputFromOutputSide ? trans("095", "Input from Output Side allowed") : trans("096", "Input from Output Side forbidden"));
+ }
}
}
@@ -810,11 +819,16 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
if (aSide == mMainFacing || aIndex < getInputSlot() || aIndex >= getInputSlot() + mInputSlotCount || (!mAllowInputFromOutputSide && aSide == aBaseMetaTileEntity.getFrontFacing()))
return false;
+ if (mDisableFilter) return true;
for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++)
if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get(aStack), mInventory[i])) return i == aIndex;
return true;
}
+ protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
+ return true;
+ }
+
/**
* @return the Recipe List which is used for this Machine, this is a useful Default Handler
*/
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
index 7b622cb45c..147973b183 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
@@ -746,7 +746,7 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
if (!super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) return false;
- if (this.mInventory[aIndex] != null) return true;
+ if (this.mInventory[aIndex] != null || mDisableFilter) return true;
switch (this.mInputSlotCount) {
case 0:
return false;
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
index b3998b62e7..1e5c86108b 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
@@ -35,8 +35,8 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch {
System.arraycopy(mDescriptionArray, 0, desc, 0, mDescriptionArray.length);
desc[mDescriptionArray.length] = "DO NOT OBSTRUCT THE OUTPUT!";
desc[mDescriptionArray.length + 1] = "Reduces Pollution to " + calculatePollutionReduction(100) + "%";
- //Pollution Recovery scales from 5% at LV to 100% at MAX Voltage
- desc[mDescriptionArray.length + 2] = "Recovers " + (105 - calculatePollutionReduction(100)) + "% of CO2/CO/SO2";
+ //Pollution Recovery scales from 0% at LV to 100% at UHV Voltage
+ desc[mDescriptionArray.length + 2] = "Recovers " + (100 - calculatePollutionReduction(100)) + "% of CO2/CO/SO2";
return desc;
}
@@ -97,7 +97,9 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch {
}
public int calculatePollutionReduction(int aPollution) {
- return (int) (aPollution * (Math.pow(0.85F, mTier - 1)));
+ if ((float) mTier < 2)
+ return aPollution;
+ return (int) ((float) aPollution * ((100F - (12.5F * ((float) mTier - 1F))) / 100F));
}
@Override
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
index 1dafbcce5a..aaa0dc9df5 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
@@ -20,6 +20,10 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch {
"Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")});
}
+ public GT_MetaTileEntity_Hatch_OutputBus(int aID, String aName, String aNameRegional, int aTier, String[] aDescription) {
+ super(aID, aName, aNameRegional, aTier, getSlots(aTier), aDescription);
+ }
+
public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures);
}
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 e15166cf62..6f211631f2 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
@@ -16,6 +16,8 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
import gregtech.common.GT_Pollution;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
+import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME;
+
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
@@ -23,6 +25,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
+import org.lwjgl.input.Keyboard;
import java.util.ArrayList;
@@ -70,6 +73,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
@Override
+ public boolean isDisplaySecondaryDescription() {
+ return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
+ }
+
+ @Override
public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCoverID) {
return aSide != getBaseMetaTileEntity().getFrontFacing();
}
@@ -727,11 +735,25 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
public boolean addOutput(ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) return false;
aStack = GT_Utility.copy(aStack);
-// FluidStack aLiquid = GT_Utility.getFluidForFilledItem(aStack, true);
-// if (aLiquid == null) {
boolean outputSuccess = true;
while (outputSuccess && aStack.stackSize > 0) {
outputSuccess = false;
+
+ if (GregTech_API.mAE2) {
+ // this separate cycle may be refactored out, after this function will hopefully be totally refactored
+ // for now it is here to avoid splitting stack when we have ME output bus
+ for (GT_MetaTileEntity_Hatch_OutputBus tHatch : mOutputBusses) {
+ // TODO: If ever there will be another hatch storing in some external storage, here should be an interface check
+ if (tHatch instanceof GT_MetaTileEntity_Hatch_OutputBus_ME && isValidMetaTileEntity(tHatch)) {
+ int rest = ((GT_MetaTileEntity_Hatch_OutputBus_ME) tHatch).store(aStack);
+ if (rest != aStack.stackSize)
+ outputSuccess = true;
+ aStack.stackSize = rest;
+ if (rest == 0)
+ return true;
+ }
+ }
+ }
ItemStack single = aStack.splitStack(1);
for (GT_MetaTileEntity_Hatch_OutputBus tHatch : mOutputBusses) {
if (!outputSuccess && isValidMetaTileEntity(tHatch)) {
@@ -746,16 +768,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
}
}
-// }else {
-// for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
-// if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid)?tHatch.outputsSteam():tHatch.outputsLiquids()) {
-// int tAmount = tHatch.fill(aLiquid, false);
-// if (tAmount >= aLiquid.amount) {
-// return tHatch.fill(aLiquid, true) >= aLiquid.amount;
-// }
-// }
-// }
-// }
return outputSuccess;
}
diff --git a/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java b/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java
index 8b26ef6423..fff5965d3d 100644
--- a/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java
+++ b/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java
@@ -17,7 +17,7 @@ public class AE2DigitalChestHandler implements appeng.api.storage.IExternalStora
@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.IMEInventory getInventory(final TileEntity te, final ForgeDirection d, final appeng.api.storage.StorageChannel chan, final appeng.api.networking.security.BaseActionSource src) {
if (chan == appeng.api.storage.StorageChannel.ITEMS) {
- return new appeng.me.storage.MEMonitorIInventory(new appeng.util.inv.IMEAdaptor((GT_MetaTileEntity_DigitalChestBase) (((BaseMetaTileEntity) te).getMetaTileEntity()), src));
+ return ((GT_MetaTileEntity_DigitalChestBase) (((BaseMetaTileEntity) te).getMetaTileEntity()));
}
return null;
}
diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
index 8f7a84e2cb..3ce1daf9b2 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
@@ -3,6 +3,7 @@ package gregtech.api.threads;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable;
+import gregtech.common.GT_Proxy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
@@ -101,8 +102,19 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
try {
while (!tQueue.isEmpty()) {
final ChunkCoordinates aCoords = tQueue.poll();
- TileEntity tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
-
+ final TileEntity tTileEntity;
+ final boolean isMachineBlock;
+
+ // This might load a chunk... which might load a TileEntity... which might get added to `loadedTileEntityList`... which might be in the process
+ // of being iterated over during `UpdateEntities()`... which might cause a ConcurrentModificationException. So, lock that shit.
+ GT_Proxy.TICK_LOCK.lock();
+ try {
+ tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
+ isMachineBlock = GregTech_API.isMachineBlock(world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ), world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ));
+ } finally {
+ GT_Proxy.TICK_LOCK.unlock();
+ }
+
// See if the block itself needs an update
if (tTileEntity instanceof IMachineBlockUpdateable)
((IMachineBlockUpdateable) tTileEntity).onMachineBlockUpdate();
@@ -113,7 +125,7 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
// 3) If the block at the coordinates is marked as a machine block
if (visited.size() < 5
|| (tTileEntity instanceof IMachineBlockUpdateable && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())
- || GregTech_API.isMachineBlock(world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ), world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ)))
+ || isMachineBlock)
{
ChunkCoordinates tCoords;
diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java
index c87e0f7417..5046af9e5f 100644
--- a/src/main/java/gregtech/api/util/GT_LanguageManager.java
+++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java
@@ -33,8 +33,12 @@ public class GT_LanguageManager {
TEMPMAP.put(aKey.trim(), aEnglish);
LanguageRegistry.instance().injectLanguage("en_US", TEMPMAP);
TEMPMAP.clear();
- if(sUseEnglishFile && !aWriteIntoLangFile && LANGMAP.containsKey(aKey)){
- aEnglish = LANGMAP.get(aKey);
+ if(sUseEnglishFile && !aWriteIntoLangFile){
+ if (!LANGMAP.containsKey(aKey)) {
+ Property tProperty = sEnglishFile.get("LanguageFile", aKey, aEnglish);
+ aEnglish = tProperty.getString();
+ LANGMAP.put(aKey, aEnglish);
+ } else aEnglish = LANGMAP.get(aKey);
}
return aEnglish;
}
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index bfa3f86e77..484e4d29b9 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -54,13 +54,14 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Set;
import java.util.stream.Collectors;
+import static gregtech.GT_Mod.GT_FML_LOGGER;
import static gregtech.api.enums.GT_Values.B;
import static gregtech.api.enums.GT_Values.D1;
import static gregtech.api.enums.GT_Values.DW;
@@ -78,22 +79,28 @@ import static gregtech.api.enums.GT_Values.W;
* Due to the many imports, this File can cause compile Problems if not all the APIs are installed
*/
public class GT_ModHandler {
- public static final List<IRecipe> sSingleNonBlockDamagableRecipeList = new ArrayList<IRecipe>(1000);
- private static final Map<String, ItemStack> sIC2ItemMap = new HashMap<String, ItemStack>();
- private static final List<IRecipe> sAllRecipeList = /*Collections.synchronizedList(*/new ArrayList<IRecipe>(5000)/*)*/, sBufferRecipeList = new ArrayList<IRecipe>(1000);
+ public static final List<IRecipe> sSingleNonBlockDamagableRecipeList = new ArrayList<>(1000);
+ private static final Map<String, ItemStack> sIC2ItemMap = new HashMap<>();
+
+ private static final List<IRecipe> sAllRecipeList = new ArrayList<>(5000), sBufferRecipeList = new ArrayList<>(1000);
+ private static final List<ItemStack> delayedRemovalByOutput = new ArrayList<>();
+ private static final List<InventoryCrafting> delayedRemovalByRecipe = new ArrayList<>();
+
+
public static volatile int VERSION = 509;
- public static Collection<String> sNativeRecipeClasses = new HashSet<String>(), sSpecialRecipeClasses = new HashSet<String>();
- public static GT_HashSet<GT_ItemStack> sNonReplaceableItems = new GT_HashSet<GT_ItemStack>();
+ public static Collection<String> sNativeRecipeClasses = new HashSet<>(), sSpecialRecipeClasses = new HashSet<>();
+ public static GT_HashSet<GT_ItemStack> sNonReplaceableItems = new GT_HashSet<>();
public static Object sBoxableWrapper = GT_Utility.callConstructor("gregtechmod.api.util.GT_IBoxableWrapper", 0, null, false);
- private static Map<IRecipeInput, RecipeOutput> sExtractorRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
- private static Map<IRecipeInput, RecipeOutput> sMaceratorRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
- private static Map<IRecipeInput, RecipeOutput> sCompressorRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
- private static Map<IRecipeInput, RecipeOutput> sOreWashingRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
- private static Map<IRecipeInput, RecipeOutput> sThermalCentrifugeRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
- private static Map<IRecipeInput, RecipeOutput> sMassfabRecipes = new /*Concurrent*/HashMap<IRecipeInput, RecipeOutput>();
+ private static final Map<IRecipeInput, RecipeOutput> sExtractorRecipes = new HashMap<>();
+ private static final Map<IRecipeInput, RecipeOutput> sMaceratorRecipes = new HashMap<>();
+ private static final Map<IRecipeInput, RecipeOutput> sCompressorRecipes = new HashMap<>();
+ private static final Map<IRecipeInput, RecipeOutput> sOreWashingRecipes = new HashMap<>();
+ private static final Map<IRecipeInput, RecipeOutput> sThermalCentrifugeRecipes = new HashMap<>();
+ private static final Map<IRecipeInput, RecipeOutput> sMassfabRecipes = new HashMap<>();
+
private static boolean sBufferCraftingRecipes = true;
- public static List<Integer> sSingleNonBlockDamagableRecipeList_list = new ArrayList<Integer>(100);
- private static boolean sSingleNonBlockDamagableRecipeList_create = true;
+ public static List<Integer> sSingleNonBlockDamagableRecipeList_list = new ArrayList<>(100);
+ private static final boolean sSingleNonBlockDamagableRecipeList_create = true;
private static final ItemStack sMt1 = new ItemStack(Blocks.dirt, 1, 0), sMt2 = new ItemStack(Blocks.dirt, 1, 0);
private static final String s_H = "h", s_F = "f", s_I = "I", s_P = "P", s_R = "R";
private static final ItemStack[][]
@@ -143,12 +150,12 @@ public class GT_ModHandler {
{sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null},
{null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2}
};
- public static List<Integer> sSingleNonBlockDamagableRecipeList_validsShapes1 = new ArrayList<Integer>(44);
+ public static List<Integer> sSingleNonBlockDamagableRecipeList_validsShapes1 = new ArrayList<>(44);
public static boolean sSingleNonBlockDamagableRecipeList_validsShapes1_update = false;
- public static List<Integer> sSingleNonBlockDamagableRecipeList_warntOutput = new ArrayList<Integer>(50);
- public static List<Integer> sVanillaRecipeList_warntOutput = new ArrayList<Integer>(50);
- public static final List<IRecipe> sSingleNonBlockDamagableRecipeList_verified = new ArrayList<IRecipe>(1000);
- private static Cache<GT_ItemStack, ItemStack> sSmeltingRecipeCache = CacheBuilder.newBuilder().maximumSize(1000).build();
+ public static List<Integer> sSingleNonBlockDamagableRecipeList_warntOutput = new ArrayList<>(50);
+ public static List<Integer> sVanillaRecipeList_warntOutput = new ArrayList<>(50);
+ public static final List<IRecipe> sSingleNonBlockDamagableRecipeList_verified = new ArrayList<>(1000);
+ private static final Cache<GT_ItemStack, ItemStack> sSmeltingRecipeCache = CacheBuilder.newBuilder().maximumSize(1000).build();
public static List<Integer> sAnySteamFluidIDs = new ArrayList<>();
public static List<Integer> sSuperHeatedSteamFluidIDs = new ArrayList<>();
@@ -542,10 +549,8 @@ public class GT_ModHandler {
public static boolean addExtractionRecipe(ItemStack aInput, ItemStack aOutput) {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null) return false;
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getExtractorRecipeList(), null);
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.extractor, aInput, true)) return false;
RA.addExtractorRecipe(aInput, aOutput, 300, 2);
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.addSimpleIC2MachineRecipe(aInput, getExtractorRecipeList(), null, aOutput);
return true;
}
@@ -597,12 +602,8 @@ public class GT_ModHandler {
aOutput1 = GT_OreDictUnificator.get(true, aOutput1);
aOutput2 = GT_OreDictUnificator.get(true, aOutput2);
if (GT_Utility.isStackInvalid(aInput) || GT_Utility.isStackInvalid(aOutput1)) return false;
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getMaceratorRecipeList(), null);
if (GT_Utility.getContainerItem(aInput, false) == null) {
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.maceration, aInput, true)) {
- GT_Utility.addSimpleIC2MachineRecipe(aInput, getMaceratorRecipeList(), null, aOutput1);
- }
addMagneticraftRecipe(aInput, aOutput1, aOutput2, aChance2, aOutput3, aChance3);
addImmersiveEngineeringRecipe(aInput, aOutput1, aOutput2, aChance2, aOutput3, aChance3);
RA.addPulveriserRecipe(aInput, new ItemStack[]{aOutput1, aOutput2, aOutput3}, new int[]{10000, aChance2 <= 0 ? 1000 : 100 * aChance2, aChance3 <= 0 ? 1000 : 100 * aChance3}, 400, 2);
@@ -720,39 +721,34 @@ public class GT_ModHandler {
*/
public static void addIC2RecipesToGT(Map<IRecipeInput, RecipeOutput> aIC2RecipeList, GT_Recipe.GT_Recipe_Map aGTRecipeMap, boolean aAddGTRecipe, boolean aRemoveIC2Recipe, boolean aExcludeGTIC2Items) {
Map<ItemStack, ItemStack> aRecipesToRemove = new HashMap<>();
- for (Iterator i$ = aIC2RecipeList.entrySet().iterator(); i$.hasNext(); ) {
- Entry tRecipe = (Map.Entry) i$.next();
- if (((RecipeOutput) tRecipe.getValue()).items.size() > 0) {
- for (ItemStack tStack : ((IRecipeInput) tRecipe.getKey()).getInputs()) {
+ for (Entry<IRecipeInput, RecipeOutput> iRecipeInputRecipeOutputEntry : aIC2RecipeList.entrySet()) {
+ if ((iRecipeInputRecipeOutputEntry.getValue()).items.size() > 0) {
+ for (ItemStack tStack : (iRecipeInputRecipeOutputEntry.getKey()).getInputs()) {
if (GT_Utility.isStackValid(tStack)) {
if (aAddGTRecipe && (aGTRecipeMap.findRecipe(null, false, Long.MAX_VALUE, null, tStack) == null)) {
- try{
- if (aExcludeGTIC2Items && ((tStack.getUnlocalizedName().contains("gt.metaitem.01") || tStack.getUnlocalizedName().contains("gt.blockores") || tStack.getUnlocalizedName().contains("ic2.itemCrushed") || tStack.getUnlocalizedName().contains("ic2.itemPurifiedCrushed")))) continue;
- switch (aGTRecipeMap.mUnlocalizedName) {
- case "gt.recipe.macerator":
- aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount(((IRecipeInput) tRecipe.getKey()).getAmount(), tStack)}, (ItemStack[]) ((RecipeOutput) tRecipe.getValue()).items.toArray(), null, null, null, null, 300, 2, 0);
- break;
- case "gt.recipe.compressor":
- aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount(((IRecipeInput) tRecipe.getKey()).getAmount(), tStack)}, (ItemStack[]) ((RecipeOutput) tRecipe.getValue()).items.toArray(), null, null, null, null, 300, 2, 0);
- break;
- case "gt.recipe.extractor":
- aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount(((IRecipeInput) tRecipe.getKey()).getAmount(), tStack)}, (ItemStack[]) ((RecipeOutput) tRecipe.getValue()).items.toArray(), null, null, null, null, 300, 2, 0);
- break;
- case "gt.recipe.thermalcentrifuge":
- aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount(((IRecipeInput) tRecipe.getKey()).getAmount(), tStack)}, (ItemStack[]) ((RecipeOutput) tRecipe.getValue()).items.toArray(), null, null, null, null, 500, 48, 0);
- break;
+ try {
+ if (aExcludeGTIC2Items && ((tStack.getUnlocalizedName().contains("gt.metaitem.01") || tStack.getUnlocalizedName().contains("gt.blockores") || tStack.getUnlocalizedName().contains("ic2.itemCrushed") || tStack.getUnlocalizedName().contains("ic2.itemPurifiedCrushed"))))
+ continue;
+ switch (aGTRecipeMap.mUnlocalizedName) {
+ case "gt.recipe.macerator":
+ case "gt.recipe.extractor":
+ case "gt.recipe.compressor":
+ aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount((iRecipeInputRecipeOutputEntry.getKey()).getAmount(), tStack)}, (ItemStack[]) (iRecipeInputRecipeOutputEntry.getValue()).items.toArray(), null, null, null, null, 300, 2, 0);
+ break;
+ case "gt.recipe.thermalcentrifuge":
+ aGTRecipeMap.addRecipe(true, new ItemStack[]{GT_Utility.copyAmount((iRecipeInputRecipeOutputEntry.getKey()).getAmount(), tStack)}, (ItemStack[]) (iRecipeInputRecipeOutputEntry.getValue()).items.toArray(), null, null, null, null, 500, 48, 0);
+ break;
+ }
+ } catch (Exception e) {
+ System.err.println(e);
}
- }catch(Exception e){System.err.println(e);}
- //GT_FML_LOGGER.info("#####Processed IC2 " + aGTRecipeMap.mUnlocalizedName + " Recipe: In(" + tStack.getUnlocalizedName() + ") - Out(" + ((RecipeOutput) tRecipe.getValue()).items.get(0).getUnlocalizedName() + ")");
}
- if (aRemoveIC2Recipe) aRecipesToRemove.put(tStack, ((RecipeOutput) tRecipe.getValue()).items.get(0));
+ if (aRemoveIC2Recipe) aRecipesToRemove.put(tStack, ((RecipeOutput) iRecipeInputRecipeOutputEntry.getValue()).items.get(0));
}
}
}
}
- for (Entry<ItemStack, ItemStack> aEntry : aRecipesToRemove.entrySet()) {
- GT_Utility.removeSimpleIC2MachineRecipe(aEntry.getKey(), aIC2RecipeList, aEntry.getValue());
- }
+ GT_Utility.bulkRemoveSimpleIC2MachineRecipe(aRecipesToRemove, aIC2RecipeList);
}
public static Map<IRecipeInput, RecipeOutput> getExtractorRecipeList() {
@@ -802,14 +798,8 @@ public class GT_ModHandler {
*/
public static boolean addThermalCentrifugeRecipe(ItemStack aInput, int aHeat, Object... aOutput) {
if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false;
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getThermalCentrifugeRecipeList(), null);
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.thermalcentrifuge, aInput, true)) return false;
RA.addThermalCentrifugeRecipe(aInput, aOutput.length >= 1 ? (ItemStack)aOutput[0] : null, aOutput.length >= 2 ? (ItemStack)aOutput[1] : null, aOutput.length >= 3 ? (ItemStack)aOutput[2] : null, 500, 48);
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) {
- NBTTagCompound tNBT = new NBTTagCompound();
- tNBT.setInteger("minHeat", aHeat);
- GT_Utility.addSimpleIC2MachineRecipe(aInput, getThermalCentrifugeRecipeList(), tNBT, aOutput);
- }
return true;
}
@@ -818,15 +808,9 @@ public class GT_ModHandler {
*/
public static boolean addOreWasherRecipe(ItemStack aInput, int aWaterAmount, Object... aOutput) {
if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return false;
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getOreWashingRecipeList(), null);
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.orewashing, aInput, true)) return false;
RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getWater(1000L), 500, 16);
RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getDistilledWater(200L), 300, 16);
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) {
- NBTTagCompound tNBT = new NBTTagCompound();
- tNBT.setInteger("amount", aWaterAmount);
- GT_Utility.addSimpleIC2MachineRecipe(aInput, getOreWashingRecipeList(), tNBT, aOutput);
- }
return true;
}
@@ -836,10 +820,8 @@ public class GT_ModHandler {
public static boolean addCompressionRecipe(ItemStack aInput, ItemStack aOutput) {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null || GT_Utility.areStacksEqual(aInput, aOutput, true)) return false;
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getCompressorRecipeList(), null);
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.compression, aInput, true)) return false;
RA.addCompressorRecipe(aInput, aOutput, 300, 2);
- if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.addSimpleIC2MachineRecipe(aInput, getCompressorRecipeList(), null, aOutput);
return true;
}
@@ -873,7 +855,13 @@ public class GT_ModHandler {
public static void stopBufferingCraftingRecipes() {
sBufferCraftingRecipes = false;
- for (IRecipe tRecipe : sBufferRecipeList) {GameRegistry.addRecipe(tRecipe);}
+
+ bulkRemoveRecipeByOutput(delayedRemovalByOutput);
+ bulkRemoveByRecipe(delayedRemovalByRecipe);
+ sBufferRecipeList.forEach(GameRegistry::addRecipe);
+
+ delayedRemovalByOutput.clear();
+ delayedRemovalByRecipe.clear();
sBufferRecipeList.clear();
}
@@ -937,18 +925,54 @@ public class GT_ModHandler {
* 'x' ToolDictNames.craftingToolWireCutter,
*/
public static boolean addCraftingRecipe(ItemStack aResult, long aBitMask, Object[] aRecipe) {
- return addCraftingRecipe(aResult, new Enchantment[0], new int[0], (aBitMask & RecipeBits.MIRRORED) != 0, (aBitMask & RecipeBits.BUFFERED) != 0, (aBitMask & RecipeBits.KEEPNBT) != 0, (aBitMask & RecipeBits.DISMANTLEABLE) != 0, (aBitMask & RecipeBits.NOT_REMOVABLE) == 0, (aBitMask & RecipeBits.REVERSIBLE) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES_IF_SAME_NBT) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_SHAPED_RECIPES) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_NATIVE_RECIPES) != 0, (aBitMask & RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS) == 0, (aBitMask & RecipeBits.ONLY_ADD_IF_THERE_IS_ANOTHER_RECIPE_FOR_IT) != 0, (aBitMask & RecipeBits.ONLY_ADD_IF_RESULT_IS_NOT_NULL) != 0, aRecipe);
+ return addCraftingRecipe(
+ aResult,
+ new Enchantment[0],
+ new int[0],
+ (aBitMask & RecipeBits.MIRRORED) != 0,
+ (aBitMask & RecipeBits.BUFFERED) != 0,
+ (aBitMask & RecipeBits.KEEPNBT) != 0,
+ (aBitMask & RecipeBits.DISMANTLEABLE) != 0,
+ (aBitMask & RecipeBits.NOT_REMOVABLE) == 0,
+ (aBitMask & RecipeBits.REVERSIBLE) != 0,
+ (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES) != 0,
+ (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES_IF_SAME_NBT) != 0,
+ (aBitMask & RecipeBits.DELETE_ALL_OTHER_SHAPED_RECIPES) != 0,
+ (aBitMask & RecipeBits.DELETE_ALL_OTHER_NATIVE_RECIPES) != 0,
+ (aBitMask & RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS) == 0,
+ (aBitMask & RecipeBits.ONLY_ADD_IF_THERE_IS_ANOTHER_RECIPE_FOR_IT) != 0,
+ (aBitMask & RecipeBits.ONLY_ADD_IF_RESULT_IS_NOT_NULL) != 0,
+ aRecipe);
}
/**
* Internal realisation of the Crafting Recipe adding Process.
*/
- private static boolean addCraftingRecipe(ItemStack aResult, Enchantment[] aEnchantmentsAdded, int[] aEnchantmentLevelsAdded, boolean aMirrored, boolean aBuffered, boolean aKeepNBT, boolean aDismantleable, boolean aRemovable, boolean aReversible, boolean aRemoveAllOthersWithSameOutput, boolean aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, boolean aRemoveAllOtherShapedsWithSameOutput, boolean aRemoveAllOtherNativeRecipes, boolean aCheckForCollisions, boolean aOnlyAddIfThereIsAnyRecipeOutputtingThis, boolean aOnlyAddIfResultIsNotNull, Object[] aRecipe) {
+ private static boolean addCraftingRecipe(
+ ItemStack aResult,
+ Enchantment[] aEnchantmentsAdded,
+ int[] aEnchantmentLevelsAdded,
+ boolean aMirrored,
+ boolean aBuffered,
+ boolean aKeepNBT,
+ boolean aDismantleable,
+ boolean aRemovable,
+ boolean aReversible,
+ boolean aRemoveAllOthersWithSameOutput,
+ boolean aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT,
+ boolean aRemoveAllOtherShapedsWithSameOutput,
+ boolean aRemoveAllOtherNativeRecipes,
+ boolean aCheckForCollisions,
+ boolean aOnlyAddIfThereIsAnyRecipeOutputtingThis,
+ boolean aOnlyAddIfResultIsNotNull,
+ Object[] aRecipe
+ ) {
aResult = GT_OreDictUnificator.get(true, aResult);
if (aOnlyAddIfResultIsNotNull && aResult == null) return false;
if (aResult != null && Items.feather.getDamage(aResult) == W) Items.feather.setDamage(aResult, 0);
if (aRecipe == null || aRecipe.length <= 0) return false;
+ boolean tDoWeCareIfThereWasARecipe = aOnlyAddIfThereIsAnyRecipeOutputtingThis;
boolean tThereWasARecipe = false;
for (byte i = 0; i < aRecipe.length; i++) {
@@ -961,21 +985,21 @@ public class GT_ModHandler {
}
try {
- String shape = E;
+ StringBuilder shape = new StringBuilder(E);
int idx = 0;
if (aRecipe[idx] instanceof Boolean) {
throw new IllegalArgumentException();
}
- ArrayList<Object> tRecipeList = new ArrayList<Object>(Arrays.asList(aRecipe));
+ ArrayList<Object> tRecipeList = new ArrayList<>(Arrays.asList(aRecipe));
while (aRecipe[idx] instanceof String) {
- String s = (String) aRecipe[idx++];
- shape += s;
- while (s.length() < 3) s += " ";
+ StringBuilder s = new StringBuilder((String) aRecipe[idx++]);
+ shape.append(s);
+ while (s.length() < 3) s.append(" ");
if (s.length() > 3) throw new IllegalArgumentException();
- for (char c : s.toCharArray()) {
+ for (char c : s.toString().toCharArray()) {
switch (c) {
case 'b':
tRecipeList.add(c);
@@ -1042,8 +1066,8 @@ public class GT_ModHandler {
if (aRecipe[idx] instanceof Boolean) {
idx++;
}
- /*ConcurrentHash*/Map<Character, ItemStack> tItemStackMap = new /*ConcurrentHash*/HashMap<Character, ItemStack>();
- /*ConcurrentHash*/Map<Character, ItemData> tItemDataMap = new /*ConcurrentHash*/HashMap<Character, ItemData>();
+ Map<Character, ItemStack> tItemStackMap = new HashMap<>();
+ Map<Character, ItemData> tItemDataMap = new HashMap<>();
tItemStackMap.put(' ', null);
boolean tRemoveRecipe = true;
@@ -1063,16 +1087,22 @@ public class GT_ModHandler {
tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in));
} else if (in instanceof ItemData) {
String tString = in.toString();
- if (tString.equals("plankWood")) {
- tItemDataMap.put(chr, new ItemData(Materials.Wood, M));
- } else if (tString.equals("stoneNetherrack")) {
- tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M));
- } else if (tString.equals("stoneObsidian")) {
- tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M));
- } else if (tString.equals("stoneEndstone")) {
- tItemDataMap.put(chr, new ItemData(Materials.Endstone, M));
- } else {
- tItemDataMap.put(chr, (ItemData) in);
+ switch (tString) {
+ case "plankWood":
+ tItemDataMap.put(chr, new ItemData(Materials.Wood, M));
+ break;
+ case "stoneNetherrack":
+ tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M));
+ break;
+ case "stoneObsidian":
+ tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M));
+ break;
+ case "stoneEndstone":
+ tItemDataMap.put(chr, new ItemData(Materials.Endstone, M));
+ break;
+ default:
+ tItemDataMap.put(chr, (ItemData) in);
+ break;
}
ItemStack tStack = GT_OreDictUnificator.getFirstOre(in, 1);
if (tStack == null) tRemoveRecipe = false;
@@ -1102,7 +1132,7 @@ public class GT_ModHandler {
if (aReversible && aResult != null) {
ItemData[] tData = new ItemData[9];
int x = -1;
- for (char chr : shape.toCharArray()) tData[++x] = tItemDataMap.get(chr);
+ for (char chr : shape.toString().toCharArray()) tData[++x] = tItemDataMap.get(chr);
if (GT_Utility.arrayContainsNonNull(tData))
GT_OreDictUnificator.addItemData(aResult, new ItemData(tData));
}
@@ -1110,12 +1140,15 @@ public class GT_ModHandler {
if (aCheckForCollisions && tRemoveRecipe) {
ItemStack[] tRecipe = new ItemStack[9];
int x = -1;
- for (char chr : shape.toCharArray()) {
+ for (char chr : shape.toString().toCharArray()) {
tRecipe[++x] = tItemStackMap.get(chr);
if (tRecipe[x] != null && Items.feather.getDamage(tRecipe[x]) == W)
Items.feather.setDamage(tRecipe[x], 0);
}
- tThereWasARecipe = removeRecipe(tRecipe) != null || tThereWasARecipe;
+ if (tDoWeCareIfThereWasARecipe || !aBuffered)
+ tThereWasARecipe = removeRecipe(tRecipe) != null || tThereWasARecipe;
+ else
+ removeRecipeDelayed(tRecipe);
}
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
@@ -1123,10 +1156,14 @@ public class GT_ModHandler {
if (aResult == null || aResult.stackSize <= 0) return false;
- if (aRemoveAllOthersWithSameOutput || aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT || aRemoveAllOtherShapedsWithSameOutput || aRemoveAllOtherNativeRecipes)
- tThereWasARecipe = removeRecipeByOutput(aResult, !aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, aRemoveAllOtherShapedsWithSameOutput, aRemoveAllOtherNativeRecipes) || tThereWasARecipe;
-
- if (aOnlyAddIfThereIsAnyRecipeOutputtingThis && !tThereWasARecipe) {
+ if (aRemoveAllOthersWithSameOutput || aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT || aRemoveAllOtherShapedsWithSameOutput || aRemoveAllOtherNativeRecipes) {
+ if(tDoWeCareIfThereWasARecipe || !aBuffered)
+ tThereWasARecipe = removeRecipeByOutput(aResult, !aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, aRemoveAllOtherShapedsWithSameOutput, aRemoveAllOtherNativeRecipes) || tThereWasARecipe;
+ else
+ removeRecipeByOutputDelayed(aResult);
+ }
+
+ if (aOnlyAddIfThereIsAnyRecipeOutputtingThis && !tDoWeCareIfThereWasARecipe && !tThereWasARecipe) {
ArrayList<IRecipe> tList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
int tList_sS=tList.size();
for (int i = 0; i < tList_sS && !tThereWasARecipe; i++) {
@@ -1203,14 +1240,13 @@ public class GT_ModHandler {
} else if (tObject instanceof String) {
tRecipe[i] = GT_OreDictUnificator.getFirstOre(tObject, 1);
if (tRecipe[i] == null) break;
- }/* else if (tObject instanceof Boolean) {
- //
- } else {
- throw new IllegalArgumentException();
- }*/
+ }
i++;
}
- removeRecipe(tRecipe);
+ if (sBufferCraftingRecipes && aBuffered)
+ removeRecipeDelayed(tRecipe);
+ else
+ removeRecipe(tRecipe);
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
@@ -1252,14 +1288,8 @@ public class GT_ModHandler {
*/
public static ItemStack removeRecipe(ItemStack... aRecipe) {
if (aRecipe == null) return null;
- boolean temp = false;
- for (byte i = 0; i < aRecipe.length; i++) {
- if (aRecipe[i] != null) {
- temp = true;
- break;
- }
- }
- if (!temp) return null;
+ if (Arrays.stream(aRecipe).noneMatch(Objects::nonNull)) return null;
+
ItemStack rReturn = null;
InventoryCrafting aCrafting = new InventoryCrafting(new Container() {
@Override
@@ -1282,6 +1312,53 @@ public class GT_ModHandler {
return rReturn;
}
+
+ public static void removeRecipeDelayed(ItemStack... aRecipe) {
+ if (!sBufferCraftingRecipes) {
+ removeRecipe(aRecipe);
+ return;
+ }
+
+ if (aRecipe == null) return;
+ if (Arrays.stream(aRecipe).noneMatch(Objects::nonNull)) return;
+
+ InventoryCrafting aCrafting = new InventoryCrafting(new Container() {
+ @Override
+ public boolean canInteractWith(EntityPlayer var1) {
+ return false;
+ }
+ }, 3, 3);
+ for (int i = 0; i < aRecipe.length && i < 9; i++) aCrafting.setInventorySlotContents(i, aRecipe[i]);
+ delayedRemovalByRecipe.add(aCrafting);
+ }
+
+ public static void bulkRemoveByRecipe(List<InventoryCrafting> toRemove) {
+ ArrayList<IRecipe> tList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
+ GT_FML_LOGGER.info("BulkRemoveByRecipe: tList: " + tList.size() + " toRemove: " + toRemove.size() );
+
+ Set<IRecipe> tListToRemove = tList.parallelStream().filter(tRecipe -> {
+ if ((tRecipe instanceof IGT_CraftingRecipe) && !((IGT_CraftingRecipe) tRecipe).isRemovable()) return false;
+ return toRemove.stream().anyMatch(aCrafting -> tRecipe.matches(aCrafting, DW));
+ }).collect(Collectors.toSet());
+
+ tList.removeIf(tListToRemove::contains);
+ }
+
+ public static boolean removeRecipeByOutputDelayed(ItemStack aOutput) {
+ if (sBufferCraftingRecipes)
+ return delayedRemovalByOutput.add(aOutput);
+ else
+ return removeRecipeByOutput(aOutput);
+ }
+
+ public static boolean removeRecipeByOutputDelayed (ItemStack aOutput, boolean aIgnoreNBT, boolean aNotRemoveShapelessRecipes, boolean aOnlyRemoveNativeHandlers) {
+ if (sBufferCraftingRecipes && (aIgnoreNBT && !aNotRemoveShapelessRecipes && !aOnlyRemoveNativeHandlers))
+ // Too lazy to handle deferred versions of the parameters that aren't used very often
+ return delayedRemovalByOutput.add(aOutput);
+ else
+ return removeRecipeByOutput(aOutput, aIgnoreNBT, aNotRemoveShapelessRecipes, aOnlyRemoveNativeHandlers);
+ }
+
public static boolean removeRecipeByOutput(ItemStack aOutput) {
return removeRecipeByOutput(aOutput, true, false, false);
}
@@ -1308,7 +1385,10 @@ public class GT_ModHandler {
if (sSpecialRecipeClasses.contains(tRecipe.getClass().getName())) continue;
}
ItemStack tStack = tRecipe.getRecipeOutput();
- if ((!(tRecipe instanceof IGT_CraftingRecipe) || ((IGT_CraftingRecipe) tRecipe).isRemovable()) && GT_Utility.areStacksEqual(GT_OreDictUnificator.get(tStack), aOutput, aIgnoreNBT)) {
+ if (
+ (!(tRecipe instanceof IGT_CraftingRecipe) || ((IGT_CraftingRecipe) tRecipe).isRemovable())
+ && GT_Utility.areStacksEqual(GT_OreDictUnificator.get(tStack), aOutput, aIgnoreNBT)
+ ) {
tList.remove(i--); tList_sS=tList.size();
rReturn = true;
}
@@ -1316,6 +1396,24 @@ public class GT_ModHandler {
return rReturn;
}
+ public static boolean bulkRemoveRecipeByOutput(List<ItemStack> toRemove) {
+ ArrayList<IRecipe> tList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
+
+ Set<ItemStack> setToRemove = toRemove.parallelStream().map(GT_OreDictUnificator::get_nocopy).collect(Collectors.toSet());
+
+ GT_FML_LOGGER.info("BulkRemoveRecipeByOutput: tList: " + tList.size() + " setToRemove: " + setToRemove.size() );
+
+ Set<IRecipe> tListToRemove = tList.parallelStream().filter(tRecipe -> {
+ if ((tRecipe instanceof IGT_CraftingRecipe) && !((IGT_CraftingRecipe) tRecipe).isRemovable()) return false;
+ if (sSpecialRecipeClasses.contains(tRecipe.getClass().getName())) return false;
+ final ItemStack tStack = GT_OreDictUnificator.get_nocopy(tRecipe.getRecipeOutput());
+ return setToRemove.stream().anyMatch(aOutput -> GT_Utility.areStacksEqual(tStack, aOutput, true));
+ }).collect(Collectors.toSet());
+
+ tList.removeIf(tListToRemove::contains);
+ return true;
+ }
+
/**
* Checks all Crafting Handlers for Recipe Output
* Used for the Autocrafting Table
@@ -1326,8 +1424,8 @@ public class GT_ModHandler {
if (aWorld == null) aWorld = DW;
boolean temp = false;
- for (byte i = 0; i < aRecipe.length; i++) {
- if (aRecipe[i] != null) {
+ for (ItemStack itemStack : aRecipe) {
+ if (itemStack != null) {
temp = true;
break;
}
@@ -1393,15 +1491,8 @@ public class GT_ModHandler {
* Used for Recipe Detection.
*/
public static ItemStack getRecipeOutput(boolean aUncopiedStack, ItemStack... aRecipe) {
- if (aRecipe == null) return null;
- boolean temp = false;
- for (byte i = 0; i < aRecipe.length; i++) {
- if (aRecipe[i] != null) {
- temp = true;
- break;
- }
- }
- if (!temp) return null;
+ if (aRecipe == null || Arrays.stream(aRecipe).noneMatch(Objects::nonNull)) return null;
+
InventoryCrafting aCrafting = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer var1) {
@@ -1410,15 +1501,17 @@ public class GT_ModHandler {
}, 3, 3);
for (int i = 0; i < 9 && i < aRecipe.length; i++) aCrafting.setInventorySlotContents(i, aRecipe[i]);
ArrayList<IRecipe> tList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
- for (int i = 0; i < tList.size(); i++) {
- temp = false;
+ boolean found = false;
+
+ for (IRecipe iRecipe : tList) {
+ found = false;
try {
- temp = tList.get(i).matches(aCrafting, DW);
+ found = iRecipe.matches(aCrafting, DW);
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
- if (temp) {
- ItemStack tOutput = aUncopiedStack ? tList.get(i).getRecipeOutput() : tList.get(i).getCraftingResult(aCrafting);
+ if (found) {
+ ItemStack tOutput = aUncopiedStack ? iRecipe.getRecipeOutput() : iRecipe.getCraftingResult(aCrafting);
if (tOutput == null || tOutput.stackSize <= 0) {
// Seriously, who would ever do that shit?
if (!GregTech_API.sPostloadFinished)
@@ -1635,7 +1728,7 @@ public class GT_ModHandler {
for (Entry<IRecipeInput, RecipeOutput> tEntry : aRecipeList.entrySet()) {
if (tEntry.getKey().matches(aInput)) {
if (tEntry.getKey().getAmount() <= aInput.stackSize) {
- ItemStack[] tList = tEntry.getValue().items.toArray(new ItemStack[tEntry.getValue().items.size()]);
+ ItemStack[] tList = tEntry.getValue().items.toArray(new ItemStack[0]);
if (tList.length == 0) break;
ItemStack[] rList = new ItemStack[aOutputSlots.length];
rRecipeMetaData.setTag("return", tEntry.getValue().metadata);
@@ -1957,6 +2050,10 @@ public class GT_ModHandler {
* Only adds the Recipe if it has an Output
*/
public static long ONLY_ADD_IF_RESULT_IS_NOT_NULL = B[12];
+ /**
+ * Don't remove shapeless recipes with this output
+ */
+ public static long DONT_REMOVE_SHAPELESS = B[13];
}
/**
diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
index 188af9cfaa..a45e002cfa 100644
--- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
+++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
@@ -13,10 +13,8 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import javax.annotation.Nullable;
+import java.util.*;
import java.util.Map.Entry;
import static gregtech.api.enums.GT_Values.*;
@@ -31,10 +29,10 @@ import static gregtech.api.enums.GT_Values.*;
* P.S. It is intended to be named "Unificator" and not "Unifier", because that sounds more awesome.
*/
public class GT_OreDictUnificator {
- private static final /*ConcurrentHash*/Map<String, ItemStack> sName2StackMap = new /*ConcurrentHash*/HashMap<String, ItemStack>();
- private static final /*ConcurrentHash*/Map<GT_ItemStack, ItemData> sItemStack2DataMap = new /*ConcurrentHash*/HashMap<GT_ItemStack, ItemData>();
- private static final /*ConcurrentHash*/Map<GT_ItemStack, List<ItemStack>> sUnificationTable = new /*ConcurrentHash*/HashMap<GT_ItemStack, List<ItemStack>>();
- private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<GT_ItemStack>();
+ private static final Map<String, ItemStack> sName2StackMap = new HashMap<>();
+ private static final Map<GT_ItemStack, ItemData> sItemStack2DataMap = new HashMap<>();
+ private static final Map<GT_ItemStack, List<ItemStack>> sUnificationTable = new HashMap<>();
+ private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<>();
public static volatile int VERSION = 509;
private static int isRegisteringOre = 0, isAddingOre = 0;
private static boolean mRunThroughTheList = true;
@@ -81,7 +79,7 @@ public class GT_OreDictUnificator {
if (GT_Utility.isStringInvalid(aName)) return null;
ItemStack tStack = sName2StackMap.get(aName.toString());
if (GT_Utility.isStackValid(tStack)) return GT_Utility.copyAmount(aAmount, tStack);
- return GT_Utility.copyAmount(aAmount, getOres(aName).toArray());
+ return GT_Utility.copyAmount(aAmount, getOresImmutable(aName).toArray());
}
public static ItemStack get(Object aName, long aAmount) {
@@ -158,6 +156,12 @@ public class GT_OreDictUnificator {
/** Doesn't copy the returned stack or set quantity. Be careful and do not mutate it;
* intended only to optimize comparisons */
+ public static ItemStack get_nocopy(ItemStack aStack) {
+ return get_nocopy(true, aStack);
+ }
+
+ /** Doesn't copy the returned stack or set quantity. Be careful and do not mutate it;
+ * intended only to optimize comparisons */
static ItemStack get_nocopy(boolean aUseBlackList, ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) return null;
ItemData tPrefixMaterial = getAssociation(aStack);
@@ -217,10 +221,8 @@ public class GT_OreDictUnificator {
ItemStack tStack1 = get(false, tStack0);
if (!GT_Utility.areStacksEqual(tStack0, tStack1)) {
GT_ItemStack tGTStack1 = new GT_ItemStack(tStack1);
- List<ItemStack> list = sUnificationTable.get(tGTStack1);
- if (list == null)
- sUnificationTable.put(tGTStack1, list = new ArrayList<ItemStack>());
- if (!list.contains(tStack0))
+ List<ItemStack> list = sUnificationTable.computeIfAbsent(tGTStack1, k -> new ArrayList<>());
+ if (!list.contains(tStack0))
list.add(tStack0);
}
}
@@ -233,7 +235,7 @@ public class GT_OreDictUnificator {
aStacks = (ItemStack[]) obj;
else if (obj instanceof List) aStacks = (ItemStack[])
((List)obj).toArray(new ItemStack[0]);
- List<ItemStack> rList = new ArrayList<ItemStack>();
+ List<ItemStack> rList = new ArrayList<>();
for (ItemStack aStack : aStacks) {
rList.add(aStack);
List<ItemStack> tList = sUnificationTable.get(new GT_ItemStack(aStack));
@@ -309,7 +311,7 @@ public class GT_OreDictUnificator {
public static boolean isItemStackInstanceOf(ItemStack aStack, Object aName) {
if (GT_Utility.isStringInvalid(aName) || GT_Utility.isStackInvalid(aStack)) return false;
- for (ItemStack tOreStack : getOres(aName.toString()))
+ for (ItemStack tOreStack : getOresImmutable(aName.toString()))
if (GT_Utility.areStacksEqual(tOreStack, aStack, true)) return true;
return false;
}
@@ -338,10 +340,8 @@ public class GT_OreDictUnificator {
if (GT_Utility.isStringInvalid(tName))
return false;
- ArrayList<ItemStack> tList = getOres(tName);
-
- for (int i = 0; i < tList.size(); i++)
- if (GT_Utility.areStacksEqual(tList.get(i), aStack, true))
+ for (ItemStack itemStack : getOresImmutable(tName))
+ if (GT_Utility.areStacksEqual(itemStack, aStack, true))
return false;
isRegisteringOre++;
@@ -463,8 +463,18 @@ public class GT_OreDictUnificator {
*/
public static ArrayList<ItemStack> getOres(Object aOreName) {
String aName = aOreName == null ? E : aOreName.toString();
- ArrayList<ItemStack> rList = new ArrayList<ItemStack>();
+ ArrayList<ItemStack> rList = new ArrayList<>();
if (GT_Utility.isStringValid(aName)) rList.addAll(OreDictionary.getOres(aName));
return rList;
}
+
+ /**
+ * Fast version of {@link #getOres(Object)},
+ * which doesn't call {@link System#arraycopy(Object, int, Object, int, int)} in {@link ArrayList#addAll}
+ */
+ public static List<ItemStack> getOresImmutable(@Nullable Object aOreName) {
+ String aName = aOreName == null ? E : aOreName.toString();
+
+ return GT_Utility.isStringValid(aName) ? Collections.unmodifiableList(OreDictionary.getOres(aName)) : Collections.emptyList();
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index adc0f95881..a9ba9b9bbc 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -1,6 +1,7 @@
package gregtech.api.util;
import cofh.api.transport.IItemDuct;
+import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.FMLCommonHandler;
import gregtech.api.GregTech_API;
@@ -91,12 +92,12 @@ public class GT_Utility {
/**
* Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there.
*/
- private static final List<FluidContainerData> sFluidContainerList = new ArrayList<FluidContainerData>();
- private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new /*Concurrent*/HashMap<GT_ItemStack, FluidContainerData>();
- private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap<GT_ItemStack, Map<Fluid, FluidContainerData>>();
+ private static final List<FluidContainerData> sFluidContainerList = new ArrayList<>();
+ private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new /*Concurrent*/HashMap<>();
+ private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap<>();
public static volatile int VERSION = 509;
public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false;
- public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new /*Concurrent*/HashMap<GT_PlayedSound, Integer>();
+ public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new /*Concurrent*/HashMap<>();
private static int sBookCount = 0;
public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000");
@@ -251,8 +252,7 @@ public class GT_Utility {
Field[] var3 = EntityLiving.class.getDeclaredFields();
int var4 = var3.length;
- for (int var5 = 0; var5 < var4; ++var5) {
- Field var6 = var3[var5];
+ for (Field var6 : var3) {
if (var6.getType() == HashMap.class) {
tPotionHashmap = var6;
tPotionHashmap.setAccessible(true);
@@ -261,7 +261,7 @@ public class GT_Utility {
}
if (tPotionHashmap != null)
- return ((HashMap) tPotionHashmap.get(aPlayer)).get(Integer.valueOf(aPotionIndex)) != null;
+ return ((HashMap) tPotionHashmap.get(aPlayer)).get(aPotionIndex) != null;
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
@@ -280,8 +280,7 @@ public class GT_Utility {
Field[] var3 = EntityLiving.class.getDeclaredFields();
int var4 = var3.length;
- for (int var5 = 0; var5 < var4; ++var5) {
- Field var6 = var3[var5];
+ for (Field var6 : var3) {
if (var6.getType() == HashMap.class) {
tPotionHashmap = var6;
tPotionHashmap.setAccessible(true);
@@ -289,7 +288,7 @@ public class GT_Utility {
}
}
- if (tPotionHashmap != null) ((HashMap) tPotionHashmap.get(aPlayer)).remove(Integer.valueOf(aPotionIndex));
+ if (tPotionHashmap != null) ((HashMap) tPotionHashmap.get(aPlayer)).remove(aPotionIndex);
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
@@ -394,16 +393,16 @@ public class GT_Utility {
if (aTileEntity2 != null) {
checkAvailabilities();
if (TE_CHECK && aTileEntity2 instanceof IItemDuct) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
+ for (int aGrabSlot : aGrabSlots) {
+ if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) {
+ if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) {
+ if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) {
+ ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot));
ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack));
byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize));
if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) {
//((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F);
- aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount);
+ aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount);
aTileEntity1.markDirty();
return tMovedItemCount;
}
@@ -414,15 +413,15 @@ public class GT_Utility {
return 0;
}
if (BC_CHECK && aTileEntity2 instanceof buildcraft.api.transport.IPipeTile) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
+ for (int aGrabSlot : aGrabSlots) {
+ if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) {
+ if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) {
+ if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) {
+ ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot));
byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo));
if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) {
tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo)));
- aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount);
+ aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount);
aTileEntity1.markDirty();
return tMovedItemCount;
}
@@ -438,15 +437,15 @@ public class GT_Utility {
if (aTileEntity1 instanceof TileEntity && tDirection != ForgeDirection.UNKNOWN && tDirection.getOpposite() == ForgeDirection.getOrientation(aPutTo)) {
int tX = ((TileEntity) aTileEntity1).xCoord + tDirection.offsetX, tY = ((TileEntity) aTileEntity1).yCoord + tDirection.offsetY, tZ = ((TileEntity) aTileEntity1).zCoord + tDirection.offsetZ;
if (!hasBlockHitBox(((TileEntity) aTileEntity1).getWorldObj(), tX, tY, tZ) && dropItem) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
+ for (int aGrabSlot : aGrabSlots) {
+ if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) {
+ if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) {
+ if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) {
+ ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot));
EntityItem tEntity = new EntityItem(((TileEntity) aTileEntity1).getWorldObj(), tX + 0.5, tY + 0.5, tZ + 0.5, tStack);
tEntity.motionX = tEntity.motionY = tEntity.motionZ = 0;
((TileEntity) aTileEntity1).getWorldObj().spawnEntityInWorld(tEntity);
- aTileEntity1.decrStackSize(aGrabSlots[i], tStack.stackSize);
+ aTileEntity1.decrStackSize(aGrabSlot, tStack.stackSize);
aTileEntity1.markDirty();
return (byte) tStack.stackSize;
}
@@ -480,11 +479,10 @@ public class GT_Utility {
if (tStack3 != null) {
if (tStack2 == null) {
aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3));
- aTileEntity2.markDirty();
} else {
tStack2.stackSize += tStack3.stackSize;
- aTileEntity2.markDirty();
}
+ aTileEntity2.markDirty();
return (byte) tStack3.stackSize;
}
}
@@ -565,18 +563,17 @@ public class GT_Utility {
IInventory tPutInventory = (IInventory) aTileEntity2;
int tPutInventorySize = tPutSlots.length;
int tFirstsValidSlot = 0,tStacksMoved = 0,tTotalItemsMoved = 0;
- for (int tGrabSlotIndex = 0;tGrabSlotIndex<tGrabInventorySize;tGrabSlotIndex++)
- {
+ for (int grabSlot : tGrabSlots) {
//ItemStack tInventoryStack : mInventory
int tMovedItems;
do {
- int tGrabSlot = tGrabSlots[tGrabSlotIndex];
- tMovedItems = 0;
+ int tGrabSlot = grabSlot;
+ tMovedItems = 0;
ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlot);
if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter) &&
- (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack))) {
+ (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack))) {
int tStackSize = tGrabStack.stackSize;
-
+
for (int tPutSlotIndex = tFirstsValidSlot; tPutSlotIndex < tPutInventorySize; tPutSlotIndex++) {
int tPutSlot = tPutSlots[tPutSlotIndex];
if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) {
@@ -592,7 +589,7 @@ public class GT_Utility {
return tTotalItemsMoved;
}
}
- } while (tGrabInventorySize == 2 && tMovedItems > 0); //to suport draweres and barrels
+ } while (tMovedItems > 0); //suport inventorys thgat store motre then a stack in a aslot
}
if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) {
TileEntityChest tTileEntity1 = (TileEntityChest) aTileEntity1;
@@ -681,21 +678,21 @@ public class GT_Utility {
for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i;
}
- for (int i = 0; i < tGrabSlots.length; i++) {
- byte tMovedItemCount = 0;
- ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlots[i]);
+ for (int tGrabSlot : tGrabSlots) {
+ byte tMovedItemCount = 0;
+ ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlot);
if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter)) {
- if (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, tGrabStack)) {
- for (int j = 0; j < tPutSlots.length; j++) {
- if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, tGrabStack, aMaxTargetStackSize)) {
- tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce);
- if (tMovedItemCount >= aMaxMoveAtOnce ||(tMovedItemCount > 0 && aMaxTargetStackSize < 64))
- return tMovedItemCount;
+ if (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack)) {
+ for (int tPutSlot : tPutSlots) {
+ if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlot, aPutTo, tGrabStack, aMaxTargetStackSize)) {
+ tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlot, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce);
+ if (tMovedItemCount >= aMaxMoveAtOnce || (tMovedItemCount > 0 && aMaxTargetStackSize < 64))
+ return tMovedItemCount;
}
}
}
}
- if (tMovedItemCount > 0) return tMovedItemCount;
+ if (tMovedItemCount > 0) return tMovedItemCount;
}
if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) {
@@ -753,11 +750,11 @@ public class GT_Utility {
}
if (aTileEntity2 instanceof IInventory) {
- for (int i = 0; i < tGrabSlots.length; i++) {
- if (listContainsItem(aFilter, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot((IInventory) aTileEntity1, tGrabSlots[i], aGrabFrom, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]))) {
- if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, aPutTo, (byte) 6, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) {
- byte tMovedItemCount = moveStackFromSlotAToSlotB((IInventory) aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce);
+ for (int tGrabSlot : tGrabSlots) {
+ if (listContainsItem(aFilter, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot), true, aInvertFilter)) {
+ if (isAllowedToTakeFromSlot((IInventory) aTileEntity1, tGrabSlot, aGrabFrom, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot))) {
+ if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, aPutTo, (byte) 6, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot), aMaxTargetStackSize)) {
+ byte tMovedItemCount = moveStackFromSlotAToSlotB((IInventory) aTileEntity1, (IInventory) aTileEntity2, tGrabSlot, aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce);
if (tMovedItemCount > 0) return tMovedItemCount;
}
}
@@ -849,7 +846,7 @@ public class GT_Utility {
public static boolean listContainsItem(Collection<ItemStack> aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) {
if (aStack == null || aStack.stackSize < 1) return false;
if (aList == null) return aTIfListEmpty;
- while (aList.contains(null)) aList.remove(null);
+ aList.removeIf(Objects::isNull);
if (aList.size() < 1) return aTIfListEmpty;
Iterator<ItemStack> tIterator = aList.iterator();
ItemStack tStack = null;
@@ -879,7 +876,9 @@ public class GT_Utility {
}
public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) {
- return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem() && (aIgnoreNBT || ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound()))) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W);
+ return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem()
+ && (aIgnoreNBT || (((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound()))))
+ && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W);
}
public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2) {
@@ -910,7 +909,7 @@ public class GT_Utility {
sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData);
Map<Fluid, FluidContainerData> tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer));
if (tFluidToContainer == null) {
- sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<Fluid, FluidContainerData>());
+ sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<>());
GregTech_API.sFluidMappings.add(tFluidToContainer);
}
tFluidToContainer.put(tData.fluid.getFluid(), tData);
@@ -922,7 +921,7 @@ public class GT_Utility {
sFilledContainerToData.put(new GT_ItemStack(aData.filledContainer), aData);
Map<Fluid, FluidContainerData> tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aData.emptyContainer));
if (tFluidToContainer == null) {
- sEmptyContainerToFluidToData.put(new GT_ItemStack(aData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<Fluid, FluidContainerData>());
+ sEmptyContainerToFluidToData.put(new GT_ItemStack(aData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<>());
GregTech_API.sFluidMappings.add(tFluidToContainer);
}
tFluidToContainer.put(aData.fluid.getFluid(), aData);
@@ -973,6 +972,15 @@ public class GT_Utility {
return rStack;
}
+ public static FluidStack getFluidFromDisplayStack(ItemStack aDisplayStack) {
+ if (!isStackValid(aDisplayStack) ||
+ aDisplayStack.getItem() != ItemList.Display_Fluid.getItem() ||
+ !aDisplayStack.hasTagCompound())
+ return null;
+ Fluid tFluid = FluidRegistry.getFluid(ItemList.Display_Fluid.getItem().getDamage(aDisplayStack));
+ return new FluidStack(tFluid, (int) aDisplayStack.getTagCompound().getLong("mFluidDisplayAmount"));
+ }
+
public static boolean containsFluid(ItemStack aStack, FluidStack aFluid, boolean aCheckIFluidContainerItems) {
if (isStackInvalid(aStack) || aFluid == null) return false;
if (aCheckIFluidContainerItems && aStack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) aStack.getItem()).getCapacity(aStack) > 0)
@@ -1064,11 +1072,27 @@ public class GT_Utility {
return rReturn;
}
+ public static synchronized void bulkRemoveSimpleIC2MachineRecipe(Map<ItemStack, ItemStack> toRemove, Map<IRecipeInput, RecipeOutput> aRecipeList) {
+ if (aRecipeList == null || aRecipeList.isEmpty()) return;
+ toRemove.entrySet().removeIf(aEntry -> (isStackInvalid(aEntry.getKey()) && isStackInvalid(aEntry.getValue())));
+ final Map<ItemStack, ItemStack> finalToRemove = Maps.transformValues(toRemove, GT_OreDictUnificator::get_nocopy);
+
+ aRecipeList.entrySet().removeIf(tEntry -> finalToRemove.entrySet().stream().anyMatch(aEntry -> {
+ final ItemStack aInput = aEntry.getKey(), aOutput = aEntry.getValue();
+ final List<ItemStack> tList = tEntry.getValue().items;
+
+ if (tList == null) return false;
+ if (aInput != null && !tEntry.getKey().matches(aInput)) return false;
+
+ return tList.stream().anyMatch(tOutput -> (aOutput == null || areStacksEqual(GT_OreDictUnificator.get(tOutput), aOutput)));
+ }));
+ }
+
public static boolean addSimpleIC2MachineRecipe(ItemStack aInput, Map<IRecipeInput, RecipeOutput> aRecipeList, NBTTagCompound aNBT, Object... aOutput) {
if (isStackInvalid(aInput) || aOutput.length == 0 || aRecipeList == null) return false;
ItemData tOreName = GT_OreDictUnificator.getAssociation(aInput);
- for (int i = 0; i < aOutput.length; i++) {
- if (aOutput[i] == null) {
+ for (Object o : aOutput) {
+ if (o == null) {
GT_FML_LOGGER.info("EmptyIC2Output!" + aInput.getUnlocalizedName());
return false;
}
@@ -1203,15 +1227,15 @@ public class GT_Utility {
}
public static <T> ArrayList<T> getArrayListWithoutNulls(T... aArray) {
- if (aArray == null) return new ArrayList<T>();
- ArrayList<T> rList = new ArrayList<T>(Arrays.asList(aArray));
+ if (aArray == null) return new ArrayList<>();
+ ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray));
for (int i = 0; i < rList.size(); i++) if (rList.get(i) == null) rList.remove(i--);
return rList;
}
public static <T> ArrayList<T> getArrayListWithoutTrailingNulls(T... aArray) {
- if (aArray == null) return new ArrayList<T>();
- ArrayList<T> rList = new ArrayList<T>(Arrays.asList(aArray));
+ if (aArray == null) return new ArrayList<>();
+ ArrayList<T> rList = new ArrayList<>(Arrays.asList(aArray));
for (int i = rList.size() - 1; i >= 0 && rList.get(i) == null; ) rList.remove(i--);
return rList;
}
@@ -1682,8 +1706,7 @@ public class GT_Utility {
* re-maps all Keys of a Map after the Keys were weakened.
*/
public static <X, Y> Map<X, Y> reMap(Map<X, Y> aMap) {
- Map<X, Y> tMap = new /*Concurrent*/HashMap<X, Y>();
- tMap.putAll(aMap);
+ Map<X, Y> tMap = new HashMap<>(aMap);
aMap.clear();
aMap.putAll(tMap);
return aMap;
@@ -1693,14 +1716,9 @@ public class GT_Utility {
* Why the fuck do neither Java nor Guava have a Function to do this?
*/
public static <X, Y extends Comparable> LinkedHashMap<X, Y> sortMapByValuesAcending(Map<X, Y> aMap) {
- List<Map.Entry<X, Y>> tEntrySet = new LinkedList<Map.Entry<X, Y>>(aMap.entrySet());
- Collections.sort(tEntrySet, new Comparator<Map.Entry<X, Y>>() {
- @Override
- public int compare(Entry<X, Y> aValue1, Entry<X, Y> aValue2) {
- return aValue1.getValue().compareTo(aValue2.getValue());
- }
- });
- LinkedHashMap<X, Y> rMap = new LinkedHashMap<X, Y>();
+ List<Map.Entry<X, Y>> tEntrySet = new LinkedList<>(aMap.entrySet());
+ tEntrySet.sort(Entry.comparingByValue());
+ LinkedHashMap<X, Y> rMap = new LinkedHashMap<>();
for (Map.Entry<X, Y> tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue());
return rMap;
}
@@ -1709,14 +1727,11 @@ public class GT_Utility {
* Why the fuck do neither Java nor Guava have a Function to do this?
*/
public static <X, Y extends Comparable> LinkedHashMap<X, Y> sortMapByValuesDescending(Map<X, Y> aMap) {
- List<Map.Entry<X, Y>> tEntrySet = new LinkedList<Map.Entry<X, Y>>(aMap.entrySet());
- Collections.sort(tEntrySet, new Comparator<Map.Entry<X, Y>>() {
- @Override
- public int compare(Entry<X, Y> aValue1, Entry<X, Y> aValue2) {
- return aValue2.getValue().compareTo(aValue1.getValue());//FB: RV - RV_NEGATING_RESULT_OF_COMPARETO
- }
+ List<Map.Entry<X, Y>> tEntrySet = new LinkedList<>(aMap.entrySet());
+ tEntrySet.sort((aValue1, aValue2) -> {
+ return aValue2.getValue().compareTo(aValue1.getValue());//FB: RV - RV_NEGATING_RESULT_OF_COMPARETO
});
- LinkedHashMap<X, Y> rMap = new LinkedHashMap<X, Y>();
+ LinkedHashMap<X, Y> rMap = new LinkedHashMap<>();
for (Map.Entry<X, Y> tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue());
return rMap;
}
@@ -1856,7 +1871,7 @@ public class GT_Utility {
public static int getCoordinateScan(ArrayList<String> aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) {
if (aList == null) return 0;
- ArrayList<String> tList = new ArrayList<String>();
+ ArrayList<String> tList = new ArrayList<>();
int rEUAmount = 0;
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
@@ -2196,16 +2211,10 @@ public class GT_Utility {
public static ArrayList<String> sortByValueToList( Map<String, Integer> map ) {
List<Map.Entry<String, Integer>> list =
- new LinkedList<Map.Entry<String, Integer>>( map.entrySet() );
- Collections.sort( list, new Comparator<Map.Entry<String, Integer>>()
- {
- public int compare( Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2 )
- {
- return o2.getValue() - o1.getValue();
- }
- } );
+ new LinkedList<>(map.entrySet());
+ list.sort((o1, o2) -> o2.getValue() - o1.getValue());
- ArrayList<String> result = new ArrayList<String>();
+ ArrayList<String> result = new ArrayList<>();
for (Map.Entry<String, Integer> e : list)
result.add(e.getKey());
return result;
@@ -2219,7 +2228,7 @@ public class GT_Utility {
}
public static ItemStack getIntegratedCircuit(int config){
- return ItemList.Circuit_Integrated.getWithDamage(0, config, new Object[0]);
+ return ItemList.Circuit_Integrated.getWithDamage(0, config);
}
public static float getBlockHardnessAt(World aWorld, int aX, int aY, int aZ) {
@@ -2262,7 +2271,7 @@ public class GT_Utility {
aStack.setTagCompound(null);
return;
}
- ArrayList<String> tTagsToRemove = new ArrayList<String>();
+ ArrayList<String> tTagsToRemove = new ArrayList<>();
for (Object tKey : aNBT.func_150296_c()) {
NBTBase tValue = aNBT.getTag((String) tKey);
if (tValue == null || (tValue instanceof NBTPrimitive && ((NBTPrimitive) tValue).func_150291_c() == 0) || (tValue instanceof NBTTagString && isStringInvalid(((NBTTagString) tValue).func_150285_a_())))
@@ -2335,13 +2344,13 @@ public class GT_Utility {
public static void setProspectionData(ItemStack aStack, int aX, int aY, int aZ, int aDim, FluidStack aFluid, String... aOres) {
NBTTagCompound tNBT = getNBT(aStack);
- String tData = aX + "," + aY + "," + aZ + "," + aDim + ",";
+ StringBuilder tData = new StringBuilder(aX + "," + aY + "," + aZ + "," + aDim + ",");
if (aFluid!=null)
- tData += (aFluid.amount) + "," + aFluid.getLocalizedName() + ",";//TODO CHECK IF THAT /5000 is needed (Not needed)
+ tData.append(aFluid.amount).append(",").append(aFluid.getLocalizedName()).append(",");//TODO CHECK IF THAT /5000 is needed (Not needed)
for (String tString : aOres) {
- tData += tString + ",";
+ tData.append(tString).append(",");
}
- tNBT.setString("prospection", tData);
+ tNBT.setString("prospection", tData.toString());
setNBT(aStack, tNBT);
}
@@ -2365,7 +2374,7 @@ public class GT_Utility {
tNBT.setString("prospection_ores", joinListToString(aOres));
// oils
- ArrayList<String> tOilsTransformed = new ArrayList<String>(aOils.size());
+ ArrayList<String> tOilsTransformed = new ArrayList<>(aOils.size());
for (String aStr : aOils) {
String[] aStats = aStr.split(",");
tOilsTransformed.add(aStats[0] + ": " + aStats[1] + "L " + aStats[2]);
@@ -2417,14 +2426,13 @@ public class GT_Utility {
if (tDataArray.length > 6) {
tNBT.setString("author", " Dim: " + tDataArray[3] + "X: " + tDataArray[0] + " Y: " + tDataArray[1] + " Z: " + tDataArray[2]);
NBTTagList tNBTList = new NBTTagList();
- String tOres = " Prospected Ores: ";
+ StringBuilder tOres = new StringBuilder(" Prospected Ores: ");
for (int i = 6; tDataArray.length > i; i++) {
- tOres += (tDataArray[i] + " ");
+ tOres.append(tDataArray[i]).append(" ");
}
tNBTList.appendTag(new NBTTagString("Tier " + tTier + " Prospecting Data From: X" + tDataArray[0] + " Z:" + tDataArray[2] + " Dim:" + tDataArray[3] + " Produces " + tDataArray[4] + "L " + tDataArray[5] + " " + tOres));
tNBT.setTag("pages", tNBTList);
}
- setNBT(aStack, tNBT);
} else { // advanced prospection data
String tPos = tNBT.getString("prospection_pos");
String tRadius = tNBT.getString("prospection_radius");
@@ -2470,28 +2478,28 @@ public class GT_Utility {
tNBT.setString("author", tPos.replace("\n"," "));
tNBT.setTag("pages", tNBTList);
- setNBT(aStack, tNBT);
}
+ setNBT(aStack, tNBT);
}
public static void fillBookWithList(NBTTagList aBook, String aPageHeader, String aListDelimiter, int aItemsPerPage, String[] list) {
String aPageFormatter = " %d/%d";
int tTotalPages = list.length / aItemsPerPage + (list.length % aItemsPerPage > 0 ? 1 : 0);
int tPage = 0;
- String tPageText;
+ StringBuilder tPageText;
do {
- tPageText = "";
+ tPageText = new StringBuilder();
for (int i = tPage*aItemsPerPage; i < (tPage+1)*aItemsPerPage && i < list.length; i += 1)
- tPageText += (tPageText.isEmpty() ? "" : aListDelimiter) + list[i];
+ tPageText.append((tPageText.length() == 0) ? "" : aListDelimiter).append(list[i]);
- if (!tPageText.isEmpty()) {
+ if (tPageText.length() > 0) {
String tPageCounter = tTotalPages > 1 ? String.format(aPageFormatter, tPage + 1, tTotalPages) : "";
NBTTagString tPageTag = new NBTTagString(String.format(aPageHeader, tPageCounter) + tPageText);
aBook.appendTag(tPageTag);
}
++tPage;
- } while (!tPageText.isEmpty());
+ } while (tPageText.length() > 0);
}
public static void addEnchantment(ItemStack aStack, Enchantment aEnchantment, int aLevel) {
@@ -2769,4 +2777,16 @@ public class GT_Utility {
)
);
}
+
+ /**
+ * Add an itemstack to player inventory, or drop on ground if full.
+ * Can be called on client but it probably won't work very well.
+ */
+ public static void addItemToPlayerInventory(EntityPlayer aPlayer, ItemStack aStack) {
+ if (isStackInvalid(aStack)) return;
+ if (!aPlayer.inventory.addItemStackToInventory(aStack) && !aPlayer.worldObj.isRemote) {
+ EntityItem dropItem = aPlayer.entityDropItem(aStack, 0);
+ dropItem.delayBeforeCanPickup = 0;
+ }
+ }
}