From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: The Great Renaming (#3014) * move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names --- src/main/java/bwcrossmod/BartWorksCrossmod.java | 89 ++++++ .../bwcrossmod/GTpp/loader/RadioHatchCompat.java | 284 +++++++++++++++++++ src/main/java/bwcrossmod/cls/CLSCompat.java | 104 +++++++ .../bwcrossmod/galacticgreg/MTEVoidMinerBase.java | 309 +++++++++++++++++++++ .../bwcrossmod/galacticgreg/MTEVoidMiners.java | 115 ++++++++ .../bwcrossmod/galacticgreg/VoidMinerUtility.java | 275 ++++++++++++++++++ .../bwcrossmod/galacticraft/GalacticraftProxy.java | 82 ++++++ .../galacticraft/PlanetsHelperClass.java | 33 +++ .../galacticraft/UniversalTeleportType.java | 78 ++++++ .../atmosphere/BWAtmosphereManager.java | 121 ++++++++ .../planets/AbstractWorldProviderSpace.java | 37 +++ .../planets/ross128b/ChunkProviderRoss128b.java | 185 ++++++++++++ .../planets/ross128b/SkyProviderRoss128b.java | 25 ++ .../planets/ross128b/WorldProviderRoss128b.java | 154 ++++++++++ .../planets/ross128ba/ChunkProviderRoss128ba.java | 107 +++++++ .../planets/ross128ba/WorldProviderRoss128ba.java | 112 ++++++++ .../solarsystems/Ross128SolarSystem.java | 91 ++++++ .../bwcrossmod/openComputers/GTNBTDataBase.java | 97 +++++++ .../openComputers/TileEntityGTDataServer.java | 202 ++++++++++++++ .../bwcrossmod/tectech/TecTechResearchLoader.java | 88 ++++++ .../tectech/tileentites/tiered/LowPowerLaser.java | 120 ++++++++ .../tileentites/tiered/LowPowerLaserBase.java | 155 +++++++++++ .../tileentites/tiered/MTELowPowerLaserBox.java | 171 ++++++++++++ .../tileentites/tiered/MTELowPowerLaserDynamo.java | 76 +++++ .../tileentites/tiered/MTELowPowerLaserHatch.java | 60 ++++ .../tileentites/tiered/MTELowPowerLaserPipe.java | 162 +++++++++++ .../bwcrossmod/tgregworks/MaterialsInjector.java | 81 ++++++ .../thaumcraft/util/ThaumcraftHandler.java | 58 ++++ 28 files changed, 3471 insertions(+) create mode 100644 src/main/java/bwcrossmod/BartWorksCrossmod.java create mode 100644 src/main/java/bwcrossmod/GTpp/loader/RadioHatchCompat.java create mode 100644 src/main/java/bwcrossmod/cls/CLSCompat.java create mode 100644 src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java create mode 100644 src/main/java/bwcrossmod/galacticgreg/MTEVoidMiners.java create mode 100644 src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java create mode 100644 src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java create mode 100644 src/main/java/bwcrossmod/galacticraft/PlanetsHelperClass.java create mode 100644 src/main/java/bwcrossmod/galacticraft/UniversalTeleportType.java create mode 100644 src/main/java/bwcrossmod/galacticraft/atmosphere/BWAtmosphereManager.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/AbstractWorldProviderSpace.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/ross128b/ChunkProviderRoss128b.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/ross128b/SkyProviderRoss128b.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/ross128b/WorldProviderRoss128b.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/ross128ba/ChunkProviderRoss128ba.java create mode 100644 src/main/java/bwcrossmod/galacticraft/planets/ross128ba/WorldProviderRoss128ba.java create mode 100644 src/main/java/bwcrossmod/galacticraft/solarsystems/Ross128SolarSystem.java create mode 100644 src/main/java/bwcrossmod/openComputers/GTNBTDataBase.java create mode 100644 src/main/java/bwcrossmod/openComputers/TileEntityGTDataServer.java create mode 100644 src/main/java/bwcrossmod/tectech/TecTechResearchLoader.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/LowPowerLaser.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/LowPowerLaserBase.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/MTELowPowerLaserBox.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/MTELowPowerLaserDynamo.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/MTELowPowerLaserHatch.java create mode 100644 src/main/java/bwcrossmod/tectech/tileentites/tiered/MTELowPowerLaserPipe.java create mode 100644 src/main/java/bwcrossmod/tgregworks/MaterialsInjector.java create mode 100644 src/main/java/bwcrossmod/thaumcraft/util/ThaumcraftHandler.java (limited to 'src/main/java/bwcrossmod') diff --git a/src/main/java/bwcrossmod/BartWorksCrossmod.java b/src/main/java/bwcrossmod/BartWorksCrossmod.java new file mode 100644 index 0000000000..e7e2ca44ed --- /dev/null +++ b/src/main/java/bwcrossmod/BartWorksCrossmod.java @@ -0,0 +1,89 @@ +/* + * 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 bwcrossmod; + +import static gregtech.api.enums.Mods.GalacticraftCore; + +import java.io.StringReader; + +import net.minecraft.util.StringTranslate; + +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import bwcrossmod.GTpp.loader.RadioHatchCompat; +import bwcrossmod.galacticraft.GalacticraftProxy; +import bwcrossmod.tectech.TecTechResearchLoader; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import gregtech.GT_Version; + +@Mod( + modid = BartWorksCrossmod.MOD_ID, + name = BartWorksCrossmod.NAME, + version = BartWorksCrossmod.VERSION, + dependencies = """ + required-after:IC2;\ + required-after:gregtech;\ + required-after:bartworks;\ + after:GalacticraftMars;\ + after:GalacticraftCore;\ + after:Micdoodlecore;\ + after:miscutils;\ + after:EMT;\ + after:tectech;""") +public class BartWorksCrossmod { + + public static final String NAME = "BartWorks Mod Additions"; + public static final String VERSION = GT_Version.VERSION; + public static final String MOD_ID = "bartworkscrossmod"; + public static final Logger LOGGER = LogManager.getLogger(BartWorksCrossmod.NAME); + + @Mod.Instance(BartWorksCrossmod.MOD_ID) + public static BartWorksCrossmod instance; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent preinit) { + if (GalacticraftCore.isModLoaded()) { + GalacticraftProxy.preInit(preinit); + } + } + + @Mod.EventHandler + public void init(FMLInitializationEvent init) { + if (GalacticraftCore.isModLoaded()) { + GalacticraftProxy.init(init); + } + } + + @Mod.EventHandler + public void postInit(FMLPostInitializationEvent init) { + if (GalacticraftCore.isModLoaded()) { + GalacticraftProxy.postInit(init); + } + RadioHatchCompat.run(); + TecTechResearchLoader.runResearches(); + } + + @Mod.EventHandler + public void onFMLServerStart(FMLServerStartingEvent event) { + for (Object s : RadioHatchCompat.TranslateSet) { + StringTranslate.inject(new ReaderInputStream(new StringReader((String) s))); + } + } +} diff --git a/src/main/java/bwcrossmod/GTpp/loader/RadioHatchCompat.java b/src/main/java/bwcrossmod/GTpp/loader/RadioHatchCompat.java new file mode 100644 index 0000000000..b410ec7e3e --- /dev/null +++ b/src/main/java/bwcrossmod/GTpp/loader/RadioHatchCompat.java @@ -0,0 +1,284 @@ +/* + * 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 bwcrossmod.GTpp.loader; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.RegistryNamespaced; +import net.minecraftforge.oredict.OreDictionary; + +import bartworks.API.IRadMaterial; +import bartworks.util.log.DebugLog; +import bwcrossmod.BartWorksCrossmod; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.registry.GameData; +import cpw.mods.fml.common.registry.GameRegistry; + +public class RadioHatchCompat { + + private static Class intf; + private static Class materialClass; + private static Class enu; + private static Class materialStackClass; + + private static Field isRadioactive; + private static Field f; + private static Field componentType; + private static Field radlevel; + private static Field protons; + + private static Field vMaterialInput; + private static Field stackMaterial; + private static Field RGBA; + private static Field localizedName; + private static Field unlocalizedName; + + private static Object rod; + private static Object longRod; + + public static HashSet TranslateSet = new HashSet<>(); + + static { + try { + RadioHatchCompat.intf = Class.forName("gtPlusPlus.core.item.base.BaseItemComponent"); + RadioHatchCompat.enu = Class.forName("gtPlusPlus.core.item.base.BaseItemComponent$ComponentTypes"); + RadioHatchCompat.materialClass = Class.forName("gtPlusPlus.core.material.Material"); + RadioHatchCompat.materialStackClass = Class.forName("gtPlusPlus.core.material.MaterialStack"); + + RadioHatchCompat.f = RadioHatchCompat.intf.getField("componentMaterial"); + RadioHatchCompat.isRadioactive = RadioHatchCompat.materialClass.getField("isRadioactive"); + RadioHatchCompat.componentType = RadioHatchCompat.intf.getDeclaredField("componentType"); + RadioHatchCompat.radlevel = RadioHatchCompat.materialClass.getField("vRadiationLevel"); + + RadioHatchCompat.vMaterialInput = RadioHatchCompat.materialClass.getDeclaredField("vMaterialInput"); + RadioHatchCompat.stackMaterial = RadioHatchCompat.materialStackClass.getDeclaredField("stackMaterial"); + RadioHatchCompat.protons = RadioHatchCompat.materialClass.getDeclaredField("vProtons"); + RadioHatchCompat.RGBA = RadioHatchCompat.materialClass.getDeclaredField("RGBA"); + RadioHatchCompat.localizedName = RadioHatchCompat.materialClass.getDeclaredField("localizedName"); + RadioHatchCompat.unlocalizedName = RadioHatchCompat.materialClass.getDeclaredField("unlocalizedName"); + + RadioHatchCompat.vMaterialInput.setAccessible(true); + RadioHatchCompat.stackMaterial.setAccessible(true); + RadioHatchCompat.protons.setAccessible(true); + RadioHatchCompat.RGBA.setAccessible(true); + RadioHatchCompat.localizedName.setAccessible(true); + RadioHatchCompat.unlocalizedName.setAccessible(true); + + Object[] arr = RadioHatchCompat.enu.getEnumConstants(); + for (Object o : arr) { + if (RadioHatchCompat.rod != null && RadioHatchCompat.longRod != null) break; + if ("ROD".equalsIgnoreCase(o.toString())) RadioHatchCompat.rod = o; + else if ("RODLONG".equalsIgnoreCase(o.toString())) RadioHatchCompat.longRod = o; + } + + } catch (NoSuchFieldException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + public static void run() { + DebugLog.log("Starting Generation of missing GT++ rods/longrods"); + try { + Class rodclass = (Class) Class + .forName("gtPlusPlus.core.item.base.rods.BaseItemRod"); + Class longrodclass = (Class) Class + .forName("gtPlusPlus.core.item.base.rods.BaseItemRodLong"); + Constructor c1 = rodclass.getConstructor(RadioHatchCompat.materialClass); + Constructor c2 = longrodclass.getConstructor(RadioHatchCompat.materialClass); + Field cOwners = GameData.class.getDeclaredField("customOwners"); + cOwners.setAccessible(true); + Field map = RegistryNamespaced.class.getDeclaredField("field_148758_b"); + map.setAccessible(true); + Map UniqueIdentifierMap = (Map) map.get(GameData.getItemRegistry()); + + Map ownerItems = (Map) cOwners + .get(null); + ModContainer gtpp = null; + ModContainer bartworks = null; + + for (ModContainer container : Loader.instance() + .getModList()) { + if (gtpp != null && bartworks != null) break; + if (BartWorksCrossmod.MOD_ID.equalsIgnoreCase(container.getModId())) bartworks = container; + else if (container.getModId() + .equalsIgnoreCase(GTPlusPlus.ID)) gtpp = container; + } + + for (Object mats : (Set) RadioHatchCompat.materialClass.getField("mMaterialMap") + .get(null)) { + if (RadioHatchCompat.isRadioactive.getBoolean(mats)) { + + if (OreDictionary.getOres("stick" + RadioHatchCompat.unlocalizedName.get(mats)) + .isEmpty()) { + Item it = c1.newInstance(mats); + UniqueIdentifierMap.replace(it, "miscutils:" + it.getUnlocalizedName()); + GameRegistry.UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(it); + ownerItems.replace(ui, bartworks, gtpp); + + String tanslate = it.getUnlocalizedName() + ".name=" + + RadioHatchCompat.localizedName.get(mats) + + " Rod"; + RadioHatchCompat.TranslateSet.add(tanslate); + + DebugLog.log(tanslate); + DebugLog.log("Generate: " + RadioHatchCompat.rod + RadioHatchCompat.unlocalizedName.get(mats)); + } + if (OreDictionary.getOres("stickLong" + RadioHatchCompat.unlocalizedName.get(mats)) + .isEmpty()) { + Item it2 = c2.newInstance(mats); + UniqueIdentifierMap.replace(it2, "miscutils:" + it2.getUnlocalizedName()); + GameRegistry.UniqueIdentifier ui2 = GameRegistry.findUniqueIdentifierFor(it2); + ownerItems.replace(ui2, bartworks, gtpp); + + DebugLog + .log("Generate: " + RadioHatchCompat.longRod + RadioHatchCompat.unlocalizedName.get(mats)); + } + } + } + } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException + | InstantiationException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + public static IRadMaterial GTppRadChecker(ItemStack lStack) { + try { + if (RadioHatchCompat.intf.isAssignableFrom( + lStack.getItem() + .getClass())) { + if (!RadioHatchCompat.isRadioactive.getBoolean(RadioHatchCompat.f.get(lStack.getItem()))) return null; + int amount = RadioHatchCompat.componentType.get(lStack.getItem()) + .equals(RadioHatchCompat.rod) ? 1 + : RadioHatchCompat.componentType.get(lStack.getItem()) + .equals(RadioHatchCompat.longRod) ? 2 : 0; + if (amount == 0) return null; + return new RadioHatchCompat.GTPPRadAdapter(amount, RadioHatchCompat.f.get(lStack.getItem())); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + static class GTPPRadAdapter implements IRadMaterial { + + static final HashMap BUFFER = new HashMap<>(); + + GTPPRadAdapter(Object m) { + this.m = m; + } + + GTPPRadAdapter(int amount, Object m) { + this.amount = (byte) amount; + this.m = m; + } + + byte amount; + final Object m; + + private static ArrayList getMaterialInput(Object GTPPMaterial) throws IllegalAccessException { + Object ret = RadioHatchCompat.vMaterialInput.get(GTPPMaterial); + return ret instanceof ArrayList ? (ArrayList) ret : new ArrayList<>(); + } + + private static boolean isElement(Object GTPPMaterial) throws IllegalAccessException { + return RadioHatchCompat.GTPPRadAdapter.getMaterialInput(GTPPMaterial) + .isEmpty(); + } + + private static List getElemets(Object GTPPMaterial) throws IllegalAccessException { + ArrayList elements = new ArrayList<>(); + Queue toCheck = new LinkedList<>(); + ArrayList materialInputs = RadioHatchCompat.GTPPRadAdapter.getMaterialInput(GTPPMaterial); + if (materialInputs.isEmpty()) return Collections.singletonList(GTPPMaterial); + for (Object materialStack : materialInputs) { + if (!RadioHatchCompat.GTPPRadAdapter.isElement(RadioHatchCompat.stackMaterial.get(materialStack))) + toCheck.add(RadioHatchCompat.stackMaterial.get(materialStack)); + else elements.add(RadioHatchCompat.stackMaterial.get(materialStack)); + } + while (!toCheck.isEmpty()) { + elements.addAll(GTPPRadAdapter.getElemets(toCheck.poll())); + } + return elements; + } + + private static Integer calulateRad(Object m) { + int ret = 0; + try { + List pureElements = RadioHatchCompat.GTPPRadAdapter.getElemets(m); + for (Object materialObj : pureElements) if (RadioHatchCompat.isRadioactive.getBoolean(materialObj)) + ret += RadioHatchCompat.radlevel.getByte(m) + + RadioHatchCompat.GTPPRadAdapter.clampToZero(RadioHatchCompat.protons.getLong(materialObj)); + else ret += RadioHatchCompat.radlevel.getByte(m); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return ret; + } + + @Override + public int getRadiationLevel(ItemStack aStack) { + return RadioHatchCompat.GTPPRadAdapter.BUFFER + .computeIfAbsent(this.m, radlvl -> RadioHatchCompat.GTPPRadAdapter.calulateRad(this.m)); + } + + private static long clampToZero(long number) { + return number > 0 ? number : 0; + } + + @Override + public byte getAmountOfMaterial(ItemStack aStack) { + return this.amount; + } + + @Override + public short[] getColorForGUI(ItemStack aStack) { + short[] rgba = { 0, 0, 0, 0 }; + try { + rgba = (short[]) RadioHatchCompat.RGBA.get(this.m); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return rgba; + } + + @Override + public String getNameForGUI(ItemStack aStack) { + String ret = ""; + try { + ret = (String) RadioHatchCompat.localizedName.get(this.m); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return ret; + } + } +} diff --git a/src/main/java/bwcrossmod/cls/CLSCompat.java b/src/main/java/bwcrossmod/cls/CLSCompat.java new file mode 100644 index 0000000000..9cb9c6fc9c --- /dev/null +++ b/src/main/java/bwcrossmod/cls/CLSCompat.java @@ -0,0 +1,104 @@ +/* + * 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 bwcrossmod.cls; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Optional; + +import bartworks.system.material.Werkstoff; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class CLSCompat { + + private CLSCompat() {} + + private static final long MINIMAL_UPDATE_INTERVAL = 1000 / 30; // target 30 fps + private static long lastUpdate = 0; + private static Class alexiilMinecraftDisplayer; + private static Class alexiilProgressDisplayer; + private static Method displayProgress; + private static Field isRegisteringBartWorks; + + static { + try { + alexiilMinecraftDisplayer = Class.forName("alexiil.mods.load.MinecraftDisplayer"); + alexiilProgressDisplayer = Class.forName("alexiil.mods.load.ProgressDisplayer"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + Optional.ofNullable(alexiilMinecraftDisplayer) + .ifPresent(e -> { + try { + isRegisteringBartWorks = e.getField("isRegisteringBartWorks"); + } catch (NoSuchFieldException ex) { + ex.printStackTrace(); + } + }); + + Optional.ofNullable(alexiilProgressDisplayer) + .ifPresent(e -> { + try { + displayProgress = e.getMethod("displayProgress", String.class, float.class); + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + }); + } + + public static Integer[] initCls() { + int sizeStep; + int sizeStep2 = 1; + + try { + isRegisteringBartWorks.set(null, true); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + if (Werkstoff.werkstoffHashSet.size() >= 100) sizeStep = Werkstoff.werkstoffHashSet.size() / 100 - 1; + else sizeStep = sizeStep2 = Werkstoff.werkstoffHashSet.size(); + + return new Integer[] { sizeStep, sizeStep2, sizeStep }; + } + + public static int invokeStepSize(Werkstoff werkstoff, Integer[] steps, int size) { + --steps[0]; + + long time = System.currentTimeMillis(); + if (time - lastUpdate >= MINIMAL_UPDATE_INTERVAL) { + try { + displayProgress.invoke(null, werkstoff.getDefaultName(), (float) size / 10000); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + lastUpdate = time; + } + + if (steps[0] == 0 && Werkstoff.werkstoffHashSet.size() >= 100) steps[0] = steps[2]; + + size += steps[1]; + return size; + } + + public static void disableCls() { + try { + isRegisteringBartWorks.set(null, false); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java new file mode 100644 index 0000000000..1eb6d8e312 --- /dev/null +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java @@ -0,0 +1,309 @@ +/* + * 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 bwcrossmod.galacticgreg; + +import static bartworks.util.BWTooltipReference.MULTIBLOCK_ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS; +import static gregtech.api.enums.GTValues.VN; +import static gregtech.api.enums.HatchElement.Energy; +import static gregtech.api.enums.HatchElement.InputBus; +import static gregtech.api.enums.HatchElement.InputHatch; +import static gregtech.api.enums.HatchElement.Maintenance; +import static gregtech.api.enums.HatchElement.OutputBus; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.gen.ChunkProviderServer; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import com.google.common.collect.ImmutableList; + +import gregtech.api.enums.GTValues; +import gregtech.api.interfaces.IHatchElement; +import gregtech.api.objects.XSTR; +import gregtech.api.util.GTUtility; +import gregtech.api.util.MultiblockTooltipBuilder; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gregtech.common.tileentities.machines.multi.MTEDrillerBase; + +public abstract class MTEVoidMinerBase extends MTEDrillerBase { + + private VoidMinerUtility.DropMap dropMap = null; + private VoidMinerUtility.DropMap extraDropMap = null; + private float totalWeight; + private int multiplier = 1; + + protected final byte TIER_MULTIPLIER; + + private boolean mBlacklist = false; + + /** + * @Deprecated Use {@link VoidMinerUtility#addBlockToDimensionList} + */ + @Deprecated + public static void addBlockToDimensionList(int dimId, Block block, int meta, float weight) { + VoidMinerUtility.addBlockToDimensionList(dimId, block, meta, weight); + } + + public MTEVoidMinerBase(int aID, String aName, String aNameRegional, int tier) { + super(aID, aName, aNameRegional); + this.TIER_MULTIPLIER = (byte) Math.max(tier, 1); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mBlacklist", this.mBlacklist); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mBlacklist = aNBT.getBoolean("mBlacklist"); + } + + public MTEVoidMinerBase(String aName, int tier) { + super(aName); + this.TIER_MULTIPLIER = (byte) tier; + } + + @Override + protected int getMinTier() { + return this.TIER_MULTIPLIER + 5; // min tier = LuV + } + + @Override + protected boolean checkHatches() { + return true; + } + + @Override + protected void setElectricityStats() { + try { + this.mEUt = this.isPickingPipes ? 60 : Math.toIntExact(GTValues.V[this.getMinTier()]); + } catch (ArithmeticException e) { + e.printStackTrace(); + this.mEUt = Integer.MAX_VALUE - 7; + } + this.mOutputItems = new ItemStack[0]; + this.mProgresstime = 0; + this.mMaxProgresstime = 10; + this.mEfficiency = this.getCurrentEfficiency(null); + this.mEfficiencyIncrease = 10000; + this.mEUt = this.mEUt > 0 ? -this.mEUt : this.mEUt; + } + + @Override + protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe, + int yHead, int oldYHead) { + // if the dropMap has never been initialised or if the dropMap is empty + if (this.dropMap == null || this.totalWeight == 0) this.calculateDropMap(); + + if (this.totalWeight != 0.f) { + this.handleFluidConsumption(); + this.handleOutputs(); + return true; + } else { + this.stopMachine(ShutDownReasonRegistry.NONE); + return false; + } + } + + @Override + protected MultiblockTooltipBuilder createTooltip() { + String casings = this.getCasingBlockItem() + .get(0) + .getDisplayName(); + + final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder(); + tt.addMachineType("Miner") + .addInfo("Controller Block for the Void Miner " + GTValues.VN[this.getMinTier()]) + .addInfo("Consumes " + GTValues.V[this.getMinTier()] + "EU/t") + .addInfo( + "Can be supplied with 2L/s of Neon(x4), Krypton(x8), Xenon(x16) or Oganesson(x64) for higher outputs.") + .addInfo( + "Will output " + 2 * this.TIER_MULTIPLIER + + " Ores per Second depending on the Dimension it is build in") + .addInfo("Put the Ore into the input bus to set the Whitelist/Blacklist") + .addInfo("Use a screwdriver to toggle Whitelist/Blacklist") + .addInfo( + "Blacklist or non Whitelist Ore will be " + EnumChatFormatting.DARK_RED + + "VOIDED" + + EnumChatFormatting.RESET + + ".") + .addSeparator() + .beginStructureBlock(3, 7, 3, false) + .addController("Front bottom") + .addOtherStructurePart(casings, "form the 3x1x3 Base") + .addOtherStructurePart(casings, "1x3x1 pillar above the center of the base (2 minimum total)") + .addOtherStructurePart( + this.getFrameMaterial().mName + " Frame Boxes", + "Each pillar's side and 1x3x1 on top") + .addEnergyHatch(VN[this.getMinTier()] + "+, Any base casing") + .addMaintenanceHatch("Any base casing") + .addInputBus("Mining Pipes or Ores, optional, any base casing") + .addInputHatch("Optional noble gas, any base casing") + .addOutputBus("Any base casing") + .toolTipFinisher(MULTIBLOCK_ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS); + return tt; + } + + @Override + protected List> getAllowedHatches() { + return ImmutableList.of(InputHatch, InputBus, OutputBus, Maintenance, Energy); + } + + /** + * method used to pick the next ore in the dropMap. + * + * @return the chosen ore + */ + private ItemStack nextOre() { + float currentWeight = 0.f; + while (true) { + float randomNumber = XSTR.XSTR_INSTANCE.nextFloat() * this.totalWeight; + for (Map.Entry entry : this.dropMap.getInternalMap() + .entrySet()) { + currentWeight += entry.getValue(); + if (randomNumber < currentWeight) return entry.getKey() + .getItemStack(); + } + for (Map.Entry entry : this.extraDropMap.getInternalMap() + .entrySet()) { + currentWeight += entry.getValue(); + if (randomNumber < currentWeight) return entry.getKey() + .getItemStack(); + } + } + } + + /** + * Method used to check the current gat and its corresponding multiplier + * + * @return the noble gas in the hatch. returns null if there is no noble gas found. + */ + private FluidStack getNobleGasInputAndSetMultiplier() { + for (FluidStack s : this.getStoredFluids()) { + for (int i = 0; i < VoidMinerUtility.NOBLE_GASSES.length; i++) { + FluidStack ng = VoidMinerUtility.NOBLE_GASSES[i]; + if (ng.isFluidEqual(s)) { + this.multiplier = this.TIER_MULTIPLIER * VoidMinerUtility.NOBEL_GASSES_MULTIPLIER[i]; + return s; + } + } + } + return null; + } + + /** + * method used to decrement the quantity of gas in the hatch + * + * @param gasToConsume the fluid stack in the hatch + * @return if yes or no it was able to decrement the quantity of the fluidStack + */ + private boolean consumeNobleGas(FluidStack gasToConsume) { + for (FluidStack s : this.getStoredFluids()) { + if (s.isFluidEqual(gasToConsume) && s.amount >= 1) { + s.amount -= 1; + this.updateSlots(); + return true; + } + } + return false; + } + + /** + * handler for the fluid consumption + */ + private void handleFluidConsumption() { + FluidStack storedNobleGas = this.getNobleGasInputAndSetMultiplier(); + if (storedNobleGas == null || !this.consumeNobleGas(storedNobleGas)) this.multiplier = this.TIER_MULTIPLIER; + } + + /** + * Handles the ores added manually with {@link VoidMinerUtility#addMaterialToDimensionList} + * + * @param id the specified dim id + */ + private void handleExtraDrops(int id) { + if (VoidMinerUtility.extraDropsDimMap.containsKey(id)) { + extraDropMap = VoidMinerUtility.extraDropsDimMap.get(id); + } + } + + /** + * Gets the DropMap of the dim for the specified dim id + * + * @param id the dim number + */ + private void handleModDimDef(int id) { + if (VoidMinerUtility.dropMapsByDimId.containsKey(id)) { + this.dropMap = VoidMinerUtility.dropMapsByDimId.get(id); + } else { + String chunkProviderName = ((ChunkProviderServer) this.getBaseMetaTileEntity() + .getWorld() + .getChunkProvider()).currentChunkProvider.getClass() + .getName(); + + if (VoidMinerUtility.dropMapsByChunkProviderName.containsKey(chunkProviderName)) { + this.dropMap = VoidMinerUtility.dropMapsByChunkProviderName.get(chunkProviderName); + } + } + } + + /** + * Computes first the ores related to the dim the VM is in, then the ores added manually, then it computes the + * totalWeight for normalisation + */ + private void calculateDropMap() { + this.dropMap = new VoidMinerUtility.DropMap(); + this.extraDropMap = new VoidMinerUtility.DropMap(); + int id = this.getBaseMetaTileEntity() + .getWorld().provider.dimensionId; + this.handleModDimDef(id); + this.handleExtraDrops(id); + this.totalWeight = dropMap.getTotalWeight() + extraDropMap.getTotalWeight(); + } + + /** + * Output logic of the VM + */ + private void handleOutputs() { + final List inputOres = this.getStoredInputs() + .stream() + .filter(GTUtility::isOre) + .collect(Collectors.toList());; + final ItemStack output = this.nextOre(); + output.stackSize = multiplier; + if (inputOres.size() == 0 || this.mBlacklist && inputOres.stream() + .noneMatch(is -> GTUtility.areStacksEqual(is, output)) + || !this.mBlacklist && inputOres.stream() + .anyMatch(is -> GTUtility.areStacksEqual(is, output))) + this.addOutput(output); + this.updateSlots(); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mBlacklist = !this.mBlacklist; + GTUtility.sendChatToPlayer(aPlayer, "Mode: " + (this.mBlacklist ? "Blacklist" : "Whitelist")); + } +} diff --git a/src/main/java/bwcrossmod/galacticgreg/MTEVoidMiners.java b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMiners.java new file mode 100644 index 0000000000..03caf26a25 --- /dev/null +++ b/src/main/java/bwcrossmod/galacticgreg/MTEVoidMiners.java @@ -0,0 +1,115 @@ +/* + * 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 bwcrossmod.galacticgreg; + +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public class MTEVoidMiners { + + public static class VMLUV extends MTEVoidMinerBase { + + public VMLUV(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 1); + } + + public VMLUV(String aName, int tier) { + super(aName, tier); + } + + @Override + protected ItemList getCasingBlockItem() { + return ItemList.Casing_UV; + } + + @Override + protected Materials getFrameMaterial() { + return Materials.Europium; + } + + @Override + protected int getCasingTextureIndex() { + return 8; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { + return new VMLUV(this.mName, this.TIER_MULTIPLIER); + } + } + + public static class VMZPM extends MTEVoidMinerBase { + + public VMZPM(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 2); + } + + public VMZPM(String aName, int tier) { + super(aName, tier); + } + + @Override + protected ItemList getCasingBlockItem() { + return ItemList.Casing_MiningBlackPlutonium; + } + + @Override + protected Materials getFrameMaterial() { + return Materials.BlackPlutonium; + } + + @Override + protected int getCasingTextureIndex() { + return 179; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { + return new VMZPM(this.mName, this.TIER_MULTIPLIER); + } + } + + public static class VMUV extends MTEVoidMinerBase { + + public VMUV(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 3); + } + + public VMUV(String aName, int tier) { + super(aName, tier); + } + + @Override + protected ItemList getCasingBlockItem() { + return ItemList.Casing_MiningNeutronium; + } + + @Override + protected Materials getFrameMaterial() { + return Materials.Neutronium; + } + + @Override + protected int getCasingTextureIndex() { + return 178; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { + return new VMUV(this.mName, this.TIER_MULTIPLIER); + } + } +} diff --git a/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java new file mode 100644 index 0000000000..b0782f91ae --- /dev/null +++ b/src/main/java/bwcrossmod/galacticgreg/VoidMinerUtility.java @@ -0,0 +1,275 @@ +package bwcrossmod.galacticgreg; + +import static galacticgreg.registry.GalacticGregRegistry.getModContainers; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import bartworks.common.configs.ConfigHandler; +import bartworks.system.material.Werkstoff; +import bartworks.system.material.WerkstoffLoader; +import bartworks.system.oregen.BWOreLayer; +import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.GalacticGreg; +import galacticgreg.WorldgenOreLayerSpace; +import galacticgreg.WorldgenOreSmallSpace; +import galacticgreg.api.ModContainer; +import galacticgreg.api.ModDimensionDef; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.ISubTagContainer; +import gregtech.api.util.GTUtility; +import gregtech.common.WorldgenGTOreLayer; +import gregtech.common.WorldgenGTOreSmallPieces; + +public class VoidMinerUtility { + + public static final FluidStack[] NOBLE_GASSES = { WerkstoffLoader.Neon.getFluidOrGas(1), + WerkstoffLoader.Krypton.getFluidOrGas(1), WerkstoffLoader.Xenon.getFluidOrGas(1), + WerkstoffLoader.Oganesson.getFluidOrGas(1) }; + public static final int[] NOBEL_GASSES_MULTIPLIER = { 4, 8, 16, 64 }; + + public static class DropMap { + + private float totalWeight; + private final Map internalMap; + + public DropMap() { + internalMap = new HashMap<>(); + totalWeight = 0; + } + + /** + * Method used to add an ore to the DropMap + * + * @param weight the non normalised weight + * @param isBWOres true for BW ores, false for GT ores + */ + public void addDrop(int meta, float weight, boolean isBWOres) { + if (isBWOres) { + addDrop(WerkstoffLoader.BWOres, meta, weight); + } else { + addDrop(GregTechAPI.sBlockOres1, meta, weight); + } + } + + /** + * Method used to add any item to the DropMap. Will be blocked if blacklisted. + * + * @param weight the non normalised weight + */ + public void addDrop(Block block, int meta, float weight) { + if (ConfigHandler.voidMinerBlacklist.contains( + String.format( + "%s:%d", + GameRegistry.findUniqueIdentifierFor(block) + .toString(), + meta))) + return; + Item item = Item.getItemFromBlock(block); + addDrop(item, meta, weight); + } + + /** + * Method used to add any item to the DropMap. Will be blocked if blacklisted. + * + * @param weight the non normalised weight + */ + public void addDrop(ItemStack itemStack, float weight) { + Item item = itemStack.getItem(); + int meta = Items.feather.getDamage(itemStack); + if (ConfigHandler.voidMinerBlacklist.contains( + String.format( + "%s:%d", + GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(item)) + .toString(), + meta))) + return; + addDrop(item, meta, weight); + } + + private void addDrop(Item item, int meta, float weight) { + GTUtility.ItemId ore = GTUtility.ItemId.createNoCopy(item, meta, null); + internalMap.merge(ore, weight, Float::sum); + totalWeight += weight; + } + + public float getTotalWeight() { + return totalWeight; + } + + public Map getInternalMap() { + return internalMap; + } + } + + public static final Map dropMapsByDimId = new HashMap<>(); + public static final Map dropMapsByChunkProviderName = new HashMap<>(); + public static final Map extraDropsDimMap = new HashMap<>(); + + // Adds tellurium to OW to ensure a way to get it, as it's used in Magneto Resonatic + // Dust and Circuit Compound MK3 Dust + static { + addMaterialToDimensionList(0, Materials.Tellurium, 8.0f); + } + + /** + * Computes the ores of the dims + */ + public static void generateDropMaps() { + // vanilla dims + dropMapsByDimId.put(-1, getDropMapVanilla(-1)); + dropMapsByDimId.put(0, getDropMapVanilla(0)); + dropMapsByDimId.put(1, getDropMapVanilla(1)); + // Twilight Forest + dropMapsByDimId.put(7, getDropMapVanilla(7)); + + // ross dims + dropMapsByDimId.put(ConfigHandler.ross128BID, getDropMapRoss(ConfigHandler.ross128BID)); + dropMapsByDimId.put(ConfigHandler.ross128BAID, getDropMapRoss(ConfigHandler.ross128BAID)); + + // other space dims + for (ModContainer modContainer : getModContainers()) { + for (ModDimensionDef dimDef : modContainer.getDimensionList()) { + dropMapsByChunkProviderName.put(dimDef.getChunkProviderName(), getDropMapSpace(dimDef)); + } + } + } + + /** + * Method to generate a DropMap that contains ores of a vanilla GT worldgen + */ + private static DropMap getDropMapVanilla(int dimId) { + DropMap dropMap = new DropMap(); + + // Ore Veins + Predicate oreLayerPredicate = makeOreLayerPredicate(dimId); + WorldgenGTOreLayer.sList.stream() + .filter(gt_worldgen -> gt_worldgen.mEnabled && oreLayerPredicate.test(gt_worldgen)) + .forEach(element -> { + dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false); + dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false); + dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false); + dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false); + }); + + // Small Ores + Predicate smallOresPredicate = makeSmallOresPredicate(dimId); + WorldgenGTOreSmallPieces.sList.stream() + .filter(gt_worldgen -> gt_worldgen.mEnabled && smallOresPredicate.test(gt_worldgen)) + .forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false)); + return dropMap; + } + + /** + * Makes a predicate for the GT normal ore veins worldgen + * + * @return the predicate + */ + private static Predicate makeOreLayerPredicate(int dimensionId) { + return switch (dimensionId) { + case -1 -> gt_worldgen -> gt_worldgen.mNether; + case 0 -> gt_worldgen -> gt_worldgen.mOverworld; + case 1 -> gt_worldgen -> gt_worldgen.mEnd || gt_worldgen.mEndAsteroid; + case 7 -> gt_worldgen -> gt_worldgen.twilightForest; + default -> throw new IllegalStateException(); + }; + } + + /** + * Makes a predicate for the GT normal small ore worldgen + * + * @return the predicate + */ + private static Predicate makeSmallOresPredicate(int dimensionId) { + return switch (dimensionId) { + case -1 -> gt_worldgen -> gt_worldgen.mNether; + case 0 -> gt_worldgen -> gt_worldgen.mOverworld; + case 1 -> gt_worldgen -> gt_worldgen.mEnd; + case 7 -> gt_worldgen -> gt_worldgen.twilightForest; + default -> throw new IllegalStateException(); + }; + } + + /** + * Create a DropMap that contains ores of Ross dims + * + * @param aID dim id of Ross128b or Ross128ba + */ + private static DropMap getDropMapRoss(int aID) { + DropMap dropMap = new DropMap(); + for (BWOreLayer oreLayer : BWOreLayer.sList) { + if (oreLayer.mEnabled && oreLayer.isGenerationAllowed("", aID, 0)) { + List data = oreLayer.getStacks(); + dropMap.addDrop(data.get(0), oreLayer.mWeight); + dropMap.addDrop(data.get(1), oreLayer.mWeight); + dropMap.addDrop(data.get(2), oreLayer.mWeight / 8f); + dropMap.addDrop(data.get(3), oreLayer.mWeight / 8f); + } + } + return dropMap; + } + + /** + * Create a DropMap contains the ores from the galacticGreg space worldgen corresponding to the target dim + * + * @param finalDef ModDimensionDef corresponding to the target dim + */ + private static DropMap getDropMapSpace(ModDimensionDef finalDef) { + DropMap dropMap = new DropMap(); + + // Normal Ore Veins + GalacticGreg.oreVeinWorldgenList.stream() + .filter( + gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreLayerSpace oreLayerSpace + && oreLayerSpace.isEnabledForDim(finalDef)) + .map(gt_worldgen -> (WorldgenOreLayerSpace) gt_worldgen) + .forEach(element -> { + dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false); + dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false); + dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false); + dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false); + }); + + // Normal Small Ores + GalacticGreg.smallOreWorldgenList.stream() + .filter( + gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreSmallSpace oreSmallPiecesSpace + && oreSmallPiecesSpace.isEnabledForDim(finalDef)) + .map(gt_worldgen -> (WorldgenOreSmallSpace) gt_worldgen) + .forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false)); + return dropMap; + } + + public static void addBlockToDimensionList(int dimId, Block block, int meta, float weight) { + if (!extraDropsDimMap.containsKey(dimId)) { + extraDropsDimMap.put(dimId, new DropMap()); + } + extraDropsDimMap.get(dimId) + .addDrop(block, meta, weight); + } + + /** + * Public method giving other mods the ability to add manually a material with an ore version into the external + * dropMap for a specified dim id + * + * @param DimensionID the dim id targeted + * @param Material the material with an ore version + * @param weight the non normalised version of the given weight + */ + public static void addMaterialToDimensionList(int DimensionID, ISubTagContainer Material, float weight) { + if (Material instanceof Materials gtMaterial) { + addBlockToDimensionList(DimensionID, GregTechAPI.sBlockOres1, gtMaterial.mMetaItemSubID, weight); + } else if (Material instanceof Werkstoff werkstoff) { + addBlockToDimensionList(DimensionID, WerkstoffLoader.BWOres, werkstoff.getmID(), weight); + } + } +} diff --git a/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java b/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java new file mode 100644 index 0000000000..d6ee41c48b --- /dev/null +++ b/src/main/java/bwcrossmod/galacticraft/GalacticraftProxy.java @@ -0,0 +1,82 @@ +/* + * 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 bwcrossmod.galacticraft; + +import net.minecraftforge.common.MinecraftForge; + +import bartworks.API.SideReference; +import bartworks.common.configs.ConfigHandler; +import bartworks.system.oregen.BWWorldGenRoss128b; +import bartworks.system.oregen.BWWorldGenRoss128ba; +import bwcrossmod.galacticraft.atmosphere.BWAtmosphereManager; +import bwcrossmod.galacticraft.solarsystems.Ross128SolarSystem; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; + +public class GalacticraftProxy { + + private GalacticraftProxy() {} + + public static void postInit(FMLPostInitializationEvent e) { + if (SideReference.Side.Server || SideReference.EffectiveSide.Server) { + GalacticraftProxy.serverPostInit(e); + } else { + GalacticraftProxy.clientPostInit(e); + } + GalacticraftProxy.commonPostInit(e); + } + + public static void preInit(FMLPreInitializationEvent e) { + if (SideReference.Side.Server || SideReference.EffectiveSide.Server) { + GalacticraftProxy.serverpreInit(e); + } else { + GalacticraftProxy.clientpreInit(e); + } + GalacticraftProxy.commonpreInit(e); + } + + private static void serverpreInit(FMLPreInitializationEvent e) {} + + private static void clientpreInit(FMLPreInitializationEvent e) {} + + private static void commonpreInit(FMLPreInitializationEvent e) { + BWWorldGenRoss128b.initOres(); + BWWorldGenRoss128ba.init_Ores(); + MinecraftForge.EVENT_BUS.register(BWAtmosphereManager.INSTANCE); + } + + public static void init(FMLInitializationEvent e) { + if (SideReference.Side.Server || SideReference.EffectiveSide.Server) { + GalacticraftProxy.serverInit(e); + } else { + GalacticraftProxy.clientInit(e); + } + GalacticraftProxy.commonInit(e); + } + + private static void serverInit(FMLInitializationEvent e) {} + + private static void clientInit(FMLInitializationEvent e) {} + + private static void commonInit(FMLInitializationEvent e) { + if (ConfigHandler.Ross128Enabled) Ross128SolarSystem.init(); + } + + private static void serverPostInit(FMLPostInitializationEvent e) {} + + private static void clientPostInit(FMLPostInitializationEvent e) {} + + private static void commonPostInit(FMLPostInitializationEvent e) {} +} diff --git a/src/main/java/bwcrossmod/galacticraft/PlanetsHelperClass.java b/src/main/java/bwcrossmod/galacticraft/PlanetsHelperClass.java new file mode 100644 index 0000000000..eecd5bd8fe --- /dev/null +++ b/src/main/java/bwcrossmod/galacticraft/PlanetsHelperClass.java @@ -0,0 +1,33 @@ +/* + * 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 bwcrossmod.galacticraft; + +import net.minecraft.entity.player.EntityPlayerMP; + +import bartworks.common.configs.ConfigHandler; +import micdoodle8.mods.galacticraft.core.entities.EntityLander; +import micdoodle8.mods.galacticraft.core.entities.EntityLanderBase; +import micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityEntryPod; +import micdoodle8.mods.galacticraft.planets.mars.entities.EntityLandingBalloons; + +public class PlanetsHelperClass { + + public static EntityLanderBase getLanderType(EntityPlayerMP player) { + return switch (ConfigHandler.landerType) { + case 1 -> new EntityLander(player); + case 2 -> new EntityLandingBalloons(player); + default -> new EntityEntryPod(player); + }; + } +} diff --git a/src/main/java/bwcrossmod/galacticraft/UniversalTeleportType.java b/src/main/java/bwcrossmod/galacticraft/UniversalTeleportType.java new file mode 100644 index 0000000000..4507cadca2 --- /dev/null +++ b/src/main/java/bwcrossmod/galacticraft/UniversalTeleportType.java @@ -0,0 +1,78 @@ +/* + * 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 bwcrossmod.galacticraft; + +import static gregtech.api.enums.Mods.GalacticraftMars; + +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; + +import micdoodle8.mods.galacticraft.api.vector.Vector3; +import micdoodle8.mods.galacticraft.api.world.ITeleportType; +import micdoodle8.mods.galacticraft.core.entities.EntityLander; +import micdoodle8.mods.galacticraft.core.entities.EntityLanderBase; +import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats; + +public class UniversalTeleportType implements ITeleportType { + + @Override + public boolean useParachute() { + return false; + } + + @Override + public Vector3 getPlayerSpawnLocation(WorldServer world, EntityPlayerMP player) { + return this.getEntitySpawnLocation(world, player); + } + + @Override + public Vector3 getEntitySpawnLocation(WorldServer world, Entity entity) { + if (entity instanceof EntityPlayerMP) { + GCPlayerStats stats = GCPlayerStats.get((EntityPlayerMP) entity); + return new Vector3(stats.coordsTelep