aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_Assemblyline_Server.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_BaseCrop.java13
-rw-r--r--src/main/java/gregtech/api/util/GT_CircuitryBehavior.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_ClientPreference.java24
-rw-r--r--src/main/java/gregtech/api/util/GT_Config.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_CoverBehavior.java10
-rw-r--r--src/main/java/gregtech/api/util/GT_CreativeTab.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_FoodStat.java25
-rw-r--r--src/main/java/gregtech/api/util/GT_IBoxableWrapper.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_LanguageManager.java15
-rw-r--r--src/main/java/gregtech/api/util/GT_Log.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java494
-rw-r--r--src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java202
-rw-r--r--src/main/java/gregtech/api/util/GT_OreDictUnificator.java72
-rw-r--r--src/main/java/gregtech/api/util/GT_PlayedSound.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java121
-rw-r--r--src/main/java/gregtech/api/util/GT_RecipeRegistrator.java165
-rw-r--r--src/main/java/gregtech/api/util/GT_Shaped_Recipe.java27
-rw-r--r--src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java38
-rw-r--r--src/main/java/gregtech/api/util/GT_SpawnEventHandler.java4
-rw-r--r--src/main/java/gregtech/api/util/GT_StructureUtility.java183
-rw-r--r--src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java61
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java746
-rw-r--r--src/main/java/gregtech/api/util/IGT_HatchAdder.java15
-rw-r--r--src/main/java/gregtech/api/util/LightingHelper.java729
-rw-r--r--src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java604
-rw-r--r--src/main/java/gregtech/api/util/extensions/ArrayExt.java80
-rw-r--r--src/main/java/gregtech/api/util/extensions/IteratorExt.java12
30 files changed, 3064 insertions, 594 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Assemblyline_Server.java b/src/main/java/gregtech/api/util/GT_Assemblyline_Server.java
index 358e21a9a6..1769a4770a 100644
--- a/src/main/java/gregtech/api/util/GT_Assemblyline_Server.java
+++ b/src/main/java/gregtech/api/util/GT_Assemblyline_Server.java
@@ -339,4 +339,4 @@ public class GT_Assemblyline_Server {
internal3 = null;
internal4 = null;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java
index 41bdcac3dc..97f8db0547 100644
--- a/src/main/java/gregtech/api/util/GT_BaseCrop.java
+++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java
@@ -68,7 +68,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
aID = GT_Config.addIDConfig(ConfigCategories.IDs.crops, mName.replaceAll(" ", "_"), aID);
if (aDiscoveredBy != null && !aDiscoveredBy.equals(E)) mDiscoveredBy = aDiscoveredBy;
if (aDrop != null && aID > 0 && aID < 256) {
- mDrop = GT_Utility.copy(aDrop);
+ mDrop = GT_Utility.copyOrNull(aDrop);
mSpecialDrops = aSpecialDrops;
mTier = Math.max(1, aTier);
mMaxSize = Math.max(3, aMaxSize);
@@ -119,6 +119,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
return tier() * mGrowthSpeed;
}
+ @Override
public int getrootslength(ICropTile crop) {
return 5;
}
@@ -176,9 +177,9 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
public ItemStack getGain(ICropTile aCrop) {
int tDrop = 0;
if (mSpecialDrops != null && (tDrop = java.util.concurrent.ThreadLocalRandom.current().nextInt(0, (mSpecialDrops.length*2) + 2)) < mSpecialDrops.length && mSpecialDrops[tDrop] != null) {
- return GT_Utility.copy(mSpecialDrops[tDrop]);
+ return GT_Utility.copyOrNull(mSpecialDrops[tDrop]);
}
- return GT_Utility.copy(mDrop);
+ return GT_Utility.copyOrNull(mDrop);
}
@Override
@@ -233,6 +234,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
return false;
}
+ @Override
public List<String> getCropInformation() {
if (mBlock != null) {
ArrayList<String> result = new ArrayList<String>(1);
@@ -242,11 +244,12 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
return null;
}
+ @Override
public ItemStack getDisplayItem() {
if (mSpecialDrops != null && mSpecialDrops[mSpecialDrops.length - 1] != null) {
- return GT_Utility.copy(mSpecialDrops[mSpecialDrops.length - 1]);
+ return GT_Utility.copyOrNull(mSpecialDrops[mSpecialDrops.length - 1]);
}
- return GT_Utility.copy(mDrop);
+ return GT_Utility.copyOrNull(mDrop);
}
}
diff --git a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java
index 4adf7e0f26..f25b88728d 100644
--- a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java
+++ b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java
@@ -178,4 +178,4 @@ public abstract class GT_CircuitryBehavior {
public String getDataDisplay(int[] aCircuitData, int aCircuitDataIndex) {
return null;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_ClientPreference.java b/src/main/java/gregtech/api/util/GT_ClientPreference.java
new file mode 100644
index 0000000000..e679f4ece6
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_ClientPreference.java
@@ -0,0 +1,24 @@
+package gregtech.api.util;
+
+public class GT_ClientPreference {
+ private final boolean mSingleBlockInitialFilter;
+ private final boolean mInputBusInitialFilter;
+
+ public GT_ClientPreference(boolean mSingleBlockInitialFilter, boolean mInputBusInitialFilter) {
+ this.mSingleBlockInitialFilter = mSingleBlockInitialFilter;
+ this.mInputBusInitialFilter = mInputBusInitialFilter;
+ }
+
+ public GT_ClientPreference(GT_Config aClientDataFile) {
+ this.mSingleBlockInitialFilter = aClientDataFile.get("preference", "mSingleBlockInitialFilter", false);
+ this.mInputBusInitialFilter = aClientDataFile.get("preference", "mInputBusInitialFilter", true);
+ }
+
+ public boolean isSingleBlockInitialFilterEnabled() {
+ return mSingleBlockInitialFilter;
+ }
+
+ public boolean isInputBusInitialFilterEnabled() {
+ return mInputBusInitialFilter;
+ }
+}
diff --git a/src/main/java/gregtech/api/util/GT_Config.java b/src/main/java/gregtech/api/util/GT_Config.java
index 23a43f7085..6849988a77 100644
--- a/src/main/java/gregtech/api/util/GT_Config.java
+++ b/src/main/java/gregtech/api/util/GT_Config.java
@@ -96,4 +96,4 @@ public class GT_Config implements Runnable {
public void run() {
mConfig.save();
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java
index c0ad751add..14c8cc1308 100644
--- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java
+++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java
@@ -15,6 +15,13 @@ import static gregtech.api.enums.GT_Values.E;
* For Covers with a special behavior.
*/
public abstract class GT_CoverBehavior {
+
+ public EntityPlayer lastPlayer = null;
+
+ public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) {
+ return true;
+ }
+
/**
* Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time.
*/
@@ -54,6 +61,7 @@ public abstract class GT_CoverBehavior {
*/
public boolean onCoverShiftRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) {
if(hasCoverGUI() && aPlayer instanceof EntityPlayerMP) {
+ lastPlayer = aPlayer;
GT_Values.NW.sendToPlayer(new GT_Packet_TileEntityCoverGUI(aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), (EntityPlayerMP) aPlayer);
return true;
}
@@ -241,4 +249,4 @@ public abstract class GT_CoverBehavior {
public String trans(String aNr, String aEnglish){
return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aNr, aEnglish, false);
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_CreativeTab.java b/src/main/java/gregtech/api/util/GT_CreativeTab.java
index 80dac95df2..ccebd9d4a9 100644
--- a/src/main/java/gregtech/api/util/GT_CreativeTab.java
+++ b/src/main/java/gregtech/api/util/GT_CreativeTab.java
@@ -21,4 +21,4 @@ public class GT_CreativeTab extends CreativeTabs {
public Item getTabIconItem() {
return ItemList.Circuit_Integrated.getItem();
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java
index d0fe9bdbf4..193977476a 100644
--- a/src/main/java/gregtech/api/util/GT_FoodStat.java
+++ b/src/main/java/gregtech/api/util/GT_FoodStat.java
@@ -36,7 +36,7 @@ public class GT_FoodStat implements IFoodStat {
mSaturation = aSaturation;
mAction = aAction == null ? EnumAction.eat : aAction;
mPotionEffects = aPotionEffects;
- mEmptyContainer = GT_Utility.copy(aEmptyContainer);
+ mEmptyContainer = GT_Utility.copyOrNull(aEmptyContainer);
mInvisibleParticles = aInvisibleParticles;
mAlwaysEdible = aAlwaysEdible;
mIsRotten = aIsRotten;
@@ -65,10 +65,18 @@ public class GT_FoodStat implements IFoodStat {
@Override
public void onEaten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) {
aStack.stackSize--;
- ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer));
+ ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copyOrNull(mEmptyContainer));
if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack))
aPlayer.dropPlayerItemWithRandomChoice(tStack, true);
- aPlayer.worldObj.playSoundAtEntity(aPlayer, "random.burp", 0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F);
+
+ new WorldSpawnedEventBuilder.SoundAtEntityEventBuilder()
+ .setIdentifier("random.burp")
+ .setVolume(0.5F)
+ .setPitch(aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F)
+ .setEntity(aPlayer)
+ .setWorld(aPlayer.worldObj)
+ .run();
+
if (!aPlayer.worldObj.isRemote) {
if (mMilk) {
aPlayer.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0));
@@ -79,7 +87,14 @@ public class GT_FoodStat implements IFoodStat {
}
}
if (mExplosive) {
- aPlayer.worldObj.newExplosion(aPlayer, aPlayer.posX, aPlayer.posY, aPlayer.posZ, 4, true, true);
+ new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder()
+ .setSmoking(true)
+ .setFlaming(true)
+ .setStrength(4f)
+ .setPosition(aPlayer.posX, aPlayer.posY, aPlayer.posZ)
+ .setEntity(aPlayer)
+ .setWorld(aPlayer.worldObj)
+ .run();
aPlayer.attackEntityFrom(GT_DamageSources.getExplodingDamage(), Float.MAX_VALUE);
}
}
@@ -99,4 +114,4 @@ public class GT_FoodStat implements IFoodStat {
public boolean isRotten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) {
return mIsRotten;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java b/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java
index fd1d229284..dadbe57518 100644
--- a/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java
+++ b/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java
@@ -8,4 +8,4 @@ public class GT_IBoxableWrapper implements IBoxable {
public boolean canBeStoredInToolbox(ItemStack itemstack) {
return true;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java b/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java
index c3b7d34eb4..f742be20cb 100644
--- a/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java
+++ b/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java
@@ -13,4 +13,4 @@ public class GT_ItsNotMyFaultException extends RuntimeException {
public String toString() {
return "The GregTech-Addon has a Problem.\nIT'S NOT MY FAULT!!! Below is how to fix it.\n" + mError + "\nDO NOT COME TO ME WITH THIS CRASH. YOU CAUSED IT YOURSELF, AND I TOLD YOU HOW TO FIX IT!!!";
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java
index c87e0f7417..e0c23fce8e 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;
}
@@ -63,7 +67,12 @@ public class GT_LanguageManager {
public static String getTranslation(String aKey) {
if (aKey == null) return E;
- String tTrimmedKey = aKey.trim(), rTranslation = LanguageRegistry.instance().getStringLocalization(tTrimmedKey);
+ String tTrimmedKey = aKey.trim(), rTranslation;
+ if (sUseEnglishFile) {
+ rTranslation = LanguageRegistry.instance().getStringLocalization(tTrimmedKey);
+ } else {
+ rTranslation = StatCollector.translateToLocal(tTrimmedKey);
+ }
if (GT_Utility.isStringInvalid(rTranslation)) {
rTranslation = StatCollector.translateToLocal(tTrimmedKey);
if (GT_Utility.isStringInvalid(rTranslation) || tTrimmedKey.equals(rTranslation)) {
diff --git a/src/main/java/gregtech/api/util/GT_Log.java b/src/main/java/gregtech/api/util/GT_Log.java
index c336eed094..888f471317 100644
--- a/src/main/java/gregtech/api/util/GT_Log.java
+++ b/src/main/java/gregtech/api/util/GT_Log.java
@@ -37,4 +37,4 @@ public class GT_Log {
mBufferedOreDictLog.add(aString);
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index 4d264bec9b..a910723069 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -6,7 +6,12 @@ import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
-import gregtech.api.enums.*;
+import gregtech.api.enums.ConfigCategories;
+import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OreDictNames;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.api.enums.ToolDictNames;
import gregtech.api.interfaces.IDamagableItem;
import gregtech.api.interfaces.IItemContainer;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
@@ -31,7 +36,11 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
-import net.minecraft.item.crafting.*;
+import net.minecraft.item.crafting.CraftingManager;
+import net.minecraft.item.crafting.FurnaceRecipes;
+import net.minecraft.item.crafting.IRecipe;
+import net.minecraft.item.crafting.ShapedRecipes;
+import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
@@ -40,11 +49,28 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+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.api.enums.GT_Values.*;
+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;
+import static gregtech.api.enums.GT_Values.E;
+import static gregtech.api.enums.GT_Values.M;
+import static gregtech.api.enums.GT_Values.RA;
+import static gregtech.api.enums.GT_Values.V;
+import static gregtech.api.enums.GT_Values.W;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -54,22 +80,28 @@ import static gregtech.api.enums.GT_Values.*;
* 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[][]
@@ -119,12 +151,14 @@ 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<>();
static {
sNativeRecipeClasses.add(ShapedRecipes.class.getName());
@@ -217,6 +251,20 @@ public class GT_ModHandler {
}
/**
+ * Returns if that Liquid is Any Steam (including other mods)
+ */
+ public static boolean isAnySteam(FluidStack aFluid) {
+ return(aFluid != null && (isSteam(aFluid) || sAnySteamFluidIDs.contains(aFluid.getFluidID())));
+ }
+
+ /**
+ * Returns if that Liquid is Super Heated Steam (including other mods)
+ */
+ public static boolean isSuperHeatedSteam(FluidStack aFluid) {
+ return(aFluid != null && sSuperHeatedSteamFluidIDs.contains(aFluid.getFluidID()));
+ }
+
+ /**
* Returns a Liquid Stack with given amount of Steam.
*/
public static FluidStack getSteam(long aAmount) {
@@ -335,14 +383,14 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft
+ * Gets an Item from the specified mod
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount) {
return getModItem(aModID, aItem, aAmount, null);
}
/**
- * Gets an Item from RailCraft, and returns a Replacement Item if not possible
+ * Gets an Item from the specified mod, and returns a Replacement Item if not possible
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, ItemStack aReplacement) {
if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null;
@@ -350,7 +398,7 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft, but the Damage Value can be specified
+ * Gets an Item from the specified mod, but the Damage Value can be specified
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta) {
ItemStack rStack = getModItem(aModID, aItem, aAmount);
@@ -360,7 +408,7 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible
+ * Gets an Item from the specified mod, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta, ItemStack aReplacement) {
ItemStack rStack = getModItem(aModID, aItem, aAmount, aReplacement);
@@ -412,8 +460,8 @@ public class GT_ModHandler {
aChance = (float) GregTech_API.sRecipeFile.get(ConfigCategories.Machines.scrapboxdrops, aOutput, aChance);
if (aChance <= 0) return false;
try {
- GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copy(aOutput), aChance);
- GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copy(aOutput), aChance);
+ GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copyOrNull(aOutput), aChance);
+ GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copyOrNull(aOutput), aChance);
} catch (Throwable e) {/*Do nothing*/}
return true;
}
@@ -436,7 +484,7 @@ public class GT_ModHandler {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null || GT_Utility.getContainerItem(aInput, false) != null) return false;
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.smelting, aInput, true)) return false;
- FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F);
+ FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F);
return true;
}
@@ -502,10 +550,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;
}
@@ -516,8 +562,8 @@ public class GT_ModHandler {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null || aTime <= 0) return false;
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rcblastfurnace, aInput, true)) return false;
- aInput = GT_Utility.copy(aInput);
- aOutput = GT_Utility.copy(aOutput);
+ aInput = GT_Utility.copyOrNull(aInput);
+ aOutput = GT_Utility.copyOrNull(aOutput);
try {
mods.railcraft.api.crafting.RailcraftCraftingManager.blastFurnace.addRecipe(aInput, true, false, aTime, aOutput);
} catch (Throwable e) {
@@ -557,12 +603,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);
@@ -572,28 +614,28 @@ public class GT_ModHandler {
if (Materials.Wood.contains(aOutput1)) {
if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) {
if (aOutput2 == null)
- ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1));
+ ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1));
else
- ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2);
+ ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2);
}
} else {
if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rockcrushing, aInput, true)) {
try {
if (GT_Utility.getBlockFromStack(aInput) != Blocks.obsidian && GT_Utility.getBlockFromStack(aInput) != Blocks.gravel) {
mods.railcraft.api.crafting.IRockCrusherRecipe tRecipe = mods.railcraft.api.crafting.RailcraftCraftingManager.rockCrusher.createNewRecipe(GT_Utility.copyAmount(1, aInput), aInput.getItemDamage() != W, false);
- tRecipe.addOutput(GT_Utility.copy(aOutput1), 1.0F / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput1), 1.0F / aInput.stackSize);
if (aOutput2 != null)
- tRecipe.addOutput(GT_Utility.copy(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize);
if (aOutput3 != null)
- tRecipe.addOutput(GT_Utility.copy(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize);
}
} catch (Throwable e) {/*Do nothing*/}
}
if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) {
if (aOutput2 == null)
- ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1));
+ ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1));
else
- ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2);
+ ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2);
}
}
}
@@ -660,7 +702,7 @@ public class GT_ModHandler {
if (!GT_Mod.gregtechproxy.mTEMachineRecipes && !GregTech_API.sRecipeFile.get(ConfigCategories.Machines.inductionsmelter, aInput2 == null ? aInput1 : aOutput1, true))
return false;
try {
- ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copy(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance);
+ ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copyOrNull(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance);
} catch (Throwable e) {/*Do nothing*/}
return true;
}
@@ -671,7 +713,7 @@ public class GT_ModHandler {
public static boolean addOreToIngotSmeltingRecipe(ItemStack aInput, ItemStack aOutput) {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null) return false;
- FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F);
+ FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F);
return true;
}
@@ -680,39 +722,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() {
@@ -762,14 +799,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;
}
@@ -778,15 +809,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;
}
@@ -796,10 +821,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;
}
@@ -824,16 +847,22 @@ public class GT_ModHandler {
aResult = GT_OreDictUnificator.get(true, aResult);
if (aResult == null || aRecipe == null || aResult.stackSize <= 0) return false;
try {
- mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copy(aResult), aRecipe));
+ mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copyOrNull(aResult), aRecipe));
} catch (Throwable e) {
- return addCraftingRecipe(GT_Utility.copy(aResult), aRecipe);
+ return addCraftingRecipe(GT_Utility.copyOrNull(aResult), aRecipe);
}
return true;
}
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();
}
@@ -897,18 +926,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++) {
@@ -921,21 +986,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);
@@ -1002,8 +1067,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;
@@ -1019,20 +1084,27 @@ public class GT_ModHandler {
Character chr = (Character) aRecipe[idx];
Object in = aRecipe[idx + 1];
if (in instanceof ItemStack) {
- tItemStackMap.put(chr, GT_Utility.copy(in));
- tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in));
+ ItemStack is = (ItemStack) in;
+ tItemStackMap.put(chr, GT_Utility.copyOrNull(is));
+ tItemDataMap.put(chr, GT_OreDictUnificator.getItemData(is));
} 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;
@@ -1062,7 +1134,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));
}
@@ -1070,12 +1142,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);
@@ -1083,10 +1158,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++) {
@@ -1106,9 +1185,9 @@ public class GT_ModHandler {
if (tThereWasARecipe || !aOnlyAddIfThereIsAnyRecipeOutputtingThis) {
if (sBufferCraftingRecipes && aBuffered)
- sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
+ sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
else
- GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
+ GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
}
return true;
}
@@ -1163,14 +1242,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);
}
@@ -1183,9 +1261,9 @@ public class GT_ModHandler {
GT_Utility.updateItemStack(aResult);
if (sBufferCraftingRecipes && aBuffered)
- sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
+ sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
else
- GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
+ GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
return true;
}
@@ -1212,14 +1290,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
@@ -1242,6 +1314,54 @@ 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ 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);
}
@@ -1268,7 +1388,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;
}
@@ -1276,6 +1399,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
@@ -1286,8 +1427,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;
}
@@ -1345,23 +1486,25 @@ public class GT_ModHandler {
* Used for Recipe Detection.
*/
public static ItemStack getRecipeOutput(ItemStack... aRecipe) {
- return getRecipeOutput(false, aRecipe);
+ return getRecipeOutput(false, true, aRecipe);
}
-
+
+ public static ItemStack getRecipeOutputNoOreDict(ItemStack... aRecipe) {
+ return getRecipeOutput(false,false, aRecipe);
+ }
+
+ public static ItemStack getRecipeOutput(boolean aUncopiedStack, ItemStack... aRecipe) {
+ return getRecipeOutput(aUncopiedStack, true, aRecipe);
+ }
+
/**
* Gives you a copy of the Output from a Crafting Recipe
* 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;
+ @SuppressWarnings("unchecked")
+ public static ItemStack getRecipeOutput(boolean aUncopiedStack, boolean allowOreDict, ItemStack... aRecipe) {
+ if (aRecipe == null || Arrays.stream(aRecipe).noneMatch(Objects::nonNull)) return null;
+
InventoryCrafting aCrafting = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer var1) {
@@ -1370,22 +1513,26 @@ 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;
+ if (!allowOreDict && iRecipe instanceof ShapedOreRecipe) continue;
+
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)
throw new GT_ItsNotMyFaultException("Seems another Mod added a Crafting Recipe with null Output. Tell the Developer of said Mod to fix that.");
} else {
if (aUncopiedStack) return tOutput;
- return GT_Utility.copy(tOutput);
+ return GT_Utility.copyOrNull(tOutput);
}
}
}
@@ -1533,7 +1680,7 @@ public class GT_ModHandler {
if (tRecipe instanceof ShapelessRecipes) continue;
if (tRecipe instanceof ShapelessOreRecipe) continue;
if (tRecipe instanceof IGT_CraftingRecipe) continue;
- rList.add(GT_Utility.copy(tOutput));
+ rList.add(GT_Utility.copyOrNull(tOutput));
aList.remove(i--);
}
}
@@ -1545,7 +1692,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getMaceratorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1553,7 +1700,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getExtractorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1561,7 +1708,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getCompressorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1595,14 +1742,14 @@ 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);
for (byte i = 0; i < aOutputSlots.length && i < tList.length; i++) {
if (tList[i] != null) {
if (aOutputSlots[i] == null || (GT_Utility.areStacksEqual(tList[i], aOutputSlots[i]) && tList[i].stackSize + aOutputSlots[i].stackSize <= aOutputSlots[i].getMaxStackSize())) {
- rList[i] = GT_Utility.copy(tList[i]);
+ rList[i] = GT_Utility.copyOrNull(tList[i]);
} else {
return new ItemStack[aOutputSlots.length];
}
@@ -1685,7 +1832,7 @@ public class GT_ModHandler {
int tTier = ((ic2.api.item.IElectricItem) aStack.getItem()).getTier(aStack);
if (tTier < 0 || tTier == aTier || aTier == Integer.MAX_VALUE) {
if (!aIgnoreLimit && tTier >= 0)
- aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))]);
+ aCharge = (int) Math.min(aCharge, V[Math.max(0, Math.min(V.length - 1, tTier))] + B[Math.max(0, Math.min(V.length - 1, tTier))]);
if (aCharge > 0) {
// int rCharge = Math.max(0, ic2.api.item.ElectricItem.manager.discharge(aStack, aCharge + (aCharge * 4 > aTier ? aTier : 0), tTier, T, aSimulate));
int rCharge = (int) Math.max(0, ic2.api.item.ElectricItem.manager.discharge(aStack, aCharge + (aCharge * 4 > aTier ? aTier : 0), tTier, true, !aIgnoreDischargability, aSimulate));
@@ -1861,7 +2008,22 @@ public class GT_ModHandler {
public static int getCapsuleCellContainerCount(ItemStack aStack) {
if (aStack == null) return 0;
- return GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1)) || OrePrefixes.cell.contains(aStack) || OrePrefixes.cellMolten.contains(aStack) || OrePrefixes.cellPlasma.contains(aStack) || GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W)) ? 1 : 0;
+
+ if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1))) {
+ return 1;
+ }
+
+ if (GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W))) {
+ return 1;
+ }
+
+ for (OrePrefixes cellType : OrePrefixes.CELL_TYPES) {
+ if (cellType.contains(aStack)) {
+ return 1;
+ }
+ }
+
+ return 0;
}
public static class RecipeBits {
@@ -1917,6 +2079,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_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
index e30fe5d606..3071cb95a3 100644
--- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
+++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
@@ -1,11 +1,19 @@
package gregtech.api.util;
-import java.util.LinkedList;
-import java.util.List;
-
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import gregtech.api.enums.Materials;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
/**
* This makes it easier to build multi tooltips, with a standardized format. <br>
* Info section order should be:<br>
@@ -32,12 +40,16 @@ import net.minecraft.util.StatCollector;
public class GT_Multiblock_Tooltip_Builder {
private static final String TAB = " ";
private static final String COLON = ": ";
-
+ private static final String SEPARATOR = ", ";
+
private final List<String> iLines;
private final List<String> sLines;
-
+ private final List<String> hLines;
+ private final SetMultimap<Integer, String> hBlocks;
+
private String[] iArray;
private String[] sArray;
+ private String[] hArray;
//Localized tooltips
private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType");
@@ -58,11 +70,17 @@ public class GT_Multiblock_Tooltip_Builder {
private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS");
private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold");
private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display");
+ private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint");
private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod");
+ private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air");
+ private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("structurelib.blockhint." + i + ".name")).toArray(String[]::new);
public GT_Multiblock_Tooltip_Builder() {
iLines = new LinkedList<>();
sLines = new LinkedList<>();
+ hLines = new LinkedList<>();
+ hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new);
+ hBlocks.put(StructureLibAPI.HINT_BLOCK_META_AIR, TT_air);
}
/**
@@ -103,11 +121,10 @@ public class GT_Multiblock_Tooltip_Builder {
}
/**
- * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br>
- * Machine Type: machine
+ * Add a line telling how much this machine pollutes.
*
- * @param machine
- * Name of the machine type
+ * @param pollution
+ * Amount of pollution per second when active
*
* @return Instance this method was called on.
*/
@@ -307,7 +324,136 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + TT_outputhatch + COLON + info);
return this;
}
-
+
+ /**
+ * Use this method to add a structural part that isn't covered by the other methods.<br>
+ * (indent)name: info
+ * @param name
+ * Name of the hatch or other component.
+ * @param info
+ * Positional information.
+ * @param dots
+ * The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info, int... dots) {
+ sLines.add(TAB + name + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, name);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Maintenance Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info, int... dots) {
+ sLines.add(TAB + TT_maintenancehatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_maintenancehatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Muffler Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info, int... dots) {
+ sLines.add(TAB + TT_mufflerhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_mufflerhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Energy Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info, int... dots) {
+ sLines.add(TAB + TT_energyhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_energyhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Dynamo Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info, int... dots) {
+ sLines.add(TAB + TT_dynamohatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_dynamohatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputBus(String info, int... dots) {
+ sLines.add(TAB + TT_inputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_inputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputBus(String info, int... dots) {
+ sLines.add(TAB + TT_outputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Hatch: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_outputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputhatch);
+ return this;
+ }
+
/**
* Use this method to add non-standard structural info.<br>
* (indent)info
@@ -319,6 +465,30 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + info);
return this;
}
+
+ /**
+ * Use this method to add non-standard structural hint. This info will appear before the standard structural hint.
+ * @param info
+ * The line to be added. This should be an entry into minecraft's localization system.
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String info) {
+ hLines.add(StatCollector.translateToLocal(info));
+ return this;
+ }
+
+ /**
+ * Use this method to add an entry to standard structural hint without creating a corresponding line in structure information
+ * @param name
+ * The name of block This should be an entry into minecraft's localization system.
+ * @param dots
+ * Possible locations of this block
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String name, int... dots) {
+ for (int dot : dots) hBlocks.put(dot, StatCollector.translateToLocal(name));
+ return this;
+ }
/**
* Call at the very end.<br>
@@ -331,10 +501,11 @@ public class GT_Multiblock_Tooltip_Builder {
public void toolTipFinisher(String mod) {
iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay);
iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY);
- iArray = new String[iLines.size()];
- sArray = new String[sLines.size()];
- iLines.toArray(iArray);
- sLines.toArray(sArray);
+ hLines.add(TT_structurehint);
+ iArray = iLines.toArray(new String[0]);
+ sArray = sLines.toArray(new String[0]);
+ // e.getKey() - 1 because 1 dot is meta 0.
+ hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey() - 1] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new);
}
public String[] getInformation() {
@@ -345,4 +516,7 @@ public class GT_Multiblock_Tooltip_Builder {
return sArray;
}
+ public String[] getStructureHint() {
+ return hArray;
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
index 188af9cfaa..54ef5b2866 100644
--- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
+++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
@@ -13,13 +13,17 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
+import javax.annotation.Nullable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import static gregtech.api.enums.GT_Values.*;
+import static gregtech.api.enums.GT_Values.E;
+import static gregtech.api.enums.GT_Values.M;
+import static gregtech.api.enums.GT_Values.W;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -31,10 +35,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 +85,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) {
@@ -104,13 +108,22 @@ public class GT_OreDictUnificator {
public static ItemStack get(Object aName, ItemStack aReplacement, long aAmount, boolean aMentionPossibleTypos, boolean aNoInvalidAmounts) {
if (aNoInvalidAmounts && aAmount < 1) return null;
- if (!sName2StackMap.containsKey(aName.toString()) && aMentionPossibleTypos)
+ final ItemStack stackFromName = sName2StackMap.get(aName.toString());
+ if (stackFromName != null) return GT_Utility.copyAmount(aAmount, stackFromName);
+ if (aMentionPossibleTypos) {
GT_Log.err.println("Unknown Key for Unification, Typo? " + aName);
- return GT_Utility.copyAmount(aAmount, sName2StackMap.get(aName.toString()), getFirstOre(aName, aAmount), aReplacement);
+ // Debug callstack of entries not in sName2StackMap
+ // StackTraceElement[] cause = Thread.currentThread().getStackTrace();
+ // GT_Log.err.println(Arrays.toString(cause));
+
+ }
+ final ItemStack stackFirstOre = getFirstOre(aName, aAmount);
+ if (stackFirstOre != null) return GT_Utility.copyAmount(aAmount, stackFirstOre);
+ return GT_Utility.copyAmount(aAmount, aReplacement);
}
public static ItemStack[] setStackArray(boolean aUseBlackList, ItemStack... aStacks) {
- for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i]));
+ for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copyOrNull(aStacks[i]));
return aStacks;
}
@@ -142,15 +155,15 @@ public class GT_OreDictUnificator {
ItemData tPrefixMaterial = getAssociation(aStack);
ItemStack rStack = null;
if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed))
- return GT_Utility.copy(aStack);
+ return GT_Utility.copyOrNull(aStack);
if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) {
tPrefixMaterial.mBlackListed = true;
- return GT_Utility.copy(aStack);
+ return GT_Utility.copyOrNull(aStack);
}
if (tPrefixMaterial.mUnificationTarget == null)
tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString());
rStack = tPrefixMaterial.mUnificationTarget;
- if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copy(aStack);
+ if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copyOrNull(aStack);
assert rStack != null;
rStack.setTagCompound(aStack.getTagCompound());
return GT_Utility.copyAmount(aStack.stackSize, rStack);
@@ -158,6 +171,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 +236,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 +250,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 +326,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 +355,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++;
@@ -433,7 +448,6 @@ public class GT_OreDictUnificator {
public static ItemStack getIngotOrDust(MaterialStack aMaterial) {
ItemStack rStack = getIngot(aMaterial);
- if(aMaterial!=null&&aMaterial.mMaterial!=null&&(aMaterial.mMaterial==Materials.Naquadah||aMaterial.mMaterial==Materials.NaquadahEnriched))rStack = getDust(aMaterial);
if (rStack == null) rStack = getDust(aMaterial);
return rStack;
}
@@ -463,8 +477,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_PlayedSound.java b/src/main/java/gregtech/api/util/GT_PlayedSound.java
index 136171f7b7..82c728ff8b 100644
--- a/src/main/java/gregtech/api/util/GT_PlayedSound.java
+++ b/src/main/java/gregtech/api/util/GT_PlayedSound.java
@@ -25,4 +25,4 @@ public class GT_PlayedSound {
public int hashCode() {
return mX + mY + mZ + mSoundName.hashCode();
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java b/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java
index e25a0209d9..853a493f4a 100644
--- a/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java
+++ b/src/main/java/gregtech/api/util/GT_ProcessingArray_Manager.java
@@ -28,4 +28,4 @@ public class GT_ProcessingArray_Manager {
return mRecipeCache.get(mMetaKeyMap.get(aMeta));
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index 537d92b365..f941a86f5c 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -9,6 +9,7 @@ import gregtech.api.objects.GT_FluidStack;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.ItemData;
import gregtech.api.objects.MaterialStack;
+import gregtech.api.util.extensions.ArrayExt;
import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator;
import gregtech.nei.GT_NEI_DefaultHandler.FixedPositionedStack;
import ic2.core.Ic2Items;
@@ -96,7 +97,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
mEnabled = aRecipe.mEnabled;
mHidden = aRecipe.mHidden;
}
- protected GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) {
+
+ public GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) {
if (aInputs == null)
aInputs = new ItemStack[0];
if (aOutputs == null)
@@ -110,10 +112,10 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (aChances.length < aOutputs.length)
aChances = Arrays.copyOf(aChances, aOutputs.length);
- aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]);
- aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]);
- aFluidInputs = GT_Utility.getArrayListWithoutNulls(aFluidInputs).toArray(new FluidStack[0]);
- aFluidOutputs = GT_Utility.getArrayListWithoutNulls(aFluidOutputs).toArray(new FluidStack[0]);
+ aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new);
+ aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new);
+ aFluidInputs = ArrayExt.withoutNulls(aFluidInputs, FluidStack[]::new);
+ aFluidOutputs = ArrayExt.withoutNulls(aFluidOutputs, FluidStack[]::new);
GT_OreDictUnificator.setStackArray(true, aInputs);
GT_OreDictUnificator.setStackArray(true, aOutputs);
@@ -196,6 +198,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
this(aInput1, aOutput1, null, null, null, aFuelValue, aType);
}
+ private static FluidStack[] tryGetFluidInputsFromCells(ItemStack aInput) {
+ FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true);
+ return tFluid == null ? null : new FluidStack[] {tFluid};
+ }
+
// aSpecialValue = EU per Liter! If there is no Liquid for this Object, then it gets multiplied with 1000!
public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aSpecialValue, int aType) {
this(true, new ItemStack[]{aInput1}, new ItemStack[]{aOutput1, aOutput2, aOutput3, aOutput4}, null, null, null, null, 0, 0, Math.max(1, aSpecialValue));
@@ -312,12 +319,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public ItemStack getRepresentativeInput(int aIndex) {
if (aIndex < 0 || aIndex >= mInputs.length) return null;
- return GT_Utility.copy(mInputs[aIndex]);
+ return GT_Utility.copyOrNull(mInputs[aIndex]);
}
public ItemStack getOutput(int aIndex) {
if (aIndex < 0 || aIndex >= mOutputs.length) return null;
- return GT_Utility.copy(mOutputs[aIndex]);
+ return GT_Utility.copyOrNull(mOutputs[aIndex]);
}
public int getOutputChance(int aIndex) {
@@ -365,6 +372,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static boolean GTppRecipeHelper;
public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) {
+
+ if (mInputs.length > 0 && aInputs == null) return false;
if (mFluidInputs.length > 0 && aFluidInputs == null) return false;
int amt;
for (FluidStack tFluid : mFluidInputs)
@@ -386,15 +395,18 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (temp) return false;
}
- if (mInputs.length > 0 && aInputs == null) return false;
-
+ HashSet<Integer> isVisited = new HashSet<>();
+
for (ItemStack tStack : mInputs) {
ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack);
if (unified_tStack != null) {
amt = tStack.stackSize;
boolean temp = true;
+ int it = 0;
for (ItemStack aStack : aInputs) {
- if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack)) {
+ it ++;
+ if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isVisited.contains(it)) {
+ isVisited.add(it);
if (GTppRecipeHelper) {//remove once the fix is out
if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) {
if (!GT_Utility.areStacksEqual(aStack, tStack, false))
@@ -562,6 +574,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static final GT_Recipe_Map sFurnaceRecipes = new GT_Recipe_Map_Furnace(new HashSet<>(0), "mc.recipe.furnace", "Furnace", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false);
public static final GT_Recipe_Map sMicrowaveRecipes = new GT_Recipe_Map_Microwave(new HashSet<>(0), "gt.recipe.microwave", "Microwave", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false);
+ /** Set {@code aSpecialValue = -100} to bypass the disassembler tier check and default recipe duration. */
+ public static final GT_Recipe_Map sDisassemblerRecipes = new GT_Recipe_Map(new HashSet<>(250), "gt.recipe.disassembler", "Disassembler", null, RES_PATH_GUI + "basicmachines/Disassembler", 1, 9, 1, 0, 1, E, 1, E, true, false);
public static final GT_Recipe_Map sScannerFakeRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.scanner", "Scanner", null, RES_PATH_GUI + "basicmachines/Scanner", 1, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map(new HashSet<>(200), "gt.recipe.rockbreaker", "Rock Breaker", null, RES_PATH_GUI + "basicmachines/RockBreaker", 1, 1, 0, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sByProductList = new GT_Recipe_Map(new HashSet<>(1000), "gt.recipe.byproductlist", "Ore Byproduct List", null, RES_PATH_GUI + "basicmachines/Default", 1, 6, 1, 0, 1, E, 1, E, true, true);
@@ -599,7 +613,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map(new HashSet<>(1170), "gt.recipe.chemicalreactor", "Chemical Reactor", null, RES_PATH_GUI + "basicmachines/ChemicalReactor", 2, 2, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sMultiblockChemicalRecipes = new GT_Recipe_Map_LargeChemicalReactor();
public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map_DistillationTower();
- public static final GT_Recipe_Map sCrakingRecipes = new GT_Recipe_Map(new HashSet<>(70), "gt.recipe.craker", "Oil Cracker", null, RES_PATH_GUI + "basicmachines/OilCracker", 1, 1, 1, 2, 1, E, 1, E, true, true);
+ public static final GT_Recipe_Map_OilCracker sCrackingRecipes = new GT_Recipe_Map_OilCracker();
+ /**
+ * Use sCrackingRecipes instead
+ */
+ @Deprecated
+ public static final GT_Recipe_Map sCrakingRecipes = sCrackingRecipes;
public static final GT_Recipe_Map sPyrolyseRecipes = new GT_Recipe_Map(new HashSet<>(150), "gt.recipe.pyro", "Pyrolyse Oven", null, RES_PATH_GUI + "basicmachines/Default", 2, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sWiremillRecipes = new GT_Recipe_Map(new HashSet<>(450), "gt.recipe.wiremill", "Wiremill", null, RES_PATH_GUI + "basicmachines/Wiremill", 1, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sBenderRecipes = new GT_Recipe_Map(new HashSet<>(5000), "gt.recipe.metalbender", "Bending Machine", null, RES_PATH_GUI + "basicmachines/Bender", 2, 1, 2, 0, 1, E, 1, E, true, true);
@@ -898,7 +917,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
/**
* Abstract Class for general Recipe Handling of non GT Recipes
*/
- public static abstract class GT_Recipe_Map_NonGTRecipes extends GT_Recipe_Map {
+ public abstract static class GT_Recipe_Map_NonGTRecipes extends GT_Recipe_Map {
public GT_Recipe_Map_NonGTRecipes(Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) {
super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed);
}
@@ -971,6 +990,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
* Just a Recipe Map with Utility specifically for Fuels.
*/
public static class GT_Recipe_Map_Fuel extends GT_Recipe_Map {
+ private final Map<String, GT_Recipe> mRecipesByFluidInput = new HashMap<>();
public GT_Recipe_Map_Fuel(Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) {
super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed);
}
@@ -994,6 +1014,24 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe addFuel(ItemStack aInput, ItemStack aOutput, FluidStack aFluidInput, FluidStack aFluidOutput, int aChance, int aFuelValueInEU) {
return addRecipe(true, new ItemStack[]{aInput}, new ItemStack[]{aOutput}, null, new int[]{aChance}, new FluidStack[]{aFluidInput}, new FluidStack[]{aFluidOutput}, 0, 0, aFuelValueInEU);
}
+
+ @Override
+ public GT_Recipe add(GT_Recipe aRecipe) {
+ aRecipe = super.add(aRecipe);
+ if (aRecipe.mInputs != null && GT_Utility.getNonnullElementCount(aRecipe.mInputs) == 1 &&
+ (aRecipe.mFluidInputs == null || GT_Utility.getNonnullElementCount(aRecipe.mFluidInputs) == 0)) {
+ FluidStack tFluid = GT_Utility.getFluidForFilledItem(aRecipe.mInputs[0], true);
+ if (tFluid != null) {
+ tFluid.amount = 0;
+ mRecipesByFluidInput.put(tFluid.getUnlocalizedName(), aRecipe);
+ }
+ }
+ return aRecipe;
+ }
+
+ public GT_Recipe findFuel(FluidStack aFluidInput) {
+ return mRecipesByFluidInput.get(aFluidInput.getUnlocalizedName());
+ }
}
/**
@@ -1215,7 +1253,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.compressor.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1238,7 +1276,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.extractor.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1261,7 +1299,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.centrifuge.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 48, 0) : null;
}
@@ -1285,7 +1323,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null || aFluids == null || aFluids.length < 1 || !GT_ModHandler.isWater(aFluids[0]))
return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
NBTTagCompound aRecipeMetaData = new NBTTagCompound();
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.oreWashing.getRecipes(), true, aRecipeMetaData, null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, new FluidStack[]{new FluidStack(aFluids[0].getFluid(), ((NBTTagCompound) aRecipeMetaData.getTag("return")).getInteger("amount"))}, null, 400, 16, 0) : null;
@@ -1334,7 +1372,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (D1) GT_Log.err.println("Railcraft Not loaded");
} catch (NullPointerException e) {/**/}
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.macerator.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1597,12 +1635,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
}
}
-
- public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map{
- private static int TOTAL_INPUT_COUNT = 6;
- private static int OUTPUT_COUNT = 2;
- private static int FLUID_OUTPUT_COUNT = 4;
-
+
+ public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map {
+ private static final int TOTAL_INPUT_COUNT = 6;
+ private static final int OUTPUT_COUNT = 2;
+ private static final int FLUID_OUTPUT_COUNT = 4;
+
public GT_Recipe_Map_LargeChemicalReactor() {
super(new HashSet<>(1000), "gt.recipe.largechemicalreactor", "Large Chemical Reactor", null, RES_PATH_GUI + "basicmachines/Default", 2, OUTPUT_COUNT, 0, 0, 1, E, 1, E, true, true);
}
@@ -1618,7 +1656,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (aInputs == null) {
aInputs = new ItemStack[0];
} else {
- aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]);
+ aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new);
}
for (ItemStack input : aInputs) {
@@ -1658,7 +1696,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (aOutputs == null) {
aOutputs = new ItemStack[0];
} else {
- aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]);
+ aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new);
}
for (ItemStack output : aOutputs) {
@@ -1704,9 +1742,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
for (int i = 0; i < itemLimit; i++, j++) {
if (this.mInputs == null || (this.mInputs[i] == null && (i == 0 && itemLimit == 1))) {
if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null)
- GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!");
+ GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!");
else
- GT_Log.out.println("recipe " + this.toString() + " has errored!");
+ GT_Log.out.println("recipe " + this + " has errored!");
new Exception("Recipe Fixme").printStackTrace(GT_Log.out);
}
@@ -1721,9 +1759,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
for (int i = 0; i < fluidLimit; i++, j++) {
if (this.mFluidInputs == null || this.mFluidInputs[i] == null) {
if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null)
- GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!");
+ GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!");
else
- GT_Log.out.println("recipe " + this.toString() + " has errored!");
+ GT_Log.out.println("recipe " + this + " has errored!");
new Exception("Recipe Fixme").printStackTrace(GT_Log.out);
}
@@ -1807,6 +1845,26 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
}
}
+ public static class GT_Recipe_Map_OilCracker extends GT_Recipe_Map {
+ private final Set<String> mValidCatalystFluidNames = new HashSet<>();
+ public GT_Recipe_Map_OilCracker() {
+ super(new HashSet<>(70), "gt.recipe.craker", "Oil Cracker", null, RES_PATH_GUI + "basicmachines/OilCracker", 1, 1, 1, 2, 1, E, 1, E, true, true);
+ }
+
+ @Override
+ public GT_Recipe add(GT_Recipe aRecipe) {
+ GT_Recipe ret = super.add(aRecipe);
+ if (ret != null && ret.mFluidInputs != null && ret.mFluidInputs.length>1 && ret.mFluidInputs[1] != null) {
+ mValidCatalystFluidNames.add(ret.mFluidInputs[1].getFluid().getName());
+ }
+ return ret;
+ }
+
+ public boolean isValidCatalystFluid(FluidStack aFluidStack) {
+ return mValidCatalystFluidNames.contains(aFluidStack.getFluid().getName());
+ }
+ }
+
public static class GT_Recipe_WithAlt extends GT_Recipe {
ItemStack[][] mOreDictAlt;
@@ -1823,13 +1881,13 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (mOreDictAlt[aIndex] != null && mOreDictAlt[aIndex].length > 0) {
ItemStack[] rStacks = new ItemStack[mOreDictAlt[aIndex].length];
for (int i = 0; i < mOreDictAlt[aIndex].length; i++) {
- rStacks[i] = GT_Utility.copy(mOreDictAlt[aIndex][i]);
+ rStacks[i] = GT_Utility.copyOrNull(mOreDictAlt[aIndex][i]);
}
return rStacks;
}
}
if (aIndex >= mInputs.length) return null;
- return GT_Utility.copy(mInputs[aIndex]);
+ return GT_Utility.copyOrNull(mInputs[aIndex]);
}
}
@@ -1840,6 +1898,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed);
}
+ @Override
public GT_Recipe addFakeRecipe(boolean aCheckForCollisions, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecial, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) {
AtomicInteger ai = new AtomicInteger();
Optional.ofNullable(GT_OreDictUnificator.getAssociation(aOutputs[0]))
diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
index d10f6da434..34cf7ca80e 100644
--- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
+++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
@@ -1,5 +1,6 @@
package gregtech.api.util;
+import com.google.common.base.Stopwatch;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.*;
@@ -28,52 +29,52 @@ public class GT_RecipeRegistrator {
public static final List<Materials> sRodMaterialList = new ArrayList<Materials>();
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[][]
- sShapes1 = new ItemStack[][]{
- {sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null},
- {sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1},
- {null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1},
- {sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null},
- {sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1},
- {sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1},
- {null, null, null, sMt1, null, sMt1, sMt1, null, sMt1},
- {null, sMt1, null, null, sMt1, null, null, sMt2, null},
- {sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null},
- {null, sMt1, null, null, sMt2, null, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null},
- {null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, null, sMt2, null, null, sMt2, null},
- {null, sMt1, sMt1, null, sMt2, null, null, sMt2, null},
- {null, sMt1, null, sMt1, null, null, null, sMt1, sMt2},
- {null, sMt1, null, null, null, sMt1, sMt2, sMt1, null},
- {null, sMt1, null, sMt1, null, sMt1, null, null, sMt2},
- {null, sMt1, null, sMt1, null, sMt1, sMt2, null, null},
- {null, sMt2, null, null, sMt1, null, null, sMt1, null},
- {null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1},
- {null, sMt2, null, null, sMt2, null, null, sMt1, null},
- {null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null},
- {null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, null, sMt2, null, sMt1, sMt1, null},
- {sMt1, null, null, null, sMt2, null, null, null, sMt2},
- {null, null, sMt1, null, sMt2, null, sMt2, null, null},
- {sMt1, null, null, null, sMt2, null, null, null, null},
- {null, null, sMt1, null, sMt2, null, null, null, null},
- {sMt1, sMt2, null, null, null, null, null, null, null},
- {sMt2, sMt1, null, null, null, null, null, null, null},
- {sMt1, null, null, sMt2, null, null, null, null, null},
- {sMt2, null, null, sMt1, null, null, null, null, null},
- {sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null},
- {null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1},
- {sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null},
- {null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1},
- {sMt1, null, null, null, sMt1, null, null, null, null},
- {null, sMt1, null, sMt1, null, null, null, null, null},
- {sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null},
- {null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2}
+ private static final RecipeShape[]
+ sShapes = new RecipeShape[]{
+ new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null),
+ new RecipeShape(sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null),
+ new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1),
+ new RecipeShape(null, null, null, sMt1, null, sMt1, sMt1, null, sMt1),
+ new RecipeShape(null, sMt1, null, null, sMt1, null, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, null, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, null, null, sMt1, sMt2),
+ new RecipeShape(null, sMt1, null, null, null, sMt1, sMt2, sMt1, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, sMt1, null, null, sMt2),
+ new RecipeShape(null, sMt1, null, sMt1, null, sMt1, sMt2, null, null),
+ new RecipeShape(null, sMt2, null, null, sMt1, null, null, sMt1, null),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, null, sMt1, null),
+ new RecipeShape(null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null),
+ new RecipeShape(null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, null),
+ new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, sMt2),
+ new RecipeShape(null, null, sMt1, null, sMt2, null, sMt2, null, null),
+ new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, null),
+ new RecipeShape(null, null, sMt1, null, sMt2, null, null, null, null),
+ new RecipeShape(sMt1, sMt2, null, null, null, null, null, null, null),
+ new RecipeShape(sMt2, sMt1, null, null, null, null, null, null, null),
+ new RecipeShape(sMt1, null, null, sMt2, null, null, null, null, null),
+ new RecipeShape(sMt2, null, null, sMt1, null, null, null, null, null),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null),
+ new RecipeShape(null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null),
+ new RecipeShape(null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, null, null, null, sMt1, null, null, null, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null),
+ new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null),
+ new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2)
};
private static final String[][] sShapesA = new String[][]{
null,
@@ -260,14 +261,15 @@ public class GT_RecipeRegistrator {
long tAmount = 0;
for (MaterialStack tMaterial : aData.getAllMaterialStacks())
tAmount += tMaterial.mAmount * tMaterial.mMaterial.getMass();
- boolean tHide = (aData.mMaterial.mMaterial != Materials.Iron)&&(GT_Mod.gregtechproxy.mHideRecyclingRecipes);
+ boolean tHide = (aData.mMaterial.mMaterial != Materials.Iron) && (GT_Mod.gregtechproxy.mHideRecyclingRecipes);
RA.addPulveriserRecipe(aStack, new ItemStack[]{GT_OreDictUnificator.getDust(aData.mMaterial), GT_OreDictUnificator.getDust(aData.getByProduct(0)), GT_OreDictUnificator.getDust(aData.getByProduct(1)), GT_OreDictUnificator.getDust(aData.getByProduct(2))}, null, aData.mMaterial.mMaterial==Materials.Marble ? 1 : (int) Math.max(16, tAmount / M), 4, tHide);
- if (aAllowHammer) for (MaterialStack tMaterial : aData.getAllMaterialStacks())
- if (tMaterial.mMaterial.contains(SubTag.CRYSTAL) && !tMaterial.mMaterial.contains(SubTag.METAL) && tMaterial.mMaterial != Materials.Glass) {
- if (RA.addForgeHammerRecipe(GT_Utility.copyAmount(1, aStack), GT_OreDictUnificator.getDust(aData.mMaterial), 200, 30))
- break;
- }
+ if (aAllowHammer)
+ for (MaterialStack tMaterial : aData.getAllMaterialStacks())
+ if (tMaterial.mMaterial.contains(SubTag.CRYSTAL) && !tMaterial.mMaterial.contains(SubTag.METAL) && tMaterial.mMaterial != Materials.Glass) {
+ if (RA.addForgeHammerRecipe(GT_Utility.copyAmount(1, aStack), GT_OreDictUnificator.getDust(aData.mMaterial), 200, 30))
+ break;
+ }
ItemStack tDust = GT_OreDictUnificator.getDust(aData.mMaterial);
if (tDust != null && GT_ModHandler.addPulverisationRecipe(GT_Utility.copyAmount(1, aStack), tDust, GT_OreDictUnificator.getDust(aData.getByProduct(0)), 100, GT_OreDictUnificator.getDust(aData.getByProduct(1)), 100, true)) {
if (GregTech_API.sThaumcraftCompat != null)
@@ -278,7 +280,7 @@ public class GT_RecipeRegistrator {
/**
* Place Materials which you want to replace in Non-GT-Recipes here (warning HUGHE impact on loading times!)
*/
- private final static Materials[] VANILLA_MATS = {
+ private static final Materials[] VANILLA_MATS = {
Cobalt,
Gold,
Iron,
@@ -306,10 +308,7 @@ public class GT_RecipeRegistrator {
*/
public static synchronized void registerUsagesForMaterials(String aPlate, boolean aRecipeReplacing, ItemStack... aMats) {
for (ItemStack aMat : aMats) {
- if (aMat == null)
- continue;
-
- aMat = GT_Utility.copy(aMat);
+ aMat = GT_Utility.copyOrNull(aMat);
if (aMat == null)
continue;
@@ -326,20 +325,17 @@ public class GT_RecipeRegistrator {
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, 0);
- for (ItemStack[] tRecipe : sShapes1) {
- int tAmount1 = 0;
- for (ItemStack tMat : tRecipe) {
- if (tMat == sMt1) tAmount1++;
- }
- if (aItemData != null && aItemData.hasValidPrefixMaterialData())
- for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe)) {
- GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1));
-// GT_Log.out.println("###################################################################################");
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate);
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName());
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName());
-// GT_Log.out.println("###################################################################################");
+ if(aItemData != null && aItemData.hasValidPrefixMaterialData()) {
+ for (RecipeShape tRecipe : sShapes) {
+ for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe.shape)) {
+ GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1));
+ // GT_Log.out.println("###################################################################################");
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate);
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName());
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName());
+ // GT_Log.out.println("###################################################################################");
}
+ }
}
registerStickStuff(aPlate, aItemData, aRecipeReplacing);
}
@@ -354,22 +350,17 @@ public class GT_RecipeRegistrator {
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, Items.feather.getDamage(tMt2));
- for (int i = 0; i < sShapes1.length; i++) {
- ItemStack[] tRecipe = sShapes1[i];
+ for (int i = 0; i < sShapes.length; i++) {
+ RecipeShape tRecipe = sShapes[i];
- int tAmount1 = 0, tAmount2 = 0;
- for (ItemStack tMat : tRecipe) {
- if (tMat == sMt1) tAmount1++;
- if (tMat == sMt2) tAmount2++;
- }
- for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe)) {
+ for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe.shape)) {
if (aItemData != null && aItemData.hasValidPrefixMaterialData())
- GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tAmount2)));
+ GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tRecipe.amount2)));
if (aRecipeReplacing && aPlate != null && sShapesA[i] != null && sShapesA[i].length > 1) {
assert aItemData != null;
if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.recipereplacements, aItemData.mMaterial.mMaterial + "." + sShapesA[i][0], true)) {
- if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe))) {
+ if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe.shape))) {
// GT_Log.out.println("###################################################################################");
// GT_Log.out.println("registerStickStuff used aPlate: "+aPlate);
// GT_Log.out.println("###################################################################################");
@@ -397,4 +388,18 @@ public class GT_RecipeRegistrator {
return Arrays.stream(VANILLA_MATS).anyMatch(mat -> mat == materials);
}
+ private static class RecipeShape {
+ private final ItemStack[] shape;
+ private int amount1;
+ private int amount2;
+
+ public RecipeShape(ItemStack... shape) {
+ this.shape = shape;
+
+ for (ItemStack stack : shape) {
+ if(stack == sMt1) this.amount1++;
+ if(stack == sMt2) this.amount2++;
+ }
+ }
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java b/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
index e51c490519..7ecabaffeb 100644
--- a/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Shaped_Recipe.java
@@ -1,7 +1,7 @@
package gregtech.api.util;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
-import gregtech.api.items.GT_MetaGenerated_Tool;
+import gregtech.api.objects.ReverseShapedRecipe;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.inventory.InventoryCrafting;
@@ -11,7 +11,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRecipe {
- public final boolean mDismantleable, mRemovableByGT, mKeepingNBT;
+ public final boolean mRemovableByGT, mKeepingNBT;
private final Enchantment[] mEnchantmentsAdded;
private final int[] mEnchantmentLevelsAdded;
@@ -21,7 +21,9 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec
mEnchantmentLevelsAdded = aEnchantmentLevelsAdded;
mRemovableByGT = aRemovableByGT;
mKeepingNBT = aKeepingNBT;
- mDismantleable = aDismantleAble;
+ if (aDismantleAble) {
+ new ReverseShapedRecipe(aResult, aRecipe);
+ }
}
@Override
@@ -65,23 +67,6 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec
if (tCharge > 0) GT_ModHandler.chargeElectricItem(rStack, tCharge, Integer.MAX_VALUE, true, false);
}
- // Saving Ingredients inside the Item.
- if (mDismantleable) {
- NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound();
- if (rNBT == null) rNBT = new NBTTagCompound();
- for (int i = 0; i < 9; i++) {
- ItemStack tStack = aGrid.getStackInSlot(i);
- if (tStack != null && GT_Utility.getContainerItem(tStack, true) == null && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) {
- tStack = GT_Utility.copyAmount(1, tStack);
- if(GT_Utility.isStackValid(tStack)){
- GT_ModHandler.dischargeElectricItem(tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
- tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound()));}
- }
- }
- rNBT.setTag("GT.CraftingComponents", tNBT);
- rStack.setTagCompound(rNBT);
- }
-
// Add Enchantments
for (int i = 0; i < mEnchantmentsAdded.length; i++)
GT_Utility.ItemNBT.addEnchantment(rStack, mEnchantmentsAdded[i], EnchantmentHelper.getEnchantmentLevel(mEnchantmentsAdded[i].effectId, rStack) + mEnchantmentLevelsAdded[i]);
@@ -96,4 +81,4 @@ public class GT_Shaped_Recipe extends ShapedOreRecipe implements IGT_CraftingRec
public boolean isRemovable() {
return mRemovableByGT;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java b/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
index 937ba0a837..2718ea3efa 100644
--- a/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java
@@ -1,7 +1,7 @@
package gregtech.api.util;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
-import gregtech.api.items.GT_MetaGenerated_Tool;
+import gregtech.api.objects.ReverseShapelessRecipe;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.inventory.InventoryCrafting;
@@ -11,7 +11,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapelessOreRecipe;
public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_CraftingRecipe {
- public final boolean mDismantleable, mRemovableByGT, mKeepingNBT;
+ public final boolean /*mDismantleable,*/ mRemovableByGT, mKeepingNBT;
private final Enchantment[] mEnchantmentsAdded;
private final int[] mEnchantmentLevelsAdded;
@@ -21,7 +21,9 @@ public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_Craft
mEnchantmentLevelsAdded = aEnchantmentLevelsAdded;
mRemovableByGT = aRemovableByGT;
mKeepingNBT = aKeepingNBT;
- mDismantleable = aDismantleAble;
+ if (aDismantleAble){
+ new ReverseShapelessRecipe(aResult, aRecipe);
+ }
}
@Override
@@ -66,20 +68,20 @@ public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_Craft
}
// Saving Ingredients inside the Item.
- if (mDismantleable) {
- NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound();
- if (rNBT == null) rNBT = new NBTTagCompound();
- for (int i = 0; i < 9; i++) {
- ItemStack tStack = aGrid.getStackInSlot(i);
- if (tStack != null && GT_Utility.getContainerItem(tStack, true) == null && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) {
- tStack = GT_Utility.copyAmount(1, tStack);
- GT_ModHandler.dischargeElectricItem(tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
- tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound()));
- }
- }
- rNBT.setTag("GT.CraftingComponents", tNBT);
- rStack.setTagCompound(rNBT);
- }
+// if (mDismantleable) {
+// NBTTagCompound rNBT = rStack.getTagCompound(), tNBT = new NBTTagCompound();
+// if (rNBT == null) rNBT = new NBTTagCompound();
+// for (int i = 0; i < 9; i++) {
+// ItemStack tStack = aGrid.getStackInSlot(i);
+// if (tStack != null && GT_Utility.getContainerItem(tStack, true) == null && !(tStack.getItem() instanceof GT_MetaGenerated_Tool)) {
+// tStack = GT_Utility.copyAmount(1, tStack);
+// GT_ModHandler.dischargeElectricItem(tStack, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, true);
+// tNBT.setTag("Ingredient." + i, tStack.writeToNBT(new NBTTagCompound()));
+// }
+// }
+// rNBT.setTag("GT.CraftingComponents", tNBT);
+// rStack.setTagCompound(rNBT);
+// }
// Add Enchantments
for (int i = 0; i < mEnchantmentsAdded.length; i++)
@@ -95,4 +97,4 @@ public class GT_Shapeless_Recipe extends ShapelessOreRecipe implements IGT_Craft
public boolean isRemovable() {
return mRemovableByGT;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java b/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java
index 9063b1f7c9..0e29950dbd 100644
--- a/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java
+++ b/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java
@@ -9,12 +9,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent.CheckSpawn;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
public class GT_SpawnEventHandler {
- public static volatile List<int[]> mobReps = new ArrayList();
+ public static volatile List<int[]> mobReps = new CopyOnWriteArrayList<>();
public GT_SpawnEventHandler() {
MinecraftForge.EVENT_BUS.register(this);
diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java
new file mode 100644
index 0000000000..a627da4fd6
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java
@@ -0,0 +1,183 @@
+package gregtech.api.util;
+
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.HeatingCoilLevel;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.api.interfaces.IHeatingCoil;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.BaseMetaPipeEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame;
+import gregtech.common.blocks.GT_Block_Casings5;
+import net.minecraft.block.Block;
+import net.minecraft.init.Items;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.World;
+
+import java.util.Arrays;
+import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
+import java.util.function.Function;
+
+public class GT_StructureUtility {
+ private GT_StructureUtility() {
+ throw new AssertionError("Not instantiable");
+ }
+
+ public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, int aDots) {
+ return ofHatchAdder(aHatchAdder, aTextureIndex, StructureLibAPI.getBlockHint(), aDots - 1);
+ }
+
+ public static <T> IStructureElement<T> ofFrame(Materials aFrameMaterial) {
+ if (aFrameMaterial == null) throw new IllegalArgumentException();
+ return new IStructureElement<T>() {
+
+ private IIcon[] mIcons;
+
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tBase = world.getTileEntity(x, y, z);
+ if (tBase instanceof BaseMetaPipeEntity) {
+ BaseMetaPipeEntity tPipeBase = (BaseMetaPipeEntity) tBase;
+ if (tPipeBase.isInvalidTileEntity()) return false;
+ if (tPipeBase.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame)
+ return aFrameMaterial == ((GT_MetaPipeEntity_Frame) tPipeBase.getMetaTileEntity()).mMaterial;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ if (mIcons == null) {
+ mIcons = new IIcon[6];
+ Arrays.fill(mIcons, aFrameMaterial.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon());
+ }
+ StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, aFrameMaterial.mRGBa);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ ItemStack tFrameStack = GT_OreDictUnificator.get(OrePrefixes.frameGt, aFrameMaterial, 1);
+ if (tFrameStack.getItem() instanceof ItemBlock) {
+ ItemBlock tFrameStackItem = (ItemBlock) tFrameStack.getItem();
+ return tFrameStackItem.placeBlockAt(tFrameStack, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrameStack));
+ }
+ return false;
+ }
+ };
+ }
+
+ public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int aHintMeta) {
+ if (aHatchAdder == null || aHintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElementNoPlacement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ return tileEntity instanceof IGregTechTileEntity && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex);
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta);
+ return true;
+ }
+ };
+ }
+
+ public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) {
+ return ofHatchAdderOptional(aHatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta);
+ }
+
+ public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) {
+ if (aHatchAdder == null || aHintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ Block worldBlock = world.getBlock(x, y, z);
+ return (tileEntity instanceof IGregTechTileEntity &&
+ aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex)) ||
+ (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta);
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, hintMeta);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2);
+ return true;
+ }
+ };
+ }
+
+ /**
+ * Assume all coils accepted.
+ * @see #ofCoil(BiPredicate, Function)
+ */
+ public static <T> IStructureElement<T> ofCoil(BiConsumer<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) {
+ return ofCoil((t, l) -> {
+ aHeatingCoilSetter.accept(t, l);
+ return true;
+ }, aHeatingCoilGetter);
+ }
+
+ /**
+ * Heating coil structure element.
+ * @param aHeatingCoilSetter Notify the controller of this new coil.
+ * Got called exactly once per coil.
+ * Might be called less times if structure test fails.
+ * If the setter returns false then it assumes the coil is rejected.
+ * @param aHeatingCoilGetter Get the current heating level. Null means no coil recorded yet.
+ */
+ public static <T> IStructureElement<T> ofCoil(BiPredicate<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) {
+ if (aHeatingCoilSetter == null || aHeatingCoilGetter == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ Block block = world.getBlock(x, y, z);
+ if (!(block instanceof IHeatingCoil))
+ return false;
+ HeatingCoilLevel existingLevel = aHeatingCoilGetter.apply(t),
+ newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z));
+ if (existingLevel == null || existingLevel == HeatingCoilLevel.None) {
+ return aHeatingCoilSetter.test(t, newLevel);
+ } else {
+ return newLevel == existingLevel;
+ }
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger));
+ return true;
+ }
+
+ private int getMeta(ItemStack trigger) {
+ // -4 to skip unimplemented tiers
+ return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize - 1))));
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ return world.setBlock(x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger), 3);
+ }
+ };
+ }
+}
diff --git a/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java b/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java
new file mode 100644
index 0000000000..271b361da0
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_ToolHarvestHelper.java
@@ -0,0 +1,61 @@
+package gregtech.api.util;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+public class GT_ToolHarvestHelper {
+
+ public static boolean isAppropriateTool(Block aBlock, byte aMetaData, String... tTools) {
+
+ if (aBlock == null || tTools == null) {
+ return false;
+ }
+ String targetTool = aBlock.getHarvestTool(aMetaData);
+ return !isStringEmpty(targetTool) && isArrayContains(targetTool, tTools);
+ }
+
+ public static boolean isAppropriateMaterial(Block aBlock, Material... tMats) {
+ if (aBlock == null || tMats == null) {
+ return false;
+ }
+ return isArrayContains(aBlock.getMaterial(), tMats);
+ }
+
+
+ public static boolean isSpecialBlock(Block aBlock, Block... tBlocks) {
+ if (aBlock == null || tBlocks == null) {
+ return false;
+ }
+ return isArrayContains(aBlock, tBlocks);
+ }
+
+
+ public static <T> boolean isArrayContains(T obj, T[] list) {
+
+ if (obj == null || list == null) {
+ return false;
+ }
+
+ for (T iObj : list) {
+ if (obj == iObj || obj.equals(iObj)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isStringEmpty(String s) {
+ return s == null || s.length() == 0;
+ }
+
+ public static boolean hasNull(Object... obj) {
+ for (Object iObj : obj) {
+ if (iObj == null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 05e0874e7a..64a60e8630 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -1,24 +1,32 @@
package gregtech.api.util;
import cofh.api.transport.IItemDuct;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import com.gtnewhorizon.structurelib.alignment.IAlignment;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.FMLCommonHandler;
import gregtech.api.GregTech_API;
import gregtech.api.damagesources.GT_DamageSources;
+import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem;
import gregtech.api.enchants.Enchantment_Radioactivity;
import gregtech.api.enums.*;
import gregtech.api.events.BlockScanningEvent;
+import gregtech.api.interfaces.IBlockContainer;
import gregtech.api.interfaces.IDebugableBlock;
import gregtech.api.interfaces.IProjectileItem;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.*;
import gregtech.api.items.GT_EnergyArmor_Item;
import gregtech.api.items.GT_Generic_Item;
+import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.net.GT_Packet_Sound;
-import gregtech.api.objects.GT_CopiedBlockTexture;
+import gregtech.api.objects.CollectorUtils;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.ItemData;
import gregtech.api.threads.GT_Runnable_Sound;
+import gregtech.api.util.extensions.ArrayExt;
import gregtech.common.GT_Proxy;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeInputItemStack;
@@ -49,10 +57,7 @@ import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
-import net.minecraft.util.AxisAlignedBB;
-import net.minecraft.util.ChatComponentText;
-import net.minecraft.util.EnumChatFormatting;
-import net.minecraft.util.MathHelper;
+import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
@@ -67,14 +72,15 @@ import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.oredict.OreDictionary;
+import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
import java.util.*;
import java.util.Map.Entry;
+import java.util.function.IntFunction;
import static gregtech.GT_Mod.GT_FML_LOGGER;
import static gregtech.api.enums.GT_Values.*;
@@ -87,19 +93,28 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation;
* Just a few Utility Functions I use.
*/
public class GT_Utility {
+ /** Formats a number with group separator and at most 2 fraction digits. */
+ private static final DecimalFormat decimalFormat = new DecimalFormat();
+
/**
* 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<>();
+ private static final Map<Fluid, List<ItemStack>> sFluidToContainers = new 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");
static {
+ DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();
+ symbols.setGroupingSeparator(' ');
+ decimalFormat.setDecimalFormatSymbols(symbols);
+ decimalFormat.setMaximumFractionDigits(2);
+
GregTech_API.sItemStackMappings.add(sFilledContainerToData);
GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData);
}
@@ -109,7 +124,7 @@ public class GT_Utility {
}
public static int safeInt(long number){
- return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number<Integer.MIN_VALUE ? Integer.MIN_VALUE : (int)number;
+ return number> V[V.length-1] ? safeInt(V[V.length-1],1) : number<Integer.MIN_VALUE ? Integer.MIN_VALUE : (int)number;
}
public static Field getPublicField(Object aObject, String aField) {
@@ -250,8 +265,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);
@@ -260,7 +274,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);
}
@@ -279,8 +293,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);
@@ -288,7 +301,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);
}
@@ -369,9 +382,7 @@ public class GT_Utility {
if (TE_CHECK && aTileEntity instanceof IItemDuct) return true;
if (BC_CHECK && aTileEntity instanceof buildcraft.api.transport.IPipeTile)
return ((buildcraft.api.transport.IPipeTile) aTileEntity).isPipeConnected(ForgeDirection.getOrientation(aSide));
- if (GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator) return true;
-
- return false;
+ return GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator;
}
/**
* Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed.
@@ -393,16 +404,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]));
- ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack));
+ 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), copyOrNull(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;
}
@@ -413,15 +424,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]));
- byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo));
+ 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(copyOrNull(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;
}
@@ -437,15 +448,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;
}
@@ -469,7 +480,7 @@ public class GT_Utility {
ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null;
if (tStack1 != null) {
if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0;
- tStack3 = copy(tStack1);
+ tStack3 = copyOrNull(tStack1);
aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit())));
tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize));
if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce;
@@ -478,12 +489,11 @@ public class GT_Utility {
aTileEntity1.markDirty();
if (tStack3 != null) {
if (tStack2 == null) {
- aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3));
- aTileEntity2.markDirty();
+ aTileEntity2.setInventorySlotContents(aPutTo, copyOrNull(tStack3));
} else {
tStack2.stackSize += tStack3.stackSize;
- aTileEntity2.markDirty();
}
+ aTileEntity2.markDirty();
return (byte) tStack3.stackSize;
}
}
@@ -537,24 +547,46 @@ public class GT_Utility {
public static int moveMultipleItemStacks(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce,int aMaxStackTransfer, boolean aDoCheckChests) {
if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce || aMaxStackTransfer == 0)
return 0;
- int tGrabInventorySize = aTileEntity1.getSizeInventory();
+
+ int[] tGrabSlots = null;
+ if (aTileEntity1 instanceof ISidedInventory)
+ tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom);
+ if (tGrabSlots == null) {
+ tGrabSlots = new int[aTileEntity1.getSizeInventory()];
+ for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i;
+ }
+
+
+
+
+ int tGrabInventorySize = tGrabSlots.length;
if (aTileEntity2 instanceof IInventory)
{
+ int[] tPutSlots = null;
+ if (aTileEntity2 instanceof ISidedInventory)
+ tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo);
+
+ if (tPutSlots == null) {
+ tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()];
+ for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i;
+ }
+
IInventory tPutInventory = (IInventory) aTileEntity2;
- int tPutInventorySize = tPutInventory.getSizeInventory();
+ int tPutInventorySize = tPutSlots.length;
int tFirstsValidSlot = 0,tStacksMoved = 0,tTotalItemsMoved = 0;
- for (int tGrabSlot = 0;tGrabSlot<tGrabInventorySize;tGrabSlot++)
- {
+ for (int grabSlot : tGrabSlots) {
//ItemStack tInventoryStack : mInventory
int tMovedItems;
do {
- 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 tPutSlot = tFirstsValidSlot; tPutSlot < tPutInventorySize; tPutSlot++) {
+
+ for (int tPutSlotIndex = tFirstsValidSlot; tPutSlotIndex < tPutInventorySize; tPutSlotIndex++) {
+ int tPutSlot = tPutSlots[tPutSlotIndex];
if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) {
int tMoved = moveStackFromSlotAToSlotB(aTileEntity1, tPutInventory, tGrabSlot, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItems), aMinMoveAtOnce);
tTotalItemsMoved += tMoved;
@@ -568,7 +600,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;
@@ -609,10 +641,6 @@ public class GT_Utility {
}
//there should be a function to transfer more then 1 stack in a pipe
//ut i dont see any ways to improve it too much work for what it is worth
- int[] tGrabSlots = new int[tGrabInventorySize];
- for (int i = 0; i < tGrabInventorySize; i++) {
- tGrabSlots[i] = i;
- }
int tTotalItemsMoved = 0;
for (int i = 0; i < tGrabInventorySize; i++) {
int tMoved = moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests);
@@ -661,21 +689,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) {
@@ -733,11 +761,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;
}
}
@@ -829,13 +857,16 @@ 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);
- if (aList.size() < 1) return aTIfListEmpty;
- Iterator<ItemStack> tIterator = aList.iterator();
- ItemStack tStack = null;
- while (tIterator.hasNext())
- if ((tStack = tIterator.next()) != null && areStacksEqual(aStack, tStack)) return !aInvertFilter;
- return aInvertFilter;
+ boolean tEmpty = true;
+ for (ItemStack tStack : aList) {
+ if (tStack != null) {
+ tEmpty = false;
+ if (areStacksEqual(aStack, tStack)) {
+ return !aInvertFilter;
+ }
+ }
+ }
+ return tEmpty ? aTIfListEmpty : aInvertFilter;
}
public static boolean areStacksOrToolsEqual(ItemStack aStack1, ItemStack aStack2) {
@@ -859,7 +890,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) {
@@ -867,7 +900,7 @@ public class GT_Utility {
}
public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) {
- return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT);
+ return areStacksEqual(GT_OreDictUnificator.get_nocopy(aStack1), GT_OreDictUnificator.get_nocopy(aStack2), aIgnoreNBT);
}
public static String getFluidName(Fluid aFluid, boolean aLocalized) {
@@ -886,14 +919,22 @@ public class GT_Utility {
public static void reInit() {
sFilledContainerToData.clear();
sEmptyContainerToFluidToData.clear();
+ sFluidToContainers.clear();
for (FluidContainerData tData : sFluidContainerList) {
sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData);
Map<Fluid, FluidContainerData> tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer));
+ List<ItemStack> tContainers = sFluidToContainers.get(tData.fluid.getFluid());
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);
+ if (tContainers == null) {
+ tContainers = new ArrayList<>();
+ tContainers.add(tData.filledContainer);
+ sFluidToContainers.put(tData.fluid.getFluid(), tContainers);
+ }
+ else tContainers.add(tData.filledContainer);
}
}
@@ -901,11 +942,27 @@ public class GT_Utility {
sFluidContainerList.add(aData);
sFilledContainerToData.put(new GT_ItemStack(aData.filledContainer), aData);
Map<Fluid, FluidContainerData> tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(aData.emptyContainer));
+ List<ItemStack> tContainers = sFluidToContainers.get(aData.fluid.getFluid());
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);
+ if (tContainers == null) {
+ tContainers = new ArrayList<>();
+ tContainers.add(aData.filledContainer);
+ sFluidToContainers.put(aData.fluid.getFluid(), tContainers);
+ }
+ else tContainers.add(aData.filledContainer);
+ }
+
+ public static List<ItemStack> getContainersFromFluid(FluidStack tFluidStack) {
+ if (tFluidStack != null) {
+ List<ItemStack> tContainers = sFluidToContainers.get(tFluidStack.getFluid());
+ if (tContainers == null) return new ArrayList<>();
+ return tContainers;
+ }
+ return new ArrayList<>();
}
public static ItemStack fillFluidContainer(FluidStack aFluid, ItemStack aStack, boolean aRemoveFluidDirectly, boolean aCheckIFluidContainerItems) {
@@ -937,6 +994,10 @@ public class GT_Utility {
}
public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) {
+ return getFluidDisplayStack(aFluid, aUseStackSize, false);
+ }
+
+ public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize, boolean aHideStackSize) {
if (aFluid == null || aFluid.getFluid() == null) return null;
int tmp = 0;
try {
@@ -949,16 +1010,26 @@ public class GT_Utility {
tNBT.setLong("mFluidDisplayAmount", aUseStackSize ? aFluid.amount : 0);
tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid));
tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid));
+ tNBT.setBoolean("mHideStackSize", aHideStackSize);
rStack.setTagCompound(tNBT);
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)
return aFluid.isFluidEqual(((IFluidContainerItem) aStack.getItem()).getFluid(aStack = copyAmount(1, aStack)));
FluidContainerData tData = sFilledContainerToData.get(new GT_ItemStack(aStack));
- return tData == null ? false : tData.fluid.isFluidEqual(aFluid);
+ return tData != null && tData.fluid.isFluidEqual(aFluid);
}
public static FluidStack getFluidForFilledItem(ItemStack aStack, boolean aCheckIFluidContainerItems) {
@@ -1003,7 +1074,7 @@ public class GT_Utility {
return copyMetaData(Items.feather.getDamage(aStack) + 1, aStack);
return null;
}
-
+
public static synchronized boolean removeIC2BottleRecipe(ItemStack aContainer, ItemStack aInput, Map<ic2.api.recipe.ICannerBottleRecipeManager.Input, RecipeOutput> aRecipeList, ItemStack aOutput){
if ((isStackInvalid(aInput) && isStackInvalid(aOutput) && isStackInvalid(aContainer)) || aRecipeList == null) return false;
boolean rReturn = false;
@@ -1044,22 +1115,38 @@ 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;
}
}
ItemStack[] tStack = GT_OreDictUnificator.getStackArray(true, aOutput);
- if(tStack==null||(tStack.length>0&&GT_Utility.areStacksEqual(aInput, tStack[0])))return false;
+ if(tStack==null||(tStack.length>0&& areStacksEqual(aInput, tStack[0])))return false;
if (tOreName != null) {
if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false;
aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack));
} else {
- aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack));
+ aRecipeList.put(new RecipeInputItemStack(copyOrNull(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack));
}
return true;
}
@@ -1103,7 +1190,7 @@ public class GT_Utility {
rStack.setTagCompound(tNBT);
GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'");
GregTech_API.sBookList.put(aMapping, rStack);
- return copy(rStack);
+ return copyOrNull(rStack);
}
public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) {
@@ -1182,20 +1269,27 @@ public class GT_Utility {
return false;
}
+ /**
+ * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result.
+ */
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;
}
+ /**
+ * Note: use {@link ArrayExt#withoutTrailingNulls(Object[], IntFunction)} if you want an array as a result.
+ */
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;
}
+ @Deprecated // why do you use Objects?
public static Block getBlock(Object aBlock) {
return (Block) aBlock;
}
@@ -1209,12 +1303,14 @@ public class GT_Utility {
return Block.getBlockFromItem(item);
}
+ @Deprecated // why do you use Objects? And if you want to check your block to be not null, check it directly!
public static boolean isBlockValid(Object aBlock) {
return (aBlock instanceof Block);
}
+ @Deprecated // why do you use Objects? And if you want to check your block to be null, check it directly!
public static boolean isBlockInvalid(Object aBlock) {
- return aBlock == null || !(aBlock instanceof Block);
+ return !(aBlock instanceof Block);
}
public static boolean isStringValid(Object aString) {
@@ -1352,24 +1448,24 @@ public class GT_Utility {
* Return texture id from item stack, unoptimized but readable?
* @return casing texture 0 to 16383
*/
- public static int getTextureId(Block blockFromBlock,byte metaFromBlock){
+ public static int getTextureId(Block blockFromBlock, byte metaFromBlock) {
for (int page = 0; page < Textures.BlockIcons.casingTexturePages.length; page++) {
ITexture[] casingTexturePage = Textures.BlockIcons.casingTexturePages[page];
- if(casingTexturePage!=null){
+ if (casingTexturePage != null) {
for (int index = 0; index < casingTexturePage.length; index++) {
ITexture iTexture = casingTexturePage[index];
- if(iTexture instanceof GT_CopiedBlockTexture){
- Block block = ((GT_CopiedBlockTexture) iTexture).getBlock();
- byte meta = ((GT_CopiedBlockTexture) iTexture).getMeta();
- if(meta==metaFromBlock && blockFromBlock==block){
- return (page<<7)+index;
+ if (iTexture instanceof IBlockContainer) {
+ Block block = ((IBlockContainer) iTexture).getBlock();
+ byte meta = ((IBlockContainer) iTexture).getMeta();
+ if (meta == metaFromBlock && blockFromBlock == block) {
+ return (page << 7) + index;
}
}
}
}
}
- throw new RuntimeException("Probably missing mapping or different texture class used for: "+
- blockFromBlock.getUnlocalizedName()+" meta:"+metaFromBlock);
+ throw new RuntimeException("Probably missing mapping or different texture class used for: " +
+ blockFromBlock.getUnlocalizedName() + " meta:" + metaFromBlock);
}
/**
@@ -1499,9 +1595,17 @@ public class GT_Utility {
return isWearingFullGasHazmat(aEntity);
}
- public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) {
+ public static boolean applyHeatDamage(EntityLivingBase entity, float damage) {
+ return applyHeatDamage(entity, damage, GT_DamageSources.getHeatDamage());
+ }
+
+ public static boolean applyHeatDamageFromItem(EntityLivingBase entity, float damage, ItemStack item) {
+ return applyHeatDamage(entity, damage, new DamageSourceHotItem(item));
+ }
+
+ private static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage, DamageSource source) {
if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.fireResistance) == null && !isWearingFullHeatHazmat(aEntity)) {
- aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage);
+ aEntity.attackEntityFrom(source, aDamage);
return true;
}
return false;
@@ -1564,6 +1668,12 @@ public class GT_Utility {
return null;
}
+ @Nullable
+ public static ItemStack copyOrNull(@Nullable ItemStack stack) {
+ if (isStackValid(stack)) return stack.copy();
+ return null;
+ }
+
public static ItemStack copyAmount(long aAmount, Object... aStacks) {
ItemStack rStack = copy(aStacks);
if (isStackInvalid(rStack)) return null;
@@ -1662,41 +1772,25 @@ 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;
}
- /**
- * 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>();
- for (Map.Entry<X, Y> tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue());
- return rMap;
+ public static <X, Y extends Comparable<Y>> LinkedHashMap<X, Y> sortMapByValuesAcending(Map<X, Y> map) {
+ return map.entrySet().stream().sorted(Entry.comparingByValue()).collect(CollectorUtils.entriesToMap(LinkedHashMap::new));
}
/**
* 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;
}
@@ -1723,7 +1817,7 @@ public class GT_Utility {
if(aDimensionID<=1 && aDimensionID>=-1 && !GregTech_API.sDimensionalList.contains(aDimensionID)) return true;
return !GregTech_API.sDimensionalList.contains(aDimensionID) && DimensionManager.isDimensionRegistered(aDimensionID);
}
-
+
//public static boolean isRealDimension(int aDimensionID) {
// try {
// if (DimensionManager.getProvider(aDimensionID).getClass().getName().contains("com.xcompwiz.mystcraft"))
@@ -1737,7 +1831,7 @@ public class GT_Utility {
// } catch (Throwable e) {/*Do nothing*/}
// return GregTech_API.sDimensionalList.contains(aDimensionID);
//}
-
+
public static boolean moveEntityToDimensionAtCoords(Entity entity, int aDimension, double aX, double aY, double aZ) {
//Credit goes to BrandonCore Author :!:
@@ -1836,22 +1930,32 @@ 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);
Block tBlock = aWorld.getBlock(aX, aY, aZ);
- tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----");
+ tList.add(
+ "----- X: " + EnumChatFormatting.AQUA + formatNumbers(aX) + EnumChatFormatting.RESET +
+ " Y: " + EnumChatFormatting.AQUA + formatNumbers(aY) + EnumChatFormatting.RESET +
+ " Z: " + EnumChatFormatting.AQUA + formatNumbers(aZ) + EnumChatFormatting.RESET +
+ " D: " + EnumChatFormatting.AQUA + aWorld.provider.dimensionId + EnumChatFormatting.RESET + " -----");
try {
- if (tTileEntity != null && tTileEntity instanceof IInventory)
- tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET);
+ if (tTileEntity instanceof IInventory)
+ tList.add(
+ trans("162","Name: ") + EnumChatFormatting.BLUE + ((IInventory) tTileEntity).getInventoryName() + EnumChatFormatting.RESET +
+ trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET);
else
- tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET);
-
- tList.add(trans("164","Hardness: ") +EnumChatFormatting.YELLOW+ tBlock.getBlockHardness(aWorld, aX, aY, aZ) +EnumChatFormatting.RESET+ trans("165"," Blast Resistance: ") +EnumChatFormatting.YELLOW+ tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) +EnumChatFormatting.RESET);
- if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD+ trans("166","Is valid Beacon Pyramid Material") +EnumChatFormatting.RESET);
+ tList.add(
+ trans("162","Name: ") + EnumChatFormatting.BLUE + tBlock.getUnlocalizedName() + EnumChatFormatting.RESET +
+ trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET);
+
+ tList.add(
+ trans("164","Hardness: ") + EnumChatFormatting.YELLOW + tBlock.getBlockHardness(aWorld, aX, aY, aZ) + EnumChatFormatting.RESET +
+ trans("165"," Blast Resistance: ") + EnumChatFormatting.YELLOW + tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) + EnumChatFormatting.RESET);
+ if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD + trans("166","Is valid Beacon Pyramid Material") + EnumChatFormatting.RESET);
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
@@ -1861,7 +1965,10 @@ public class GT_Utility {
rEUAmount += 500;
FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(ForgeDirection.getOrientation(aSide));
if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) {
- tList.add(trans("167","Tank ") + i + ": " +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) +EnumChatFormatting.RESET+ " L / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(tTanks[i].capacity) +EnumChatFormatting.RESET+ " L " +EnumChatFormatting.GOLD+ getFluidName(tTanks[i].fluid, true)+EnumChatFormatting.RESET);
+ tList.add(
+ trans("167","Tank ") + i + ": " +
+ EnumChatFormatting.GREEN + formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + EnumChatFormatting.RESET + " L / " +
+ EnumChatFormatting.YELLOW + formatNumbers(tTanks[i].capacity) + EnumChatFormatting.RESET + " L " + EnumChatFormatting.GOLD + getFluidName(tTanks[i].fluid, true) + EnumChatFormatting.RESET);
}
}
} catch (Throwable e) {
@@ -1878,8 +1985,23 @@ public class GT_Utility {
try {
if (tTileEntity instanceof ic2.api.reactor.IReactor) {
rEUAmount += 500;
- tList.add(trans("168","Heat: ") +EnumChatFormatting.GREEN+ ((ic2.api.reactor.IReactor) tTileEntity).getHeat() +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()+EnumChatFormatting.RESET);
- tList.add(trans("169","HEM: ") +EnumChatFormatting.YELLOW+((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() +EnumChatFormatting.RESET/*+ trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/);
+ tList.add(
+ trans("168","Heat: ") + EnumChatFormatting.GREEN + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getHeat()) + EnumChatFormatting.RESET + " / " +
+ EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()) + EnumChatFormatting.RESET);
+ tList.add(
+ trans("169","HEM: ") + EnumChatFormatting.YELLOW + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() + EnumChatFormatting.RESET
+ /* + trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/);
+ }
+ } catch (Throwable e) {
+ if (D1) e.printStackTrace(GT_Log.err);
+ }
+ try {
+ if (tTileEntity instanceof IAlignmentProvider) {
+ IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment();
+ if (tAlignment != null) {
+ rEUAmount += 100;
+ tList.add(trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + tAlignment.getExtendedFacing() + EnumChatFormatting.RESET);
+ }
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
@@ -1922,7 +2044,7 @@ public class GT_Utility {
try {
if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) {
rEUAmount += 200;
- tList.add(trans("175","Conduction Loss: ") +EnumChatFormatting.YELLOW+ ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()+EnumChatFormatting.RESET);
+ tList.add(trans("175","Conduction Loss: ") + EnumChatFormatting.YELLOW + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss() + EnumChatFormatting.RESET);
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
@@ -1930,7 +2052,9 @@ public class GT_Utility {
try {
if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) {
rEUAmount += 200;
- tList.add(trans("176","Contained Energy: ") +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()+EnumChatFormatting.RESET+" EU");
+ tList.add(
+ trans("176","Contained Energy: ") + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getStored()) + EnumChatFormatting.RESET + " EU / " +
+ EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()) + EnumChatFormatting.RESET + " EU");
//aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible");
}
} catch (Throwable e) {
@@ -1939,17 +2063,24 @@ public class GT_Utility {
try {
if (tTileEntity instanceof IUpgradableMachine) {
rEUAmount += 500;
- if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN+ trans("177","Has Muffler Upgrade") +EnumChatFormatting.RESET);
+ if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN + trans("177","Has Muffler Upgrade") + EnumChatFormatting.RESET);
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
try {
if (tTileEntity instanceof IMachineProgress) {
+ if (((IMachineProgress) tTileEntity).isAllowedToWork()) {
+ tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET);
+ }
+ if (((IMachineProgress) tTileEntity).wasShutdown()) {
+ tList.add("Shut down due to power loss." + EnumChatFormatting.RED + EnumChatFormatting.RESET);
+ }
rEUAmount += 400;
int tValue = 0;
if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress()))
- tList.add(trans("178","Progress/Load: ") +EnumChatFormatting.GREEN+GT_Utility.formatNumbers(((IMachineProgress) tTileEntity).getProgress()) +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+GT_Utility.formatNumbers(tValue) +EnumChatFormatting.RESET);
+ tList.add(trans("178","Progress/Load: ") + EnumChatFormatting.GREEN + formatNumbers(((IMachineProgress) tTileEntity).getProgress()) + EnumChatFormatting.RESET + " / " +
+ EnumChatFormatting.YELLOW + formatNumbers(tValue) + EnumChatFormatting.RESET);
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
@@ -1965,16 +2096,22 @@ public class GT_Utility {
}
try {
if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) {
- tList.add(trans("179","Max IN: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+((IBasicEnergyContainer)tTileEntity).getInputAmperage()+EnumChatFormatting.RESET+trans("183"," A"));
- tList.add(trans("181","Max OUT: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() +EnumChatFormatting.RESET+ trans("183"," A"));
- tList.add(trans("184","Energy: ") +EnumChatFormatting.GREEN+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) +EnumChatFormatting.RESET+ " EU");
+ tList.add(
+ trans("179","Max IN: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getInputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " + EnumChatFormatting.RESET +
+ trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer)tTileEntity).getInputAmperage()) + EnumChatFormatting.RESET + trans("183"," A"));
+ tList.add(
+ trans("181","Max OUT: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " + EnumChatFormatting.RESET +
+ trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputAmperage()) + EnumChatFormatting.RESET + trans("183"," A"));
+ tList.add(
+ trans("184","Energy: ") + EnumChatFormatting.GREEN + formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + EnumChatFormatting.RESET + " EU / " +
+ EnumChatFormatting.YELLOW + formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + EnumChatFormatting.RESET + " EU");
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
try {
if (tTileEntity instanceof IGregTechTileEntity) {
- tList.add(trans("186","Owned by: ") +EnumChatFormatting.BLUE+ ((IGregTechTileEntity) tTileEntity).getOwnerName()+EnumChatFormatting.RESET);
+ tList.add(trans("186","Owned by: ") + EnumChatFormatting.BLUE + ((IGregTechTileEntity) tTileEntity).getOwnerName() + EnumChatFormatting.RESET);
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
@@ -1988,52 +2125,53 @@ public class GT_Utility {
}
try {
if (tTileEntity instanceof ic2.api.crops.ICropTile) {
- if (((ic2.api.crops.ICropTile) tTileEntity).getScanLevel() < 4) {
- rEUAmount += 10000;
- ((ic2.api.crops.ICropTile) tTileEntity).setScanLevel((byte) 4);
- }
- if (((ic2.api.crops.ICropTile) tTileEntity).getID() >= 0 && ((ic2.api.crops.ICropTile) tTileEntity).getID() < ic2.api.crops.Crops.instance.getCropList().length && ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()] != null) {
- rEUAmount += 1000;
- tList.add(trans("187","Type -- Crop-Name: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].name()
- + trans("188"," Growth: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGrowth()
- + trans("189"," Gain: ") + ((ic2.api.crops.ICropTile) tTileEntity).getGain()
- + trans("190"," Resistance: ") + ((ic2.api.crops.ICropTile) tTileEntity).getResistance()
- );
- tList.add(trans("191","Plant -- Fertilizer: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrientStorage()
- + trans("192"," Water: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHydrationStorage()
- + trans("193"," Weed-Ex: ") + ((ic2.api.crops.ICropTile) tTileEntity).getWeedExStorage()
- + trans("194"," Scan-Level: ") + ((ic2.api.crops.ICropTile) tTileEntity).getScanLevel()
- );
- tList.add(trans("195","Environment -- Nutrients: ") + ((ic2.api.crops.ICropTile) tTileEntity).getNutrients()
- + trans("196"," Humidity: ") + ((ic2.api.crops.ICropTile) tTileEntity).getHumidity()
- + trans("197"," Air-Quality: ") + ((ic2.api.crops.ICropTile) tTileEntity).getAirQuality()
+ rEUAmount += 1000;
+ ic2.api.crops.ICropTile crop = (ic2.api.crops.ICropTile) tTileEntity;
+ if (crop.getScanLevel() < 4)
+ crop.setScanLevel((byte) 4);
+ if (crop.getCrop() != null) {
+ tList.add(trans("187", "Type -- Crop-Name: ") + crop.getCrop().name()
+ + trans("188", " Growth: ") + crop.getGrowth()
+ + trans("189", " Gain: ") + crop.getGain()
+ + trans("190", " Resistance: ") + crop.getResistance()
);
+ }
+ tList.add(trans("191","Plant -- Fertilizer: ") + crop.getNutrientStorage()
+ + trans("192"," Water: ") + crop.getHydrationStorage()
+ + trans("193"," Weed-Ex: ") + crop.getWeedExStorage()
+ + trans("194"," Scan-Level: ") + crop.getScanLevel()
+ );
+ tList.add(trans("195","Environment -- Nutrients: ") + crop.getNutrients()
+ + trans("196"," Humidity: ") + crop.getHumidity()
+ + trans("197"," Air-Quality: ") + crop.getAirQuality()
+ );
+ if (crop.getCrop() != null) {
StringBuilder tStringB = new StringBuilder();
- for (String tAttribute : ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].attributes()) {
+ for (String tAttribute : crop.getCrop().attributes()) {
tStringB.append(", ").append(tAttribute);
}
String tString = tStringB.toString();
tList.add(trans("198","Attributes:") + tString.replaceFirst(",", E));
- tList.add(trans("199","Discovered by: ") + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile) tTileEntity).getID()].discoveredBy());
+ tList.add(trans("199","Discovered by: ") + crop.getCrop().discoveredBy());
}
}
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
}
-
+
if (aPlayer.capabilities.isCreativeMode) {
FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read
if (tFluid!=null)
- tList.add(EnumChatFormatting.GOLD+tFluid.getLocalizedName()+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ tFluid.amount +EnumChatFormatting.RESET+" L");
+ tList.add(EnumChatFormatting.GOLD + tFluid.getLocalizedName() + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + formatNumbers(tFluid.amount) + EnumChatFormatting.RESET + " L");
else
- tList.add(EnumChatFormatting.GOLD+trans("201","Nothing")+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ '0' +EnumChatFormatting.RESET+" L");
+ tList.add(EnumChatFormatting.GOLD + trans("201","Nothing") + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + '0' + EnumChatFormatting.RESET + " L");
}
// if(aPlayer.capabilities.isCreativeMode){
int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair());
- if(chunkData !=null){
+ if(chunkData != null){
if(chunkData[GTPOLLUTION]>0){
- tList.add(trans("202","Pollution in Chunk: ")+EnumChatFormatting.RED+chunkData[GTPOLLUTION]+EnumChatFormatting.RESET+trans("203"," gibbl"));
+ tList.add(trans("202","Pollution in Chunk: ") + EnumChatFormatting.RED + formatNumbers(chunkData[GTPOLLUTION]) + EnumChatFormatting.RESET + trans("203"," gibbl"));
}else{
tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET);
}
@@ -2141,10 +2279,11 @@ public class GT_Utility {
}
public static String formatNumbers(long aNumber) {
- DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
- DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
- symbols.setGroupingSeparator(' ');
- return formatter.format(aNumber);
+ return decimalFormat.format(aNumber);
+ }
+
+ public static String formatNumbers(double aNumber) {
+ return decimalFormat.format(aNumber);
}
/*
@@ -2176,16 +2315,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;
@@ -2199,7 +2332,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) {
@@ -2242,7 +2375,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_())))
@@ -2315,13 +2448,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);
}
@@ -2335,8 +2468,8 @@ public class GT_Utility {
setBookTitle(aStack, "Raw Prospection Data");
- NBTTagCompound tNBT = GT_Utility.ItemNBT.getNBT(aStack);
-
+ NBTTagCompound tNBT = getNBT(aStack);
+
tNBT.setByte("prospection_tier", aTier);
tNBT.setString("prospection_pos", "Dim: " + aDim + "\nX: " + aX + " Y: " + aY + " Z: " + aZ);
@@ -2345,32 +2478,32 @@ 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]);
}
-
+
tNBT.setString("prospection_oils", joinListToString(tOilsTransformed));
String tOilsPosStr = "X: " + Math.floorDiv(aX, 16*8)*16*8 + " Z: " + Math.floorDiv(aZ, 16*8)*16*8 + "\n";
int xOff = aX - Math.floorDiv(aX, 16*8)*16*8;
xOff = xOff/16;
int xOffRemain = 7 - xOff;
-
+
int zOff = aZ - Math.floorDiv(aZ, 16*8)*16*8;
zOff = zOff/16;
int zOffRemain = 7 - zOff;
-
+
for( ; zOff > 0; zOff-- ) {
tOilsPosStr = tOilsPosStr.concat("--------\n");
}
for( ; xOff > 0; xOff-- ) {
tOilsPosStr = tOilsPosStr.concat("-");
}
-
+
tOilsPosStr = tOilsPosStr.concat("P");
-
+
for( ; xOffRemain > 0; xOffRemain-- ) {
tOilsPosStr = tOilsPosStr.concat("-");
}
@@ -2397,14 +2530,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");
@@ -2425,11 +2557,11 @@ public class GT_Utility {
+ "Location is center of orevein\n\n"
+ "Check NEI to confirm orevein type";
tNBTList.appendTag(new NBTTagString(tPageText));
-
+
if (tOres != null)
fillBookWithList(tNBTList, "Ores Found %s\n\n", "\n", 7, tOres);
-
+
if (tOils != null)
fillBookWithList(tNBTList, "Oils%s\n\n", "\n", 9, tOils);
@@ -2447,31 +2579,31 @@ public class GT_Utility {
tOilsPosStr + "\n" +
"P - Prospector in 8x8 field";
tNBTList.appendTag(new NBTTagString(tPageText));
-
+
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) {
@@ -2587,12 +2719,23 @@ public class GT_Utility {
}
public static boolean isPartOfMaterials(ItemStack aStack, Materials aMaterials){
- return GT_OreDictUnificator.getAssociation(aStack) != null ? GT_OreDictUnificator.getAssociation(aStack).mMaterial.mMaterial.equals(aMaterials) : false;
+ return GT_OreDictUnificator.getAssociation(aStack) != null && GT_OreDictUnificator.getAssociation(aStack).mMaterial.mMaterial.equals(aMaterials);
}
public static boolean isPartOfOrePrefix(ItemStack aStack, OrePrefixes aPrefix){
- return GT_OreDictUnificator.getAssociation(aStack) != null ? GT_OreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix) : false;
+ return GT_OreDictUnificator.getAssociation(aStack) != null && GT_OreDictUnificator.getAssociation(aStack).mPrefix.equals(aPrefix);
}
+
+ public static final ImmutableSet<String> ORE_BLOCK_CLASSES = ImmutableSet.of(
+ "com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Ores",
+ "com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_SmallOres",
+ "gtPlusPlus.core.block.base.BlockBaseOre"
+ );
+
+ public static boolean isOre(Block aBlock, int aMeta) {
+ return isOre(new ItemStack(aBlock, 1, aMeta)) || ORE_BLOCK_CLASSES.contains(aBlock.getClass().getName());
+ }
+
public static boolean isOre(ItemStack aStack) {
for (int id: OreDictionary.getOreIDs(aStack)) {
if (OreDictionary.getOreName(id).startsWith("ore"))
@@ -2601,4 +2744,173 @@ public class GT_Utility {
return false;
}
+ public static Optional<GT_Recipe> reverseShapelessRecipe(ItemStack output, Object... aRecipe) {
+ if (output == null) {
+ return Optional.empty();
+ }
+
+ List<ItemStack> inputs = new ArrayList<>();
+
+ for (Object o : aRecipe) {
+ if (o instanceof ItemStack) {
+ ItemStack toAdd = ((ItemStack) o).copy();
+ inputs.add(toAdd);
+ } else if (o instanceof String) {
+ ItemStack stack = GT_OreDictUnificator.get(o, 1);
+ if (stack == null) {
+ Optional<ItemStack> oStack = OreDictionary.getOres((String) o)
+ .stream()
+ .findAny();
+ if (oStack.isPresent()) {
+ ItemStack copy = oStack.get().copy();
+ inputs.add(copy);
+ }
+ } else {
+ ItemStack copy = stack.copy();
+ inputs.add(copy);
+ }
+ } else if (o instanceof Item)
+ inputs.add(new ItemStack((Item) o));
+ else if (o instanceof Block)
+ inputs.add(new ItemStack((Block) o));
+ else
+ throw new IllegalStateException("A Recipe contains an invalid input! Output: " + output);
+ }
+
+ inputs.removeIf(x -> x.getItem() instanceof GT_MetaGenerated_Tool);
+
+ return Optional.of(
+ new GT_Recipe(
+ false,
+ new ItemStack[]{output},
+ inputs.toArray(new ItemStack[0]),
+ null, null,
+ null, null,
+ 300, 30, 0
+ )
+ );
+ }
+
+
+ public static Optional<GT_Recipe> reverseShapedRecipe(ItemStack output, Object... aRecipe) {
+ if (output == null) {
+// System.out.println("Null Recipe detected!");
+ return Optional.empty();
+ }
+// System.out.println("Registering Reverse Recipe for: " + GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(output) + "|" + output.getUnlocalizedName()));
+// for (Object o : aRecipe) {
+// String toPrint;
+// if (o instanceof String) {
+// toPrint = (String) o;
+// toPrint += " String";
+// } else if (o instanceof ItemStack) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName((ItemStack) o));
+// toPrint += " ItemStack";
+// } else if (o instanceof List) {
+// toPrint = String.join(", ", ((List<String>) o));
+// toPrint += " List<String>";
+// } else if (o instanceof Item) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Item) o)));
+// toPrint += " Item";
+// } else if (o instanceof Block) {
+// toPrint = GT_LanguageManager.getTranslation(GT_LanguageManager.getTranslateableItemStackName(new ItemStack((Block) o)));
+// toPrint += " Block";
+// } else if (o != null) {
+// toPrint = o.toString();
+// toPrint += " Other";
+// } else {
+// toPrint = "NULL";
+// }
+// System.out.println(toPrint);
+// }
+ Map<Object, Integer> recipeAsMap = new HashMap<>();
+ Map<Character, Object> ingridients = new HashMap<>();
+ Map<Character, Integer> amounts = new HashMap<>();
+ boolean startFound = false;
+ for (int i = 0, aRecipeLength = aRecipe.length; i < aRecipeLength; i++) {
+ Object o = aRecipe[i];
+ if (!startFound) {
+ if (o instanceof String) {
+ for (Character c : ((String) o).toCharArray())
+ amounts.merge(c, 1, (a, b) -> ++a);
+ } else if (o instanceof Character)
+ startFound = true;
+ } else if (!(o instanceof Character))
+ ingridients.put((Character) aRecipe[i - 1], o);
+ }
+ for (Map.Entry<Character, Object> characterObjectEntry : ingridients.entrySet()) {
+ for (Map.Entry<Character, Integer> characterIntegerEntry : amounts.entrySet()) {
+ if (characterObjectEntry.getKey() != characterIntegerEntry.getKey())
+ continue;
+ recipeAsMap.put(characterObjectEntry.getValue(), characterIntegerEntry.getValue());
+ }
+ }
+ List<ItemStack> inputs = new ArrayList<>();
+
+ for (Map.Entry<Object, Integer> o : recipeAsMap.entrySet()) {
+ final int amount = o.getValue();
+ if (o.getKey() instanceof ItemStack) {
+ ItemStack toAdd = ((ItemStack) o.getKey()).copy();
+ toAdd.stackSize = amount;
+ inputs.add(toAdd);
+ } else if (o.getKey() instanceof String) {
+// System.out.println("Found OreDictEntry: "+o.getKey());
+ final String dictName = (String) o.getKey();
+ // Do not register tools dictName in inputs
+ if (ToolDictNames.contains(dictName)) continue;
+ ItemStack stack = GT_OreDictUnificator.get(dictName, null, amount, false, true);
+ if (stack == null) {
+ Optional<ItemStack> oStack = OreDictionary.getOres(dictName)
+ .stream()
+ .findAny();
+ if (oStack.isPresent()) {
+ ItemStack copy = oStack.get().copy();
+ copy.stackSize = amount;
+ inputs.add(copy);
+ }
+// else
+// System.out.println("OreDict Entry "+o.getKey()+" couldn't be found!");
+ } else {
+ ItemStack copy = stack.copy();
+ copy.stackSize = amount;
+ inputs.add(copy);
+ }
+ } else if (o.getKey() instanceof Item)
+ inputs.add(new ItemStack((Item) o.getKey(), amount));
+ else if (o.getKey() instanceof Block)
+ inputs.add(new ItemStack((Block) o.getKey(), amount));
+ else
+ throw new IllegalStateException("A Recipe contains an invalid input! Output: " + output);
+ }
+
+ // Remove tools from inputs in case a recipe has one as a direct Item or ItemStack reference
+ inputs.removeIf(x -> x.getItem() instanceof GT_MetaGenerated_Tool);
+
+ return Optional.of(
+ new GT_Recipe(
+ false,
+ new ItemStack[]{output},
+ inputs.toArray(new ItemStack[0]),
+ null, null,
+ null, null,
+ 300, 30, 0
+ )
+ );
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+ public static long getNonnullElementCount(Object[] tArray) {
+ return Arrays.stream(tArray).filter(Objects::nonNull).count();
+ }
}
diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
new file mode 100644
index 0000000000..362fddaf1f
--- /dev/null
+++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
@@ -0,0 +1,15 @@
+package gregtech.api.util;
+
+
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+
+public interface IGT_HatchAdder<T> {
+ /**
+ * Callback to add hatch, needs to check if hatch is valid (and add it)
+ *
+ * @param iGregTechTileEntity hatch
+ * @param aShort requested texture index, or null if not...
+ * @return managed to add hatch (structure still valid)
+ */
+ boolean apply(T t, IGregTechTileEntity iGregTechTileEntity, Short aShort);
+}
diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java
new file mode 100644
index 0000000000..f131ef74a0
--- /dev/null
+++ b/src/main/java/gregtech/api/util/LightingHelper.java
@@ -0,0 +1,729 @@
+/*
+ * LightingHelper - Derived and adapted from @Mineshopper / carpentersblocks
+ * Copyright (c) 2013-2021.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package gregtech.api.util;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.block.Block;
+import net.minecraft.client.renderer.EntityRenderer;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.client.renderer.Tessellator;
+
+@SuppressWarnings("unused")
+@SideOnly(Side.CLIENT)
+public class LightingHelper {
+ public static final int NORMAL_BRIGHTNESS = 0xff00ff;
+ public static final int MAX_BRIGHTNESS = 0xf000f0;
+ public static final float NO_Z_FIGHT_OFFSET = 1.0F / 1024.0F;
+ protected static final float[] LIGHTNESS = {0.5F, 1.0F, 0.8F, 0.8F, 0.6F, 0.6F};
+ private final RenderBlocks renderBlocks;
+ /**
+ * Brightness for side.
+ */
+ private int brightness;
+ /**
+ * Ambient occlusion values for all four corners of side.
+ */
+ private float aoTopLeft, aoBottomLeft, aoBottomRight, aoTopRight;
+ private boolean hasLightnessOverride;
+ private float lightnessOverride;
+ private boolean hasBrightnessOverride;
+ private int brightnessOverride;
+ private boolean hasColorOverride;
+ private int colorOverride = 0xffffff;
+
+ /**
+ * Class constructor specifying the {@link RenderBlocks}.
+ *
+ * @param renderBlocks the {@link RenderBlocks}
+ */
+ public LightingHelper(RenderBlocks renderBlocks) {
+ this.renderBlocks = renderBlocks;
+ if (renderBlocks.useInventoryTint) {
+ // Block will be rendered in an inventory, so it needs its lightness maxed
+ setLightnessOverride(1.0F);
+ }
+ }
+
+ /**
+ * Gets average brightness from two brightness values.
+ *
+ * @param brightnessA the first brightness value
+ * @param brightnessB the second brightness value
+ * @return the mixed brightness
+ */
+ public static int getAverageBrightness(int brightnessA, int brightnessB) {
+ int sectionA1 = brightnessA >> 16 & 0xff;
+ int sectionA2 = brightnessA & 255;
+
+ int sectionB1 = brightnessB >> 16 & 0xff;
+ int sectionB2 = brightnessB & 255;
+
+ int difference1 = (int) ((sectionA1 + sectionB1) / 2.0F);
+ int difference2 = (int) ((sectionA2 + sectionB2) / 2.0F);
+
+ return difference1 << 16 | difference2;
+ }
+
+ /**
+ * Gets rgb color from RGBA array.
+ *
+ * @param color the integer color
+ * @return a float array with rgb values
+ */
+ public static float[] getRGB(short[] color) {
+ float red = color[0] / 255.0F;
+ float green = color[1] / 255.0F;
+ float blue = color[2] / 255.0F;
+
+ return new float[]{red, green, blue};
+ }
+
+ /**
+ * Clears brightness override.
+ */
+ public void clearBrightnessOverride() {
+ hasBrightnessOverride = false;
+ }
+
+ /**
+ * Clears color override.
+ */
+ public void clearColorOverride() {
+ hasColorOverride = false;
+ }
+
+ /**
+ * Clears lightness override.
+ */
+ public void clearLightnessOverride() {
+ hasLightnessOverride = false;
+ }
+
+ /**
+ * @return the Ambient Occlusion for Bottom-Left corner
+ */
+ public float getAoBottomLeft() {
+ return aoBottomLeft;
+ }
+
+ /**
+ * @return the Ambient Occlusion for Bottom-Right corner
+ */
+ public float getAoBottomRight() {
+ return aoBottomRight;
+ }
+
+ /**
+ * @return the Ambient Occlusion for Top-Left corner
+ */
+ public float getAoTopLeft() {
+ return aoTopLeft;
+ }
+
+ /**
+ * @return the Ambient Occlusion for Top-Right corner
+ */
+ public float getAoTopRight() {
+ return aoTopRight;
+ }
+
+ /**
+ * Sets brightness override.
+ *
+ * @param brightness the brightness override
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setBrightnessOverride(int brightness) {
+ hasBrightnessOverride = true;
+ brightnessOverride = brightness;
+ return this;
+ }
+
+ public LightingHelper setColorOverride(short[] color) {
+ return setColorOverride(getColor(color));
+ }
+
+ /**
+ * Sets color override.
+ *
+ * @param color the color override
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setColorOverride(int color) {
+ hasColorOverride = true;
+ colorOverride = color;
+ return this;
+ }
+
+ /**
+ * Gets int color from RGBA array.
+ *
+ * @param rgba the short RGBA color array
+ * @return int color
+ */
+ public static int getColor(short[] rgba) {
+ return (rgba[2] & 0xff) | (rgba[1] & 0xff) << 8 | (rgba[0] & 0xff) << 16;
+ }
+
+ /**
+ * Sets lightness override.
+ *
+ * @param lightness the lightness override
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setLightnessOverride(float lightness) {
+ hasLightnessOverride = true;
+ lightnessOverride = lightness;
+ return this;
+ }
+
+ /**
+ * Sets up the color using lightness, brightness, and the primary color
+ * value (usually the dye color) for the side.
+ *
+ * @param side the side
+ * @param rgba the primary short[] RGBA color array
+ */
+ public void setupColor(int side, short[] rgba) {
+ setupColor(side, getColor(rgba));
+ }
+
+ /**
+ * Sets up the color using lightness, brightness, and the primary color
+ * value (usually the dye color) for the side.
+ *
+ * @param side the side
+ * @param hexColor the primary color
+ */
+ public void setupColor(int side, int hexColor) {
+ Tessellator tessellator = Tessellator.instance;
+ float lightness = hasLightnessOverride ? lightnessOverride : LIGHTNESS[side];
+ float[] rgb = getRGB(hexColor);
+
+ if (hasColorOverride && !renderBlocks.hasOverrideBlockTexture()) {
+ rgb = getRGB(colorOverride);
+ }
+
+ applyAnaglyph(rgb);
+
+ if (renderBlocks.enableAO) {
+ tessellator.setBrightness(hasBrightnessOverride ? brightnessOverride : brightness);
+
+ if (renderBlocks.hasOverrideBlockTexture()) {
+
+ renderBlocks.colorRedTopLeft = renderBlocks.colorRedBottomLeft = renderBlocks.colorRedBottomRight = renderBlocks.colorRedTopRight = rgb[0];
+ renderBlocks.colorGreenTopLeft = renderBlocks.colorGreenBottomLeft = renderBlocks.colorGreenBottomRight = renderBlocks.colorGreenTopRight = rgb[1];
+ renderBlocks.colorBlueTopLeft = renderBlocks.colorBlueBottomLeft = renderBlocks.colorBlueBottomRight = renderBlocks.colorBlueTopRight = rgb[2];
+
+ } else {
+
+ renderBlocks.colorRedTopLeft = renderBlocks.colorRedBottomLeft = renderBlocks.colorRedBottomRight = renderBlocks.colorRedTopRight = rgb[0] * lightness;
+ renderBlocks.colorGreenTopLeft = renderBlocks.colorGreenBottomLeft = renderBlocks.colorGreenBottomRight = renderBlocks.colorGreenTopRight = rgb[1] * lightness;
+ renderBlocks.colorBlueTopLeft = renderBlocks.colorBlueBottomLeft = renderBlocks.colorBlueBottomRight = renderBlocks.colorBlueTopRight = rgb[2] * lightness;
+
+ renderBlocks.colorRedTopLeft *= aoTopLeft;
+ renderBlocks.colorGreenTopLeft *= aoTopLeft;
+ renderBlocks.colorBlueTopLeft *= aoTopLeft;
+ renderBlocks.colorRedBottomLeft *= aoBottomLeft;
+ renderBlocks.colorGreenBottomLeft *= aoBottomLeft;
+ renderBlocks.colorBlueBottomLeft *= aoBottomLeft;
+ renderBlocks.colorRedBottomRight *= aoBottomRight;
+ renderBlocks.colorGreenBottomRight *= aoBottomRight;
+ renderBlocks.colorBlueBottomRight *= aoBottomRight;
+ renderBlocks.colorRedTopRight *= aoTopRight;
+ renderBlocks.colorGreenTopRight *= aoTopRight;
+ renderBlocks.colorBlueTopRight *= aoTopRight;
+ }
+
+ } else {
+
+ if (hasBrightnessOverride) tessellator.setBrightness(brightnessOverride);
+ tessellator.setColorOpaque_F(rgb[0] * lightness, rgb[1] * lightness, rgb[2] * lightness);
+
+ }
+ }
+
+ /**
+ * Gets rgb color from integer.
+ *
+ * @param color the integer color
+ * @return a float array with rgb values
+ */
+ public static float[] getRGB(int color) {
+ float red = (color >> 16 & 0xff) / 255.0F;
+ float green = (color >> 8 & 0xff) / 255.0F;
+ float blue = (color & 0xff) / 255.0F;
+
+ return new float[]{red, green, blue};
+ }
+
+ /**
+ * Will apply anaglyph color multipliers to RGB float array.
+ * <p>
+ * If {@link EntityRenderer#anaglyphEnable} is false,
+ * will do nothing.
+ *
+ * @param rgb array containing red, green and blue float values
+ */
+ public void applyAnaglyph(float[] rgb) {
+ if (EntityRenderer.anaglyphEnable) {
+ rgb[0] = (rgb[0] * 30.0F + rgb[1] * 59.0F + rgb[2] * 11.0F) / 100.0F;
+ rgb[1] = (rgb[0] * 30.0F + rgb[1] * 70.0F) / 100.0F;
+ rgb[2] = (rgb[0] * 30.0F + rgb[2] * 70.0F) / 100.0F;
+ }
+ }
+
+ /**
+ * Gets mixed ambient occlusion value from two inputs, with a
+ * ratio applied to the final result.
+ *
+ * @param ao1 the first ambient occlusion value
+ * @param ao2 the second ambient occlusion value
+ * @param ratio the ratio for mixing
+ * @return the mixed red, green, blue float values
+ */
+ public static float getMixedAo(float ao1, float ao2, double ratio) {
+ float diff = (float) (Math.abs(ao1 - ao2) * (1.0F - ratio));
+
+ return ao1 > ao2 ? ao1 - diff : ao1 + diff;
+ }
+
+ /**
+ * Sets up lighting for the West face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingXNeg(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int xOffset = renderBlocks.renderMinX > 0.0F + NO_Z_FIGHT_OFFSET ? x : x - 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z);
+ brightness = mixedBrightness;
+
+ float ratio = (float) (1.0F - renderBlocks.renderMinX);
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x - 1, y, z).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXYNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z);
+ renderBlocks.aoBrightnessXZNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z - 1);
+ renderBlocks.aoBrightnessXZNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z + 1);
+ renderBlocks.aoBrightnessXYNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z);
+ renderBlocks.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z - 1);
+ renderBlocks.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z + 1);
+ renderBlocks.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z - 1);
+ renderBlocks.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z + 1);
+ renderBlocks.aoLightValueScratchXYNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXZNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXZNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z + 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z + 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNPN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNPP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z + 1).getAmbientOcclusionLightValue(), ratio);
+
+ int brightnessMixedXYZNPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZNN, renderBlocks.aoBrightnessXYZNPN, renderBlocks.aoBrightnessXYNP, mixedBrightness);
+ int brightnessMixedXYZNNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZNNN, renderBlocks.aoBrightnessXYNN, renderBlocks.aoBrightnessXZNN, mixedBrightness);
+ int brightnessMixedXYZNNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYNN, renderBlocks.aoBrightnessXYZNNP, renderBlocks.aoBrightnessXZNP, mixedBrightness);
+ int brightnessMixedXYZNPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZNP, renderBlocks.aoBrightnessXYNP, renderBlocks.aoBrightnessXYZNPP, mixedBrightness);
+
+ float aoMixedXYZNPN = (renderBlocks.aoLightValueScratchXZNN + aoLightValue + renderBlocks.aoLightValueScratchXYZNPN + renderBlocks.aoLightValueScratchXYNP) / 4.0F;
+ float aoMixedXYZNNN = (renderBlocks.aoLightValueScratchXYZNNN + renderBlocks.aoLightValueScratchXYNN + renderBlocks.aoLightValueScratchXZNN + aoLightValue) / 4.0F;
+ float aoMixedXYZNNP = (renderBlocks.aoLightValueScratchXYNN + renderBlocks.aoLightValueScratchXYZNNP + aoLightValue + renderBlocks.aoLightValueScratchXZNP) / 4.0F;
+ float aoMixedXYZNPP = (aoLightValue + renderBlocks.aoLightValueScratchXZNP + renderBlocks.aoLightValueScratchXYNP + renderBlocks.aoLightValueScratchXYZNPP) / 4.0F;
+
+ aoTopLeft = (float) (aoMixedXYZNPP * renderBlocks.renderMaxY * renderBlocks.renderMaxZ + aoMixedXYZNPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZNNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxZ);
+ aoBottomLeft = (float) (aoMixedXYZNPP * renderBlocks.renderMaxY * renderBlocks.renderMinZ + aoMixedXYZNPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZNNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinZ);
+ aoBottomRight = (float) (aoMixedXYZNPP * renderBlocks.renderMinY * renderBlocks.renderMinZ + aoMixedXYZNPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZNNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinZ);
+ aoTopRight = (float) (aoMixedXYZNPP * renderBlocks.renderMinY * renderBlocks.renderMaxZ + aoMixedXYZNPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZNNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxZ);
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNPN, brightnessMixedXYZNNN, brightnessMixedXYZNNP, renderBlocks.renderMaxY * renderBlocks.renderMaxZ, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxZ), (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxZ), (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxZ);
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNPN, brightnessMixedXYZNNN, brightnessMixedXYZNNP, renderBlocks.renderMaxY * renderBlocks.renderMinZ, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinZ), (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinZ), (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinZ);
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNPN, brightnessMixedXYZNNN, brightnessMixedXYZNNP, renderBlocks.renderMinY * renderBlocks.renderMinZ, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinZ), (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinZ), (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinZ);
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNPN, brightnessMixedXYZNNN, brightnessMixedXYZNNP, renderBlocks.renderMinY * renderBlocks.renderMaxZ, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxZ), (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxZ), (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxZ);
+
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets up lighting for the East face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingXPos(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int xOffset = renderBlocks.renderMaxX < 1.0F - NO_Z_FIGHT_OFFSET ? x : x + 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z);
+ brightness = mixedBrightness;
+
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXYPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z);
+ renderBlocks.aoBrightnessXZPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z - 1);
+ renderBlocks.aoBrightnessXZPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y, z + 1);
+ renderBlocks.aoBrightnessXYPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z);
+ renderBlocks.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z - 1);
+ renderBlocks.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y - 1, z + 1);
+ renderBlocks.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z - 1);
+ renderBlocks.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, xOffset, y + 1, z + 1);
+ renderBlocks.aoLightValueScratchXYPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXZPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXZPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXYPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXYZPNN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXYZPNP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXYZPPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+ renderBlocks.aoLightValueScratchXYZPPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxX);
+
+ int brightnessMixedXYZPPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZPP, renderBlocks.aoBrightnessXYPP, renderBlocks.aoBrightnessXYZPPP, mixedBrightness);
+ int brightnessMixedXYZPNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYPN, renderBlocks.aoBrightnessXYZPNP, renderBlocks.aoBrightnessXZPP, mixedBrightness);
+ int brightnessMixedXYZPNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZPNN, renderBlocks.aoBrightnessXYPN, renderBlocks.aoBrightnessXZPN, mixedBrightness);
+ int brightnessMixedXYZPPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZPN, renderBlocks.aoBrightnessXYZPPN, renderBlocks.aoBrightnessXYPP, mixedBrightness);
+
+ float aoMixedXYZPPP = (aoLightValue + renderBlocks.aoLightValueScratchXZPP + renderBlocks.aoLightValueScratchXYPP + renderBlocks.aoLightValueScratchXYZPPP) / 4.0F;
+ float aoMixedXYZPNP = (renderBlocks.aoLightValueScratchXYPN + renderBlocks.aoLightValueScratchXYZPNP + aoLightValue + renderBlocks.aoLightValueScratchXZPP) / 4.0F;
+ float aoMixedXYZPNN = (renderBlocks.aoLightValueScratchXYZPNN + renderBlocks.aoLightValueScratchXYPN + renderBlocks.aoLightValueScratchXZPN + aoLightValue) / 4.0F;
+ float aoMixedXYZPPN = (renderBlocks.aoLightValueScratchXZPN + aoLightValue + renderBlocks.aoLightValueScratchXYZPPN + renderBlocks.aoLightValueScratchXYPP) / 4.0F;
+
+ aoTopLeft = (float) (aoMixedXYZPNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxZ + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZPPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZPPP * renderBlocks.renderMinY * renderBlocks.renderMaxZ);
+ aoBottomLeft = (float) (aoMixedXYZPNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinZ + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZPPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZPPP * renderBlocks.renderMinY * renderBlocks.renderMinZ);
+ aoBottomRight = (float) (aoMixedXYZPNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinZ + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZPPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinZ) + aoMixedXYZPPP * renderBlocks.renderMaxY * renderBlocks.renderMinZ);
+ aoTopRight = (float) (aoMixedXYZPNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxZ + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZPPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxZ) + aoMixedXYZPPP * renderBlocks.renderMaxY * renderBlocks.renderMaxZ);
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZPPN, brightnessMixedXYZPPP, (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxZ, (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxZ), renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxZ), renderBlocks.renderMinY * renderBlocks.renderMaxZ);
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZPPN, brightnessMixedXYZPPP, (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinZ, (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinZ), renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinZ), renderBlocks.renderMinY * renderBlocks.renderMinZ);
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZPPN, brightnessMixedXYZPPP, (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinZ, (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinZ), renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinZ), renderBlocks.renderMaxY * renderBlocks.renderMinZ);
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZPPN, brightnessMixedXYZPPP, (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxZ, (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxZ), renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxZ), renderBlocks.renderMaxY * renderBlocks.renderMaxZ);
+
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets up lighting for the bottom face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingYNeg(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int yOffset = renderBlocks.renderMinY > 0.0F + NO_Z_FIGHT_OFFSET ? y : y - 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z);
+ brightness = mixedBrightness;
+
+ float ratio = (float) (1.0F - renderBlocks.renderMinY);
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x, y - 1, z).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXYNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z);
+ renderBlocks.aoBrightnessYZNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z - 1);
+ renderBlocks.aoBrightnessYZNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z + 1);
+ renderBlocks.aoBrightnessXYPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z);
+ renderBlocks.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z - 1);
+ renderBlocks.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z + 1);
+ renderBlocks.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z - 1);
+ renderBlocks.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z + 1);
+ renderBlocks.aoLightValueScratchXYNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchYZNN = getMixedAo(renderBlocks.blockAccess.getBlock(x, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchYZNP = getMixedAo(renderBlocks.blockAccess.getBlock(x, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z + 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z + 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZPNN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z - 1).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZPNP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z + 1).getAmbientOcclusionLightValue(), ratio);
+
+ int brightnessMixedXYZPNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZNP, renderBlocks.aoBrightnessXYZPNP, renderBlocks.aoBrightnessXYPN, mixedBrightness);
+ int brightnessMixedXYZPNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZNN, renderBlocks.aoBrightnessXYPN, renderBlocks.aoBrightnessXYZPNN, mixedBrightness);
+ int brightnessMixedXYZNNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYNN, renderBlocks.aoBrightnessXYZNNN, renderBlocks.aoBrightnessYZNN, mixedBrightness);
+ int brightnessMixedXYZNNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZNNP, renderBlocks.aoBrightnessXYNN, renderBlocks.aoBrightnessYZNP, mixedBrightness);
+
+ float aoMixedXYZPNP = (renderBlocks.aoLightValueScratchYZNP + aoLightValue + renderBlocks.aoLightValueScratchXYZPNP + renderBlocks.aoLightValueScratchXYPN) / 4.0F;
+ float aoMixedXYZPNN = (aoLightValue + renderBlocks.aoLightValueScratchYZNN + renderBlocks.aoLightValueScratchXYPN + renderBlocks.aoLightValueScratchXYZPNN) / 4.0F;
+ float aoMixedXYZNNN = (renderBlocks.aoLightValueScratchXYNN + renderBlocks.aoLightValueScratchXYZNNN + aoLightValue + renderBlocks.aoLightValueScratchYZNN) / 4.0F;
+ float aoMixedXYZNNP = (renderBlocks.aoLightValueScratchXYZNNP + renderBlocks.aoLightValueScratchXYNN + renderBlocks.aoLightValueScratchYZNP + aoLightValue) / 4.0F;
+
+ aoTopLeft = (float) (aoMixedXYZNNP * renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPNP * renderBlocks.renderMaxZ * renderBlocks.renderMinX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMinX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMinX));
+ aoBottomLeft = (float) (aoMixedXYZNNP * renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPNP * renderBlocks.renderMinZ * renderBlocks.renderMinX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMinX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMinX));
+ aoBottomRight = (float) (aoMixedXYZNNP * renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPNP * renderBlocks.renderMinZ * renderBlocks.renderMaxX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMaxX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMaxX));
+ aoTopRight = (float) (aoMixedXYZNNP * renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPNP * renderBlocks.renderMaxZ * renderBlocks.renderMaxX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMaxX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMaxX));
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMaxZ * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMinX));
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMinZ * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMinX));
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMinZ * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMaxX));
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMaxZ * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMaxX));
+
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets up lighting for the top face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingYPos(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int yOffset = renderBlocks.renderMaxY < 1.0F - NO_Z_FIGHT_OFFSET ? y : y + 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z);
+ brightness = mixedBrightness;
+
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x, y + 1, z).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXYNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z);
+ renderBlocks.aoBrightnessXYPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z);
+ renderBlocks.aoBrightnessYZPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z - 1);
+ renderBlocks.aoBrightnessYZPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, yOffset, z + 1);
+ renderBlocks.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z - 1);
+ renderBlocks.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z - 1);
+ renderBlocks.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, yOffset, z + 1);
+ renderBlocks.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, yOffset, z + 1);
+ renderBlocks.aoLightValueScratchXYNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchXYPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchYZPN = getMixedAo(renderBlocks.blockAccess.getBlock(x, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchYZPP = getMixedAo(renderBlocks.blockAccess.getBlock(x, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchXYZNPN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchXYZPPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchXYZNPP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+ renderBlocks.aoLightValueScratchXYZPPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.renderMaxY);
+
+ int brightnessMixedXYZPPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZPP, renderBlocks.aoBrightnessXYZPPP, renderBlocks.aoBrightnessXYPP, mixedBrightness);
+ int brightnessMixedXYZPPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZPN, renderBlocks.aoBrightnessXYPP, renderBlocks.aoBrightnessXYZPPN, mixedBrightness);
+ int brightnessMixedXYZNPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYNP, renderBlocks.aoBrightnessXYZNPN, renderBlocks.aoBrightnessYZPN, mixedBrightness);
+ int brightnessMixedXYZNPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZNPP, renderBlocks.aoBrightnessXYNP, renderBlocks.aoBrightnessYZPP, mixedBrightness);
+
+ float aoMixedXYZPPP = (renderBlocks.aoLightValueScratchYZPP + aoLightValue + renderBlocks.aoLightValueScratchXYZPPP + renderBlocks.aoLightValueScratchXYPP) / 4.0F;
+ float aoMixedXYZPPN = (aoLightValue + renderBlocks.aoLightValueScratchYZPN + renderBlocks.aoLightValueScratchXYPP + renderBlocks.aoLightValueScratchXYZPPN) / 4.0F;
+ float aoMixedXYZNPN = (renderBlocks.aoLightValueScratchXYNP + renderBlocks.aoLightValueScratchXYZNPN + aoLightValue + renderBlocks.aoLightValueScratchYZPN) / 4.0F;
+ float aoMixedXYZNPP = (renderBlocks.aoLightValueScratchXYZNPP + renderBlocks.aoLightValueScratchXYNP + renderBlocks.aoLightValueScratchYZPP + aoLightValue) / 4.0F;
+
+ aoTopLeft /*SE*/ = (float) (aoMixedXYZNPP * renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPP * renderBlocks.renderMaxZ * renderBlocks.renderMaxX + aoMixedXYZPPN * (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMaxX + aoMixedXYZNPN * (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMaxX));
+ aoBottomLeft /*NE*/ = (float) (aoMixedXYZNPP * renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPP * renderBlocks.renderMinZ * renderBlocks.renderMaxX + aoMixedXYZPPN * (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMaxX + aoMixedXYZNPN * (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMaxX));
+ aoBottomRight /*NW*/ = (float) (aoMixedXYZNPP * renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPP * renderBlocks.renderMinZ * renderBlocks.renderMinX + aoMixedXYZPPN * (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMinX + aoMixedXYZNPN * (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMinX));
+ aoTopRight /*SW*/ = (float) (aoMixedXYZNPP * renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPP * renderBlocks.renderMaxZ * renderBlocks.renderMinX + aoMixedXYZPPN * (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMinX + aoMixedXYZNPN * (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMinX));
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZPPP, brightnessMixedXYZPPN, brightnessMixedXYZNPN, renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMaxZ * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMaxX));
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZPPP, brightnessMixedXYZPPN, brightnessMixedXYZNPN, renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMinZ * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMaxX));
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZPPP, brightnessMixedXYZPPN, brightnessMixedXYZNPN, renderBlocks.renderMinZ * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMinZ * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinZ) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinZ) * (1.0D - renderBlocks.renderMinX));
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZPPP, brightnessMixedXYZPPN, brightnessMixedXYZNPN, renderBlocks.renderMaxZ * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMaxZ * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxZ) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxZ) * (1.0D - renderBlocks.renderMinX));
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets up lighting for the North face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingZNeg(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int zOffset = renderBlocks.renderMinZ > 0.0F + NO_Z_FIGHT_OFFSET ? z : z - 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y, zOffset);
+ brightness = mixedBrightness;
+
+ float ratio = (float) (1.0F - renderBlocks.renderMinZ);
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x, y, z - 1).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXZNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y, zOffset);
+ renderBlocks.aoBrightnessYZNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y - 1, zOffset);
+ renderBlocks.aoBrightnessYZPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y + 1, zOffset);
+ renderBlocks.aoBrightnessXZPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y, zOffset);
+ renderBlocks.aoBrightnessXYZNNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y - 1, zOffset);
+ renderBlocks.aoBrightnessXYZNPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y + 1, zOffset);
+ renderBlocks.aoBrightnessXYZPNN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y - 1, zOffset);
+ renderBlocks.aoBrightnessXYZPPN = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y + 1, zOffset);
+ renderBlocks.aoLightValueScratchXZNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchYZNN = getMixedAo(renderBlocks.blockAccess.getBlock(x, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchYZPN = getMixedAo(renderBlocks.blockAccess.getBlock(x, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXZPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNNN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y - 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZNPN = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y + 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZPNN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y - 1, z).getAmbientOcclusionLightValue(), ratio);
+ renderBlocks.aoLightValueScratchXYZPPN = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z - 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y + 1, z).getAmbientOcclusionLightValue(), ratio);
+
+ int brightnessMixedXYZPPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZPN, renderBlocks.aoBrightnessXZPN, renderBlocks.aoBrightnessXYZPPN, mixedBrightness);
+ int brightnessMixedXYZPNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZNN, renderBlocks.aoBrightnessXYZPNN, renderBlocks.aoBrightnessXZPN, mixedBrightness);
+ int brightnessMixedXYZNNN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZNNN, renderBlocks.aoBrightnessXZNN, renderBlocks.aoBrightnessYZNN, mixedBrightness);
+ int brightnessMixedXYZNPN = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZNN, renderBlocks.aoBrightnessXYZNPN, renderBlocks.aoBrightnessYZPN, mixedBrightness);
+
+ float aoMixedXYZPPN = (aoLightValue + renderBlocks.aoLightValueScratchYZPN + renderBlocks.aoLightValueScratchXZPN + renderBlocks.aoLightValueScratchXYZPPN) / 4.0F;
+ float aoMixedXYZPNN = (renderBlocks.aoLightValueScratchYZNN + aoLightValue + renderBlocks.aoLightValueScratchXYZPNN + renderBlocks.aoLightValueScratchXZPN) / 4.0F;
+ float aoMixedXYZNNN = (renderBlocks.aoLightValueScratchXYZNNN + renderBlocks.aoLightValueScratchXZNN + renderBlocks.aoLightValueScratchYZNN + aoLightValue) / 4.0F;
+ float aoMixedXYZNPN = (renderBlocks.aoLightValueScratchXZNN + renderBlocks.aoLightValueScratchXYZNPN + aoLightValue + renderBlocks.aoLightValueScratchYZPN) / 4.0F;
+
+ aoTopLeft = (float) (aoMixedXYZNPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPN * renderBlocks.renderMaxY * renderBlocks.renderMinX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinX));
+ aoBottomLeft = (float) (aoMixedXYZNPN * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPN * renderBlocks.renderMaxY * renderBlocks.renderMaxX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxX));
+ aoBottomRight = (float) (aoMixedXYZNPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPN * renderBlocks.renderMinY * renderBlocks.renderMaxX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxX));
+ aoTopRight = (float) (aoMixedXYZNPN * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPN * renderBlocks.renderMinY * renderBlocks.renderMinX + aoMixedXYZPNN * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinX + aoMixedXYZNNN * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinX));
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPN, brightnessMixedXYZPPN, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMaxY * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinX));
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPN, brightnessMixedXYZPPN, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMaxY * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxX));
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPN, brightnessMixedXYZPPN, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxX), renderBlocks.renderMinY * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxX, (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxX));
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPN, brightnessMixedXYZPPN, brightnessMixedXYZPNN, brightnessMixedXYZNNN, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinX), renderBlocks.renderMinY * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinX, (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinX));
+
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets up lighting for the South face and returns the {@link LightingHelper}.
+ * <p>
+ * This is a consolidated <code>method</code> that sets side shading
+ * with respect to the following attributes:
+ * <p>
+ * <ul>
+ * <li>{@link RenderBlocks#enableAO}</li>
+ * <li>{@link RenderBlocks#partialRenderBounds}</li>
+ * </ul>
+ *
+ * @param block the block {@link Block}
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param z the z coordinate
+ * @return the {@link LightingHelper}
+ */
+ public LightingHelper setupLightingZPos(Block block, int x, int y, int z) {
+
+ if (renderBlocks.enableAO) {
+
+ int zOffset = renderBlocks.renderMaxZ < 1.0F - NO_Z_FIGHT_OFFSET ? z : z + 1;
+
+ int mixedBrightness = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y, zOffset);
+ brightness = mixedBrightness;
+
+ float aoLightValue = renderBlocks.blockAccess.getBlock(x, y, z + 1).getAmbientOcclusionLightValue();
+
+ renderBlocks.aoBrightnessXZNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y, zOffset);
+ renderBlocks.aoBrightnessXZPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y, zOffset);
+ renderBlocks.aoBrightnessYZNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y - 1, zOffset);
+ renderBlocks.aoBrightnessYZPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x, y + 1, zOffset);
+ renderBlocks.aoBrightnessXYZNNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y - 1, zOffset);
+ renderBlocks.aoBrightnessXYZNPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x - 1, y + 1, zOffset);
+ renderBlocks.aoBrightnessXYZPNP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y - 1, zOffset);
+ renderBlocks.aoBrightnessXYZPPP = block.getMixedBrightnessForBlock(renderBlocks.blockAccess, x + 1, y + 1, zOffset);
+ renderBlocks.aoLightValueScratchXZNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchXZPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchYZNP = getMixedAo(renderBlocks.blockAccess.getBlock(x, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchYZPP = getMixedAo(renderBlocks.blockAccess.getBlock(x, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchXYZNNP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchXYZNPP = getMixedAo(renderBlocks.blockAccess.getBlock(x - 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x - 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchXYZPNP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y - 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y - 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+ renderBlocks.aoLightValueScratchXYZPPP = getMixedAo(renderBlocks.blockAccess.getBlock(x + 1, y + 1, z + 1).getAmbientOcclusionLightValue(), renderBlocks.blockAccess.getBlock(x + 1, y + 1, z).getAmbientOcclusionLightValue(), renderBlocks.renderMaxZ);
+
+ int brightnessMixedXYZNPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXZNP, renderBlocks.aoBrightnessXYZNPP, renderBlocks.aoBrightnessYZPP, mixedBrightness);
+ int brightnessMixedXYZNNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessXYZNNP, renderBlocks.aoBrightnessXZNP, renderBlocks.aoBrightnessYZNP, mixedBrightness);
+ int brightnessMixedXYZPNP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZNP, renderBlocks.aoBrightnessXYZPNP, renderBlocks.aoBrightnessXZPP, mixedBrightness);
+ int brightnessMixedXYZPPP = renderBlocks.getAoBrightness(renderBlocks.aoBrightnessYZPP, renderBlocks.aoBrightnessXZPP, renderBlocks.aoBrightnessXYZPPP, mixedBrightness);
+
+ float aoMixedXYZNPP = (renderBlocks.aoLightValueScratchXZNP + renderBlocks.aoLightValueScratchXYZNPP + aoLightValue + renderBlocks.aoLightValueScratchYZPP) / 4.0F;
+ float aoMixedXYZNNP = (renderBlocks.aoLightValueScratchXYZNNP + renderBlocks.aoLightValueScratchXZNP + renderBlocks.aoLightValueScratchYZNP + aoLightValue) / 4.0F;
+ float aoMixedXYZPNP = (renderBlocks.aoLightValueScratchYZNP + aoLightValue + renderBlocks.aoLightValueScratchXYZPNP + renderBlocks.aoLightValueScratchXZPP) / 4.0F;
+ float aoMixedXYZPPP = (aoLightValue + renderBlocks.aoLightValueScratchYZPP + renderBlocks.aoLightValueScratchXZPP + renderBlocks.aoLightValueScratchXYZPPP) / 4.0F;
+
+ aoTopLeft = (float) (aoMixedXYZNPP * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPP * renderBlocks.renderMaxY * renderBlocks.renderMinX + aoMixedXYZPNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinX + aoMixedXYZNNP * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinX));
+ aoBottomLeft = (float) (aoMixedXYZNPP * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinX) + aoMixedXYZPPP * renderBlocks.renderMinY * renderBlocks.renderMinX + aoMixedXYZPNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinX + aoMixedXYZNNP * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinX));
+ aoBottomRight = (float) (aoMixedXYZNPP * renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPP * renderBlocks.renderMinY * renderBlocks.renderMaxX + aoMixedXYZPNP * (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxX + aoMixedXYZNNP * (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxX));
+ aoTopRight = (float) (aoMixedXYZNPP * renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxX) + aoMixedXYZPPP * renderBlocks.renderMaxY * renderBlocks.renderMaxX + aoMixedXYZPNP * (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxX + aoMixedXYZNNP * (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxX));
+
+ renderBlocks.brightnessTopLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPPP, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMinX), (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMinX), (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMinX, renderBlocks.renderMaxY * renderBlocks.renderMinX);
+ renderBlocks.brightnessBottomLeft = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPPP, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMinX), (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMinX), (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMinX, renderBlocks.renderMinY * renderBlocks.renderMinX);
+ renderBlocks.brightnessBottomRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPPP, renderBlocks.renderMinY * (1.0D - renderBlocks.renderMaxX), (1.0D - renderBlocks.renderMinY) * (1.0D - renderBlocks.renderMaxX), (1.0D - renderBlocks.renderMinY) * renderBlocks.renderMaxX, renderBlocks.renderMinY * renderBlocks.renderMaxX);
+ renderBlocks.brightnessTopRight = renderBlocks.mixAoBrightness(brightnessMixedXYZNPP, brightnessMixedXYZNNP, brightnessMixedXYZPNP, brightnessMixedXYZPPP, renderBlocks.renderMaxY * (1.0D - renderBlocks.renderMaxX), (1.0D - renderBlocks.renderMaxY) * (1.0D - renderBlocks.renderMaxX), (1.0D - renderBlocks.renderMaxY) * renderBlocks.renderMaxX, renderBlocks.renderMaxY * renderBlocks.renderMaxX);
+ }
+
+ return this;
+ }
+}
diff --git a/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java b/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java
new file mode 100644
index 0000000000..354b3748be
--- /dev/null
+++ b/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java
@@ -0,0 +1,604 @@
+package gregtech.api.util;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.util.Vec3;
+import net.minecraft.world.World;
+
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+@SuppressWarnings("unused")
+public abstract class WorldSpawnedEventBuilder implements Runnable {
+ private static final String ILLEGAL_STATE_STR1 = "Position, identifier and world must be set";
+ /* Variables */
+
+ private World world;
+
+ /* Getters, Setters */
+
+ public World getWorld() {
+ return world;
+ }
+
+ public WorldSpawnedEventBuilder setWorld(World world) {
+ this.world = world;
+ return this;
+ }
+
+ /* Methodes */
+
+ @SuppressWarnings("unchecked")
+ public <U extends WorldSpawnedEventBuilder> void times(int times, Consumer<U> action) {
+ Objects.requireNonNull(action);
+ for (int i = 0; i < times; i++) {
+ action.accept((U) this);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <U extends WorldSpawnedEventBuilder> void times(int times, BiConsumer<U, Integer> action) {
+ Objects.requireNonNull(action);
+ for (int i = 0; i < times; i++) {
+ action.accept((U) this, i);
+ }
+ }
+
+ /* Interfaces */
+
+ private interface IPositionedWorldSpawnedEvent {
+ Vec3 getPosition();
+ IPositionedWorldSpawnedEvent setPosition(Vec3 position);
+ IPositionedWorldSpawnedEvent setPosition(double x, double y, double z);
+ }
+
+ private interface IEntityWorldSpawnedEvent {
+ Entity getEntity();
+ IEntityWorldSpawnedEvent setEntity(Entity entity);
+ }
+
+ private interface IEntityPlayerWorldSpawnedEvent {
+ EntityPlayer getEntityPlayer();
+ IEntityPlayerWorldSpawnedEvent setEntityPlayer(EntityPlayer entity);
+ }
+
+ private interface IStringIdentifierWorldSpawnedEvent {
+ String getIdentifier();
+ IStringIdentifierWorldSpawnedEvent setIdentifier(String identifier);
+ }
+
+ private interface ISoundWorldSpawnedEvent {
+ float getPitch();
+ float getVolume();
+ ISoundWorldSpawnedEvent setPitch(float pitch);
+ ISoundWorldSpawnedEvent setVolume(float volume);
+ }
+
+ /* Abstract Classes */
+
+ private abstract static class EntityWorldSpawnedEventBuilder extends WorldSpawnedEventBuilder implements IEntityWorldSpawnedEvent {
+
+ private Entity entity;
+
+ @Override
+ public Entity getEntity() {
+ return entity;
+ }
+
+ @Override
+ public EntityWorldSpawnedEventBuilder setEntity(Entity entity) {
+ this.entity = entity;
+ return this;
+ }
+ }
+
+ private abstract static class PositionedEntityWorldSpawnedEventBuilder extends EntityWorldSpawnedEventBuilder implements IPositionedWorldSpawnedEvent {
+
+ private Vec3 position;
+
+ @Override
+ public Vec3 getPosition() {
+ return position;
+ }
+
+ @Override
+ public PositionedEntityWorldSpawnedEventBuilder setPosition(Vec3 position) {
+ this.position = position;
+ return this;
+ }
+
+ @Override
+ public PositionedEntityWorldSpawnedEventBuilder setPosition(double x, double y, double z) {
+ this.position = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+
+ }
+
+ private abstract static class PositionedWorldSpawnedEventBuilder extends WorldSpawnedEventBuilder implements IPositionedWorldSpawnedEvent {
+ private Vec3 position;
+
+ @Override
+ public Vec3 getPosition() {
+ return position;
+ }
+
+ @Override
+ public PositionedWorldSpawnedEventBuilder setPosition(Vec3 position) {
+ this.position = position;
+ return this;
+ }
+
+ @Override
+ public PositionedWorldSpawnedEventBuilder setPosition(double x, double y, double z) {
+ this.position = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+ }
+
+ private abstract static class StringIdentifierPositionedWorldSpawnedEventBuilder extends PositionedWorldSpawnedEventBuilder implements IStringIdentifierWorldSpawnedEvent {
+ private String identifier;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public StringIdentifierPositionedWorldSpawnedEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+ }
+
+ private abstract static class SoundStringIdentifierPositionedWorldSpawnedEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundStringIdentifierPositionedWorldSpawnedEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundStringIdentifierPositionedWorldSpawnedEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+ }
+
+ /* Implementations */
+
+ public static final class ParticleEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ private Vec3 motion;
+
+ public Vec3 getMotion() {
+ return motion;
+ }
+
+ public ParticleEventBuilder setMotion(double x, double y, double z) {
+ this.motion = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+
+ public ParticleEventBuilder setMotion(Vec3 motion) {
+ this.motion = motion;
+ return this;
+ }
+
+ @Override
+ public ParticleEventBuilder setWorld(World world) {
+ return (ParticleEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ParticleEventBuilder setPosition(Vec3 position) {
+ return (ParticleEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public ParticleEventBuilder setPosition(double x, double y, double z) {
+ return (ParticleEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public ParticleEventBuilder setIdentifier(String identifier) {
+ return (ParticleEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getMotion() == null || getWorld() == null)
+ throw new IllegalStateException("Position, identifier, motion and world must be set");
+
+ getWorld().spawnParticle(
+ getIdentifier(),
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getMotion().xCoord, getMotion().yCoord, getMotion().zCoord
+ );
+ }
+ }
+
+ public static final class SoundEffectEventBuilder extends SoundStringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ @Override
+ public SoundEffectEventBuilder setWorld(World world) {
+ return (SoundEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPosition(Vec3 position) {
+ return (SoundEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPosition(double x, double y, double z) {
+ return (SoundEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setIdentifier(String identifier) {
+ return (SoundEffectEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPitch(float pitch) {
+ return (SoundEffectEventBuilder) super.setPitch(pitch);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setVolume(float volume) {
+ return (SoundEffectEventBuilder) super.setVolume(volume);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException(ILLEGAL_STATE_STR1);
+
+ getWorld().playSoundEffect(
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getIdentifier(),
+ getPitch(), getVolume()
+ );
+ }
+ }
+
+ public static final class SoundEventBuilder extends SoundStringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ private boolean proximity;
+
+ public boolean isProximity() {
+ return proximity;
+ }
+
+ @Override
+ public SoundEventBuilder setWorld(World world) {
+ return (SoundEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundEventBuilder setPosition(Vec3 position) {
+ return (SoundEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public SoundEventBuilder setPosition(double x, double y, double z) {
+ return (SoundEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public SoundEventBuilder setIdentifier(String identifier) {
+ return (SoundEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public SoundEventBuilder setPitch(float pitch) {
+ return (SoundEventBuilder) super.setPitch(pitch);
+ }
+
+ @Override
+ public SoundEventBuilder setVolume(float volume) {
+ return (SoundEventBuilder) super.setVolume(volume);
+ }
+
+ public SoundEventBuilder setProximity(boolean proximity) {
+ this.proximity = proximity;
+ return this;
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException(ILLEGAL_STATE_STR1);
+
+ getWorld().playSound(
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getIdentifier(),
+ getPitch(), getVolume(), isProximity()
+ );
+ }
+ }
+
+ /**
+ * Positional Data is rounded down due to this targeting a block.
+ */
+ public static final class RecordEffectEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ @Override
+ public RecordEffectEventBuilder setWorld(World world) {
+ return (RecordEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setPosition(Vec3 position) {
+ return (RecordEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setPosition(double x, double y, double z) {
+ return (RecordEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setIdentifier(String identifier) {
+ return (RecordEffectEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException(ILLEGAL_STATE_STR1);
+
+ getWorld().playRecord(
+ getIdentifier(),
+ (int) getPosition().xCoord,(int) getPosition().yCoord,(int) getPosition().zCoord
+ );
+ }
+ }
+
+ public static final class ExplosionEffectEventBuilder extends PositionedEntityWorldSpawnedEventBuilder {
+ private boolean isFlaming, isSmoking;
+ private float strength;
+
+
+ public float getStrength() {
+ return strength;
+ }
+
+ public ExplosionEffectEventBuilder setStrength(float strength) {
+ this.strength = strength;
+ return this;
+ }
+
+ public boolean isFlaming() {
+ return isFlaming;
+ }
+
+ public ExplosionEffectEventBuilder setFlaming(boolean flaming) {
+ isFlaming = flaming;
+ return this;
+ }
+
+ public boolean isSmoking() {
+ return isSmoking;
+ }
+
+ public ExplosionEffectEventBuilder setSmoking(boolean smoking) {
+ isSmoking = smoking;
+ return this;
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setWorld(World world) {
+ return (ExplosionEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setEntity(Entity entity) {
+ return (ExplosionEffectEventBuilder) super.setEntity(entity);
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setPosition(double x, double y, double z) {
+ return (ExplosionEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getWorld() == null)
+ throw new IllegalStateException("Position and world must be set");
+
+ getWorld().newExplosion(getEntity(), getPosition().xCoord, getPosition().yCoord, getPosition().zCoord, strength, isFlaming, isSmoking);
+ }
+ }
+
+ /**
+ * Positional Data is rounded down due to this targeting a block.
+ */
+ public static final class ExtinguishFireEffectEventBuilder extends PositionedWorldSpawnedEventBuilder implements IEntityPlayerWorldSpawnedEvent {
+
+ private int side;
+ private EntityPlayer entityPlayer;
+
+ public int getSide() {
+ return side;
+ }
+
+ public ExtinguishFireEffectEventBuilder setSide(int side) {
+ this.side = side;
+ return this;
+ }
+
+ @Override
+ public EntityPlayer getEntityPlayer() {
+ return entityPlayer;
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setEntityPlayer(EntityPlayer entity) {
+ this.entityPlayer = entity;
+ return this;
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setWorld(World world) {
+ return (ExtinguishFireEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setPosition(Vec3 position) {
+ return (ExtinguishFireEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setPosition(double x, double y, double z) {
+ return (ExtinguishFireEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public void run() {
+ if (getEntityPlayer() == null || getPosition() == null || getWorld() == null)
+ throw new IllegalStateException("EntityPlayer, position and world must be set");
+
+ getWorld().extinguishFire(getEntityPlayer(), (int) getPosition().xCoord, (int) getPosition().yCoord, (int) getPosition().zCoord, side);
+ }
+ }
+
+ public static final class SoundAtEntityEventBuilder extends EntityWorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent, IStringIdentifierWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+ private String identifier;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setWorld(World world) {
+ return (SoundAtEntityEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setEntity(Entity entity) {
+ return (SoundAtEntityEventBuilder) super.setEntity(entity);
+ }
+
+ @Override
+ public void run() {
+ if (getWorld() == null || getIdentifier() == null || getEntity() == null)
+ throw new IllegalStateException("World, Identifier and entity must be set!");
+
+ getWorld().playSoundAtEntity(getEntity(), getIdentifier(), volume, pitch);
+ }
+ }
+
+ public static final class SoundToNearExceptEventBuilder extends WorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent, IStringIdentifierWorldSpawnedEvent, IEntityPlayerWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+ private String identifier;
+ private EntityPlayer entityPlayer;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setWorld(World world) {
+ return (SoundToNearExceptEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public void run() {
+ if (getWorld() == null || getIdentifier() == null || getEntityPlayer() == null)
+ throw new IllegalStateException("World, Identifier and EntityPlayer must be set!");
+
+ getWorld().playSoundAtEntity(getEntityPlayer(), getIdentifier(), volume, pitch);
+ }
+
+ @Override
+ public EntityPlayer getEntityPlayer() {
+ return entityPlayer;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setEntityPlayer(EntityPlayer entity) {
+ entityPlayer = entity;
+ return this;
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/util/extensions/ArrayExt.java b/src/main/java/gregtech/api/util/extensions/ArrayExt.java
new file mode 100644
index 0000000000..51486bc036
--- /dev/null
+++ b/src/main/java/gregtech/api/util/extensions/ArrayExt.java
@@ -0,0 +1,80 @@
+package gregtech.api.util.extensions;
+
+import java.util.function.IntFunction;
+
+public class ArrayExt {
+ public static int[] of(int... objects) {
+ return objects;
+ }
+
+ public static float[] of(float... objects) {
+ return objects;
+ }
+
+ public static double[] of(double... objects) {
+ return objects;
+ }
+
+ public static char[] of(char... objects) {
+ return objects;
+ }
+
+ public static byte[] of(byte... objects) {
+ return objects;
+ }
+
+ public static long[] of(long... objects) {
+ return objects;
+ }
+
+ @SafeVarargs
+ public static <T> T[] of(T... objects) {
+ return objects;
+ }
+
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ public static <T> T[] withoutNulls(T[] array, IntFunction<T[]> arrayFactory) {
+ int count = 0;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ count++;
+ }
+ }
+
+ T[] newArr = arrayFactory.apply(count);
+ if (count == 0) return newArr;
+
+ int j = 0;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ newArr[j] = array[i];
+ j++;
+ }
+ }
+
+ return newArr;
+ }
+
+ public static <T> T[] withoutTrailingNulls(T[] array, IntFunction<T[]> arrayFactory) {
+ int firstNull = -1;
+ for (int i = array.length - 1; i >= 0; i--) {
+ if (array[i] == null) {
+ firstNull = i;
+ } else {
+ break;
+ }
+ }
+
+ if (firstNull == -1) {
+ T[] newArray = arrayFactory.apply(array.length);
+ System.arraycopy(array, 0, newArray, 0, array.length);
+ return newArray;
+ } else if (firstNull == 0) {
+ return arrayFactory.apply(0);
+ } else {
+ T[] newArray = arrayFactory.apply(firstNull);
+ System.arraycopy(array, 0, newArray, 0, firstNull);
+ return newArray;
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/util/extensions/IteratorExt.java b/src/main/java/gregtech/api/util/extensions/IteratorExt.java
new file mode 100644
index 0000000000..d59bb298a4
--- /dev/null
+++ b/src/main/java/gregtech/api/util/extensions/IteratorExt.java
@@ -0,0 +1,12 @@
+package gregtech.api.util.extensions;
+
+import gregtech.api.objects.iterators.MergedIterator;
+
+import java.util.Iterator;
+
+public class IteratorExt {
+ @SafeVarargs
+ public static <T> Iterator<T> merge(Iterator<T>... iterators) {
+ return new MergedIterator<>(iterators);
+ }
+}