diff options
Diffstat (limited to 'src/main/java/gregtech/api')
7 files changed, 572 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/enums/TAE.java b/src/main/java/gregtech/api/enums/TAE.java new file mode 100644 index 0000000000..246b2006ea --- /dev/null +++ b/src/main/java/gregtech/api/enums/TAE.java @@ -0,0 +1,145 @@ +package gregtech.api.enums; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.HashSet; + +import gregtech.api.interfaces.ITexture; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; + +public class TAE { + + // TAE stands for Texture Array Expansion. + + public static int gtPPLastUsedIndex = 64; + public static int secondaryIndex = 0; + + public static HashMap<Integer, GTPP_CopiedBlockTexture> mTAE = new HashMap<>(); + private static final HashSet<Integer> mFreeSlots = new HashSet<>(64); + + static { + for (int i = 64; i < 128; i++) { + mFreeSlots.add(i); + } + Logger.INFO("Initialising TAE."); + } + + /** + * + * @param aPage - The Texture page (0-3) + * @param aID - The ID on the specified page (0-15) + * @param GTPP_CopiedBlockTexture - The Texture to register + * @return - Did it register correctly? + */ + public static boolean registerTexture(int aPage, int aID, GTPP_CopiedBlockTexture GTPP_CopiedBlockTexture) { + int aRealID = aID + (aPage * 16); + return registerTexture(64 + aRealID, GTPP_CopiedBlockTexture); + } + + public static boolean registerTexture(int aID, GTPP_CopiedBlockTexture GTPP_CopiedBlockTexture) { + if (mFreeSlots.contains(aID)) { + mFreeSlots.remove(aID); + mTAE.put(aID, GTPP_CopiedBlockTexture); + return true; + } else { + CORE.crash("Tried to register texture with ID " + aID + " to TAE, but it is already in use."); + return false; // Dead Code + } + } + + public static void finalizeTAE() { + String aFreeSpaces = ""; + String aPageAndSlotFree = ""; + AutoMap<Integer> aTemp = new AutoMap<>(mFreeSlots); + for (int i = 0; i < mFreeSlots.size(); i++) { + int j = aTemp.get(i); + aFreeSpaces += j; + aPageAndSlotFree += getPageFromIndex(j); + if (i != (mFreeSlots.size() - 1)) { + aFreeSpaces += ", "; + aPageAndSlotFree += ", "; + } + } + Logger.INFO("Free Indexes within TAE: " + aFreeSpaces); + Logger.INFO("Free Page slots within TAE: " + aPageAndSlotFree); + Logger.INFO("Filling them with ERROR textures."); + for (int aFreeSlot : aTemp.values()) { + registerTexture(aFreeSlot, new GTPP_CopiedBlockTexture(ModBlocks.blockCasingsTieredGTPP, 1, 15)); + } + Logger.INFO("Finalising TAE."); + for (int aKeyTae : mTAE.keySet()) { + Textures.BlockIcons.setCasingTextureForId(aKeyTae, mTAE.get(aKeyTae)); + } + Logger.INFO("Finalised TAE."); + } + + private static boolean registerTextures(GTPP_CopiedBlockTexture GTPP_CopiedBlockTexture) { + try { + // Handle page 2. + Logger.INFO("[TAE} Registering Texture, Last used casing ID is " + gtPPLastUsedIndex + "."); + if (gtPPLastUsedIndex >= 128) { + Field x = ReflectionUtils.getField(Textures.BlockIcons.class, "casingTexturePages"); + if (x != null) { + ITexture[][] h = (ITexture[][]) x.get(null); + if (h != null) { + h[64][secondaryIndex++] = GTPP_CopiedBlockTexture; + x.set(null, h); + Logger + .INFO("[TAE} Registered Texture with ID " + (secondaryIndex - 1) + " in secondary index."); + return true; + } + } + } + + // set to page 1. + else { + Textures.BlockIcons.setCasingTextureForId(gtPPLastUsedIndex, GTPP_CopiedBlockTexture); + Logger.INFO("[TAE} Registered Texture with ID " + (gtPPLastUsedIndex) + " in main index."); + gtPPLastUsedIndex++; + return true; + } + } catch (Throwable t) { + t.printStackTrace(); + } + Logger.INFO("[TAE} Failed to register texture, Last used casing ID is " + gtPPLastUsedIndex + "."); + return false; + } + + public static ITexture getTexture(int index) { + if (gtPPLastUsedIndex >= 128) { + return Textures.BlockIcons.getCasingTextureForId(((64 * 128) + index)); + } + return Textures.BlockIcons.getCasingTextureForId((64 + index)); + } + + public static int GTPP_INDEX(int ID) { + + if (ID >= 64) { + if (gtPPLastUsedIndex >= 128) { + return (128 + ID); + } + } + return (64 + ID); + } + + public static int getIndexFromPage(int page, int blockMeta) { + int id = 64; + id += (page == 0 ? 0 : page == 1 ? 16 : page == 2 ? 32 : page == 3 ? 48 : page == 4 ? 64 : 0); + id += blockMeta; + return id; + } + + public static String getPageFromIndex(int aIndex) { + int aPage = 0; + int aSlot = 0; + int aAdjustedIndex = aIndex > 64 ? (aIndex - 64) : aIndex; + aPage = aAdjustedIndex / 16; + aSlot = aAdjustedIndex - (16 * aPage); + return "[" + aIndex + " | " + aPage + ", " + aSlot + "]"; + } +} diff --git a/src/main/java/gregtech/api/util/AdvancedFusionOverclockDescriber.java b/src/main/java/gregtech/api/util/AdvancedFusionOverclockDescriber.java new file mode 100644 index 0000000000..7a6e609f93 --- /dev/null +++ b/src/main/java/gregtech/api/util/AdvancedFusionOverclockDescriber.java @@ -0,0 +1,23 @@ +package gregtech.api.util; + +import javax.annotation.ParametersAreNonnullByDefault; + +import gregtech.api.objects.overclockdescriber.FusionOverclockDescriber; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class AdvancedFusionOverclockDescriber extends FusionOverclockDescriber { + + public AdvancedFusionOverclockDescriber(byte energyTier, long capableStartup) { + super(energyTier, capableStartup); + } + + @Override + protected int getEUtIncreasePerOC() { + return 2; + } + + protected int getDurationDecreasePerOC() { + return 2; + } +} diff --git a/src/main/java/gregtech/api/util/FishPondFakeRecipe.java b/src/main/java/gregtech/api/util/FishPondFakeRecipe.java new file mode 100644 index 0000000000..dc579ebd9b --- /dev/null +++ b/src/main/java/gregtech/api/util/FishPondFakeRecipe.java @@ -0,0 +1,80 @@ +package gregtech.api.util; + +import java.util.ArrayList; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.WeightedRandomFishable; +import net.minecraftforge.common.FishingHooks; +import net.minecraftforge.fluids.FluidStack; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; + +public class FishPondFakeRecipe { + + public static ArrayList<WeightedRandomFishable> fish = new ArrayList<>(); + public static ArrayList<WeightedRandomFishable> junk = new ArrayList<>(); + public static ArrayList<WeightedRandomFishable> treasure = new ArrayList<>(); + + @SuppressWarnings("unchecked") + public static boolean generateFishPondRecipes() { + + try { + fish = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "fish") + .get(null); + junk = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "junk") + .get(null); + treasure = (ArrayList<WeightedRandomFishable>) ReflectionUtils.getField(FishingHooks.class, "treasure") + .get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + Logger.INFO("Error generating Fish Pond Recipes. [1]"); + e.printStackTrace(); + } + + AutoMap<ArrayList<WeightedRandomFishable>> mega = new AutoMap<>(); + mega.put(fish); + mega.put(junk); + mega.put(treasure); + + int mType = 14; + for (ArrayList<WeightedRandomFishable> f : mega.values()) { + for (WeightedRandomFishable weightedRandomFishable : f) { + if (weightedRandomFishable != null) { + WeightedRandomFishable u = weightedRandomFishable; + try { + ItemStack t = (ItemStack) ReflectionUtils + .getField(WeightedRandomFishable.class, "field_150711_b") + .get(u); + addNewFishPondLoot(mType, new ItemStack[] { t }, new int[] { 10000 }); + } catch (IllegalArgumentException | IllegalAccessException e1) { + Logger.INFO("Error generating Fish Pond Recipes. [2]"); + e1.printStackTrace(); + } + } + } + mType++; + } + + return true; + } + + public static void addNewFishPondLoot(int circuit, ItemStack[] outputItems, int[] chances) { + GT_Recipe x = new GT_Recipe( + true, + new ItemStack[] { CI.getNumberedCircuit(circuit) }, + outputItems, + null, + chances, + new FluidStack[] { null }, + new FluidStack[] { null }, + 100, // 1 Tick + 0, // No Eu produced + 0); + Logger.INFO("Fishing [" + circuit + "]: " + ItemUtils.getArrayStackNames(outputItems)); + GTPPRecipeMaps.fishPondRecipes.addRecipe(x, false, false, false); + } +} diff --git a/src/main/java/gregtech/api/util/GasSpargingRecipe.java b/src/main/java/gregtech/api/util/GasSpargingRecipe.java new file mode 100644 index 0000000000..667cc78d85 --- /dev/null +++ b/src/main/java/gregtech/api/util/GasSpargingRecipe.java @@ -0,0 +1,103 @@ +package gregtech.api.util; + +import net.minecraftforge.fluids.FluidStack; + +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.data.ArrayUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; + +public class GasSpargingRecipe implements Comparable<GasSpargingRecipe> { + + public final FluidStack mInputGas; + public final FluidStack mInputSpentFuel; + public final FluidStack mOutputSpargedFuel; + public final int[] mMaxOutputQuantity; + public final FluidStack[] mFluidInputs; + public final FluidStack[] mFluidOutputs; + public final int mDuration; + public final int mEUt; + + public GasSpargingRecipe(FluidStack aSpargeGas, FluidStack aSpentFuel, FluidStack aSpargedFuel, + FluidStack[] aOutputs, int[] aMaxOutputQuantity) { + mInputGas = aSpargeGas; + mInputSpentFuel = aSpentFuel; + mOutputSpargedFuel = aSpargedFuel; + mFluidInputs = new FluidStack[] { mInputGas, mInputSpentFuel }; + aOutputs = ArrayUtils.insertElementAtIndex(aOutputs, 0, aSpargeGas); + aOutputs = ArrayUtils.insertElementAtIndex(aOutputs, 1, aSpargedFuel); + mFluidOutputs = aOutputs; + mMaxOutputQuantity = aMaxOutputQuantity; + mDuration = 500; + mEUt = MaterialUtils.getVoltageForTier(5); + } + + @Override + public boolean equals(Object o) { + if (o instanceof GasSpargingRecipe i) { + if (this.mInputGas.equals(i.mInputGas) && this.mInputSpentFuel.equals(i.mInputSpentFuel)) { + return true; + } + } + return false; + } + + public int getMaxOutput(int aIndex) { + if (aIndex == 0) { + return mInputGas.amount * 100; + } else if (aIndex == 1) { + return mOutputSpargedFuel.amount * 100; + } + aIndex -= 2; + if ((aIndex < 0) || (aIndex >= this.mMaxOutputQuantity.length)) { + return 10000; + } + return this.mMaxOutputQuantity[aIndex]; + } + + public boolean isValid() { + if (mInputGas == null || mInputGas.amount <= 0 + || mInputSpentFuel == null + || mInputSpentFuel.amount <= 0 + || mFluidOutputs == null + || mFluidOutputs.length < 1 + || mMaxOutputQuantity == null + || mMaxOutputQuantity.length < 1 + || mFluidOutputs.length != mMaxOutputQuantity.length) { + return false; + } + return true; + } + + public boolean containsInputs(FluidStack aSpargeGas, FluidStack aSpentFuel) { + if (aSpargeGas != null && aSpargeGas.getFluid() + .equals(this.mInputGas.getFluid())) { + if (aSpentFuel != null && aSpentFuel.getFluid() + .equals(this.mInputSpentFuel.getFluid())) { + return true; + } + } + return false; + } + + @Override + public int compareTo(GasSpargingRecipe o) { + if (o.mFluidOutputs.length > this.mFluidOutputs.length) { + return 1; + } else if (o.mFluidOutputs.length == this.mFluidOutputs.length) { + return 0; + } else { + return -1; + } + } + + public String[] getRecipeInfo() { + AutoMap<String> result = new AutoMap<>(); + result.put("Input " + ItemUtils.getArrayStackNames(mFluidInputs)); + result.put("Output " + ItemUtils.getArrayStackNames(mFluidOutputs)); + result.put("Duration: " + mDuration); + result.put("EU/t: " + mEUt); + String s[] = result.toArray(); + return s; + } +} diff --git a/src/main/java/gregtech/api/util/GasSpargingRecipeMap.java b/src/main/java/gregtech/api/util/GasSpargingRecipeMap.java new file mode 100644 index 0000000000..6dcc7721e0 --- /dev/null +++ b/src/main/java/gregtech/api/util/GasSpargingRecipeMap.java @@ -0,0 +1,45 @@ +package gregtech.api.util; + +import static gregtech.api.enums.Mods.GregTech; + +import net.minecraftforge.fluids.FluidStack; + +import gtPlusPlus.api.objects.data.AutoMap; + +public class GasSpargingRecipeMap extends AutoMap<GasSpargingRecipe> { + + public static final AutoMap<GasSpargingRecipe> mRecipes = new AutoMap<>(); + public static final String mUnlocalizedName = "gtpp.recipe.lftr.sparging"; + public static final String mNEIName = mUnlocalizedName; + public static final String mNEIDisplayName = "LFTR Gas Sparging"; + public static final String mNEIGUIPath = GregTech.getResourcePath("textures", "gui/basicmachines/FissionFuel.png"); + + public static boolean addRecipe(FluidStack aSpargeGas, FluidStack aSpentFuel, FluidStack aSpargedFuel, + FluidStack[] aOutputs, int[] aMaxOutputs) { + if (aSpargeGas == null || aSpargeGas.amount <= 0 + || aSpentFuel == null + || aSpentFuel.amount <= 0 + || aSpargedFuel == null + || aSpargedFuel.amount <= 0 + || aOutputs == null + || aOutputs.length < 1 + || aMaxOutputs == null + || aMaxOutputs.length < 1 + || aOutputs.length != aMaxOutputs.length) { + return false; + } + int aMapSize = mRecipes.size(); + GasSpargingRecipe aRecipe = new GasSpargingRecipe(aSpargeGas, aSpentFuel, aSpargedFuel, aOutputs, aMaxOutputs); + mRecipes.put(aRecipe); + return mRecipes.size() > aMapSize; + } + + public static GasSpargingRecipe findRecipe(FluidStack aSpargeGas, FluidStack aSpentFuel) { + for (GasSpargingRecipe aRecipe : mRecipes) { + if (aRecipe.containsInputs(aSpargeGas, aSpentFuel)) { + return aRecipe; + } + } + return null; + } +} diff --git a/src/main/java/gregtech/api/util/HotFuel.java b/src/main/java/gregtech/api/util/HotFuel.java new file mode 100644 index 0000000000..6054a57b84 --- /dev/null +++ b/src/main/java/gregtech/api/util/HotFuel.java @@ -0,0 +1,40 @@ +package gregtech.api.util; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import gtPlusPlus.api.recipe.GTPPRecipeMaps; + +public class HotFuel { + + public static void addNewHotFuel(FluidStack aInput1, FluidStack aOutput1, ItemStack[] outputItems, int[] chances, + int aSpecialValue) { + GTPPRecipeMaps.thermalBoilerRecipes.addRecipe( + true, + null, + outputItems, + null, + chances, + new FluidStack[] { aInput1 }, + new FluidStack[] { aOutput1 }, + 1, // 1 Tick + 0, // No Eu produced + aSpecialValue // Magic Number + ); + } + + public static void addNewHotFuel(FluidStack aInput1, FluidStack aOutput1, FluidStack aOutput2, int aSpecialValue) { + GTPPRecipeMaps.thermalBoilerRecipes.addRecipe( + false, + null, + null, + null, + null, + new FluidStack[] { aInput1 }, + new FluidStack[] { aOutput1, aOutput2 }, + 20, // 1 Second + 0, // No Eu produced + aSpecialValue // Magic Number + ); + } +} diff --git a/src/main/java/gregtech/api/util/SemiFluidFuelHandler.java b/src/main/java/gregtech/api/util/SemiFluidFuelHandler.java new file mode 100644 index 0000000000..e3baa9ac90 --- /dev/null +++ b/src/main/java/gregtech/api/util/SemiFluidFuelHandler.java @@ -0,0 +1,136 @@ +package gregtech.api.util; + +import static gtPlusPlus.api.recipe.GTPPRecipeMaps.semiFluidFuels; + +import java.util.HashMap; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.recipe.RecipeMaps; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.util.minecraft.FluidUtils; + +public class SemiFluidFuelHandler { + + public static boolean addSemiFluidFuel(ItemStack aFuelItem, int aFuelValue) { + FluidStack p = FluidContainerRegistry.getFluidForFilledItem(aFuelItem); + if (p != null && aFuelValue > 0) { + return addSemiFluidFuel(p, aFuelValue); + } else { + Logger.INFO("Fuel value for " + aFuelItem.getDisplayName() + " is <= 0, ignoring."); + } + return false; + } + + public static boolean addSemiFluidFuel(FluidStack aFuel, int aFuelValue) { + FluidStack p = aFuel; + if (p != null && aFuelValue > 0) { + GT_Recipe aRecipe = new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { p }, + null, + 0, + 0, + aFuelValue); + if (aRecipe.mSpecialValue > 0) { + Logger.INFO( + "Added " + aRecipe.mFluidInputs[0].getLocalizedName() + + " to the Semi-Fluid Generator fuel map. Fuel Produces " + + (aRecipe.mSpecialValue * 1000) + + "EU per 1000L."); + semiFluidFuels.add(aRecipe); + return true; + } + } else { + Logger.INFO("Fuel value for " + p != null ? p.getLocalizedName() : "NULL Fluid" + " is <= 0, ignoring."); + } + return false; + } + + public static boolean generateFuels() { + final FluidStack aCreosote = FluidUtils.getFluidStack("creosote", 1000); + final FluidStack aHeavyFuel = FluidUtils.getFluidStack("liquid_heavy_fuel", 1000); + final FluidStack aHeavyOil = FluidUtils.getFluidStack("liquid_heavy_oil", 1000); + final HashMap<Integer, Pair<FluidStack, Integer>> aFoundFluidsFromItems = new HashMap<>(); + // Find Fluids From items + for (final GT_Recipe r : RecipeMaps.denseLiquidFuels.getAllRecipes()) { + + GT_Recipe g = r.copy(); + + if (g != null && g.mEnabled && g.mInputs.length > 0 && g.mInputs[0] != null) { + for (ItemStack i : g.mInputs) { + FluidStack f = FluidContainerRegistry.getFluidForFilledItem(i); + if (f != null) { + Pair<FluidStack, Integer> aData = new Pair<>(f, g.mSpecialValue); + aFoundFluidsFromItems.put(aData.hashCode(), aData); + } + } + } else if (g != null && g.mEnabled && g.mFluidInputs.length > 0 && g.mFluidInputs[0] != null) { + boolean aContainsCreosote = false; + for (FluidStack f : g.mFluidInputs) { + if (f.isFluidEqual(aCreosote)) { + aContainsCreosote = true; + } + } + g.mSpecialValue *= aContainsCreosote ? 6 : 3; + Logger.INFO( + "Added " + g.mFluidInputs[0].getLocalizedName() + + " to the Semi-Fluid Generator fuel map. Fuel Produces " + + g.mSpecialValue + + "EU per 1000L."); + semiFluidFuels.add(g); + } + } + for (Pair<FluidStack, Integer> p : aFoundFluidsFromItems.values()) { + if (p != null) { + int aFuelValue = p.getValue(); + if (p.getKey() + .isFluidEqual(aCreosote)) { + aFuelValue *= 6; + } else if (p.getKey() + .isFluidEqual(aHeavyFuel) + || p.getKey() + .isFluidEqual(aHeavyOil)) { + aFuelValue *= 1.5; + } else { + aFuelValue *= 2; + } + + if (aFuelValue <= (128 * 3)) { + GT_Recipe aRecipe = new GT_Recipe( + true, + new ItemStack[] {}, + new ItemStack[] {}, + null, + new int[] {}, + new FluidStack[] { p.getKey() }, + null, + 0, + 0, + aFuelValue); + if (aRecipe.mSpecialValue > 0) { + Logger.INFO( + "Added " + aRecipe.mFluidInputs[0].getLocalizedName() + + " to the Semi-Fluid Generator fuel map. Fuel Produces " + + (aRecipe.mSpecialValue * 1000) + + "EU per 1000L."); + semiFluidFuels.add(aRecipe); + } + } else { + Logger.INFO( + "Boosted Fuel value for " + p.getKey() + .getLocalizedName() + " exceeds 512k, ignoring."); + } + } + } + return !semiFluidFuels.getAllRecipes() + .isEmpty(); + } +} |