diff options
author | Jason Mitchell <mitchej+github@gmail.com> | 2020-12-31 09:30:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-31 09:30:05 -0800 |
commit | 0ed11a6794e34ef4b104ff3a6ebc224d5efa80df (patch) | |
tree | 744a8d24726da1b06beb5f0490306ad0dde77a66 /src/main/java/gregtech/api | |
parent | 23b550192c3b528dac9ef25c85da99611e00529f (diff) | |
parent | 116009659e461ac81f451406a5041a9b55f80a6f (diff) | |
download | GT5-Unofficial-0ed11a6794e34ef4b104ff3a6ebc224d5efa80df.tar.gz GT5-Unofficial-0ed11a6794e34ef4b104ff3a6ebc224d5efa80df.tar.bz2 GT5-Unofficial-0ed11a6794e34ef4b104ff3a6ebc224d5efa80df.zip |
Merge branch 'experimental' into long_distance_transfer
Diffstat (limited to 'src/main/java/gregtech/api')
14 files changed, 434 insertions, 70 deletions
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 5336e93068..94efa0605f 100644 --- a/src/main/java/gregtech/api/enums/ItemList.java +++ b/src/main/java/gregtech/api/enums/ItemList.java @@ -1443,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 18203faed1..de2c0919e7 100644 --- a/src/main/java/gregtech/api/enums/Textures.java +++ b/src/main/java/gregtech/api/enums/Textures.java @@ -294,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/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_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/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 + ) + ); + } } |