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/galacticgreg/GalacticGreg.java | 113 +++++ src/main/java/galacticgreg/SpaceDimRegisterer.java | 140 +++++ .../java/galacticgreg/TileEntitySpaceOres.java | 144 ++++++ .../java/galacticgreg/WorldGeneratorSpace.java | 564 +++++++++++++++++++++ src/main/java/galacticgreg/WorldgenGaGT.java | 28 + .../java/galacticgreg/WorldgenOreLayerSpace.java | 320 ++++++++++++ .../java/galacticgreg/WorldgenOreSmallSpace.java | 116 +++++ .../java/galacticgreg/api/AsteroidBlockComb.java | 77 +++ src/main/java/galacticgreg/api/BlockMetaComb.java | 50 ++ src/main/java/galacticgreg/api/Enums.java | 51 ++ src/main/java/galacticgreg/api/GTOreTypes.java | 66 +++ .../galacticgreg/api/ISpaceObjectGenerator.java | 58 +++ src/main/java/galacticgreg/api/ModContainer.java | 85 ++++ src/main/java/galacticgreg/api/ModDBMDef.java | 159 ++++++ .../java/galacticgreg/api/ModDimensionDef.java | 461 +++++++++++++++++ .../java/galacticgreg/api/SpecialBlockComb.java | 69 +++ .../galacticgreg/api/StructureInformation.java | 59 +++ .../enums/DimensionBlockMetaDefinitionList.java | 57 +++ .../java/galacticgreg/api/enums/DimensionDef.java | 228 +++++++++ .../java/galacticgreg/api/enums/ModContainers.java | 19 + .../enums/properties/AsteroidPropertyBuilder.java | 105 ++++ .../api/enums/properties/Asteroids.java | 78 +++ .../java/galacticgreg/auxiliary/ConfigManager.java | 79 +++ .../java/galacticgreg/auxiliary/GTOreGroup.java | 19 + .../galacticgreg/auxiliary/GalacticGregConfig.java | 141 ++++++ .../java/galacticgreg/auxiliary/LogHelper.java | 267 ++++++++++ .../galacticgreg/auxiliary/PlayerChatHelper.java | 106 ++++ .../galacticgreg/auxiliary/ProfilingStorage.java | 74 +++ .../galacticgreg/command/AEStorageCommand.java | 180 +++++++ .../galacticgreg/command/ProfilingCommand.java | 99 ++++ .../dynconfig/DynamicDimensionConfig.java | 160 ++++++ .../java/galacticgreg/generators/GenEllipsoid.java | 126 +++++ .../registry/GalacticGregRegistry.java | 183 +++++++ .../galacticgreg/schematics/SpaceSchematic.java | 100 ++++ .../schematics/SpaceSchematicFactory.java | 33 ++ .../schematics/SpaceSchematicHandler.java | 182 +++++++ .../schematics/SpaceSchematicWrapper.java | 104 ++++ 37 files changed, 4900 insertions(+) create mode 100644 src/main/java/galacticgreg/GalacticGreg.java create mode 100644 src/main/java/galacticgreg/SpaceDimRegisterer.java create mode 100644 src/main/java/galacticgreg/TileEntitySpaceOres.java create mode 100644 src/main/java/galacticgreg/WorldGeneratorSpace.java create mode 100644 src/main/java/galacticgreg/WorldgenGaGT.java create mode 100644 src/main/java/galacticgreg/WorldgenOreLayerSpace.java create mode 100644 src/main/java/galacticgreg/WorldgenOreSmallSpace.java create mode 100644 src/main/java/galacticgreg/api/AsteroidBlockComb.java create mode 100644 src/main/java/galacticgreg/api/BlockMetaComb.java create mode 100644 src/main/java/galacticgreg/api/Enums.java create mode 100644 src/main/java/galacticgreg/api/GTOreTypes.java create mode 100644 src/main/java/galacticgreg/api/ISpaceObjectGenerator.java create mode 100644 src/main/java/galacticgreg/api/ModContainer.java create mode 100644 src/main/java/galacticgreg/api/ModDBMDef.java create mode 100644 src/main/java/galacticgreg/api/ModDimensionDef.java create mode 100644 src/main/java/galacticgreg/api/SpecialBlockComb.java create mode 100644 src/main/java/galacticgreg/api/StructureInformation.java create mode 100644 src/main/java/galacticgreg/api/enums/DimensionBlockMetaDefinitionList.java create mode 100644 src/main/java/galacticgreg/api/enums/DimensionDef.java create mode 100644 src/main/java/galacticgreg/api/enums/ModContainers.java create mode 100644 src/main/java/galacticgreg/api/enums/properties/AsteroidPropertyBuilder.java create mode 100644 src/main/java/galacticgreg/api/enums/properties/Asteroids.java create mode 100644 src/main/java/galacticgreg/auxiliary/ConfigManager.java create mode 100644 src/main/java/galacticgreg/auxiliary/GTOreGroup.java create mode 100644 src/main/java/galacticgreg/auxiliary/GalacticGregConfig.java create mode 100644 src/main/java/galacticgreg/auxiliary/LogHelper.java create mode 100644 src/main/java/galacticgreg/auxiliary/PlayerChatHelper.java create mode 100644 src/main/java/galacticgreg/auxiliary/ProfilingStorage.java create mode 100644 src/main/java/galacticgreg/command/AEStorageCommand.java create mode 100644 src/main/java/galacticgreg/command/ProfilingCommand.java create mode 100644 src/main/java/galacticgreg/dynconfig/DynamicDimensionConfig.java create mode 100644 src/main/java/galacticgreg/generators/GenEllipsoid.java create mode 100644 src/main/java/galacticgreg/registry/GalacticGregRegistry.java create mode 100644 src/main/java/galacticgreg/schematics/SpaceSchematic.java create mode 100644 src/main/java/galacticgreg/schematics/SpaceSchematicFactory.java create mode 100644 src/main/java/galacticgreg/schematics/SpaceSchematicHandler.java create mode 100644 src/main/java/galacticgreg/schematics/SpaceSchematicWrapper.java (limited to 'src/main/java/galacticgreg') diff --git a/src/main/java/galacticgreg/GalacticGreg.java b/src/main/java/galacticgreg/GalacticGreg.java new file mode 100644 index 0000000000..03cb4d1569 --- /dev/null +++ b/src/main/java/galacticgreg/GalacticGreg.java @@ -0,0 +1,113 @@ +package galacticgreg; + +import static gregtech.api.enums.Mods.AppliedEnergistics2; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import galacticgreg.auxiliary.GalacticGregConfig; +import galacticgreg.auxiliary.LogHelper; +import galacticgreg.auxiliary.ProfilingStorage; +import galacticgreg.command.AEStorageCommand; +import galacticgreg.command.ProfilingCommand; +import galacticgreg.registry.GalacticGregRegistry; +import galacticgreg.schematics.SpaceSchematicHandler; +import gregtech.GT_Version; +import gregtech.api.world.GTWorldgen; + +@Mod( + modid = GalacticGreg.MODID, + name = GalacticGreg.MODNAME, + version = GalacticGreg.VERSION, + dependencies = "after:GalacticraftCore; required-after:gregtech@5.09.32.30;", + acceptableRemoteVersions = "*") +public class GalacticGreg { + + public static final List smallOreWorldgenList = new ArrayList<>(); + public static final List oreVeinWorldgenList = new ArrayList<>(); + + public static final String NICE_MODID = "GalacticGreg"; + public static final String MODID = "galacticgreg"; + public static final String MODNAME = "Galactic Greg"; + + public static final String VERSION = GT_Version.VERSION; + + public static final LogHelper Logger = new LogHelper(NICE_MODID); + public static ProfilingStorage Profiler = new ProfilingStorage(); + public static SpaceSchematicHandler SchematicHandler; + + public static Random GalacticRandom = null; + + public static GalacticGregConfig GalacticConfig = null; + + /** + * Preload phase. Read config values and set various features.. n stuff... + * + * @param aEvent + */ + @EventHandler + public void onPreLoad(FMLPreInitializationEvent aEvent) { + GalacticConfig = new GalacticGregConfig(aEvent.getModConfigurationDirectory(), NICE_MODID, NICE_MODID); + if (!GalacticConfig.LoadConfig()) GalacticGreg.Logger + .warn("Something went wrong while reading GalacticGregs config file. Things will be wonky.."); + + GalacticRandom = new Random(System.currentTimeMillis()); + + if (GalacticConfig.SchematicsEnabled) + SchematicHandler = new SpaceSchematicHandler(aEvent.getModConfigurationDirectory()); + + Logger.trace("Leaving PRELOAD"); + } + + public static final ArrayList ADDITIONALVEINREGISTER = new ArrayList<>(); + + /** + * Postload phase. Mods can add their custom definition to our api in their own PreLoad or Init-phase Once + * GalacticGregRegistry.InitRegistry() is called, no changes are accepted. (Well you can with reflection, but on a + * "normal" way it's not possible) + * + * @param aEvent + */ + @EventHandler + public void onPostLoad(FMLPostInitializationEvent aEvent) { + Logger.trace("Entering POSTLOAD"); + + if (!GalacticGregRegistry.InitRegistry()) throw new RuntimeException( + "GalacticGreg registry has been finalized from a 3rd-party mod, this is forbidden!"); + + for (Runnable r : ADDITIONALVEINREGISTER) { + try { + r.run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + GalacticConfig.serverPostInit(); + + Logger.trace("Leaving POSTLOAD"); + } + + /** + * If oregen profiling is enabled, then register the command + * + * @param pEvent + */ + @EventHandler + public void serverLoad(FMLServerStartingEvent pEvent) { + Logger.trace("Entering SERVERLOAD"); + + if (GalacticConfig.ProfileOreGen) pEvent.registerServerCommand(new ProfilingCommand()); + + if (AppliedEnergistics2.isModLoaded() && GalacticConfig.EnableAEExportCommand + && GalacticConfig.SchematicsEnabled) pEvent.registerServerCommand(new AEStorageCommand()); + + Logger.trace("Leaving SERVERLOAD"); + } +} diff --git a/src/main/java/galacticgreg/SpaceDimRegisterer.java b/src/main/java/galacticgreg/SpaceDimRegisterer.java new file mode 100644 index 0000000000..611477f7df --- /dev/null +++ b/src/main/java/galacticgreg/SpaceDimRegisterer.java @@ -0,0 +1,140 @@ +package galacticgreg; + +import net.minecraft.init.Blocks; + +import galacticgreg.api.AsteroidBlockComb; +import galacticgreg.api.Enums; +import galacticgreg.api.GTOreTypes; +import galacticgreg.api.ModContainer; +import galacticgreg.api.SpecialBlockComb; +import galacticgreg.api.enums.DimensionDef; +import galacticgreg.api.enums.ModContainers; +import galacticgreg.registry.GalacticGregRegistry; + +/** + * In this class, you'll find everything you need in order to tell GGreg what to do and where. Everything is done in + * here. If you're trying to use anything else, you're probably doing something wrong (Or I forgot to add it. In that + * case, find me on github and create an issue please) + */ +public class SpaceDimRegisterer { + + public static void register() { + GalacticGregRegistry.registerModContainer(setupVanilla()); + GalacticGregRegistry.registerModContainer(setupGalactiCraftCore()); + GalacticGregRegistry.registerModContainer(setupGalactiCraftPlanets()); + GalacticGregRegistry.registerModContainer(setupGalaxySpace()); + GalacticGregRegistry.registerModContainer(setupAmunRa()); + } + + /** + * Vanilla MC (End Asteroids) + */ + private static ModContainer setupVanilla() { + + // If you happen to have an asteroid dim, just skip the blocklist, and setDimensionType() to + // DimensionType.Asteroid + // also don't forget to add at least one asteroid type, or nothing will generate! + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + DimensionDef.EndAsteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.EndStone)); + + // These Blocks will randomly be generated + DimensionDef.EndAsteroids.modDimensionDef.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); + DimensionDef.EndAsteroids.modDimensionDef + .addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, Enums.AllowedBlockPosition.AsteroidCore)); + + ModContainers.Vanilla.modContainer.addDimensionDef(DimensionDef.EndAsteroids.modDimensionDef); + + return ModContainers.Vanilla.modContainer; + } + + /** + * Mod GalactiCraft + */ + private static ModContainer setupGalactiCraftCore() { + ModContainers.GalactiCraftCore.modContainer.addDimensionDef(DimensionDef.Moon.modDimensionDef); + return ModContainers.GalactiCraftCore.modContainer; + } + + /** + * As GalactiCraftPlanets is an optional mod, don't hardlink it here + */ + private static ModContainer setupGalactiCraftPlanets() { + // Overwrite ore blocks on mars with red granite ones. This will default to regular stone if not set + DimensionDef.Mars.modDimensionDef.setStoneType(GTOreTypes.RedGranite); + ModContainers.GalacticraftMars.modContainer.addDimensionDef(DimensionDef.Mars.modDimensionDef); + + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + DimensionDef.Asteroids.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + ModContainers.GalacticraftMars.modContainer.addDimensionDef(DimensionDef.Asteroids.modDimensionDef); + + return ModContainers.GalacticraftMars.modContainer; + } + + /** + * Mod GalaxySpace by BlesseNtumble + */ + private static ModContainer setupGalaxySpace() { + // First, we create a mod-container that will be populated with dimensions later. + // The Name must match your ID, as it is checked if this mod is loaded, in order + // to enable/disable the parsing/registering of dimensions + // See enum ModContainers + + // Now lets first define a block here for our dimension. You can add the ID, but you don't have to. + // It will automatically add the mods name that is defined in the modcontainer. + // See enum DimensionBlockMetaDefinitionList + + // Now define the available dimensions, and their chunkprovider. + // Same as above, to not have any dependency in your code, you can just give it a string. + // But it's better to use the actual ChunkProvider class. The Name is used for the GalacticGreg config file. + // The resulting config setting will be: __false = false + // make sure to never change this name once you've generated your config files, as it will overwrite everything! + + // 30.11.2016 GSpace v1.1.3 Stable + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Pluto.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Triton.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Proteus.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Oberon.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Titan.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Callisto.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Ganymede.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Ceres.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Deimos.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Enceladus.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Io.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Europa.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Phobos.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Venus.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Mercury.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.MakeMake.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Haumea.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.CentauriAlpha.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.VegaB.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.BarnardC.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.BarnardE.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.BarnardF.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.TcetiE.modDimensionDef); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.Miranda.modDimensionDef); + DimensionDef.KuiperBelt.modDimensionDef.setDimensionType(Enums.DimensionType.Asteroid); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + DimensionDef.KuiperBelt.modDimensionDef.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + ModContainers.GalaxySpace.modContainer.addDimensionDef(DimensionDef.KuiperBelt.modDimensionDef); + return ModContainers.GalaxySpace.modContainer; + } + + /** + * Mod Amun-Ra + */ + private static ModContainer setupAmunRa() { + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Neper.modDimensionDef); + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Maahes.modDimensionDef); + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Anubis.modDimensionDef); + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Horus.modDimensionDef); + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.Seth.modDimensionDef); + DimensionDef.MehenBelt.modDimensionDef.addAsteroidMaterial(GTOreTypes.BlackGranite); + ModContainers.AmunRa.modContainer.addDimensionDef(DimensionDef.MehenBelt.modDimensionDef); + return ModContainers.AmunRa.modContainer; + } +} diff --git a/src/main/java/galacticgreg/TileEntitySpaceOres.java b/src/main/java/galacticgreg/TileEntitySpaceOres.java new file mode 100644 index 0000000000..00ad3ba51f --- /dev/null +++ b/src/main/java/galacticgreg/TileEntitySpaceOres.java @@ -0,0 +1,144 @@ +package galacticgreg; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import galacticgreg.api.Enums; +import galacticgreg.api.ModDimensionDef; +import gregtech.api.GregTechAPI; +import gregtech.api.util.GTLog; +import gregtech.common.blocks.BlockOresAbstract; +import gregtech.common.blocks.TileEntityOres; + +public class TileEntitySpaceOres { + + // Renamed function to prevent function shadowing with base GT-code + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, false, -1); + } + + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir) { + return setOuterSpaceOreBlock(pDimensionDef, pWorld, pX, pY, pZ, pMetaData, pAir, -1); + } + + /** + * Check if the block at given position may be replaced by an ore + * + * @param pWorld the world in question + * @param pX X-Cord + * @param pY Y-Cord + * @param pZ Z-Cord + * @return + */ + private static Enums.ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, + ModDimensionDef pDimDef) { + try { + Enums.ReplaceState tFlag = Enums.ReplaceState.Unknown; + + Block targetBlock = pWorld.getBlock(pX, pY, pZ); + int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); + + if (targetBlock == Blocks.air) tFlag = Enums.ReplaceState.Airblock; + else tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); + + return tFlag; + } catch (Exception e) { + e.printStackTrace(GTLog.err); + GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); + return Enums.ReplaceState.Unknown; + } + } + + /** + * Actually set the OreBlock + * + * @param pWorld the world in question + * @param pX + * @param pY + * @param pZ + * @param pMetaData GT-Ore metadata + * @param pAir + * @return + */ + public static boolean setOuterSpaceOreBlock(ModDimensionDef pDimensionDef, World pWorld, int pX, int pY, int pZ, + int pMetaData, boolean pAir, int pCustomGTOreOffset) { + if (!pAir) pY = Math.min(pWorld.getActualHeight(), Math.max(pY, 1)); + + if (pDimensionDef == null) { + GalacticGreg.Logger + .warn("Unknown DimensionID: %d. Will not set anything here", pWorld.provider.dimensionId); + return false; + } + try { + Block tBlock = pWorld.getBlock(pX, pY, pZ); + // If the meta is non-zero, and the target block is either non-air or the air-override is active + if ((pMetaData > 0) && ((tBlock != Blocks.air) || pAir)) { + // make sure we're either going with normal ore-metas, or small ores. + // Probably should do another check for <= 1700 + if (pMetaData < 1000 || pMetaData >= 16000) { + Enums.ReplaceState tRS = CheckForReplaceableBlock(pWorld, pX, pY, pZ, pDimensionDef); + + // Unable to lookup replacement state. Means: The block is unknown, and shall not be replaced + if (tRS == Enums.ReplaceState.Unknown) { + GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); + return false; + } else if (tRS == Enums.ReplaceState.Airblock && !pAir) { + GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); + return false; + } + if (tRS == Enums.ReplaceState.CannotReplace) { + // wrong metaData ID for target block + GalacticGreg.Logger.trace("Not placing ore Meta %d, as the state is CANNOTREPLACE", pMetaData); + return false; + } + + if (pCustomGTOreOffset == -1) pMetaData += pDimensionDef.getStoneType() + .getOffset(); + else pMetaData += pCustomGTOreOffset; + // This fix seems like cargo cult coding...The Abstract class just returns 0 for the harvest level. + // But it aligns with the GT5U method, so yay? + pWorld.setBlock( + pX, + pY, + pZ, + GregTechAPI.sBlockOres1, + TileEntityOres.getHarvestData( + (short) pMetaData, + ((BlockOresAbstract) GregTechAPI.sBlockOres1) + .getBaseBlockHarvestLevel(pMetaData % 16000 / 1000)), + 0); + TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); + if ((tTileEntity instanceof TileEntityOres)) { + ((TileEntityOres) tTileEntity).mMetaData = ((short) pMetaData); + ((TileEntityOres) tTileEntity).mNatural = true; + } else { + // This is somehow triggered randomly, and most times the target block is air, which should + // never happen as we check for air... + // That's why I put this behind a debug config option. If you ever find the reason for it, + // please tell me what caused this + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) GalacticGreg.Logger.warn( + "Something went wrong while placing GT OreTileEntity. Meta: %d X [%d] Y [%d] Z [%d]", + pMetaData, + pX, + pY, + pZ); + } + + return true; + } else GalacticGreg.Logger.warn( + "Not replacing block at pos %d %d %d due unexpected metaData for OreBlock: %d", + pX, + pY, + pZ, + pMetaData); + } + } catch (Exception e) { + if (GalacticGreg.GalacticConfig.ReportOreGenFailures) e.printStackTrace(); + } + return false; + } +} diff --git a/src/main/java/galacticgreg/WorldGeneratorSpace.java b/src/main/java/galacticgreg/WorldGeneratorSpace.java new file mode 100644 index 0000000000..336900326c --- /dev/null +++ b/src/main/java/galacticgreg/WorldGeneratorSpace.java @@ -0,0 +1,564 @@ +package galacticgreg; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.Vec3; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.ChestGenHooks; + +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.eventhandler.EventBus; +import cpw.mods.fml.common.registry.GameRegistry; +import galacticgreg.api.AsteroidBlockComb; +import galacticgreg.api.BlockMetaComb; +import galacticgreg.api.Enums; +import galacticgreg.api.GTOreTypes; +import galacticgreg.api.ISpaceObjectGenerator; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.api.SpecialBlockComb; +import galacticgreg.api.StructureInformation; +import galacticgreg.auxiliary.GTOreGroup; +import galacticgreg.dynconfig.DynamicDimensionConfig; +import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.util.GTLog; +import gregtech.api.world.GTWorldgen; +import gregtech.common.GTWorldgenerator; + +public class WorldGeneratorSpace implements IWorldGenerator { + + public static boolean sAsteroids = true; + private final EventBus eventBus = new EventBus(); + private World worldObj; + + private int chunkX; + private int chunkZ; + private int mSize = 100; + + private long mProfilingStart; + private long mProfilingEnd; + + public WorldGeneratorSpace() { + GameRegistry.registerWorldGenerator(this, Integer.MAX_VALUE); + } + + public void generate(Random pRandom, int pX, int pZ, World pWorld, IChunkProvider pChunkGenerator, + IChunkProvider pChunkProvider) { + pX *= 16; + pZ *= 16; + + String tBiome = pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; + pRandom = new Random(pRandom.nextInt()); + if (tBiome == null) { + tBiome = BiomeGenBase.plains.biomeName; + } + GalacticGreg.Logger + .trace("Triggered generate: [ChunkGenerator %s] [Biome %s]", pChunkGenerator.toString(), tBiome); + + ModDimensionDef tDimDef = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + + if (tDimDef == null) { + GalacticGreg.Logger.trace( + "Ignoring ChunkGenerator type %s as there is no definition for it in the registry", + pChunkGenerator.toString()); + return; + } else { + GalacticGreg.Logger.trace("Selected DimDef: [%s]", tDimDef.getDimIdentifier()); + } + + /* + * In some later addons maybe, not for now. Ignoring Biome-based worldgen String tBiome = + * pWorld.getBiomeGenForCoords(pX + 8, pZ + 8).biomeName; pRandom = new Random(pRandom.nextInt()); if (tBiome == + * null) { tBiome = BiomeGenBase.plains.biomeName; } + */ + + if (tDimDef.getDimensionType() != Enums.DimensionType.Planet) { + if (tDimDef.getRandomAsteroidMaterial() == null) GalacticGreg.Logger.error( + "Dimension [%s] is set to Asteroids, but no asteroid material is specified! Nothing will generate", + tDimDef.getDimensionName()); + else Generate_Asteroids(tDimDef, pRandom, pWorld, pX, pZ); + } else if (tDimDef.getDimensionType() != Enums.DimensionType.Asteroid) { + Generate_OreVeins(tDimDef, pRandom, pWorld, pX, pZ, "", pChunkGenerator, pChunkProvider); + } + + Chunk tChunk = pWorld.getChunkFromBlockCoords(pX, pZ); + if (tChunk != null) { + tChunk.isModified = true; + } + } + + private void Generate_Asteroids(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ) { + GalacticGreg.Logger.trace("Running asteroid-gen in Dim %s", pDimensionDef.getDimIdentifier()); + + DynamicDimensionConfig.AsteroidConfig tAConf = DynamicDimensionConfig.getAsteroidConfig(pDimensionDef); + if (tAConf == null) { + GalacticGreg.Logger.error( + "Dimension %s is set to asteroid, but no config object can be found. Skipping!", + pDimensionDef.getDimIdentifier()); + return; + } else { + GalacticGreg.Logger.trace("Asteroid probability: %d", tAConf.Probability); + } + + if ((tAConf.Probability <= 1) || (pRandom.nextInt(tAConf.Probability) == 0)) { + GalacticGreg.Logger.trace("Generating asteroid NOW"); + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) mProfilingStart = System.currentTimeMillis(); + // ----------------------------- + + // Get Random position + int tX = pX + pRandom.nextInt(16); + int tY = 50 + pRandom.nextInt(200 - 50); + int tZ = pZ + pRandom.nextInt(16); + + // Check if position is free + if ((pWorld.getBlock(tX, tY, tZ) + .isAir(pWorld, tX, tY, tZ))) { + + int tCustomAsteroidOffset = -1; + int tGraniteMeta = 0; + + // Select Random OreGroup and Asteroid Material + GTOreGroup tOreGroup = WorldgenOreLayerSpace.getRandomOreGroup(pDimensionDef, pRandom, true); + AsteroidBlockComb tABComb = pDimensionDef.getRandomAsteroidMaterial(); + if (tABComb == null) return; + + // Fill Vars for random Asteroid + Block tFinalAsteroidBlock = tABComb.getBlock(); + int tFinalAsteroidBlockMeta = tABComb.getMeta(); + int tFinalOreOffset = tABComb.getOreMaterial() + .getOffset(); + int tFinalUpdateMode = tABComb.getOreMaterial() + .getUpdateMode(); + GalacticGreg.Logger.debug( + "Asteroid will be build with: Block: [%s] OreType: [%s]", + Block.blockRegistry.getNameForObject(tABComb.getBlock()), + tABComb.getOreMaterial() + .toString()); + + // get random Ore-asteroid generator from the list of registered generators + ISpaceObjectGenerator aGen = pDimensionDef.getRandomSOGenerator(Enums.SpaceObjectType.OreAsteroid); + if (aGen == null) { + GalacticGreg.Logger.ot_error( + "GalacticGreg.Generate_Asteroids.NoSOGenFound", + "No SpaceObjectGenerator has been registered for type ORE_ASTEROID in Dimension %s. Nothing will generate", + pDimensionDef.getDimensionName()); + return; + } + + aGen.reset(); + aGen.setCenterPoint(tX, tY, tZ); + aGen.randomize(tAConf.MinSize, tAConf.MaxSize); // Initialize random values and set size + aGen.calculate(); // Calculate structure + + // Random loot-chest somewhere in the asteroid + Vec3 tChestPosition = Vec3.createVectorHelper(0, 0, 0); + boolean tDoLootChest = false; + int tNumLootItems = 0; + if (tAConf.LootChestChance > 0) { + GalacticGreg.Logger.trace("Random loot chest enabled, flipping the coin"); + int tChance = pRandom.nextInt(100); // Loot chest is 1 in 100 (Was: 1:1000 which actually never + // happend) + if (tAConf.LootChestChance >= tChance) { + GalacticGreg.Logger.debug("We got a match. Preparing to generate the loot chest"); + // Get amount of items for the loot chests, randomize it (1-num) if enabled + if (tAConf.RandomizeNumLootItems) tNumLootItems = pRandom.nextInt(tAConf.NumLootItems - 1) + 1; + else tNumLootItems = tAConf.NumLootItems; + + GalacticGreg.Logger + .debug(String.format("Loot chest random item count will be: %d", tNumLootItems)); + + // try to find any block that is not on the asteroids outer-shell + GalacticGreg.Logger.trace("Starting lookup for valid asteroid-block for the chest"); + for (int x = 0; x < 64; x++) // 64 enough? Should be + { + int tRndBlock = pRandom.nextInt( + aGen.getStructure() + .size()); + StructureInformation tChestSI = aGen.getStructure() + .get(tRndBlock); + if (tChestSI.getBlockPosition() != Enums.TargetBlockPosition.AsteroidShell) { + GalacticGreg.Logger.debug( + String.format( + "Chest position found [x:%d y:%d z:%d]", + tChestSI.getX(), + tChestSI.getY(), + tChestSI.getZ())); + // Found valid position "Somewhere" in the asteroid, set position... + tChestPosition = Vec3 + .createVectorHelper(tChestSI.getX(), tChestSI.getY(), tChestSI.getZ()); + // .. and set CreateFlag to true + tDoLootChest = true; + break; + } + } + } + } + + // Now build the structure + GalacticGreg.Logger.trace("Now generating Space-Structure"); + for (StructureInformation si : aGen.getStructure()) { + // Only replace airblocks + if (pWorld.isAirBlock(si.getX(), si.getY(), si.getZ())) { + // === Loot-chest generator >> + if (tDoLootChest) // If gen-lootchest enabled... + { + // Check if current x/y/z is the location where the chest shall be created + if ((int) tChestPosition.xCoord == si.getX() && (int) tChestPosition.yCoord == si.getY() + && (int) tChestPosition.zCoord == si.getZ()) { + GalacticGreg.Logger.trace("Now generating LootChest and contents"); + // Get items for the configured loot-table + WeightedRandomChestContent[] tRandomLoot = ChestGenHooks + .getItems(DynamicDimensionConfig.getLootChestTable(tAConf), pRandom); + + // Get chest-block to spawn + BlockMetaComb tTargetChestType = GalacticGreg.GalacticConfig.CustomLootChest; + + // Place down the chest + if (tTargetChestType.getMeta() > 0) pWorld.setBlock( + si.getX(), + si.getY(), + si.getZ(), + tTargetChestType.getBlock(), + tTargetChestType.getMeta(), + 2); + else pWorld.setBlock(si.getX(), si.getY(), si.getZ(), tTargetChestType.getBlock()); + + // Retrieve the TEs IInventory that should've been created + IInventory entityChestInventory = (IInventory) pWorld + .getTileEntity(si.getX(), si.getY(), si.getZ()); + // If it's not null... + if (entityChestInventory != null) { + // and if we're on the server... + if (!pWorld.isRemote) { + // Fill the chest with stuffz! + WeightedRandomChestContent.generateChestContents( + pRandom, + tRandomLoot, + entityChestInventory, + tNumLootItems); + GalacticGreg.Logger.trace("Loot chest successfully generated"); + } + } else { + // Something made a boo.. + GalacticGreg.Logger.warn( + "Could not create lootchest at X[%d] Y[%d] Z[%d]. getTileEntity() returned null", + si.getX(), + si.getY(), + si.getZ()); + } + // Make sure we never compare coordinates again (for this asteroid/Structure) + tDoLootChest = false; + // Do some debug logging + GalacticGreg.Logger + .debug("Generated LootChest at X[%d] Y[%d] Z[%d]", si.getX(), si.getY(), si.getZ()); + // And skip the rest of this function + continue; + } + } + // << Loot-chest generator === + + // === Ore generator >> + boolean tPlacedOreBlock = false; + // If a valid oregroup has been selected (more than 0 ore-veins are enabled for this dim) + if (tOreGroup != null) { + // GalacticGreg.Logger.trace("tOreGoup is populated, continuing"); + // Choose a number between 0 and 100 + int ranOre = pRandom.nextInt(100); + int tFinalOreMeta = 0; + + // If choosen number is below the configured orechance, do random between and sporadic + if (ranOre < tAConf.OreChance) { + if (pRandom.nextBoolean()) { + // Only take as final value if meta is not zero + if (tOreGroup.SporadicBetweenMeta > 0) + tFinalOreMeta = tOreGroup.SporadicBetweenMeta; + } else { + // Only take as final value if meta is not zero + if (tOreGroup.SporadicAroundMeta > 0) tFinalOreMeta = tOreGroup.SporadicAroundMeta; + } + } + // If choosen number is below the configured orechance, do random primary and secondary + // We use an offset here, so this part is always higher than the first check. + else if (ranOre < tAConf.OreChance + tAConf.OrePrimaryOffset) { + if (pRandom.nextBoolean()) { + // Only take as final value if meta is not zero + if (tOreGroup.PrimaryMeta > 0) tFinalOreMeta = tOreGroup.PrimaryMeta; + } else { + // Only take as final value if meta is not zero + if (tOreGroup.SecondaryMeta > 0) tFinalOreMeta = tOreGroup.SecondaryMeta; + } + } + + // if the final oreMeta has been found... + // GalacticGreg.Logger.info("tFinalOreMeta is %d", tFinalOreMeta); + if (tFinalOreMeta > 0) { + // make sure we obey the configured "HiddenOres" setting (No ores on the shell) + if (tAConf.HiddenOres + && (si.getBlockPosition() == Enums.TargetBlockPosition.AsteroidShell)) { + // Ore would be placed around the shell, which is disabled (hiddenores) + GalacticGreg.Logger.trace( + "Skipping ore-placement event (HiddenOres=true; TargetBlockPosition=AsteroidShell)"); + } else { + // try to place the ore block. The result is stored in tPlacedOreBlock + tPlacedOreBlock = TileEntitySpaceOres.setOuterSpaceOreBlock( + pDimensionDef, + pWorld, + si.getX(), + si.getY(), + si.getZ(), + tOreGroup.SecondaryMeta, + true, + tFinalOreOffset); + } + } + } + // << Ore generator === + + // === Additional special blocks >> + // If no ore-block has been placed yet... + if (!tPlacedOreBlock) { + // try to spawn special blocks + boolean tFlag = doGenerateSpecialBlocks( + pDimensionDef, + pRandom, + pWorld, + tAConf, + si.getX(), + si.getY(), + si.getZ(), + si.getBlockPosition()); + + // No special block placed? Try smallores + if (tFlag) tFlag = doGenerateSmallOreBlock( + pDimensionDef, + pRandom, + pWorld, + tAConf, + si.getX(), + si.getY(), + si.getZ(), + tFinalOreOffset); + + // no smallores either? do normal block + if (tFlag) pWorld.setBlock( + si.getX(), + si.getY(), + si.getZ(), + tFinalAsteroidBlock, + tFinalAsteroidBlockMeta, + tFinalUpdateMode); + + } + // << Additional special blocks === + } + } + } + // --------------------------- + // OreGen profiler stuff + if (GalacticGreg.GalacticConfig.ProfileOreGen) { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(pDimensionDef, tTotalTime); + GalacticGreg.Logger.debug( + "Done with Asteroid-Worldgen in DimensionType %s. Generation took %d ms", + pDimensionDef.getDimensionName(), + tTotalTime); + } catch (Exception ignored) {} // Silently ignore errors + } + // --------------------------- + } + GalacticGreg.Logger.trace("Leaving asteroid-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } + + /** + * Generate Special Blocks in asteroids if enabled + * + * @param pDimensionDef + * @param pRandom + * @param pWorld + * @param tAConf + * @param eX + * @param eY + * @param eZ + * @return + */ + private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, + DynamicDimensionConfig.AsteroidConfig tAConf, int eX, int eY, int eZ, + Enums.TargetBlockPosition pBlockPosition) { + + boolean tFlag = true; + // Handler to generate special BlockTypes randomly if activated + if (tAConf.SpecialBlockChance > 0) { + if (pRandom.nextInt(100) < tAConf.SpecialBlockChance) { + SpecialBlockComb bmc = pDimensionDef.getRandomSpecialAsteroidBlock(); + if (bmc != null) { + boolean tIsAllowed = false; + + switch (bmc.getBlockPosition()) { + case AsteroidCore: + if (pBlockPosition == Enums.TargetBlockPosition.AsteroidCore) tIsAllowed = true; + break; + case AsteroidCoreAndShell: + if (pBlockPosition == Enums.TargetBlockPosition.AsteroidCore + || pBlockPosition == Enums.TargetBlockPosition.AsteroidShell) tIsAllowed = true; + break; + case AsteroidShell: + if (pBlockPosition == Enums.TargetBlockPosition.AsteroidShell) tIsAllowed = true; + break; + case AsteroidInnerCore: + if (pBlockPosition == Enums.TargetBlockPosition.AsteroidInnerCore) tIsAllowed = true; + break; + default: + break; + } + + if (tIsAllowed) { + pWorld.setBlock(eX, eY, eZ, bmc.getBlock(), bmc.getMeta(), 2); + tFlag = false; + } + } + } + } + return tFlag; + } + + /** + * Pick a random small-ore block from the list of enabled small ores for this dim + * + * @param pDimDef + * @param pRandom + * @return + */ + private boolean doGenerateSmallOreBlock(ModDimensionDef pDimDef, Random pRandom, World pWorld, + DynamicDimensionConfig.AsteroidConfig pAConf, int pX, int pY, int pZ, int pTargetBlockOffset) { + boolean tFlag = true; + // If smallores are enabled... + if (pAConf.SmallOreChance > 0) { + // ... and we hit the random-chance ... + if (pRandom.nextInt(100) < pAConf.SmallOreChance) { + // Do small ores. + int tRandomWeight; + boolean continueSearch = true; + int tFoundOreMeta = -1; + // First find a small ore... + for (int i = 0; (i < 256) && (continueSearch); i++) { + tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); + for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { + + if (!(tWorldGen instanceof WorldgenOreSmallSpace)) { + continue; + } + // That is enabled for *this* dim... + if (!((WorldgenOreSmallSpace) tWorldGen).isEnabledForDim(pDimDef)) continue; + + // And in the correct y-level, of ObeyLimits is true... + if (pAConf.ObeyHeightLimits && !((WorldgenOreSmallSpace) tWorldGen).isAllowedForHeight(pY)) + continue; + + // Care about weight + tRandomWeight -= ((WorldgenOreSmallSpace) tWorldGen).mAmount; + if (tRandomWeight <= 0) { + // And return found ore meta + tFoundOreMeta = ((WorldgenOreSmallSpace) tWorldGen).mMeta; + continueSearch = false; + } + } + } + if (tFoundOreMeta > -1) { + // Make the oreID a small ore with correct type + int tCustomOffset = (GTOreTypes.SmallOres.getOffset() + pTargetBlockOffset); + + // Set the smallOre block + TileEntitySpaceOres + .setOuterSpaceOreBlock(pDimDef, pWorld, pX, pY, pZ, tFoundOreMeta, true, tCustomOffset); + tFlag = false; + } + } + } + return tFlag; + } + + /** + * Untested! But should work... Comments are todo + * + * @param pDimensionDef + * @param pRandom + * @param pWorld + * @param pX + * @param pZ + * @param pBiome + * @param pChunkGenerator + * @param pChunkProvider + */ + private void Generate_OreVeins(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, int pX, int pZ, + String pBiome, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + GalacticGreg.Logger.trace("Running orevein-gen in Dim %s", pDimensionDef.getDimIdentifier()); + + if (GTWorldgenerator.isOreChunk(pX / 16, pZ / 16)) { + if ((WorldgenOreLayerSpace.sWeight > 0) && (GalacticGreg.oreVeinWorldgenList.size() > 0)) { + + boolean temp = true; + int tRandomWeight; + for (int i = 0; (i < 256) && (temp); i++) { + tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); + for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { + if (tWorldGen instanceof WorldgenOreLayerSpace) + tRandomWeight -= ((WorldgenOreLayerSpace) tWorldGen).mWeight; + + if (tRandomWeight <= 0) { + try { + if (tWorldGen.executeWorldgen( + pWorld, + pRandom, + pBiome, + Integer.MIN_VALUE, + pX, + pZ, + pChunkGenerator, + pChunkProvider)) { + temp = false; + } + } catch (Throwable e) { + e.printStackTrace(GTLog.err); + } + break; + } + } + } + } + // Generate Small Ores + + int i = 0; + for (int tX = pX - 16; i < 3; tX += 16) { + int j = 0; + for (int tZ = pZ - 16; j < 3; tZ += 16) { + for (GTWorldgen tWorldGen : GalacticGreg.smallOreWorldgenList) { + try { + tWorldGen.executeWorldgen( + pWorld, + pRandom, + "", + Integer.MIN_VALUE, + tX, + tZ, + pChunkGenerator, + pChunkProvider); + } catch (Throwable e) { + e.printStackTrace(GTLog.err); + } + } + j++; + } + i++; + } + } + GalacticGreg.Logger.trace("Leaving orevein-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } +} diff --git a/src/main/java/galacticgreg/WorldgenGaGT.java b/src/main/java/galacticgreg/WorldgenGaGT.java new file mode 100644 index 0000000000..5814660fe7 --- /dev/null +++ b/src/main/java/galacticgreg/WorldgenGaGT.java @@ -0,0 +1,28 @@ +package galacticgreg; + +import gregtech.api.enums.OreMixes; +import gregtech.api.enums.SmallOres; + +public class WorldgenGaGT implements Runnable { + + @Override + public void run() { + new WorldGeneratorSpace(); + + /* + * This part here enables every GT Small Ore for Space Dims. + */ + for (SmallOres ore : SmallOres.values()) { + ore.addGaGregSmallOre(); + } + + /* + * This part here enables every GT Ore for Space Dims. + */ + + for (OreMixes mix : OreMixes.values()) { + mix.addGaGregOreLayer(); + } + } + +} diff --git a/src/main/java/galacticgreg/WorldgenOreLayerSpace.java b/src/main/java/galacticgreg/WorldgenOreLayerSpace.java new file mode 100644 index 0000000000..c28eb7a392 --- /dev/null +++ b/src/main/java/galacticgreg/WorldgenOreLayerSpace.java @@ -0,0 +1,320 @@ +package galacticgreg; + +import static gregtech.api.enums.GTValues.oreveinPlacerOres; +import static gregtech.api.enums.GTValues.oreveinPlacerOresMultiplier; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import galacticgreg.api.ModContainer; +import galacticgreg.api.ModDimensionDef; +import galacticgreg.auxiliary.GTOreGroup; +import galacticgreg.registry.GalacticGregRegistry; +import gregtech.api.util.GTLog; +import gregtech.api.world.GTWorldgen; +import gregtech.common.OreMixBuilder; + +public class WorldgenOreLayerSpace extends GTWorldgen { + + public static int sWeight = 0; + public final short mMinY; + public final short mMaxY; + public final short mWeight; + public final short mDensity; + public final short mSize; + public final short mPrimaryMeta; + public final short mSecondaryMeta; + public final short mBetweenMeta; + public final short mSporadicMeta; + + private long mProfilingStart; + private long mProfilingEnd; + private Map allowedDims; + + public WorldgenOreLayerSpace(OreMixBuilder mix) { + super(mix.oreMixName, GalacticGreg.oreVeinWorldgenList, mix.enabledByDefault); + + mMinY = (short) mix.minY; + mMaxY = (short) Math.max(this.mMinY + 5, mix.maxY); + mWeight = (short) mix.weight; + mDensity = (short) mix.density; + mSize = (short) Math.max(1, mix.size); + mPrimaryMeta = (short) mix.primary.mMetaItemSubID; + mSecondaryMeta = (short) mix.secondary.mMetaItemSubID; + mBetweenMeta = (short) mix.between.mMetaItemSubID; + mSporadicMeta = (short) mix.sporadic.mMetaItemSubID; + + allowedDims = new HashMap<>(); + + for (ModContainer mc : GalacticGregRegistry.getModContainers()) { + if (!mc.getEnabled()) continue; + + for (ModDimensionDef mdd : mc.getDimensionList()) { + String tDimIdentifier = mdd.getDimIdentifier(); + if (allowedDims.containsKey(tDimIdentifier)) GalacticGreg.Logger.error( + "Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", + tDimIdentifier); + else { + boolean tFlag = mix.dimsEnabled.getOrDefault(mdd.getDimensionName(), false); + allowedDims.put(tDimIdentifier, tFlag); + } + } + } + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", mix.oreMixName); + if (mEnabled) sWeight += this.mWeight; + } + + /** + * Check if *this* orelayer is enabled for pDimensionDef + * + * @param pDimensionDef the ChunkProvider in question + * @return + */ + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) { + return allowedDims.getOrDefault(pDimensionDef.getDimIdentifier(), false); + } + + private static Map> _mBufferedVeinList = new HashMap<>(); + + /** + * Get a List of all Veins which are enabled for given Dim. Query is buffered + * + * @param pDimensionDef + * @return null if nothing is found or error + */ + private static List getOreMixIDsForDim(ModDimensionDef pDimensionDef) { + List tReturn; + + if (_mBufferedVeinList.containsKey(pDimensionDef.getDimIdentifier())) + tReturn = _mBufferedVeinList.get(pDimensionDef.getDimIdentifier()); + else { + tReturn = new ArrayList<>(); + for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) if (tWorldGen instanceof WorldgenOreLayerSpace + && ((WorldgenOreLayerSpace) tWorldGen).isEnabledForDim(pDimensionDef)) + tReturn.add(tWorldGen.mWorldGenName); + + _mBufferedVeinList.put(pDimensionDef.getDimIdentifier(), tReturn); + } + + return tReturn; + } + + /** + * Select a random ore-vein from the list + * + * @param pDimensionDef + * @param pRandom + * @return + */ + public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random pRandom, boolean pIgnoreWeight) { + short primaryMeta = 0; + short secondaryMeta = 0; + short betweenMeta = 0; + short sporadicMeta = 0; + + if (pIgnoreWeight) { + List tEnabledVeins = getOreMixIDsForDim(pDimensionDef); + int tRnd = pRandom.nextInt(tEnabledVeins.size()); + String tVeinName = tEnabledVeins.get(tRnd); + + GTWorldgen tGen = null; + for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) if (tWorldGen instanceof WorldgenOreLayerSpace + && ((WorldgenOreLayerSpace) tWorldGen).mWorldGenName.equals(tVeinName)) tGen = tWorldGen; + + if (tGen != null) { + // GT_Worldgen_GT_Ore_Layer_Space tGen = GalacticGreg.oreVeinWorldgenList.get(tRndMix); + GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tGen.mWorldGenName); + primaryMeta = ((WorldgenOreLayerSpace) tGen).mPrimaryMeta; + secondaryMeta = ((WorldgenOreLayerSpace) tGen).mSecondaryMeta; + betweenMeta = ((WorldgenOreLayerSpace) tGen).mBetweenMeta; + sporadicMeta = ((WorldgenOreLayerSpace) tGen).mSporadicMeta; + } + } else { + if ((WorldgenOreLayerSpace.sWeight > 0) && (GalacticGreg.oreVeinWorldgenList.size() > 0)) { + GalacticGreg.Logger.trace("About to select oremix"); + boolean temp = true; + int tRandomWeight; + for (int i = 0; (i < 256) && (temp); i++) { + tRandomWeight = pRandom.nextInt(WorldgenOreLayerSpace.sWeight); + for (GTWorldgen tWorldGen : GalacticGreg.oreVeinWorldgenList) { + if (!(tWorldGen instanceof WorldgenOreLayerSpace)) continue; + + tRandomWeight -= ((WorldgenOreLayerSpace) tWorldGen).mWeight; + if (tRandomWeight <= 0) { + try { + if (((WorldgenOreLayerSpace) tWorldGen).isEnabledForDim(pDimensionDef)) { + GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tWorldGen.mWorldGenName); + primaryMeta = ((WorldgenOreLayerSpace) tWorldGen).mPrimaryMeta; + secondaryMeta = ((WorldgenOreLayerSpace) tWorldGen).mSecondaryMeta; + betweenMeta = ((WorldgenOreLayerSpace) tWorldGen).mBetweenMeta; + sporadicMeta = ((WorldgenOreLayerSpace) tWorldGen).mSporadicMeta; + + temp = false; + break; + } + } catch (Throwable e) { + e.printStackTrace(GTLog.err); + } + } + } + } + } + } + if (primaryMeta != 0 || secondaryMeta != 0 || betweenMeta != 0 || sporadicMeta != 0) + return new GTOreGroup(primaryMeta, secondaryMeta, betweenMeta, sporadicMeta); + else return null; + } + + @Override + public boolean executeWorldgen(World pWorld, Random pRandom, String pBiome, int pDimensionType, int pChunkX, + int pChunkZ, IChunkProvider pChunkGenerator, IChunkProvider pChunkProvider) { + GalacticGreg.Logger.trace("Entering executeWorldgen for [%s]", mWorldGenName); + ModDimensionDef tMDD = GalacticGregRegistry.getDimensionTypeByChunkGenerator(pChunkGenerator); + if (tMDD == null) { + GalacticGreg.Logger + .trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkGenerator.toString()); + return false; + } + + if (!isEnabledForDim(tMDD)) { + GalacticGreg.Logger + .trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); + return false; + } + + if (GalacticGr