aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/GregTech_API.java19
-rw-r--r--src/main/java/gregtech/api/enums/GT_Values.java11
-rw-r--r--src/main/java/gregtech/api/enums/HeatingCoilLevel.java69
-rw-r--r--src/main/java/gregtech/api/enums/ItemList.java8
-rw-r--r--src/main/java/gregtech/api/enums/Textures.java13
-rw-r--r--src/main/java/gregtech/api/interfaces/IHeatingCoil.java18
-rw-r--r--src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java7
-rw-r--r--src/main/java/gregtech/api/items/GT_Block_LongDistancePipe.java109
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java10
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaTileEntity.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java3
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java98
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java67
-rw-r--r--src/main/java/gregtech/api/objects/ReverseShapedRecipe.java43
-rw-r--r--src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java43
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java126
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Shaped_Recipe.java25
-rw-r--r--src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java36
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java179
21 files changed, 722 insertions, 170 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java
index 932d267a34..17f171a953 100644
--- a/src/main/java/gregtech/api/GregTech_API.java
+++ b/src/main/java/gregtech/api/GregTech_API.java
@@ -25,6 +25,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
@@ -89,8 +90,16 @@ public class GregTech_API {
* 9728 - 10239 are reserved for 28Smiles.
* 10240 - 10751 are reserved for VirMan.
* 10752 - 11263 are reserved for Briareos81.
- * 11264 - 12000 are reserved for the next one who asks me.
- * 9728 - 32766 are currently free.
+ * 11264 - 12000 are reserved for Quantum64.
+ * 12001 - 12500 are reserved for RedMage17.
+ * 12501 - 13000 are reserved for bartimaeusnek.
+ * 13001 - 13100 are reserved for Techlone
+ * 13101 - 13500 are reserved for kekzdealer
+ * 13501 - 14999 are currently free.
+ * 15000 - 16999 are reserved for TecTech.
+ * 17000 - 29999 are currently free.
+ * 30000 - 31999 are reserved for Alkalus.
+ * 32001 - 32766 are currently free.
* <p/>
* Contact me if you need a free ID-Range, which doesn't conflict with other Addons.
* You could make an ID-Config, but we all know, what "stupid" customers think about conflicting ID's
@@ -257,6 +266,8 @@ public class GregTech_API {
sBlockCasings5,
sBlockCasings6,
sBlockCasings8;
+ public static Block
+ sBlockLongDistancePipes;
/**
* Getting assigned by the Config
*/
@@ -389,8 +400,8 @@ public class GregTech_API {
* @param aZ is the Z-Coord of the update causing Block
*/
public static boolean causeMachineUpdate(World aWorld, int aX, int aY, int aZ) {
- if (aWorld != null && !aWorld.isRemote) { //World might be null during Worldgen
- GT_Runnable_MachineBlockUpdate.setMachineUpdateValues(aWorld, aX, aY, aZ);
+ if (aWorld != null && !aWorld.isRemote) { // World might be null during Worldgen
+ GT_Runnable_MachineBlockUpdate.setMachineUpdateValues(aWorld, new ChunkCoordinates(aX, aY, aZ));
return true;
}
return false;
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java
index 66b2e8a08f..8545f42bea 100644
--- a/src/main/java/gregtech/api/enums/GT_Values.java
+++ b/src/main/java/gregtech/api/enums/GT_Values.java
@@ -4,6 +4,7 @@ import gregtech.api.interfaces.internal.IGT_Mod;
import gregtech.api.interfaces.internal.IGT_RecipeAdder;
import gregtech.api.net.IGT_NetworkHandler;
import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -126,6 +127,16 @@ public class GT_Values {
"Ultimate High Voltage", "Ultimate Extreme Voltage", "Ultimate Insane Voltage",
"Ultimate Mega Voltage", "Ultimate Extended Mega Voltage", "Overpowered Voltage",
"Maximum Voltage"};
+
+ public static final String[] TIER_COLORS =
+ new String[]{
+ EnumChatFormatting.RED.toString(), EnumChatFormatting.GRAY.toString(), EnumChatFormatting.AQUA.toString(),
+ EnumChatFormatting.GOLD.toString(), EnumChatFormatting.DARK_PURPLE.toString(), EnumChatFormatting.DARK_BLUE.toString(),
+ EnumChatFormatting.LIGHT_PURPLE.toString(), EnumChatFormatting.WHITE.toString(), EnumChatFormatting.DARK_AQUA.toString(),
+ EnumChatFormatting.DARK_RED.toString(), EnumChatFormatting.GREEN.toString(), EnumChatFormatting.DARK_GREEN.toString(),
+ EnumChatFormatting.YELLOW.toString(), EnumChatFormatting.UNDERLINE.toString(), EnumChatFormatting.BOLD.toString(),
+ EnumChatFormatting.OBFUSCATED.toString()};
+
/**
* This way it is possible to have a Call Hierarchy of NullPointers in ItemStack based Functions, and also because most of the time I don't know what kind of Data Type the "null" stands for
*/
diff --git a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
new file mode 100644
index 0000000000..f4b28ede2b
--- /dev/null
+++ b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
@@ -0,0 +1,69 @@
+package gregtech.api.enums;
+
+import net.minecraft.util.EnumChatFormatting;
+
+public enum HeatingCoilLevel {
+ None, // 0
+ ULV, //Not implemented 901
+ LV, //Cupronickel 1801
+ MV, //KANTHAL 2701
+ HV, //NICHROME 3601
+ EV, //TUNGSTENSTEEL 4501
+ IV, //HSSG 5401
+ LuV, //HSSS 6301
+ ZPM, //NAQUADAH 7201
+ UV, //NAQUADAHALLOY 8101
+ UHV, //TRINIUM 9001
+ UEV, //ELECTRUMFLUX 9901
+ UIV, //AWAKENEDDRACONIUM 10801
+ //Not Implemented yet
+ UMV,
+ UXV,
+ OpV,
+ MAX,
+ ;
+
+ /**
+ * @return the Coils Tier Name
+ */
+ public String getTierName() {
+ if (this.ordinal() < 1 || (this.ordinal()-1) >= GT_Values.VN.length)
+ return "ERROR!";
+ return GT_Values.TIER_COLORS[this.ordinal() - 1] + GT_Values.VOLTAGE_NAMES[this.ordinal() - 1] + EnumChatFormatting.RESET;
+ }
+
+ /**
+ * @return the coil heat, used for recipes in the Electronic Blast Furnace for example
+ */
+ public long getHeat() {
+ return this == None ? 0 : 1L + (900L * this.ordinal());
+ }
+
+ /**
+ * @return the coil tier, used for discount in the Pyrolyse Ofen for example
+ */
+ public byte getTier() {
+ return (byte) (this.ordinal() - 2);
+ }
+
+ /**
+ * @return the coil Level, used for Parallels in the Multi Furnace for example
+ */
+ public byte getLevel() {
+ return (byte) Math.min(16, 2 << (this.ordinal() - 2));
+ }
+
+ /**
+ * @return the coil Discount, used for discount in the Multi Furnace for example
+ */
+ public byte getCostDiscount() {
+ return (byte) Math.max(1, 2 << (this.ordinal() - 1 - 6)); //-1 bcs. of none, -4 = offset
+ }
+
+ public static HeatingCoilLevel getFromTier(byte tier){
+ if (tier < 0 || tier > HeatingCoilLevel.values().length -1)
+ return HeatingCoilLevel.None;
+
+ return HeatingCoilLevel.values()[tier+2];
+ }
+} \ No newline at end of file
diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java
index 2fba2462b5..94efa0605f 100644
--- a/src/main/java/gregtech/api/enums/ItemList.java
+++ b/src/main/java/gregtech/api/enums/ItemList.java
@@ -1398,6 +1398,12 @@ public enum ItemList implements IItemContainer {
Super_Chest_HV,
Super_Chest_EV,
Super_Chest_IV,
+
+ Long_Distance_Pipeline_Fluid,
+ Long_Distance_Pipeline_Item,
+
+ Long_Distance_Pipeline_Fluid_Pipe,
+ Long_Distance_Pipeline_Item_Pipe,
NULL,
Cover_RedstoneTransmitterExternal,
@@ -1437,7 +1443,9 @@ public enum ItemList implements IItemContainer {
Casing_Coil_Nichrome,
Casing_Coil_TungstenSteel,
Casing_Coil_HSSG,
+ Casing_Coil_HSSS,
Casing_Coil_Naquadah,
+ Casing_Coil_Trinium,
Casing_Coil_NaquadahAlloy,
Casing_Coil_ElectrumFlux,
Casing_Coil_AwakenedDraconium,
diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java
index e0d0ce6abe..de2c0919e7 100644
--- a/src/main/java/gregtech/api/enums/Textures.java
+++ b/src/main/java/gregtech/api/enums/Textures.java
@@ -45,6 +45,17 @@ public class Textures {
OVERLAY_SCHEST,
OVERLAY_STANK,
+
+ OVERLAY_PIPELINE_FLUID_BACK,
+ OVERLAY_PIPELINE_FLUID_FRONT,
+ OVERLAY_PIPELINE_FLUID_SIDE,
+
+ OVERLAY_PIPELINE_ITEM_BACK,
+ OVERLAY_PIPELINE_ITEM_FRONT,
+ OVERLAY_PIPELINE_ITEM_SIDE,
+
+ LONG_DISTANCE_PIPE_FLUID,
+ LONG_DISTANCE_PIPE_ITEM,
MACHINE_CASING_TANK_1,
MACHINE_CASING_TANK_2,
@@ -283,6 +294,8 @@ public class Textures {
MACHINE_COIL_NAQUADAHALLOY,
MACHINE_COIL_ELECTRUMFLUX,
MACHINE_COIL_AWAKENEDDRACONIUM,
+ MACHINE_COIL_HSSS,
+ MACHINE_COIL_TRINIUM,
BOILER_SOLAR,
BOILER_FRONT,
diff --git a/src/main/java/gregtech/api/interfaces/IHeatingCoil.java b/src/main/java/gregtech/api/interfaces/IHeatingCoil.java
new file mode 100644
index 0000000000..c8ceccf941
--- /dev/null
+++ b/src/main/java/gregtech/api/interfaces/IHeatingCoil.java
@@ -0,0 +1,18 @@
+package gregtech.api.interfaces;
+
+import gregtech.api.enums.HeatingCoilLevel;
+import net.minecraft.item.ItemStack;
+
+import java.util.function.Consumer;
+
+public interface IHeatingCoil {
+
+ HeatingCoilLevel getCoilHeat(int meta);
+ default HeatingCoilLevel getCoilHeat(ItemStack stack) {
+ return getCoilHeat(stack.getItemDamage());
+ }
+
+ void setOnCoilCheck(Consumer<IHeatingCoil> callback);
+ Consumer<IHeatingCoil> getOnCoilCheck();
+}
+
diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java
index 8e135fbc85..9ab1ac0f67 100644
--- a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java
+++ b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java
@@ -141,8 +141,7 @@ public interface IGregTechTileEntity extends ITexturedTileEntity, IGearEnergyTil
*/
@Override
default void onMachineBlockUpdate(){
- if(!isDead() && getMetaTileEntity()!=null &&
- getMetaTileEntity().getBaseMetaTileEntity()==this){
+ if(!isDead() && getMetaTileEntity() != null && getMetaTileEntity().getBaseMetaTileEntity() == this){
getMetaTileEntity().onMachineBlockUpdate();
}
}
@@ -152,8 +151,8 @@ public interface IGregTechTileEntity extends ITexturedTileEntity, IGearEnergyTil
*/
@Override
default boolean isMachineBlockUpdateRecursive() {
- return !isDead() && getMetaTileEntity()!=null &&
- getMetaTileEntity().getBaseMetaTileEntity()==this &&
+ return !isDead() && getMetaTileEntity() != null &&
+ getMetaTileEntity().getBaseMetaTileEntity() == this &&
getMetaTileEntity().isMachineBlockUpdateRecursive();
}
} \ No newline at end of file
diff --git a/src/main/java/gregtech/api/items/GT_Block_LongDistancePipe.java b/src/main/java/gregtech/api/items/GT_Block_LongDistancePipe.java
new file mode 100644
index 0000000000..734eae19f4
--- /dev/null
+++ b/src/main/java/gregtech/api/items/GT_Block_LongDistancePipe.java
@@ -0,0 +1,109 @@
+package gregtech.api.items;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Textures;
+import gregtech.api.interfaces.IIconContainer;
+import gregtech.api.util.GT_LanguageManager;
+import gregtech.common.blocks.GT_Item_LongDistancePipe;
+import gregtech.common.blocks.GT_Material_Machines;
+import net.minecraft.block.Block;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EnumCreatureType;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.IIcon;
+import net.minecraft.util.StatCollector;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+
+import java.util.List;
+import java.util.Random;
+
+public class GT_Block_LongDistancePipe extends GT_Generic_Block {
+ public IIconContainer[] mIcons;
+ public GT_Block_LongDistancePipe() {
+ super(GT_Item_LongDistancePipe.class, "gt.block.longdistancepipe", new GT_Material_Machines());
+ setStepSound(soundTypeMetal);
+ setCreativeTab(GregTech_API.TAB_GREGTECH);
+ GregTech_API.registerMachineBlock(this, -1);
+
+ GT_LanguageManager.addStringLocalization(getUnlocalizedName()+".0.name", "Long Distance Fluid Pipeline Pipe");
+ GT_LanguageManager.addStringLocalization(getUnlocalizedName()+".1.name", "Long Distance Item Pipeline Pipe");
+ GT_LanguageManager.addStringLocalization(getUnlocalizedName() + "." + 32767 + ".name", "Any Sub Block of this");
+
+ ItemList.Long_Distance_Pipeline_Fluid_Pipe.set(new ItemStack(this, 1, 0));
+ ItemList.Long_Distance_Pipeline_Item_Pipe.set(new ItemStack(this, 1, 1));
+ mIcons = new IIconContainer[]{Textures.BlockIcons.LONG_DISTANCE_PIPE_FLUID, Textures.BlockIcons.LONG_DISTANCE_PIPE_ITEM};
+ }
+ public void onBlockAdded(World aWorld, int aX, int aY, int aZ) {
+ super.onBlockAdded(aWorld, aX, aY, aZ);
+ if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) {
+ GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
+ }
+ }
+ public void breakBlock(World aWorld, int aX, int aY, int aZ, Block par5, int par6) {
+ GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
+ super.breakBlock(aWorld, aX, aY, aZ, par5, par6);
+ }
+ public String getHarvestTool(int aMeta) {
+ return "wrench";
+ }
+
+ public int getHarvestLevel(int aMeta) {
+ return 2;
+ }
+
+ public float getBlockHardness(World aWorld, int aX, int aY, int aZ) {
+ return Blocks.iron_block.getBlockHardness(aWorld, aX, aY, aZ);
+ }
+
+ public float getExplosionResistance(Entity aTNT) {
+ return Blocks.iron_block.getExplosionResistance(aTNT);
+ }
+
+
+ public String getUnlocalizedName() {
+ return this.mUnlocalizedName;
+ }
+
+ public String getLocalizedName() {
+ return StatCollector.translateToLocal(this.mUnlocalizedName + ".name");
+ }
+
+ public IIcon getIcon(int aSide, int aMeta) {
+ return mIcons[aMeta % mIcons.length].getIcon();
+ }
+
+ public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
+ return false;
+ }
+
+ public int quantityDropped(Random par1Random) {
+ return 1;
+ }
+
+ public Item getItemDropped(int par1, Random par2Random, int par3) {
+ return Item.getItemFromBlock(this);
+ }
+
+ public int damageDropped(int par1) {
+ return par1;
+ }
+
+ public int getDamageValue(World par1World, int par2, int par3, int par4) {
+ return par1World.getBlockMetadata(par2, par3, par4);
+ }
+
+ @SideOnly(Side.CLIENT)
+ public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) {
+ for (int i = 0; i < 3; i++) {
+ ItemStack aStack = new ItemStack(aItem, 1, i);
+ if (!aStack.getDisplayName().contains(".name")) aList.add(aStack);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index cfb34eb34e..f5bcf8bfbd 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -843,8 +843,16 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
if (isValidFacing(aFacing)) {
mFacing = aFacing;
mMetaTileEntity.onFacingChange();
- onMachineBlockUpdate();
+
doEnetUpdate();
+
+ if (mMetaTileEntity.shouldTriggerBlockUpdate()) {
+ // If we're triggering a block update this will call onMachineBlockUpdate()
+ GregTech_API.causeMachineUpdate(worldObj, xCoord, yCoord, zCoord);
+ } else {
+ // If we're not trigger a cascading one, call the update here.
+ onMachineBlockUpdate();
+ }
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
index d08a8d9da5..d873627e21 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
@@ -933,4 +933,6 @@ public abstract class MetaTileEntity implements IMetaTileEntity {
}
public boolean shouldJoinIc2Enet() { return false; }
+
+ public boolean shouldTriggerBlockUpdate() { return false; }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
index 2c632c596b..497e42b9aa 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java
@@ -516,8 +516,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
if (tMaxStacks > mOutputItems.length)
tMaxStacks = mOutputItems.length;
- int tCost = moveMultipleItemStacks(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1,tMaxStacks);
- aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCost, true);
+ moveMultipleItemStacks(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1,tMaxStacks);
// for (int i = 0, tCosts = 1; i < mOutputItems.length && tCosts > 0 && aBaseMetaTileEntity.isUniversalEnergyStored(128); i++) {
// tCosts = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, tTileEntity2, aBaseMetaTileEntity.getFrontFacing(), aBaseMetaTileEntity.getBackFacing(), null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1);
// if (tCosts > 0) aBaseMetaTileEntity.decreaseStoredEnergyUnits(tCosts, true);
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
index 17dbd560a2..7b622cb45c 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
@@ -1,7 +1,11 @@
package gregtech.api.metatileentity.implementations;
import cpw.mods.fml.common.Loader;
-import gregtech.api.enums.*;
+import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.api.enums.Textures;
+import gregtech.api.enums.Tier;
import gregtech.api.gui.GT_Container_BasicMachine;
import gregtech.api.gui.GT_GUIContainer_BasicMachine;
import gregtech.api.interfaces.ITexture;
@@ -22,7 +26,10 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.Locale;
import java.util.Random;
-import static gregtech.api.enums.GT_Values.*;
+import static gregtech.api.enums.GT_Values.V;
+import static gregtech.api.enums.GT_Values.VN;
+import static gregtech.api.enums.GT_Values.W;
+import static gregtech.api.enums.GT_Values.ticksBetweenSounds;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -36,8 +43,21 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
private final String mSound;
private final boolean mSharedTank, mRequiresFluidForFiltering;
private final byte mGUIParameterA, mGUIParameterB;
- public GT_MetaTileEntity_BasicMachine_GT_Recipe(int aID, String aName, String aNameRegional, int aTier, String aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aGUIParameterA, int aGUIParameterB, String aGUIName, String aSound, boolean aSharedTank, boolean aRequiresFluidForFiltering, int aSpecialEffect, String aOverlays, Object[] aRecipe) {
- super(aID, aName, aNameRegional, aTier, aRecipes.mAmperage, aDescription, aInputSlots, aOutputSlots, aGUIName, aRecipes.mNEIName, new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_SIDE_ACTIVE")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_SIDE")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_FRONT_ACTIVE")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_FRONT")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_TOP_ACTIVE")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_TOP")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_BOTTOM_ACTIVE")), new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_BOTTOM")));
+
+ public GT_MetaTileEntity_BasicMachine_GT_Recipe(
+ int aID, String aName, String aNameRegional, int aTier, String aDescription, GT_Recipe.GT_Recipe_Map aRecipes,
+ int aInputSlots, int aOutputSlots, int aTankCapacity, int aGUIParameterA, int aGUIParameterB, String aGUIName, String aSound, boolean aSharedTank,
+ boolean aRequiresFluidForFiltering, int aSpecialEffect, String aOverlays, Object[] aRecipe
+ ) {
+ super(aID, aName, aNameRegional, aTier, aRecipes.mAmperage, aDescription, aInputSlots, aOutputSlots, aGUIName, aRecipes.mNEIName,
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_SIDE_ACTIVE")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_SIDE")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_FRONT_ACTIVE")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_FRONT")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_TOP_ACTIVE")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_TOP")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_BOTTOM_ACTIVE")),
+ new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("basicmachines/" + aOverlays.toLowerCase(Locale.ENGLISH) + "/OVERLAY_BOTTOM")));
this.mSharedTank = aSharedTank;
this.mTankCapacity = aTankCapacity;
this.mSpecialEffect = aSpecialEffect;
@@ -657,13 +677,22 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
throw new IllegalArgumentException("MISSING TIER MAPPING FOR: " + aRecipe[i] + " AT TIER " + mTier);
}
- if (!GT_ModHandler.addCraftingRecipe(getStackForm(1), GT_ModHandler.RecipeBits.DISMANTLEABLE | GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.NOT_REMOVABLE | GT_ModHandler.RecipeBits.REVERSIBLE, aRecipe)) {
+ if (
+ !GT_ModHandler.addCraftingRecipe(
+ getStackForm(1),
+ GT_ModHandler.RecipeBits.DISMANTLEABLE | GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.NOT_REMOVABLE | GT_ModHandler.RecipeBits.REVERSIBLE, aRecipe
+ )
+ ) {
throw new IllegalArgumentException("INVALID CRAFTING RECIPE FOR: " + getStackForm(1).getDisplayName());
}
}
}
- public GT_MetaTileEntity_BasicMachine_GT_Recipe(String aName, int aTier, String aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage, int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, String aSound, boolean aSharedTank, boolean aRequiresFluidForFiltering, int aSpecialEffect) {
+ public GT_MetaTileEntity_BasicMachine_GT_Recipe(
+ String aName, int aTier, String aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage,
+ int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, String aSound, boolean aSharedTank,
+ boolean aRequiresFluidForFiltering, int aSpecialEffect
+ ) {
super(aName, aTier, aAmperage, aDescription, aTextures, aInputSlots, aOutputSlots, aGUIName, aNEIName);
this.mSharedTank = aSharedTank;
this.mTankCapacity = aTankCapacity;
@@ -675,7 +704,11 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
this.mGUIParameterB = (byte) aGUIParameterB;
}
- public GT_MetaTileEntity_BasicMachine_GT_Recipe(String aName, int aTier, String[] aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage, int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, String aSound, boolean aSharedTank, boolean aRequiresFluidForFiltering, int aSpecialEffect) {
+ public GT_MetaTileEntity_BasicMachine_GT_Recipe(
+ String aName, int aTier, String[] aDescription, GT_Recipe.GT_Recipe_Map aRecipes, int aInputSlots, int aOutputSlots, int aTankCapacity, int aAmperage,
+ int aGUIParameterA, int aGUIParameterB, ITexture[][][] aTextures, String aGUIName, String aNEIName, String aSound, boolean aSharedTank,
+ boolean aRequiresFluidForFiltering, int aSpecialEffect
+ ) {
super(aName, aTier, aAmperage, aDescription, aTextures, aInputSlots, aOutputSlots, aGUIName, aNEIName);
this.mSharedTank = aSharedTank;
this.mTankCapacity = aTankCapacity;
@@ -689,7 +722,11 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
- return new GT_MetaTileEntity_BasicMachine_GT_Recipe(this.mName, this.mTier, this.mDescriptionArray, this.mRecipes, this.mInputSlotCount, this.mOutputItems == null ? 0 : this.mOutputItems.length, this.mTankCapacity, this.mAmperage, this.mGUIParameterA, this.mGUIParameterB, this.mTextures, this.mGUIName, this.mNEIName, this.mSound, this.mSharedTank, this.mRequiresFluidForFiltering, this.mSpecialEffect);
+ return new GT_MetaTileEntity_BasicMachine_GT_Recipe(
+ this.mName, this.mTier, this.mDescriptionArray, this.mRecipes, this.mInputSlotCount, this.mOutputItems == null ? 0 : this.mOutputItems.length,
+ this.mTankCapacity, this.mAmperage, this.mGUIParameterA, this.mGUIParameterB, this.mTextures, this.mGUIName, this.mNEIName, this.mSound,
+ this.mSharedTank, this.mRequiresFluidForFiltering, this.mSpecialEffect
+ );
}
@Override
@@ -699,7 +736,11 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
@Override
public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
- return new GT_GUIContainer_BasicMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), this.mGUIName, GT_Utility.isStringValid(this.mNEIName) ? this.mNEIName : this.getRecipeList() != null ? this.getRecipeList().mUnlocalizedName : "", this.mGUIParameterA, this.mGUIParameterB);
+ return new GT_GUIContainer_BasicMachine(
+ aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), this.mGUIName,
+ GT_Utility.isStringValid(this.mNEIName) ? this.mNEIName : this.getRecipeList() != null ? this.getRecipeList().mUnlocalizedName : "",
+ this.mGUIParameterA, this.mGUIParameterB
+ );
}
@Override
@@ -710,12 +751,39 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
case 0:
return false;
case 1:
- return this.getFillableStack() == null ? !this.mRequiresFluidForFiltering && this.getRecipeList().containsInput(aStack) : null != this.getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, true, V[this.mTier], new FluidStack[]{this.getFillableStack()}, this.getSpecialSlot(), new ItemStack[]{aStack});
+ if (this.getFillableStack() == null)
+ return !this.mRequiresFluidForFiltering && this.getRecipeList().containsInput(aStack);
+ else
+ return this.getRecipeList().findRecipe(
+ this.getBaseMetaTileEntity(), this.mLastRecipe, true, V[this.mTier], new FluidStack[]{this.getFillableStack()},
+ this.getSpecialSlot(), new ItemStack[]{aStack}
+ ) != null;
case 2:
- return (!this.mRequiresFluidForFiltering || this.getFillableStack() != null) && (((this.getInputAt(0) != null && this.getInputAt(1) != null) || (this.getInputAt(0) == null && this.getInputAt(1) == null ? this.getRecipeList().containsInput(aStack) : (this.getRecipeList().containsInput(aStack) && null != this.getRecipeList().findRecipe(this.getBaseMetaTileEntity(), this.mLastRecipe, true, V[this.mTier], new FluidStack[]{this.getFillableStack()}, this.getSpecialSlot(), aIndex == this.getInputSlot() ? new ItemStack[]{aStack, this.getInputAt(1)} : new ItemStack[]{this.getInputAt(0), aStack})))));
+
+ return (
+ !this.mRequiresFluidForFiltering || this.getFillableStack() != null) &&
+ (
+ (
+ (this.getInputAt(0) != null && this.getInputAt(1) != null) ||
+ (
+ this.getInputAt(0) == null && this.getInputAt(1) == null ?
+ this.getRecipeList().containsInput(aStack) :
+ (
+ this.getRecipeList().containsInput(aStack) &&
+ this.getRecipeList().findRecipe(
+ this.getBaseMetaTileEntity(), this.mLastRecipe, true, V[this.mTier],
+ new FluidStack[]{this.getFillableStack()},
+ this.getSpecialSlot(), aIndex == this.getInputSlot() ?
+ new ItemStack[]{aStack, this.getInputAt(1)} :
+ new ItemStack[]{this.getInputAt(0), aStack}
+ ) != null
+ )
+ )
+ )
+ );
default:{
int tID = this.getBaseMetaTileEntity().getMetaTileID();
- if (tID >= 211 && tID <= 218 || tID >= 1180 && tID <= 1187 || tID >= 10780 && tID <= 10786) {//assembler lv-iv; circuit asseblers lv - uv; assemblers luv-uev
+ if (tID >= 211 && tID <= 218 || tID >= 1180 && tID <= 1187 || tID >= 10780 && tID <= 10786) { //assembler lv-iv; circuit asseblers lv - uv; assemblers luv-uev
if (GT_Utility.isStackValid(aStack))
for (int oreID : OreDictionary.getOreIDs(aStack)) {
if (OreDictionary.getOreName(oreID).contains("circuit"))
@@ -739,7 +807,11 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
case 1:
if (aBaseMetaTileEntity.getFrontFacing() != 1 && aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0 && !aBaseMetaTileEntity.getOpacityAtSide((byte) 1)) {
Random tRandom = aBaseMetaTileEntity.getWorld().rand;
- aBaseMetaTileEntity.getWorld().spawnParticle("smoke", aBaseMetaTileEntity.getXCoord() + 0.8F - tRandom.nextFloat() * 0.6F, aBaseMetaTileEntity.getYCoord() + 0.9F + tRandom.nextFloat() * 0.2F, aBaseMetaTileEntity.getZCoord() + 0.8F - tRandom.nextFloat() * 0.6F, 0.0D, 0.0D, 0.0D);
+ aBaseMetaTileEntity.getWorld().spawnParticle(
+ "smoke", aBaseMetaTileEntity.getXCoord() + 0.8F - tRandom.nextFloat() * 0.6F,
+ aBaseMetaTileEntity.getYCoord() + 0.9F + tRandom.nextFloat() * 0.2F,
+ aBaseMetaTileEntity.getZCoord() + 0.8F - tRandom.nextFloat() * 0.6F, 0.0D, 0.0D, 0.0D
+ );
}
break;
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
index 8758ea1a02..82cda6c670 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
@@ -248,7 +248,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
- if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isUniversalEnergyStored(getMinimumStoredEU()) && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200 == 0 || mSuccess > 0)) {
+ if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide() && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200 == 0 || mSuccess > 0)) {
mSuccess--;
moveItems(aBaseMetaTileEntity, aTimer);
for(byte b = 0;b<6;b++)
@@ -261,7 +261,6 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
if (mInventory[i] == null) {
for(byte b = 0;b<6;b++)
aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b,bInvert ? (byte)15 : (byte)0);
- aBaseMetaTileEntity.decreaseStoredEnergyUnits(1, true);
break;
}
}
@@ -284,7 +283,6 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
if (tCost > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) {
mSuccess = 50;
- aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(tCost), true);
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index 202e542c88..e15166cf62 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -34,21 +34,21 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
public static boolean disableMaintenance;
public boolean mMachine = false, mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mRunningOnLoad = false;
public int mPollution = 0, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mEfficiencyIncrease = 0, mStartUpCheck = 100, mRuntime = 0, mEfficiency = 0;
- public volatile int mUpdate = 0;
+ public volatile int mUpdate = 0; //TODO: Replace with AtomicInteger
public ItemStack[] mOutputItems = null;
public FluidStack[] mOutputFluids = null;
public String mNEI;
public int damageFactorLow = 5;
public float damageFactorHigh = 0.6f;
- public ArrayList<GT_MetaTileEntity_Hatch_Input> mInputHatches = new ArrayList<GT_MetaTileEntity_Hatch_Input>();
- public ArrayList<GT_MetaTileEntity_Hatch_Output> mOutputHatches = new ArrayList<GT_MetaTileEntity_Hatch_Output>();
- public ArrayList<GT_MetaTileEntity_Hatch_InputBus> mInputBusses = new ArrayList<GT_MetaTileEntity_Hatch_InputBus>();
- public ArrayList<GT_MetaTileEntity_Hatch_OutputBus> mOutputBusses = new ArrayList<GT_MetaTileEntity_Hatch_OutputBus>();
- public ArrayList<GT_MetaTileEntity_Hatch_Dynamo> mDynamoHatches = new ArrayList<GT_MetaTileEntity_Hatch_Dynamo>();
- public ArrayList<GT_MetaTileEntity_Hatch_Muffler> mMufflerHatches = new ArrayList<GT_MetaTileEntity_Hatch_Muffler>();
- public ArrayList<GT_MetaTileEntity_Hatch_Energy> mEnergyHatches = new ArrayList<GT_MetaTileEntity_Hatch_Energy>();
- public ArrayList<GT_MetaTileEntity_Hatch_Maintenance> mMaintenanceHatches = new ArrayList<GT_MetaTileEntity_Hatch_Maintenance>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Input> mInputHatches = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Output> mOutputHatches = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_InputBus> mInputBusses = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_OutputBus> mOutputBusses = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Dynamo> mDynamoHatches = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Muffler> mMufflerHatches = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Energy> mEnergyHatches = new ArrayList<>();
+ public ArrayList<GT_MetaTileEntity_Hatch_Maintenance> mMaintenanceHatches = new ArrayList<>();
public GT_MetaTileEntity_MultiBlockBase(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional, 2);
@@ -791,7 +791,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
public ArrayList<ItemStack> getStoredOutputs() {
- ArrayList<ItemStack> rList = new ArrayList<ItemStack>();
+ ArrayList<ItemStack> rList = new ArrayList<>();
// for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
// if (isValidMetaTileEntity(tHatch)) {
// rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(1));
@@ -808,7 +808,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
public ArrayList<FluidStack> getStoredFluids() {
- ArrayList<FluidStack> rList = new ArrayList<FluidStack>();
+ ArrayList<FluidStack> rList = new ArrayList<>();
for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
tHatch.mRecipeMap = getRecipeMap();
if (isValidMetaTileEntity(tHatch) && tHatch.getFillableStack() != null) {
@@ -819,7 +819,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
}
public ArrayList<ItemStack> getStoredInputs() {
- ArrayList<ItemStack> rList = new ArrayList<ItemStack>();
+ ArrayList<ItemStack> rList = new ArrayList<>();
// for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
// tHatch.mRecipeMap = getRecipeMap();
// if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().getStackInSlot(0) != null) {
@@ -1003,4 +1003,47 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return false;
}
+
+ protected ItemStack[] getCompactedInputs(){
+ //TODO: repalce method with a cleaner one
+ ArrayList<ItemStack> tInputList = getStoredInputs();
+ int tInputList_sS = tInputList.size();
+ for (int i = 0; i < tInputList_sS - 1; i++) {
+ for (int j = i + 1; j < tInputList_sS; j++) {
+ if (!GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j)))
+ continue;
+ if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) {
+ tInputList.remove(j--);
+ tInputList_sS = tInputList.size();
+ } else {
+ tInputList.remove(i--);
+ tInputList_sS = tInputList.size();
+ break;
+ }
+ }
+ }
+ return tInputList.toArray(new ItemStack[0]);
+ }
+
+ protected FluidStack[] getCompactedFluids(){
+ //TODO: repalce method with a cleaner one
+ ArrayList<FluidStack> tFluidList = getStoredFluids();
+ int tFluidList_sS = tFluidList.size();
+ for (int i = 0; i < tFluidList_sS - 1; i++) {
+ for (int j = i + 1; j < tFluidList_sS; j++) {
+ if (!GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j)))
+ continue;
+
+ if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
+ tFluidList.remove(j--);
+ tFluidList_sS = tFluidList.size();
+ } else {
+ tFluidList.remove(i--);
+ tFluidList_sS = tFluidList.size();
+ break;
+ }
+ }
+ }
+ return tFluidList.toArray(new FluidStack[0]);
+ }
}
diff --git a/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java
new file mode 100644
index 0000000000..cb9e7d4d83
--- /dev/null
+++ b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java
@@ -0,0 +1,43 @@
+package gregtech.api.objects;
+
+import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
+import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler;
+import net.minecraft.item.ItemStack;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+import java.util.Queue;
+
+import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes;
+
+public class ReverseShapedRecipe {
+ private static Queue<ReverseShapedRecipe> reverseRecipes = new LinkedList<>();
+ private ItemStack aResult;
+ private Object[] aRecipe;
+
+ public static Queue<ReverseShapedRecipe> getReverseRecipes() {
+ return reverseRecipes;
+ }
+
+ public ReverseShapedRecipe(ItemStack output, Object[] aRecipe) {
+ this.aResult = output;
+ this.aRecipe = aRecipe;
+ reverseRecipes.add(this);
+ }
+
+ public static void runReverseRecipes() {
+ for (ReverseShapedRecipe x : reverseRecipes) {
+ Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapedRecipe(x.aResult, x.aRecipe);
+ if (!recipeOptional.isPresent())
+ continue;
+ GT_Recipe recipe = recipeOptional.get();
+ ItemStack[] replacement = new ItemStack[recipe.mOutputs.length];
+ GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs));
+
+ recipe.mOutputs = replacement;
+ sDisassemblerRecipes.add(recipe);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java
new file mode 100644
index 0000000000..1c5e27d246
--- /dev/null
+++ b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java
@@ -0,0 +1,43 @@
+package gregtech.api.objects;
+
+import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
+import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler;
+import net.minecraft.item.ItemStack;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+import java.util.Queue;
+
+import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes;
+
+public class ReverseShapelessRecipe {
+ private static Queue<ReverseShapelessRecipe> reverseRecipes = new LinkedList<>();
+ private ItemStack aResult;
+ private Object[] aRecipe;
+
+ public static Queue<ReverseShapelessRecipe> getReverseRecipes() {
+ return reverseRecipes;
+ }
+
+ public ReverseShapelessRecipe(ItemStack output, Object[] aRecipe) {
+ this.aResult = output;
+ this.aRecipe = aRecipe;
+ reverseRecipes.add(this);
+ }
+
+ public static void runReverseRecipes() {
+ for (ReverseShapelessRecipe x : reverseRecipes) {
+ Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapelessRecipe(x.aResult, x.aRecipe);
+ if (!recipeOptional.isPresent())
+ continue;
+ GT_Recipe recipe = recipeOptional.get();
+ ItemStack[] replacement = new ItemStack[recipe.mOutputs.length];
+ GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs));
+
+ recipe.mOutputs = replacement;
+ sDisassemblerRecipes.add(recipe);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
index 6e57ef486e..8f7a84e2cb 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
@@ -4,10 +4,12 @@ import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable;
import net.minecraft.tileentity.TileEntity;
-import net.minecraft.world.ChunkPosition;
+import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -15,12 +17,13 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
public class GT_Runnable_MachineBlockUpdate implements Runnable {
- //used by runner thread
- private final int x, y, z;
+ // used by runner thread
+ private final ChunkCoordinates mCoords;
private final World world;
- private final Set<ChunkPosition> visited = new HashSet<>(80);
-
- //Threading
+ private final Set<ChunkCoordinates> visited = new HashSet<>(80);
+ private final Queue<ChunkCoordinates> tQueue = new LinkedList<>();
+
+ // Threading
private static final ThreadFactory THREAD_FACTORY = r -> {
Thread thread = new Thread(r);
thread.setName("GT_MachineBlockUpdate");
@@ -28,12 +31,13 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
};
private static ExecutorService EXECUTOR_SERVICE;
- //This class should never be initiated outside of this class!
- private GT_Runnable_MachineBlockUpdate(World aWorld, int aX, int aY, int aZ) {
+ // This class should never be initiated outside of this class!
+ private GT_Runnable_MachineBlockUpdate(World aWorld, ChunkCoordinates aCoords) {
this.world = aWorld;
- this.x = aX;
- this.y = aY;
- this.z = aZ;
+ this.mCoords = aCoords;
+ visited.add(aCoords);
+ tQueue.add(aCoords);
+
}
public static boolean isEnabled() {
@@ -54,18 +58,15 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
private static boolean isEnabled = true;
- public static void setMachineUpdateValues(World aWorld, int aX, int aY, int aZ) {
+ public static void setMachineUpdateValues(World aWorld, ChunkCoordinates aCoords) {
if (isEnabled) {
- aWorld.getTileEntity(aX, aY, aZ);
- EXECUTOR_SERVICE.submit(new GT_Runnable_MachineBlockUpdate(aWorld, aX, aY, aZ));
+ aWorld.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
+ EXECUTOR_SERVICE.submit(new GT_Runnable_MachineBlockUpdate(aWorld, aCoords));
}
}
public static void initExecutorService() {
- EXECUTOR_SERVICE = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), THREAD_FACTORY);
- //Executors.newSingleThreadExecutor(THREAD_FACTORY);
- //Executors.newCachedThreadPool(THREAD_FACTORY);
- //Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),THREAD_FACTORY);
+ EXECUTOR_SERVICE = Executors.newFixedThreadPool((Runtime.getRuntime().availableProcessors() * 2 / 3), THREAD_FACTORY);
}
public static void shutdownExecutorService() {
@@ -87,7 +88,7 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
// Preserve interrupt status
Thread.currentThread().interrupt();
}catch (Exception e){
- GT_Mod.GT_FML_LOGGER.error("Well this didn't terminated well...",e);
+ GT_Mod.GT_FML_LOGGER.error("Well this didn't terminated well...", e);
// (Re-)Cancel in case
EXECUTOR_SERVICE.shutdownNow();
}finally {
@@ -95,70 +96,39 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
}
}
- private boolean shouldRecurse(TileEntity aTileEntity, int aX, int aY, int aZ) {
- //no check on IGregTechTileEntity as it should call the underlying meta tile isMachineBlockUpdateRecursive
- //if (aTileEntity instanceof IGregTechTileEntity) {
- // return ((IGregTechTileEntity) aTileEntity).isMachineBlockUpdateRecursive();
- //}
- return (aTileEntity instanceof IMachineBlockUpdateable &&
- ((IMachineBlockUpdateable) aTileEntity).isMachineBlockUpdateRecursive()) ||
- GregTech_API.isMachineBlock(world.getBlock(aX, aY, aZ), world.getBlockMetadata(aX, aY, aZ));
- }
-
- private void causeUpdate(TileEntity tileEntity) {
- //no check for IGregTechTileEntity as it should call the underlying meta tile onMachineBlockUpdate
- if (tileEntity instanceof IMachineBlockUpdateable) {
- ((IMachineBlockUpdateable) tileEntity).onMachineBlockUpdate();
- }
- }
-
- private void stepToUpdateMachine(int aX, int aY, int aZ) {
- if (!visited.add(new ChunkPosition(aX, aY, aZ)))
- return;
- TileEntity tTileEntity = world.getTileEntity(aX, aY, aZ);
-
- causeUpdate(tTileEntity);
-
- if (visited.size() < 5 || shouldRecurse(tTileEntity, aX, aY, aZ)) {
- stepToUpdateMachine(aX + 1, aY, aZ);
- stepToUpdateMachine(aX - 1, aY, aZ);
- stepToUpdateMachine(aX, aY + 1, aZ);
- stepToUpdateMachine(aX, aY - 1, aZ);
- stepToUpdateMachine(aX, aY, aZ + 1);
- stepToUpdateMachine(aX, aY, aZ - 1);
- }
- }
-
@Override
public void run() {
try {
- stepToUpdateMachine(x, y, z);
+ while (!tQueue.isEmpty()) {
+ final ChunkCoordinates aCoords = tQueue.poll();
+ TileEntity tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
+
+ // See if the block itself needs an update
+ if (tTileEntity instanceof IMachineBlockUpdateable)
+ ((IMachineBlockUpdateable) tTileEntity).onMachineBlockUpdate();
+
+ // Now see if we should add the nearby blocks to the queue:
+ // 1) If we've visited less than 5 blocks, then yes
+ // 2) If the tile says we should recursively updated (pipes don't, machine blocks do)
+ // 3) If the block at the coordinates is marked as a machine block
+ if (visited.size() < 5
+ || (tTileEntity instanceof IMachineBlockUpdateable && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())
+ || GregTech_API.isMachineBlock(world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ), world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ)))
+ {
+ ChunkCoordinates tCoords;
+
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) tQueue.add(tCoords);
+ }
+ }
} catch (Exception e) {
- GT_Mod.GT_FML_LOGGER.error("Well this update was broken... " + new Coordinates(x, y, z, world), e);
+ GT_Mod.GT_FML_LOGGER.error(
+ "Well this update was broken... " + mCoords + ", mWorld={" + world.getProviderName() + " @dimId " + world.provider.dimensionId + "}", e);
}
}
- public static class Coordinates {
- public final int mX;
- public final int mY;
- public final int mZ;
- public final World mWorld;
-
- public Coordinates(int mX, int mY, int mZ, World mWorld) {
- this.mX = mX;
- this.mY = mY;
- this.mZ = mZ;
- this.mWorld = mWorld;
- }
-
- @Override
- public String toString() {
- return "Coordinates{" +
- "mX=" + mX +
- ", mY=" + mY +
- ", mZ=" + mZ +
- ", mWorld=" + mWorld.getProviderName() + " @dimId " + mWorld.provider.dimensionId +
- '}';
- }
- }
}
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index 537d92b365..9756a8199a 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -561,7 +561,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static final GT_Recipe_Map sRecyclerRecipes = new GT_Recipe_Map_Recycler(new HashSet<>(0), "ic.recipe.recycler", "Recycler", "ic2.recycler", RES_PATH_GUI + "basicmachines/Recycler", 1, 1, 1, 0, 1, E, 1, E, true, false);
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);
-
+ 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);
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..f00fc7758e 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]);
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..fce135dfe6 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++)
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 3530fa17c2..adc0f95881 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -14,6 +14,7 @@ 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.GT_ItemStack;
@@ -1022,7 +1023,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;
@@ -1742,7 +1743,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"))
@@ -1756,7 +1757,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 :!:
@@ -2040,7 +2041,7 @@ public class GT_Utility {
if (D1) e.printStackTrace(GT_Log.err);
}
}
-
+
if (aPlayer.capabilities.isCreativeMode) {
FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read
if (tFluid!=null)
@@ -2355,7 +2356,7 @@ public class GT_Utility {
setBookTitle(aStack, "Raw Prospection Data");
NBTTagCompound tNBT = GT_Utility.ItemNBT.getNBT(aStack);
-
+
tNBT.setByte("prospection_tier", aTier);
tNBT.setString("prospection_pos", "Dim: " + aDim + "\nX: " + aX + " Y: " + aY + " Z: " + aZ);
@@ -2369,27 +2370,27 @@ public class GT_Utility {
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("-");
}
@@ -2444,11 +2445,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);
@@ -2466,7 +2467,7 @@ 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);
@@ -2606,11 +2607,11 @@ 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 boolean isOre(ItemStack aStack) {
for (int id: OreDictionary.getOreIDs(aStack)) {
@@ -2620,4 +2621,152 @@ 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()) {
+ if (o.getKey() instanceof ItemStack) {
+ ItemStack toAdd = ((ItemStack) o.getKey()).copy();
+ toAdd.stackSize = o.getValue();
+ inputs.add(toAdd);
+ } else if (o.getKey() instanceof String) {
+// System.out.println("Found OreDictEntry: "+o.getKey());
+ ItemStack stack = GT_OreDictUnificator.get(o.getKey(), o.getValue());
+ if (stack == null) {
+ Optional<ItemStack> oStack = OreDictionary.getOres((String) o.getKey())
+ .stream()
+ .findAny();
+ if (oStack.isPresent()) {
+ ItemStack copy = oStack.get().copy();
+ copy.stackSize = o.getValue();
+ inputs.add(copy);
+ }
+// else
+// System.out.println("OreDict Entry "+o.getKey()+" couldn't be found!");
+ } else {
+ ItemStack copy = stack.copy();
+ copy.stackSize = o.getValue();
+ inputs.add(copy);
+ }
+ } else if (o.getKey() instanceof Item)
+ inputs.add(new ItemStack((Item) o.getKey(), o.getValue()));
+ else if (o.getKey() instanceof Block)
+ inputs.add(new ItemStack((Block) o.getKey(), o.getValue()));
+ 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
+ )
+ );
+ }
}