diff options
Diffstat (limited to 'src/main/java/bartworks/API')
20 files changed, 1423 insertions, 0 deletions
diff --git a/src/main/java/bartworks/API/APIConfigValues.java b/src/main/java/bartworks/API/APIConfigValues.java new file mode 100644 index 0000000000..7ab0326802 --- /dev/null +++ b/src/main/java/bartworks/API/APIConfigValues.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +public class APIConfigValues { + + // One-Side-Only + public static boolean debugLog = true; +} diff --git a/src/main/java/bartworks/API/BioObjectAdder.java b/src/main/java/bartworks/API/BioObjectAdder.java new file mode 100644 index 0000000000..d82124ac57 --- /dev/null +++ b/src/main/java/bartworks/API/BioObjectAdder.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import static gregtech.api.enums.Mods.Gendustry; +import static gregtech.api.recipe.RecipeMaps.centrifugeRecipes; +import static gregtech.api.util.GTRecipeBuilder.SECONDS; + +import java.awt.Color; + +import net.minecraft.item.EnumRarity; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import bartworks.util.BioCulture; +import bartworks.util.BioDNA; +import bartworks.util.BioData; +import bartworks.util.BioPlasmid; +import gregtech.api.enums.FluidState; +import gregtech.api.enums.GTValues; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TierEU; +import gregtech.api.fluid.GTFluidFactory; +import gregtech.api.util.GTUtility; + +public final class BioObjectAdder { + + /** + * @param color the color of the Culture + * @param name the name of the Culture + * @param plasmid the cultures plasmid, get it from createAndRegisterBioPlasmid + * @param dna the cultures dna, get it from createAndRegisterBioDNA + * @param breedable if the culture can be inserted into the BacterialVat + * @param rarity visual + * @return + */ + public static BioCulture createAndRegisterBioCulture(Color color, String name, BioPlasmid plasmid, BioDNA dna, + EnumRarity rarity, boolean breedable) { + if (BioCulture.BIO_CULTURE_ARRAY_LIST.size() > 1) + return BioCulture.createAndRegisterBioCulture(color, name, plasmid, dna, rarity, breedable); + new Exception( + "Too Early to register a BioCulture! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * rarity inherits from dna + * + * @param color the color of the Culture + * @param name the name of the Culture + * @param plasmid the cultures plasmid, get it from createAndRegisterBioPlasmid + * @param dna the cultures dna, get it from createAndRegisterBioDNA + * @param breedable if the culture can be inserted into the BacterialVat + * @return + */ + public static BioCulture createAndRegisterBioCulture(Color color, String name, BioPlasmid plasmid, BioDNA dna, + boolean breedable) { + if (BioCulture.BIO_CULTURE_ARRAY_LIST.size() > 1) + return BioCulture.createAndRegisterBioCulture(color, name, plasmid, dna, breedable); + new Exception( + "Too Early to register a BioCulture! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * unspecific Biodata that can be converted into DNA and Plasmid with the propper methodes + * + * @param aName the name of the Biodata + * @param rarity visual only + * @param chance the chanche to extract this BioData + * @param tier the tier of this BioData 0=HV, 1=EV etc. + * @return + */ + public static BioData createAndRegisterBioData(String aName, EnumRarity rarity, int chance, int tier) { + if (BioData.BIO_DATA_ARRAY_LIST.size() > 1) + return BioData.createAndRegisterBioData(aName, rarity, chance, tier); + new Exception("Too Early to register a BioData! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * Default Constructor for HV Tier DNA with 75% extraction rate + * + * @param aName Name of the DNA String + * @param rarity visual + * @return + */ + public static BioDNA createAndRegisterBioDNA(String aName, EnumRarity rarity) { + if (BioData.BIO_DATA_ARRAY_LIST.size() > 1) return BioDNA.createAndRegisterBioDNA(aName, rarity); + new Exception("Too Early to register a BioData! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * Default Constructor for HV Tier Plasmid with 75% extraction rate + * + * @param aName Name of the Plasmid + * @param rarity visual + * @return + */ + public static BioPlasmid createAndRegisterBioPlasmid(String aName, EnumRarity rarity) { + if (BioData.BIO_DATA_ARRAY_LIST.size() > 1) return BioPlasmid.createAndRegisterBioPlasmid(aName, rarity); + new Exception("Too Early to register a BioData! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * @param aName Name of the DNA String + * @param rarity visual + * @param chance chanche of extracting + * @param tier tier needed to extract 0=HV, 1=EV etc. + * @return + */ + public static BioDNA createAndRegisterBioDNA(String aName, EnumRarity rarity, int chance, int tier) { + if (BioData.BIO_DATA_ARRAY_LIST.size() > 1) return BioDNA.createAndRegisterBioDNA(aName, rarity, chance, tier); + new Exception("Too Early to register a BioData! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * @param aName Name of the Plasmid + * @param rarity visual + * @param chance chanche of extracting + * @param tier tier needed to extract 0=HV, 1=EV etc. + * @return + */ + public static BioPlasmid createAndRegisterBioPlasmid(String aName, EnumRarity rarity, int chance, int tier) { + if (BioData.BIO_DATA_ARRAY_LIST.size() > 1) + return BioPlasmid.createAndRegisterBioPlasmid(aName, rarity, chance, tier); + new Exception("Too Early to register a BioData! You MUST run this either after:bartworks OR in the init Phase!") + .printStackTrace(); + return null; + } + + /** + * @param voltageTier (i.e. 6 for LuV, 7 for ZPM, only intresting for LuV+) + * @return the propper Bacteria Tier (at least 0) + */ + public static int getBacteriaTierFromVoltageTier(int voltageTier) { + return Math.max(voltageTier - 6, 0); + } + + /** + * If you get NPE's related to BioCultures (most likely because of Load Order or creating BioCultures after the + * postinit Phase) execute this. + */ + public static void regenerateBioFluids() { + FluidStack dnaFluid = Gendustry.isModLoaded() ? FluidRegistry.getFluidStack("liquiddna", 100) + : Materials.Biomass.getFluid(100L); + for (BioCulture B : BioCulture.BIO_CULTURE_ARRAY_LIST) { + if (B.getFluidNotSet()) { + B.setFluid( + GTFluidFactory.builder( + B.getName() + .replace(" ", "") + .toLowerCase() + "fluid") + .withTextureName("molten.autogenerated") + .withColorRGBA( + new short[] { (short) B.getColor() + .getRed(), + (short) B.getColor() + .getBlue(), + (short) B.getColor() + .getGreen() }) + .withStateAndTemperature(FluidState.LIQUID, 300) + .buildAndRegister() + .asFluid()); + + GTValues.RA.stdBuilder() + .itemInputs(GTUtility.getIntegratedCircuit(10)) + .fluidInputs(new FluidStack(B.getFluid(), 1000)) + .fluidOutputs(dnaFluid) + .duration(25 * SECONDS) + .eut(TierEU.RECIPE_MV) + .addTo(centrifugeRecipes); + } + } + } +} diff --git a/src/main/java/bartworks/API/BioVatLogicAdder.java b/src/main/java/bartworks/API/BioVatLogicAdder.java new file mode 100644 index 0000000000..26e612c407 --- /dev/null +++ b/src/main/java/bartworks/API/BioVatLogicAdder.java @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import static gregtech.api.enums.Mods.IndustrialCraft2; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Objects; + +import net.minecraft.item.ItemStack; + +import bartworks.system.material.BWNonMetaMaterialItems; +import bartworks.system.material.WerkstoffLoader; +import bartworks.util.BWUtil; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.util.GTModHandler; + +public final class BioVatLogicAdder { + + public static class RadioHatch { + + public static void runBasicItemIntegration() { + giveItemStackRadioHatchAbilites(ItemList.ThoriumCell_1.get(1), Materials.Thorium, 3); + giveItemStackRadioHatchAbilites(ItemList.ThoriumCell_2.get(1), Materials.Thorium, 6); + giveItemStackRadioHatchAbilites(ItemList.ThoriumCell_4.get(1), Materials.Thorium, 12); + + giveItemStackRadioHatchAbilites(ItemList.NaquadahCell_1.get(1), Materials.Naquadah, 3); + giveItemStackRadioHatchAbilites(ItemList.NaquadahCell_2.get(1), Materials.Naquadah, 6); + giveItemStackRadioHatchAbilites(ItemList.NaquadahCell_4.get(1), Materials.Naquadah, 12); + + giveItemStackRadioHatchAbilites(ItemList.Moxcell_1.get(1), Materials.Plutonium, 3); + giveItemStackRadioHatchAbilites(ItemList.Moxcell_2.get(1), Materials.Plutonium, 6); + giveItemStackRadioHatchAbilites(ItemList.Moxcell_4.get(1), Materials.Plutonium, 12); + + giveItemStackRadioHatchAbilites(ItemList.Uraniumcell_1.get(1), Materials.Uranium, 3); + giveItemStackRadioHatchAbilites(ItemList.Uraniumcell_2.get(1), Materials.Uranium, 6); + giveItemStackRadioHatchAbilites(ItemList.Uraniumcell_4.get(1), Materials.Uranium, 12); + + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.TiberiumCell_1.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 3); + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.TiberiumCell_2.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 6); + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.TiberiumCell_4.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 12); + + giveItemStackRadioHatchAbilites(BWNonMetaMaterialItems.TheCoreCell.get(1), Materials.Naquadah, 96); + + giveItemStackRadioHatchAbilites(ItemList.Depleted_Thorium_1.get(1), Materials.Thorium, 3, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_Thorium_2.get(1), Materials.Thorium, 6, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_Thorium_4.get(1), Materials.Thorium, 12, 10); + + giveItemStackRadioHatchAbilites(ItemList.Depleted_Naquadah_1.get(1), Materials.Naquadah, 3, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_Naquadah_2.get(1), Materials.Naquadah, 6, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_Naquadah_4.get(1), Materials.Naquadah, 12, 10); + + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorMOXSimpledepleted", 1), + Materials.Plutonium, + 3, + 10); + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorMOXDualdepleted", 1), + Materials.Plutonium, + 6, + 10); + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorMOXQuaddepleted", 1), + Materials.Plutonium, + 12, + 10); + + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorUraniumSimpledepleted", 1), + Materials.Uranium, + 3, + 10); + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorUraniumDualdepleted", 1), + Materials.Uranium, + 6, + 10); + giveItemStackRadioHatchAbilites( + GTModHandler.getModItem(IndustrialCraft2.ID, "reactorUraniumQuaddepleted", 1), + Materials.Uranium, + 12, + 10); + + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.Depleted_Tiberium_1.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 3, + 10); + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.Depleted_Tiberium_2.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 6, + 10); + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.Depleted_Tiberium_4.get(1), + WerkstoffLoader.Tiberium.getBridgeMaterial(), + 12, + 10); + + giveItemStackRadioHatchAbilites( + BWNonMetaMaterialItems.Depleted_TheCoreCell.get(1), + Materials.Naquadah, + 96, + 10); + + giveItemStackRadioHatchAbilites(ItemList.MNqCell_1.get(1), Materials.Naquadria, 3); + giveItemStackRadioHatchAbilites(ItemList.MNqCell_2.get(1), Materials.Naquadria, 6); + giveItemStackRadioHatchAbilites(ItemList.MNqCell_4.get(1), Materials.Naquadria, 12); + giveItemStackRadioHatchAbilites(ItemList.Depleted_MNq_1.get(1), Materials.Naquadria, 3, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_MNq_2.get(1), Materials.Naquadria, 6, 10); + giveItemStackRadioHatchAbilites(ItemList.Depleted_MNq_4.get(1), Materials.Naquadria, 12, 10); + } + + private static final HashSet<BioVatLogicAdder.MaterialSvPair> MaSv = new HashSet<>(); + private static final HashMap<ItemStack, Integer> IsSv = new HashMap<>(); + private static final HashMap<ItemStack, Integer> IsKg = new HashMap<>(); + private static final HashMap<ItemStack, short[]> IsColor = new HashMap<>(); + + public static HashSet<BioVatLogicAdder.MaterialSvPair> getMaSv() { + return RadioHatch.MaSv; + } + + public static HashMap<ItemStack, Integer> getIsKg() { + return IsKg; + } + + public static HashMap<ItemStack, Integer> getIsSv() { + return RadioHatch.IsSv; + } + + public static HashMap<ItemStack, short[]> getIsColor() { + return IsColor; + } + + public static void setOverrideSvForMaterial(Materials m, int sv) { + MaSv.add(new BioVatLogicAdder.MaterialSvPair(m, sv)); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, int sv) { + IsSv.put(stack, sv); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, Materials materials) { + IsSv.put(stack, BWUtil.calculateSv(materials)); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, int sv, int kg) { + IsSv.put(stack, sv); + IsKg.put(stack, kg); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, Materials materials, int kg) { + giveItemStackRadioHatchAbilites(stack, BWUtil.calculateSv(materials), kg); + IsColor.put(stack, materials.getRGBA()); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, Materials materials, int kg, int divider) { + giveItemStackRadioHatchAbilites(stack, BWUtil.calculateSv(materials) / divider, kg); + IsColor.put(stack, materials.getRGBA()); + } + + public static void giveItemStackRadioHatchAbilites(ItemStack stack, int sv, int kg, short[] color) { + giveItemStackRadioHatchAbilites(stack, sv, kg); + IsColor.put(stack, color); + } + + public static int MaxSV = 150; + + public static int getMaxSv() { + int ret = MaxSV; + for (MaterialSvPair pair : RadioHatch.getMaSv()) { + if (pair.getSievert() > ret) ret = pair.getSievert(); + } + for (ItemStack is : RadioHatch.IsSv.keySet()) { + if (RadioHatch.IsSv.get(is) > ret) ret = RadioHatch.IsSv.get(is); + } + return ret; + } + } + + public static class MaterialSvPair { + + final Materials materials; + final Integer sievert; + + public MaterialSvPair(Materials materials, Integer sievert) { + this.materials = materials; + this.sievert = sievert; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + BioVatLogicAdder.MaterialSvPair that = (BioVatLogicAdder.MaterialSvPair) o; + return Objects.equals(this.getMaterials(), that.getMaterials()) + && Objects.equals(this.getSievert(), that.getSievert()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getMaterials(), this.getSievert()); + } + + public Materials getMaterials() { + return this.materials; + } + + public Integer getSievert() { + return this.sievert; + } + } + +} diff --git a/src/main/java/bartworks/API/BorosilicateGlass.java b/src/main/java/bartworks/API/BorosilicateGlass.java new file mode 100644 index 0000000000..cc61ec1337 --- /dev/null +++ b/src/main/java/bartworks/API/BorosilicateGlass.java @@ -0,0 +1,211 @@ +package bartworks.API; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksTiered; + +import java.util.ArrayList; +import java.util.List; +import java.util.PriorityQueue; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.stream.Collectors; + +import net.minecraft.block.Block; + +import org.apache.commons.lang3.tuple.Pair; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.SetMultimap; +import com.google.common.collect.Table; +import com.gtnewhorizon.structurelib.structure.IStructureElement; + +import bartworks.common.loaders.ItemRegistry; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.LoaderState; + +/** + * API for bartworks borosilicate glass. + * <p> + * You might have noticed this API does not expose any Block instance, but only IStructureElements. This is in case we + * add more glass blocks later, and we run out of meta id for only one block. + * <p> + * IStructureElements returned from this class <b>SHOULD NOT</b> have its methods called before post init, or else you + * might end up with wrong autoplace hints. + */ +public class BorosilicateGlass { + + private static List<Pair<Block, Integer>> representatives; + private static SetMultimap<Byte, Pair<Block, Integer>> allLevels; + private static final Table<Block, Integer, Byte> allLevelsReverse = HashBasedTable.create(); + + private static boolean isValidTier(int tier) { + return tier > 0 && tier <= Byte.MAX_VALUE; + } + + public static Block getGlassBlock() { + return ItemRegistry.bw_realglas; + } + + public static Block getGlassBlock2() { + return ItemRegistry.bw_realglas; + } + + private static void doRegister(byte level, Block block, int meta, + SetMultimap<Byte, Pair<Block, Integer>> allLevels) { + allLevels.put(level, Pair.of(block, meta)); + allLevelsReverse.put(block, meta, level); + } + + private static SetMultimap<Byte, Pair<Block, Integer>> getAllLevels() { + if (allLevels == null) { + SetMultimap<Byte, Pair<Block, Integer>> ret = LinkedHashMultimap.create(); + Block block = getGlassBlock(); + doRegister((byte) 3, block, 0, ret); + doRegister((byte) 4, block, 1, ret); + doRegister((byte) 5, block, 12, ret); + doRegister((byte) 5, block, 2, ret); + doRegister((byte) 6, block, 3, ret); + doRegister((byte) 7, block, 4, ret); + doRegister((byte) 8, block, 5, ret); + for (int i = 6; i < 12; i++) { + doRegister((byte) 3, block, i, ret); + } + doRegister((byte) 9, block, 13, ret); + doRegister((byte) 10, block, 14, ret); + doRegister((byte) 11, block, 15, ret); + block = getGlassBlock2(); + doRegister((byte) 12, block, 0, ret); + allLevels = ret; + } + return allLevels; + } + + private static List<Pair<Block, Integer>> getRepresentatives() { + if (representatives == null) { + SetMultimap<Byte, Pair<Block, Integer>> allLevels = getAllLevels(); + ArrayList<Pair<Block, Integer>> ret = new ArrayList<>(); + for (Byte level : new PriorityQueue<>(allLevels.keySet())) { + ret.add( + allLevels.get(level) + .iterator() + .next()); + } + representatives = ret; + } + return representatives; + } + + private static Byte checkWithinBound(byte val, byte lo, byte hi) { + return val > hi || val < lo ? null : val; + } + + /** + * ONLY registers borosilicate glass. Without this, {@link #getTier} won't work properly in environments that don't + * have the coremod. + */ + public static void registerBorosilicateGlass() { + getAllLevels(); + } + + /** + * Register a new block as valid borosilicate glass with given tier (even if it doesn't contain boron at all) + * + * Does not support matching by more complex stuff like tile entity! + * + * Can only be called at INIT stage. + */ + public static void registerGlass(Block block, int meta, byte tier) { + if (Loader.instance() + .hasReachedState(LoaderState.POSTINITIALIZATION)) throw new IllegalStateException("register too late!"); + if (!Loader.instance() + .hasReachedState(LoaderState.INITIALIZATION)) throw new IllegalStateException("register too early!"); + if (!isValidTier(tier)) throw new IllegalArgumentException("not a valid tier: " + tier); + doRegister(tier, block, meta, getAllLevels()); + } + + /** + * Check if there is at least one type of boroglass in that tier. + */ + public static boolean hasGlassInTier(int tier) { + return getAllLevels().containsKey((byte) tier); + } + + /** + * Get a structure element for a certain tier of <b>borosilicate</b> glass. DOES NOT accept other glass like + * reinforced glass, magic mirror, vanilla glass, etc. unless these glass are explicitly registered as a + * borosilicate glass. + * <p> + * Use this if you just want boroglass here and doesn't care what tier it is. + */ + public static <T> IStructureElement<T> ofBoroGlass(int tier) { + if (!hasGlassInTier(tier)) throw new IllegalArgumentException(); + return lazy(t -> { + Pair<Block, Integer> pair = getRepresentatives().get(tier - 3); + return ofBlockAdder((t1, block1, meta) -> getTier(block1, meta) == tier, pair.getKey(), pair.getValue()); + }); + } + + /** + * Get a structure element for any kind of <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced + * glass, magic mirror, vanilla glass, etc. unless these glass are explicitly registered as a borosilicate glass. + * <p> + * Use this if you just want boroglass here and doesn't care what tier it is. + */ + public static <T> IStructureElement<T> ofBoroGlassAnyTier() { + return lazy(t -> ofBlockAnyMeta(getGlassBlock())); + } + + /** + * Get a structure element for <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic + * mirror, vanilla glass, etc. unless these glass are explicitly registered as a borosilicate glass. + * <p> + * This assumes you want all glass used to be of the same tier. + * <p> + * NOTE: This will accept the basic boron glass (HV tier) as well. You might not want this. Use the other overload + * to filter this out. + * + * @param initialValue the value set before structure check started + */ + public static <T> IStructureElement<T> ofBoroGlass(byte initialValue, BiConsumer<T, Byte> setter, + Function<T, Byte> getter) { + return lazy( + t -> ofBlocksTiered(BorosilicateGlass::getTier, getRepresentatives(), initialValue, setter, getter)); + } + + /** + * Get a structure element for <b>borosilicate</b> glass. DOES NOT accept other glass like reinforced glass, magic + * mirror, vanilla glass, etc. unless these glass are explicitly registered as a borosilicate glass. + * + * @param initialValue the value set before structure check started + * @param minTier minimal accepted tier. inclusive. must be greater than 0. + * @param maxTier maximal accepted tier. inclusive. + */ + public static <T> IStructureElement<T> ofBoroGlass(byte initialValue, byte minTier, byte maxTier, + BiConsumer<T, Byte> setter, Function<T, Byte> getter) { + if (minTier > maxTier || minTier < 0) throw new IllegalArgumentException(); + return lazy( + t -> ofBlocksTiered( + (block1, meta) -> checkWithinBound(getTier(block1, meta), minTier, maxTier), + getRepresentatives().stream() + .skip(Math.max(minTier - 3, 0)) + .limit(maxTier - minTier + 1) + .collect(Collectors.toList()), + initialValue, + setter, + getter)); + } + + /** + * Get the tier of this <b>borosilicate</b> glass. DOES NOT consider other glass like reinforced glass, magic + * mirror, vanilla glass, etc. unless these glass are explicitly registered as a borosilicate glass. + * + * @return glass tier, or -1 if is not a borosilicate glass + */ + public static byte getTier(Block block, int meta) { + Byte ret = allLevelsReverse.get(block, meta); + return ret == null ? -1 : ret; + } +} diff --git a/src/main/java/bartworks/API/GlassTier.java b/src/main/java/bartworks/API/GlassTier.java new file mode 100644 index 0000000000..381dae28e1 --- /dev/null +++ b/src/main/java/bartworks/API/GlassTier.java @@ -0,0 +1,78 @@ +package bartworks.API; + +import static cpw.mods.fml.common.registry.GameRegistry.findBlock; + +import java.util.HashMap; +import java.util.Objects; + +import net.minecraft.block.Block; + +import org.jetbrains.annotations.NotNull; + +public class GlassTier { + + private static final HashMap<BlockMetaPair, Integer> glasses = new HashMap<>(); + + /** + * @param modname The modid owning the block + * @param unlocalisedBlockName The name of the block itself + * @param meta The meta of the block + * @param tier the glasses Tier = Voltage tier (MIN 3) + */ + public static void addCustomGlass(String modname, String unlocalisedBlockName, int meta, int tier) { + Block block = findBlock(modname, unlocalisedBlockName); + if (block != null) { + addCustomGlass(block, meta, tier); + } else { + new IllegalArgumentException( + "Block: " + unlocalisedBlockName + + " of the Mod: " + + modname + + " was NOT found when attempting to register a glass!").printStackTrace(); + } + } + + public static void addCustomGlass(@NotNull Block block, int meta, int tier) { + GlassTier.glasses.put(new BlockMetaPair(block, (byte) meta), tier); + } + + public static HashMap<BlockMetaPair, Integer> getGlassMap() { + return glasses; + } + + public static int getGlassTier(Block block, int meta) { + return glasses.getOrDefault(new BlockMetaPair(block, (byte) meta), 0); + } + + public static class BlockMetaPair { + + private final Block block; + private final int meta; + + public BlockMetaPair(Block block, int aByte) { + this.block = block; + this.meta = aByte; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + BlockMetaPair that = (BlockMetaPair) o; + return Objects.equals(this.getBlock(), that.getBlock()) && Objects.equals(this.getMeta(), that.getMeta()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getBlock(), this.getMeta()); + } + + public Block getBlock() { + return this.block; + } + + public int getMeta() { + return this.meta; + } + } +} diff --git a/src/main/java/bartworks/API/INoiseGen.java b/src/main/java/bartworks/API/INoiseGen.java new file mode 100644 index 0000000000..6048b8e45a --- /dev/null +++ b/src/main/java/bartworks/API/INoiseGen.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +public interface INoiseGen { + + double getNoise(int x, int z); + + double[][] getNoiseForRegion(int xStart, int zStart, int xEnd, int zEnd); + + void setOctaves(int octaves); + + void setFrequency(double freq); + + void setSeed(long seed); + + void setAmplitude(double amplitude); +} diff --git a/src/main/java/bartworks/API/IRadMaterial.java b/src/main/java/bartworks/API/IRadMaterial.java new file mode 100644 index 0000000000..498f56cc6f --- /dev/null +++ b/src/main/java/bartworks/API/IRadMaterial.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import net.minecraft.item.ItemStack; + +public interface IRadMaterial { + + /** + * @return the amount of Radiation (0-150, commonly, higher values are possible but not recommended!) + */ + int getRadiationLevel(ItemStack aStack); + + /** + * @return 1 for stick, 2 for long rods, 3 for fuel rods + */ + byte getAmountOfMaterial(ItemStack aStack); + + /** + * @return the color of the material for display purposes + */ + short[] getColorForGUI(ItemStack aStack); + + /** + * @return the name of the material for display purposes + */ + String getNameForGUI(ItemStack aStack); +} diff --git a/src/main/java/bartworks/API/ITileAddsInformation.java b/src/main/java/bartworks/API/ITileAddsInformation.java new file mode 100644 index 0000000000..ad3c9bbb7c --- /dev/null +++ b/src/main/java/bartworks/API/ITileAddsInformation.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +public interface ITileAddsInformation { + + String[] getInfoData(); +} diff --git a/src/main/java/bartworks/API/ITileDropsContent.java b/src/main/java/bartworks/API/ITileDropsContent.java new file mode 100644 index 0000000000..c7a2b05afc --- /dev/null +++ b/src/main/java/bartworks/API/ITileDropsContent.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import net.minecraft.inventory.ISidedInventory; + +public interface ITileDropsContent extends ISidedInventory { + + default int[] getDropSlots() { + return new int[] { 0 }; + } +} diff --git a/src/main/java/bartworks/API/ITileHasDifferentTextureSides.java b/src/main/java/bartworks/API/ITileHasDifferentTextureSides.java new file mode 100644 index 0000000000..649129ebcc --- /dev/null +++ b/src/main/java/bartworks/API/ITileHasDifferentTextureSides.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public interface ITileHasDifferentTextureSides { + + IIcon[] texture = new IIcon[7]; + + @SideOnly(Side.CLIENT) + default IIcon getTextureForSide(ForgeDirection side, int meta) { + return texture[side.ordinal()]; + } + + @SideOnly(Side.CLIENT) + default IIcon getTextureForSide(int side, int meta) { + return this.getTextureForSide(ForgeDirection.values()[side], meta); + } + + @SideOnly(Side.CLIENT) + void registerBlockIcons(IIconRegister par1IconRegister); +} diff --git a/src/main/java/bartworks/API/SideReference.java b/src/main/java/bartworks/API/SideReference.java new file mode 100644 index 0000000000..83d083741a --- /dev/null +++ b/src/main/java/bartworks/API/SideReference.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import cpw.mods.fml.common.FMLCommonHandler; + +public class SideReference { + + public static class EffectiveSide { + + public static final boolean Server = FMLCommonHandler.instance() + .getEffectiveSide() + .isServer(); + public static final boolean Client = FMLCommonHandler.instance() + .getEffectiveSide() + .isClient(); + } + + public static class Side { + + public static final boolean Server = FMLCommonHandler.instance() + .getSide() + .isServer(); + public static final boolean Client = FMLCommonHandler.instance() + .getSide() + .isClient(); + } +} diff --git a/src/main/java/bartworks/API/VoidMinerDropAdder.java b/src/main/java/bartworks/API/VoidMinerDropAdder.java new file mode 100644 index 0000000000..de55ade363 --- /dev/null +++ b/src/main/java/bartworks/API/VoidMinerDropAdder.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import bwcrossmod.galacticgreg.VoidMinerUtility; +import gregtech.api.interfaces.ISubTagContainer; + +public class VoidMinerDropAdder { + + public static void addDropsToDim(int dimID, ISubTagContainer material, float chance) { + VoidMinerUtility.addMaterialToDimensionList(dimID, material, chance); + } +} diff --git a/src/main/java/bartworks/API/WerkstoffAPI.java b/src/main/java/bartworks/API/WerkstoffAPI.java new file mode 100644 index 0000000000..d23ef1b75c --- /dev/null +++ b/src/main/java/bartworks/API/WerkstoffAPI.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import bartworks.system.material.Werkstoff; + +public final class WerkstoffAPI { + + @SuppressWarnings("rawtypes") + static Class w; + + static { + try { + w = Class.forName("bartworks.system.material.WerkstoffLoader"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + public static Werkstoff getWerkstoff(String aName) throws NoSuchFieldException, IllegalAccessException { + return (Werkstoff) w.getField(aName) + .get(null); + } +} diff --git a/src/main/java/bartworks/API/WerkstoffAdderRegistry.java b/src/main/java/bartworks/API/WerkstoffAdderRegistry.java new file mode 100644 index 0000000000..1e122c0c3d --- /dev/null +++ b/src/main/java/bartworks/API/WerkstoffAdderRegistry.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.API; + +import java.util.HashSet; + +public final class WerkstoffAdderRegistry { + + private static final HashSet<Runnable> toRun = new HashSet<>(); + + private WerkstoffAdderRegistry() {} + + public static void addWerkstoffAdder(Runnable adder) { + toRun.add(adder); + } + + public static void run() { + for (Runnable r : toRun) r.run(); + } +} diff --git a/src/main/java/bartworks/API/modularUI/BWUITextures.java b/src/main/java/bartworks/API/modularUI/BWUITextures.java new file mode 100644 index 0000000000..86043e697d --- /dev/null +++ b/src/main/java/bartworks/API/modularUI/BWUITextures.java @@ -0,0 +1,68 @@ +package bartworks.API.modularUI; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.UITexture; + +import bartworks.MainMod; + +public class BWUITextures { + + public static final AdaptableUITexture BACKGROUND_BROWN = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/background/brown", 176, 166, 3); + public static final UITexture BACKGROUND_CIRCUIT_PROGRAMMER = UITexture + .fullImage(MainMod.MOD_ID, "GUI/background/circuit_programmer"); + + public static final AdaptableUITexture SLOT_BROWN = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/slot/brown", 18, 18, 1); + + public static final UITexture OVERLAY_SLOT_DISH = UITexture.fullImage(MainMod.MOD_ID, "GUI/overlay_slot/dish"); + public static final UITexture OVERLAY_SLOT_DNA_FLASK = UITexture + .fullImage(MainMod.MOD_ID, "GUI/overlay_slot/dna_flask"); + public static final UITexture OVERLAY_SLOT_MODULE = UITexture.fullImage(MainMod.MOD_ID, "GUI/overlay_slot/module"); + public static final UITexture OVERLAY_SLOT_ROD = UITexture.fullImage(MainMod.MOD_ID, "GUI/overlay_slot/rod"); + public static final UITexture OVERLAY_SLOT_CROSS = UITexture.fullImage(MainMod.MOD_ID, "GUI/overlay_slot/cross"); + + public static final UITexture PROGRESSBAR_SIEVERT = UITexture.fullImage(MainMod.MOD_ID, "GUI/progressbar/sievert"); + public static final UITexture PROGRESSBAR_STORED_EU_116 = UITexture + .fullImage(MainMod.MOD_ID, "GUI/progressbar/stored_eu_116"); + public static final UITexture PROGRESSBAR_FUEL = UITexture.fullImage(MainMod.MOD_ID, "GUI/progressbar/fuel"); + + public static final UITexture PICTURE_BW_LOGO_47X21 = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/bw_logo_47x21"); + public static final UITexture PICTURE_SIEVERT_CONTAINER = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/sievert_container"); + public static final UITexture PICTURE_DECAY_TIME_CONTAINER = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/decay_time_container"); + public static final UITexture PICTURE_DECAY_TIME_INSIDE = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/decay_time_inside"); + public static final UITexture PICTURE_RADIATION = UITexture.fullImage(MainMod.MOD_ID, "GUI/picture/radiation"); + public static final UITexture PICTURE_WINDMILL_EMPTY = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/windmill_empty"); + public static final UITexture[] PICTURE_WINDMILL_ROTATING = IntStream.range(0, 4) + .mapToObj( + i -> UITexture + .partly(MainMod.MOD_ID, "GUI/picture/windmill_rotating", 32, 128, 0, i * 32, 32, (i + 1) * 32)) + .collect(Collectors.toList()) + .toArray(new UITexture[0]); + public static final UITexture PICTURE_STORED_EU_FRAME = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/stored_eu_frame"); + public static final UITexture PICTURE_RADIATION_SHUTTER_FRAME = UITexture + .fullImage(MainMod.MOD_ID, "GUI/picture/radiation_shutter_frame"); + public static final AdaptableUITexture PICTURE_RADIATION_SHUTTER_INSIDE = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/picture/radiation_shutter_inside", 51, 48, 1); + + public static final AdaptableUITexture TAB_TITLE_BROWN = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/tab/title_brown", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_DARK_BROWN = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/tab/title_dark_brown", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_ANGULAR_BROWN = AdaptableUITexture + .of(MainMod.MOD_ID, "GUI/tab/title_angular_brown", 28, 28, 4); + + public static final UITexture OVERLAY_BUTTON_ASSEMBLER_MODE = UITexture + .fullImage(MainMod.MOD_ID, "GUI/overlay_button/assembler_mode"); + public static final UITexture OVERLAY_BUTTON_LINE_MODE = UITexture + .fullImage(MainMod.MOD_ID, "GUI/overlay_button/line_mode"); +} diff --git a/src/main/java/bartworks/API/recipe/BWNBTDependantCraftingRecipe.java b/src/main/java/bartworks/API/recipe/BWNBTDependantCraftingRecipe.java new file mode 100644 index 0000000000..9d7e8ca38c --- /dev/null +++ b/src/main/java/bartworks/API/recipe/BWNBTDependantCraftingRecipe.java @@ -0,0 +1,76 @@ +package bartworks.API.recipe; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; + +import bartworks.util.BWUtil; + +public class BWNBTDependantCraftingRecipe implements IRecipe { + + ItemStack result; + Map<Character, ItemStack> charToStackMap = new HashMap<>(9, 1); + String[] shape; + + @SuppressWarnings({ "SuspiciousSystemArraycopy" }) + public BWNBTDependantCraftingRecipe(ItemStack result, Object... recipe) { + this.result = result; + this.shape = new String[3]; + System.arraycopy(recipe, 0, this.shape, 0, 3); + this.charToStackMap.put(' ', null); + for (int i = 3; i < recipe.length; i += 2) { + this.charToStackMap.put((char) recipe[i], ((ItemStack) recipe[i + 1]).copy()); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BWNBTDependantCraftingRecipe that)) return false; + + if (!Objects.equals(this.result, that.result) || !Objects.equals(this.charToStackMap, that.charToStackMap)) + return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + return Arrays.equals(this.shape, that.shape); + } + + @Override + public int hashCode() { + int result1 = this.result != null ? this.result.hashCode() : 0; + result1 = 31 * result1 + (this.charToStackMap != null ? this.charToStackMap.hashCode() : 0); + return 31 * result1 + Arrays.hashCode(this.shape); + } + + @Override + public boolean matches(InventoryCrafting p_77569_1_, World p_77569_2_) { + for (int x = 0; x < 3; x++) { + for (int y = 0; y < 3; y++) { + ItemStack toCheck = p_77569_1_.getStackInRowAndColumn(y, x); + ItemStack ref = this.charToStackMap.get(this.shape[x].toCharArray()[y]); + if (!BWUtil.areStacksEqualOrNull(toCheck, ref)) return false; + } + } + return true; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting p_77572_1_) { + return this.result.copy(); + } + + @Override + public int getRecipeSize() { + return 10; + } + + @Override + public ItemStack getRecipeOutput() { + return this.result; + } +} diff --git a/src/main/java/bartworks/API/recipe/BacterialVatFrontend.java b/src/main/java/bartworks/API/recipe/BacterialVatFrontend.java new file mode 100644 index 0000000000..afca4274d9 --- /dev/null +++ b/src/main/java/bartworks/API/recipe/BacterialVatFrontend.java @@ -0,0 +1,92 @@ +package bartworks.API.recipe; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; + +import com.gtnewhorizons.modularui.api.math.Alignment; + +import bartworks.common.tileentities.multis.MTEBioVat; +import gregtech.api.recipe.BasicUIPropertiesBuilder; +import gregtech.api.recipe.NEIRecipePropertiesBuilder; +import gregtech.api.recipe.RecipeMapFrontend; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.GTNEIDefaultHandler; +import gregtech.nei.RecipeDisplayInfo; +import gregtech.nei.formatter.INEISpecialInfoFormatter; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class BacterialVatFrontend extends RecipeMapFrontend { + + public BacterialVatFrontend(BasicUIPropertiesBuilder uiPropertiesBuilder, + NEIRecipePropertiesBuilder neiPropertiesBuilder) { + super( + uiPropertiesBuilder, + neiPropertiesBuilder.neiSpecialInfoFormatter(new BacterialVatSpecialValueFormatter())); + } + + @Override + protected List<String> handleNEIItemInputTooltip(List<String> currentTip, + GTNEIDefaultHandler.FixedPositionedStack pStack) { + if (pStack.isFluid()) { + currentTip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("nei.biovat.input.tooltip")); + return currentTip; + } + return super.handleNEIItemInputTooltip(currentTip, pStack); + } + + @Override + protected List<String> handleNEIItemOutputTooltip(List<String> currentTip, + GTNEIDefaultHandler.FixedPositionedStack pStack) { + if (pStack.isFluid()) { + currentTip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("nei.biovat.output.tooltip")); + return currentTip; + } + return super.handleNEIItemOutputTooltip(currentTip, pStack); + } + + @Override + protected void drawNEIOverlayForInput(GTNEIDefaultHandler.FixedPositionedStack stack) { + drawFluidOverlay(stack); + } + + @Override + protected void drawNEIOverlayForOutput(GTNEIDefaultHandler.FixedPositionedStack stack) { + drawFluidOverlay(stack); + } + + private void drawFluidOverlay(GTNEIDefaultHandler.FixedPositionedStack stack) { + if (stack.isFluid()) { + drawNEIOverlayText( + "+", + stack, + colorOverride.getTextColorOrDefault("nei_overlay_yellow", 0xFDD835), + 0.5f, + true, + Alignment.TopRight); + return; + } + super.drawNEIOverlayForOutput(stack); + } + + private static class BacterialVatSpecialValueFormatter implements INEISpecialInfoFormatter { + + @Override + public List<String> format(RecipeDisplayInfo recipeInfo) { + int[] tSpecialA = MTEBioVat.specialValueUnpack(recipeInfo.recipe.mSpecialValue); + String glassTier = StatCollector.translateToLocalFormatted("nei.biovat.0.name", tSpecialA[0]); + String sievert; + if (tSpecialA[2] == 1) { + sievert = StatCollector.translateToLocalFormatted("nei.biovat.1.name", tSpecialA[3]); + } else { + sievert = StatCollector.translateToLocalFormatted("nei.biovat.2.name", tSpecialA[3]); + } + return Arrays.asList(glassTier, sievert); + } + } +} diff --git a/src/main/java/bartworks/API/recipe/BartWorksRecipeMaps.java b/src/main/java/bartworks/API/recipe/BartWorksRecipeMaps.java new file mode 100644 index 0000000000..a367cca300 --- /dev/null +++ b/src/main/java/bartworks/API/recipe/BartWorksRecipeMaps.java @@ -0,0 +1,89 @@ +package bartworks.API.recipe; + +import bartworks.API.modularUI.BWUITextures; +import gregtech.api.gui.modularui.GTUITextures; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMapBackend; +import gregtech.api.recipe.RecipeMapBuilder; +import gregtech.api.recipe.maps.FuelBackend; +import gregtech.nei.formatter.FuelSpecialValueFormatter; + +public class BartWorksRecipeMaps { + + public static final RecipeMap<RecipeMapBackend> bioLabRecipes = RecipeMapBuilder.of("bw.recipe.biolab") + .maxIO(6, 2, 1, 0) + .minInputs(1, 1) + .useSpecialSlot() + .slotOverlays((index, isFluid, isOutput, isSpecial) -> { + if (isSpecial) { + return BWUITextures.OVERLAY_SLOT_MODULE; + } + if (isFluid) { + return GTUITextures.OVERLAY_SLOT_VIAL_2; + } + if (!isOutput) { + switch (index) { + case 0: + return BWUITextures.OVERLAY_SLOT_DISH; + case 1: + return BWUITextures.OVERLAY_SLOT_DNA_FLASK; + case 2: + return GTUITextures.OVERLAY_SLOT_CIRCUIT; + case 3: + return GTUITextures.OVERLAY_SLOT_MOLECULAR_1; + case 4: + return GTUITextures.OVERLAY_SLOT_MOLECULAR_2; + case 5: + return GTUITextures.OVERLAY_SLOT_DATA_ORB; + } + } + return null; + }) + .progressBar(GTUITextures.PROGRESSBAR_ARROW_MULTIPLE) + .logo(BWUITextures.PICTURE_BW_LOGO_47X21) + .logoSize(47, 21) + .logoPos(125, 3) + .disableRegisterNEI() + .build(); + public static final RecipeMap<RecipeMapBackend> bacterialVatRecipes = RecipeMapBuilder.of("bw.recipe.BacteriaVat") + .maxIO(6, 2, 1, 1) + .minInputs(0, 1) + .useSpecialSlot() + .specialSlotSensitive() + .progressBar(GTUITextures.PROGRESSBAR_ARROW_MULTIPLE) + .frontend(BacterialVatFrontend::new) + .disableRegisterNEI() + .build(); + public static final RecipeMap<FuelBackend> acidGenFuels = RecipeMapBuilder.of("bw.fuels.acidgens", FuelBackend::new) + .maxIO(1, 1, 0, 0) + .neiSpecialInfoFormatter(FuelSpecialValueFormatter.INSTANCE) + .build(); + public static final RecipeMap<RecipeMapBackend> circuitAssemblyLineRecipes = RecipeMapBuilder.of("bw.recipe.cal") + .maxIO(6, 1, 1, 0) + .minInputs(1, 1) + .useSpecialSlot() + .specialSlotSensitive() + .progressBar(GTUITextures.PROGRESSBAR_CIRCUIT_ASSEMBLER) + .build(); + public static final RecipeMap<RecipeMapBackend> radioHatchRecipes = RecipeMapBuilder.of("bw.recipe.radhatch") + .maxIO(1, 0, 0, 0) + .minInputs(1, 0) + .slotOverlays((index, isFluid, isOutput, isSpecial) -> BWUITextures.OVERLAY_SLOT_ROD) + .logo(BWUITextures.PICTURE_BW_LOGO_47X21) + .logoSize(47, 21) + .logoPos(118, 55) + .dontUseProgressBar() + .addSpecialTexture(74, 20, 29, 27, BWUITextures.PICTURE_RADIATION) + .frontend(RadioHatchFrontend::new) + .build(); + public static final RecipeMap<RecipeMapBackend> electricImplosionCompressorRecipes = RecipeMapBuilder + .of("gt.recipe.electricimplosioncompressor") + .maxIO(6, 2, 1, 1) + .slotOverlays( + (index, isFluid, isOutput, isSpecial) -> !isFluid && !isOutput ? GTUITextures.OVERLAY_SLOT_IMPLOSION : null) + .progressBar(GTUITextures.PROGRESSBAR_COMPRESS) + .build(); + public static final RecipeMap<RecipeMapBackend> htgrFakeRecipes = RecipeMapBuilder.of("bw.recipe.htgr") + .maxIO(1, 1, 0, 0) + .build(); +} diff --git a/src/main/java/bartworks/API/recipe/DynamicGTRecipe.java b/src/main/java/bartworks/API/recipe/DynamicGTRecipe.java new file mode 100644 index 0000000000..3739c28042 --- /dev/null +++ b/src/main/java/bartworks/API/recipe/DynamicGTRecipe.java @@ -0,0 +1,33 @@ +package bartworks.API.recipe; + +import java.util.ArrayList; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import bartworks.MainMod; +import gregtech.api.util.GTRecipe; + +public class DynamicGTRecipe extends GTRecipe { + + public DynamicGTRecipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, + int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, + int aSpecialValue, GTRecipe originalRecipe) { + super( + aOptimize, + aInputs, + aOutputs, + aSpecialItems, + aChances, + aFluidInputs, + aFluidOutputs, + aDuration, + aEUt, + aSpecialValue); + if (originalRecipe != null) { + this.owners = new ArrayList<>(originalRecipe.owners); + this.stackTraces = new ArrayList<>(originalRecipe.stackTraces); + this.setOwner(MainMod.MOD_ID); + } + } +} diff --git a/src/main/java/bartworks/API/recipe/RadioHatchFrontend.java b/src/main/java/bartworks/API/recipe/RadioHatchFrontend.java new file mode 100644 index 0000000000..1335323f4e --- /dev/null +++ b/src/main/java/bartworks/API/recipe/RadioHatchFrontend.java @@ -0,0 +1,45 @@ +package bartworks.API.recipe; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.util.StatCollector; + +import gregtech.api.recipe.BasicUIPropertiesBuilder; +import gregtech.api.recipe.NEIRecipePropertiesBuilder; +import gregtech.api.recipe.RecipeMapFrontend; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.RecipeDisplayInfo; +import gregtech.nei.formatter.INEISpecialInfoFormatter; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class RadioHatchFrontend extends RecipeMapFrontend { + + public RadioHatchFrontend(BasicUIPropertiesBuilder uiPropertiesBuilder, + NEIRecipePropertiesBuilder neiPropertiesBuilder) { + super(uiPropertiesBuilder, neiPropertiesBuilder.neiSpecialInfoFormatter(new RadioHatchSpecialInfoFormatter())); + } + + @Override + protected void drawEnergyInfo(RecipeDisplayInfo recipeInfo) {} + + @Override + protected void drawDurationInfo(RecipeDisplayInfo recipeInfo) {} + + private static class RadioHatchSpecialInfoFormatter implements INEISpecialInfoFormatter { + + @Override + public List<String> format(RecipeDisplayInfo recipeInfo) { + int radioLevel = recipeInfo.recipe.mEUt; + int amount = recipeInfo.recipe.mDuration; + long time = recipeInfo.recipe.mSpecialValue; + return Arrays.asList( + StatCollector.translateToLocalFormatted("BW.NEI.display.radhatch.0", radioLevel), + StatCollector.translateToLocalFormatted("BW.NEI.display.radhatch.1", amount), + StatCollector.translateToLocalFormatted("BW.NEI.display.radhatch.2", time * amount / 20.0)); + } + } +} |