From 753cc02b152c83dc1067847684ddc17011ddd283 Mon Sep 17 00:00:00 2001 From: Namikon Date: Thu, 2 Jul 2015 16:09:32 +0200 Subject: Moved from Bitbucket to Github. We're open source, yaay --- .../galacticgreg/GT_TileEntity_Ores_Space.java | 132 ++++++ .../GT_Worldgen_GT_Ore_Layer_Space.java | 193 ++++++++ .../GT_Worldgen_GT_Ore_SmallPieces_Space.java | 95 ++++ .../galacticgreg/GT_Worldgenerator_Space.java | 518 +++++++++++++++++++++ .../java/bloodasp/galacticgreg/GalacticGreg.java | 109 +++++ .../java/bloodasp/galacticgreg/ModRegisterer.java | 199 ++++++++ .../java/bloodasp/galacticgreg/WorldGenGaGT.java | 95 ++++ .../galacticgreg/api/AsteroidBlockComb.java | 74 +++ .../bloodasp/galacticgreg/api/BlockMetaComb.java | 45 ++ src/main/java/bloodasp/galacticgreg/api/Enums.java | 62 +++ .../java/bloodasp/galacticgreg/api/GTOreTypes.java | 69 +++ .../galacticgreg/api/ISpaceObjectGenerator.java | 51 ++ .../bloodasp/galacticgreg/api/ModContainer.java | 91 ++++ .../java/bloodasp/galacticgreg/api/ModDBMDef.java | 154 ++++++ .../bloodasp/galacticgreg/api/ModDimensionDef.java | 474 +++++++++++++++++++ .../galacticgreg/api/SpecialBlockComb.java | 66 +++ .../galacticgreg/api/StructureInformation.java | 60 +++ .../galacticgreg/auxiliary/ConfigManager.java | 81 ++++ .../galacticgreg/auxiliary/GTOreGroup.java | 19 + .../galacticgreg/auxiliary/GalacticGregConfig.java | 128 +++++ .../bloodasp/galacticgreg/auxiliary/LogHelper.java | 250 ++++++++++ .../galacticgreg/auxiliary/PlayerChatHelper.java | 115 +++++ .../galacticgreg/auxiliary/ProfilingStorage.java | 87 ++++ .../galacticgreg/command/AEStorageCommand.java | 189 ++++++++ .../galacticgreg/command/ProfilingCommand.java | 100 ++++ .../dynconfig/DynamicDimensionConfig.java | 173 +++++++ .../dynconfig/DynamicOreMixWorldConfig.java | 95 ++++ .../galacticgreg/generators/GenEllipsoid.java | 136 ++++++ .../registry/GalacticGregRegistry.java | 183 ++++++++ .../galacticgreg/schematics/SpaceSchematic.java | 107 +++++ .../schematics/SpaceSchematicFactory.java | 34 ++ .../schematics/SpaceSchematicHandler.java | 206 ++++++++ .../schematics/SpaceSchematicWrapper.java | 109 +++++ 33 files changed, 4499 insertions(+) create mode 100644 src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java create mode 100644 src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java create mode 100644 src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java create mode 100644 src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java create mode 100644 src/main/java/bloodasp/galacticgreg/GalacticGreg.java create mode 100644 src/main/java/bloodasp/galacticgreg/ModRegisterer.java create mode 100644 src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/Enums.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/ModContainer.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java create mode 100644 src/main/java/bloodasp/galacticgreg/api/StructureInformation.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java create mode 100644 src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java create mode 100644 src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java create mode 100644 src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java create mode 100644 src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java create mode 100644 src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java create mode 100644 src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java create mode 100644 src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java create mode 100644 src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java create mode 100644 src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java create mode 100644 src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java create mode 100644 src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java (limited to 'src/main/java') diff --git a/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java b/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java new file mode 100644 index 0000000000..5bd3a8cbb9 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GT_TileEntity_Ores_Space.java @@ -0,0 +1,132 @@ +package bloodasp.galacticgreg; + +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_Log; +import gregtech.common.blocks.GT_TileEntity_Ores; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import bloodasp.galacticgreg.api.Enums.ReplaceState; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; + +public class GT_TileEntity_Ores_Space { + + // 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 ReplaceState CheckForReplaceableBlock(World pWorld, int pX, int pY, int pZ, ModDimensionDef pDimDef) + { + try + { + ReplaceState tFlag = ReplaceState.Unknown; + + Block targetBlock = pWorld.getBlock(pX, pY, pZ); + int targetBlockMeta = pWorld.getBlockMetadata(pX, pY, pZ); + + if (targetBlock == Blocks.air) + tFlag = ReplaceState.Airblock; + else + tFlag = pDimDef.getReplaceStateForBlock(targetBlock, targetBlockMeta); + + return tFlag; + } + catch(Exception e) + { + e.printStackTrace(GT_Log.err); + GalacticGreg.Logger.error("Error while processing CheckForReplaceableBlock(), defaulting to UNKNOWN"); + return 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; + } + + 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) + { + 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 == ReplaceState.Unknown) + { + GalacticGreg.Logger.trace("Not placing ore Meta %d, as target block is unknown", pMetaData); + return false; + } + else if(tRS == ReplaceState.Airblock && !pAir) + { + GalacticGreg.Logger.trace("Not placing ore Meta %d in midair, as AIR is FALSE", pMetaData); + return false; + } + if (tRS == 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; + + pWorld.setBlock(pX, pY, pZ, GregTech_API.sBlockOres1, GT_TileEntity_Ores.getHarvestData((short) pMetaData), 0); + TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ); + if ((tTileEntity instanceof GT_TileEntity_Ores)) { + ((GT_TileEntity_Ores) tTileEntity).mMetaData = ((short) pMetaData); + ((GT_TileEntity_Ores) 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); + } + return false; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java new file mode 100644 index 0000000000..fb3f9a13ea --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_Layer_Space.java @@ -0,0 +1,193 @@ +package bloodasp.galacticgreg; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.util.GT_Log; +import gregtech.api.world.GT_Worldgen; + +import java.util.ArrayList; +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.auxiliary.GTOreGroup; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; + +public class GT_Worldgen_GT_Ore_Layer_Space extends GT_Worldgen { + 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 DynamicOreMixWorldConfig _mDynWorldConfig = null; + + public GT_Worldgen_GT_Ore_Layer_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pWeight, int pDensity, int pSize, Materials pPrimary, Materials pSecondary, Materials pBetween, Materials pSporadic) + { + super(pName, GalacticGreg.oreVeinWorldgenList, pDefault); + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max(this.mMinY + 5, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mWeight = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "RandomWeight", pWeight)); + mDensity = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Density", pDensity)); + mSize = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Size", pSize))); + mPrimaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OrePrimaryLayer", pPrimary.mMetaItemSubID)); + mSecondaryMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSecondaryLayer", pSecondary.mMetaItemSubID)); + mBetweenMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporadiclyInbetween", pBetween.mMetaItemSubID)); + mSporadicMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "OreSporaticlyAround", pSporadic.mMetaItemSubID)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + + 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 _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + /** + * Select a random ore-vein from the list + * + * @param pDimensionDef + * @param pRandom + * @return + */ + public static GTOreGroup getRandomOreGroup(ModDimensionDef pDimensionDef, Random pRandom) + { + short primaryMeta = 0; + short secondaryMeta = 0; + short betweenMeta = 0; + short sporadicMeta = 0; + if ((GT_Worldgen_GT_Ore_Layer_Space.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(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen_GT_Ore_Layer_Space tWorldGen : GalacticGreg.oreVeinWorldgenList) + { + tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer_Space) tWorldGen).mWeight; + if (tRandomWeight <= 0) + { + + try + { + if (tWorldGen.isEnabledForDim(pDimensionDef)) + { + GalacticGreg.Logger.trace("Using Oremix %s for asteroid", tWorldGen.mWorldGenName); + primaryMeta = tWorldGen.mPrimaryMeta; + secondaryMeta = tWorldGen.mSecondaryMeta; + betweenMeta = tWorldGen.mBetweenMeta; + sporadicMeta = tWorldGen.mSporadicMeta; + + temp = false; + break; + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.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(pChunkProvider); + if (tMDD == null) + { + GalacticGreg.Logger.trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkProvider.toString()); + return false; + } + + if (!_mDynWorldConfig.isEnabledInDim(tMDD)) + { + GalacticGreg.Logger.trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); + return false; + } + + if (GalacticGreg.GalacticConfig.ProfileOreGen) + mProfilingStart = System.currentTimeMillis(); + // --------------------------- + int tMinY = this.mMinY + pRandom.nextInt(this.mMaxY - this.mMinY - 5); + + int cX = pChunkX - pRandom.nextInt(this.mSize); + int eX = pChunkX + 16 + pRandom.nextInt(this.mSize); + for (int tX = cX; tX <= eX; tX++) { + int cZ = pChunkZ - pRandom.nextInt(this.mSize); + int eZ = pChunkZ + 16 + pRandom.nextInt(this.mSize); + for (int tZ = cZ; tZ <= eZ; tZ++) { + if (this.mSecondaryMeta > 0) { + for (int i = tMinY - 1; i < tMinY + 2; i++) { + if ((pRandom.nextInt(Math.max(1, Math.max(Math.abs(cZ - tZ), Math.abs(eZ - tZ)) / this.mDensity)) == 0) + || (pRandom.nextInt(Math.max(1, Math.max(Math.abs(cX - tX), Math.abs(eX - tX)) / this.mDensity)) == 0)) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mSecondaryMeta); + } + } + } + if ((this.mBetweenMeta > 0) + && ((pRandom.nextInt(Math.max(1, Math.max(Math.abs(cZ - tZ), Math.abs(eZ - tZ)) / this.mDensity)) == 0) || (pRandom.nextInt(Math.max(1, + Math.max(Math.abs(cX - tX), Math.abs(eX - tX)) / this.mDensity)) == 0))) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, tMinY + 2 + pRandom.nextInt(2), tZ, this.mBetweenMeta); + } + if (this.mPrimaryMeta > 0) { + for (int i = tMinY + 3; i < tMinY + 6; i++) { + if ((pRandom.nextInt(Math.max(1, Math.max(Math.abs(cZ - tZ), Math.abs(eZ - tZ)) / this.mDensity)) == 0) + || (pRandom.nextInt(Math.max(1, Math.max(Math.abs(cX - tX), Math.abs(eX - tX)) / this.mDensity)) == 0)) { + + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, i, tZ, this.mPrimaryMeta); + } + } + } + if ((this.mSporadicMeta > 0) + && ((pRandom.nextInt(Math.max(1, Math.max(Math.abs(cZ - tZ), Math.abs(eZ - tZ)) / this.mDensity)) == 0) || (pRandom.nextInt(Math.max(1, + Math.max(Math.abs(cX - tX), Math.abs(eX - tX)) / this.mDensity)) == 0))) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, tX, tMinY - 1 + pRandom.nextInt(7), tZ, this.mSporadicMeta); + } + } + } + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) + { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); + GalacticGreg.Logger.debug("Done with OreLayer-Worldgen in DimensionType %s. Generation took %d ms", tMDD.getDimensionName(), tTotalTime); + } catch (Exception e) { } // Silently ignore errors + } + + + GalacticGreg.Logger.trace("Leaving executeWorldgen"); + return true; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java new file mode 100644 index 0000000000..eaf07907ed --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GT_Worldgen_GT_Ore_SmallPieces_Space.java @@ -0,0 +1,95 @@ +package bloodasp.galacticgreg; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.world.GT_Worldgen; + +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicOreMixWorldConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; + +public class GT_Worldgen_GT_Ore_SmallPieces_Space extends GT_Worldgen { + public final short mMinY; + public final short mMaxY; + public final short mAmount; + public final short mMeta; + + private long mProfilingStart; + private long mProfilingEnd; + private DynamicOreMixWorldConfig _mDynWorldConfig = null; + + public GT_Worldgen_GT_Ore_SmallPieces_Space(String pName, boolean pDefault, int pMinY, int pMaxY, int pAmount, Materials pPrimary) + { + super(pName, GalacticGreg.smallOreWorldgenList, pDefault); + + mMinY = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MinHeight", pMinY)); + mMaxY = ((short) Math.max(this.mMinY + 1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "MaxHeight", pMaxY))); + mAmount = ((short) Math.max(1, GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Amount", pAmount))); + mMeta = ((short) GregTech_API.sWorldgenFile.get("worldgen." + this.mWorldGenName, "Ore", pPrimary.mMetaItemSubID)); + + _mDynWorldConfig = new DynamicOreMixWorldConfig(mWorldGenName); + _mDynWorldConfig.InitDynamicConfig(); + + GalacticGreg.Logger.trace("Initialized new OreLayer: %s", pName); + } + + /** + * Check if *this* orelayer is enabled for pDimensionDef + * @param pDimensionDef the ChunkProvider in question + * @return + */ + public boolean isEnabledForDim(ModDimensionDef pDimensionDef) + { + return _mDynWorldConfig.isEnabledInDim(pDimensionDef); + } + + @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(pChunkProvider); + if (tMDD == null) + { + GalacticGreg.Logger.trace("Can't find dimension definition for ChunkProvider %s, skipping", pChunkProvider.toString()); + return false; + } + + if (!_mDynWorldConfig.isEnabledInDim(tMDD)) + { + GalacticGreg.Logger.trace("OreGen for %s is disallowed in dimension %s, skipping", mWorldGenName, tMDD.getDimensionName()); + return false; + } + + if (GalacticGreg.GalacticConfig.ProfileOreGen) + mProfilingStart = System.currentTimeMillis(); + // --------------------------- + + if (this.mMeta > 0) { + int i = 0; + for (int j = Math.max(1, this.mAmount / 2 + pRandom.nextInt(this.mAmount) / 2); i < j; i++) { + GT_TileEntity_Ores_Space.setOuterSpaceOreBlock(tMDD, pWorld, pChunkX + pRandom.nextInt(16), this.mMinY + pRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), pChunkZ + pRandom.nextInt(16), this.mMeta + 16000); + } + } + // --------------------------- + if (GalacticGreg.GalacticConfig.ProfileOreGen) + { + try { + mProfilingEnd = System.currentTimeMillis(); + long tTotalTime = mProfilingEnd - mProfilingStart; + GalacticGreg.Profiler.AddTimeToList(tMDD, tTotalTime); + GalacticGreg.Logger.debug("Done with SmallOre-Worldgen in DimensionType %s. Generation took %d ms", tMDD.getDimensionName(), tTotalTime); + } catch (Exception e) { } // Silently ignore errors + } + + GalacticGreg.Logger.trace("Leaving executeWorldgen"); + return true; + } + + public boolean isAllowedForHeight(int pTargetHeight) { + return (pTargetHeight >= mMinY && pTargetHeight <= mMaxY); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java b/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java new file mode 100644 index 0000000000..0666350267 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GT_Worldgenerator_Space.java @@ -0,0 +1,518 @@ +package bloodasp.galacticgreg; + +import gregtech.api.util.GT_Log; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntityChest; +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 bloodasp.galacticgreg.api.AsteroidBlockComb; +import bloodasp.galacticgreg.api.BlockMetaComb; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.GTOreTypes; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.api.SpecialBlockComb; +import bloodasp.galacticgreg.api.StructureInformation; +import bloodasp.galacticgreg.auxiliary.GTOreGroup; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig.AsteroidConfig; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.eventhandler.EventBus; +import cpw.mods.fml.common.registry.GameRegistry; + +public class GT_Worldgenerator_Space 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 GT_Worldgenerator_Space() { + 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() == DimensionType.Asteroid || tDimDef.getDimensionType() == DimensionType.AsteroidAndPlanet) + { + 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() == DimensionType.Planet || tDimDef.getDimensionType() == DimensionType.AsteroidAndPlanet) + { + 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()); + + 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 = GT_Worldgen_GT_Ore_Layer_Space.getRandomOreGroup(pDimensionDef, pRandom); + 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(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) + { + int tChance = pRandom.nextInt(1000); // Loot chest is 1 in 1000 + if (tAConf.LootChestChance >= tChance) + { + // 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; + + // try to find any block that is not on the asteroids outer-shell + 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() != TargetBlockPosition.AsteroidShell) + { + // 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 + 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()) + { + // 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); + } + } + 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) + { + // 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... + if (tFinalOreMeta > 0) + { + // make sure we obey the configured "HiddenOres" setting (No ores on the shell) + if (tAConf.HiddenOres && si.getBlockPosition() != TargetBlockPosition.AsteroidShell) + { + // try to place the ore block. The result is stored in tPlacedOreBlock + tPlacedOreBlock = GT_TileEntity_Ores_Space.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) + { + boolean tFlag = true; + + // try to spawn special blocks + 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 e) { } // 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 + * @param tDoGenerateRegularBlock + * @return + */ + private boolean doGenerateSpecialBlocks(ModDimensionDef pDimensionDef, Random pRandom, World pWorld, AsteroidConfig tAConf, int eX, int eY, int eZ, 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 == TargetBlockPosition.AsteroidCore) + tIsAllowed = true; + break; + case AsteroidCoreAndShell: + if (pBlockPosition == TargetBlockPosition.AsteroidCore || pBlockPosition == TargetBlockPosition.AsteroidShell) + tIsAllowed = true; + break; + case AsteroidShell: + if (pBlockPosition == TargetBlockPosition.AsteroidShell) + tIsAllowed = true; + break; + case AsteroidInnerCore: + if (pBlockPosition == 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, 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(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen_GT_Ore_SmallPieces_Space tWorldGen : GalacticGreg.smallOreWorldgenList) + { + // That is enabled for *this* dim... + if (!tWorldGen.isEnabledForDim(pDimDef)) + continue; + + // And in the correct y-level, of ObeyLimits is true... + if (pAConf.ObeyHeightLimits && !tWorldGen.isAllowedForHeight(pY)) + continue; + + // Care about weight + tRandomWeight -= tWorldGen.mAmount; + if (tRandomWeight <= 0) + { + // And return found ore meta + tFoundOreMeta = 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 + GT_TileEntity_Ores_Space.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 ((Math.abs(pX / 16) % 3 == 1) && (Math.abs(pZ / 16) % 3 == 1)) + { + if ((GT_Worldgen_GT_Ore_Layer_Space.sWeight > 0) && (GalacticGreg.oreVeinWorldgenList.size() > 0)) + { + + boolean temp = true; + int tRandomWeight; + for (int i = 0; (i < 256) && (temp); i++) + { + tRandomWeight = pRandom.nextInt(GT_Worldgen_GT_Ore_Layer_Space.sWeight); + for (GT_Worldgen_GT_Ore_Layer_Space tWorldGen : GalacticGreg.oreVeinWorldgenList) + { + tRandomWeight -= tWorldGen.mWeight; + if (tRandomWeight <= 0) + { + try + { + if (tWorldGen.executeWorldgen(pWorld, pRandom, pBiome, Integer.MIN_VALUE, pX, pZ, pChunkGenerator, pChunkProvider)) + { + temp = false; + break; + } + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + } + } + } + } + // 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 (GT_Worldgen_GT_Ore_SmallPieces_Space tWorldGen : GalacticGreg.smallOreWorldgenList) { + try { + tWorldGen.executeWorldgen(pWorld, pRandom, "", Integer.MIN_VALUE, tX, tZ, pChunkGenerator, pChunkProvider); + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + } + j++; + } + i++; + } + } + GalacticGreg.Logger.trace("Leaving orevein-gen for Dim %s", pDimensionDef.getDimIdentifier()); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/GalacticGreg.java b/src/main/java/bloodasp/galacticgreg/GalacticGreg.java new file mode 100644 index 0000000000..1d4253f01d --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GalacticGreg.java @@ -0,0 +1,109 @@ +package bloodasp.galacticgreg; + +import gregtech.api.GregTech_API; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import bloodasp.galacticgreg.auxiliary.GalacticGregConfig; +import bloodasp.galacticgreg.auxiliary.LogHelper; +import bloodasp.galacticgreg.auxiliary.ProfilingStorage; +import bloodasp.galacticgreg.command.AEStorageCommand; +import bloodasp.galacticgreg.command.ProfilingCommand; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import bloodasp.galacticgreg.schematics.SpaceSchematic; +import bloodasp.galacticgreg.schematics.SpaceSchematicFactory; +import bloodasp.galacticgreg.schematics.SpaceSchematicHandler; +import cpw.mods.fml.common.Loader; +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; + +@Mod(modid = GalacticGreg.MODID, version = GalacticGreg.VERSION, dependencies = "required-after:GalacticraftCore; required-after:gregtech;", 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 VERSION = "GRADLETOKEN_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.."); + + if (GalacticConfig.ProperConfigured) + { + GalacticRandom = new Random(System.currentTimeMillis()); + + if (GalacticConfig.SchematicsEnabled) + SchematicHandler = new SpaceSchematicHandler(aEvent.getModConfigurationDirectory()); + } + else + GalacticGreg.Logger.error("GalacticGreg will NOT continue to load. Please read the warnings and configure your config file!"); + + Logger.trace("Leaving PRELOAD"); + } + + /** + * 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 (GalacticConfig.ProperConfigured) + { + ModRegisterer atc = new ModRegisterer(); + if (atc.Init()) + atc.Register(); + + if (!GalacticGregRegistry.InitRegistry()) + throw new RuntimeException("GalacticGreg registry has been finalized from a 3rd-party mod, this is forbidden!"); + + new WorldGenGaGT().run(); + + 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.ProperConfigured) + { + if (GalacticConfig.ProfileOreGen) + pEvent.registerServerCommand(new ProfilingCommand()); + + if (Loader.isModLoaded("appliedenergistics2") && GalacticConfig.EnableAEExportCommand && GalacticConfig.SchematicsEnabled) + pEvent.registerServerCommand(new AEStorageCommand()); + } + Logger.trace("Leaving SERVERLOAD"); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/ModRegisterer.java b/src/main/java/bloodasp/galacticgreg/ModRegisterer.java new file mode 100644 index 0000000000..99e7c10aa4 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/ModRegisterer.java @@ -0,0 +1,199 @@ +package bloodasp.galacticgreg; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.init.Blocks; +import net.minecraft.world.gen.ChunkProviderEnd; +import micdoodle8.mods.galacticraft.core.blocks.GCBlocks; +import micdoodle8.mods.galacticraft.core.world.gen.ChunkProviderMoon; +import bloodasp.galacticgreg.api.*; +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; +import bloodasp.galacticgreg.api.Enums.DimensionType; + +/** + * 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 ModRegisterer +{ + /** + * Just a helper to convert a single element to a list + * @param pDef + * @return + */ + private List singleToList(ModDBMDef pDef) + { + List tLst = new ArrayList(); + tLst.add(pDef); + return tLst; + } + + private static Method registerModContainer; + /** + * Use loose binding of the register-method. Should be enough to + * provide support for GGreg without the requirement to have it in a modpack at all + * @param pModContainer + */ + public static void registerModContainer(ModContainer pModContainer) + { + try { + registerModContainer.invoke(null, pModContainer); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Try to get the instance of GalacticGregs registry in order to register stuff + * @return + */ + public boolean Init() + { + try + { + Class gGregRegistry = Class.forName("bloodasp.galacticgreg.registry.GalacticGregRegistry"); + registerModContainer = gGregRegistry.getMethod("registerModContainer", ModContainer.class); + + return true; + } + catch (Exception e) + { + // GalacticGreg is not installed or something is wrong + return false; + } + } + + public void Register() + { + if (GalacticGreg.GalacticConfig.RegisterVanillaDim) + registerModContainer(Setup_Vanilla()); + + if (GalacticGreg.GalacticConfig.RegisterGalacticCraftCore) + registerModContainer(Setup_GalactiCraftCore()); + + if (GalacticGreg.GalacticConfig.RegisterGalacticCraftPlanets) + registerModContainer(Setup_GalactiCraftPlanets()); + + if (GalacticGreg.GalacticConfig.RegisterGalaxySpace) + registerModContainer(Setup_GalaxySpace()); + } + + /** + * Vanilla MC (End Asteroids) + */ + private ModContainer Setup_Vanilla() + { + // --- Mod Vanilla (Heh, "mod") + ModContainer modMCVanilla = new ModContainer("Vanilla"); + + // 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! + ModDimensionDef dimEndAsteroids = new ModDimensionDef("EndAsteroids", ChunkProviderEnd.class); + + dimEndAsteroids.setDimensionType(DimensionType.Asteroid); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + dimEndAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.EndStone)); + + // These Blocks will randomly be generated + dimEndAsteroids.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.glowstone)); + dimEndAsteroids.addSpecialAsteroidBlock(new SpecialBlockComb(Blocks.lava, AllowedBlockPosition.AsteroidCore)); + + modMCVanilla.addDimensionDef(dimEndAsteroids); + + return modMCVanilla; + } + + /** + * Mod GalactiCraft + * Just another setup based on existing classes, due the fact that we're working with GalactiCraft + */ + private ModContainer Setup_GalactiCraftCore() + { + ModContainer modGCraftCore = new ModContainer("GalacticraftCore"); + ModDBMDef DBMMoon = new ModDBMDef(GCBlocks.blockMoon, 4); + + modGCraftCore.addDimensionDef(new ModDimensionDef("Moon", ChunkProviderMoon.class, singleToList(DBMMoon))); + + return modGCraftCore; + } + + + /** + * As GalactiCraftPlanets is an optional mod, don't hardlink it here + * @return + */ + private ModContainer Setup_GalactiCraftPlanets() + { + ModContainer modGCraftPlanets = new ModContainer("GalacticraftMars"); + ModDBMDef DBMMars = new ModDBMDef("tile.mars", 9); + + modGCraftPlanets.addDimensionDef(new ModDimensionDef("Mars", "micdoodle8.mods.galacticraft.planets.mars.world.gen.ChunkProviderMars", singleToList(DBMMars))); + + ModDimensionDef dimAsteroids = new ModDimensionDef("Asteroids", "micdoodle8.mods.galacticraft.planets.asteroids.world.gen.ChunkProviderAsteroids"); + dimAsteroids.setDimensionType(DimensionType.Asteroid); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.BlackGranite)); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.RedGranite)); + dimAsteroids.addAsteroidMaterial(new AsteroidBlockComb(GTOreTypes.Netherrack)); + modGCraftPlanets.addDimensionDef(dimAsteroids); + + return modGCraftPlanets; + } + + /** + * Mod GalaxySpace by BlesseNtumble + */ + private ModContainer Setup_GalaxySpace() + { + // First, we create a mod-container that will be populated with dimensions later. + // The Name must match your modID, as it is checked if this mod is loaded, in order + // to enable/disable the parsing/registering of dimensions + ModContainer modCGalaxySpace = new ModContainer("GalaxySpace"); + + // Now lets first define a block here for our dimension. You can add the modID, but you don't have to. + // It will automatically add the mods name that is defined in the modcontainer. + ModDBMDef DBMPhobos = new ModDBMDef("phobosstone"); + ModDBMDef DBMDeimos = new ModDBMDef("deimossubgrunt"); + ModDBMDef DBMCeres = new ModDBMDef("ceressubgrunt"); + ModDBMDef DBMIO = new ModDBMDef("iorock", 4); // This meta-4 is a copy&paste bug in GSpace and might not work in further versions + ModDBMDef DBMEurpoa = new ModDBMDef("europaice"); + ModDBMDef DBMGanymede = new ModDBMDef("ganymedesubgrunt"); + ModDBMDef DBMCallisto = new ModDBMDef("callistosubice"); + ModDBMDef DBMVenus = new ModDBMDef("venussubgrunt"); + ModDBMDef DBMMercury = new ModDBMDef("mercurycore"); + ModDBMDef DBMEnceladus = new ModDBMDef("enceladusrock"); + ModDBMDef DBMTitan = new ModDBMDef("titanstone"); + ModDBMDef DBMOberon = new ModDBMDef("oberonstone"); + ModDBMDef DBMProteus = new ModDBMDef("proteusstone"); + ModDBMDef DBMTriton = new ModDBMDef("tritonstone"); + ModDBMDef DBMPluto = new ModDBMDef("plutostone"); + + // 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! + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Pluto", "blessentumble.planets.pluto.dimension.ChunkProviderPluto", singleToList(DBMPluto))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Triton", "blessentumble.moons.triton.dimension.ChunkProviderTriton", singleToList(DBMTriton))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Proteus", "blessentumble.moons.proteus.dimension.ChunkProviderProteus", singleToList(DBMProteus))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Oberon", "blessentumble.moons.oberon.dimension.ChunkProviderOberon", singleToList(DBMOberon))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Titan", "blessentumble.moons.titan.dimension.ChunkProviderTitan", singleToList(DBMTitan))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Callisto", "blessentumble.moons.callisto.dimension.ChunkProviderCallisto", singleToList(DBMCallisto))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Ganymede", "blessentumble.moons.ganymede.dimension.ChunkProviderGanymede", singleToList(DBMGanymede))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Ceres", "blessentumble.planets.ceres.dimension.ChunkProviderCeres", singleToList(DBMCeres))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Deimos", "blessentumble.moons.deimos.dimension.ChunkProviderDeimos", singleToList(DBMDeimos))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Enceladus", "blessentumble.moons.enceladus.dimension.ChunkProviderEnceladus", singleToList(DBMEnceladus))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Io", "blessentumble.moons.io.dimension.ChunkProviderIo", singleToList(DBMIO))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Europa", "blessentumble.moons.europa.dimension.ChunkProviderEuropa", singleToList(DBMEurpoa))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Phobos", "blessentumble.moons.phobos.dimension.ChunkProviderPhobos", singleToList(DBMPhobos))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Venus", "blessentumble.planets.venus.dimension.ChunkProviderVenus", singleToList(DBMVenus))); + modCGalaxySpace.addDimensionDef(new ModDimensionDef("Mercury", "blessentumble.planets.mercury.dimension.ChunkProviderMercury", singleToList(DBMMercury))); + + return modCGalaxySpace; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java b/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java new file mode 100644 index 0000000000..fb6cc83e73 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/WorldGenGaGT.java @@ -0,0 +1,95 @@ +package bloodasp.galacticgreg; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; + +public class WorldGenGaGT implements Runnable { + + @Override + public void run() { + new GT_Worldgenerator_Space(); + + // Register all well-known generators here + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.copper", true, 60, 120, 32, Materials.Copper); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.tin", true, 60, 120, 32, Materials.Tin); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.bismuth", true, 80, 120, 8, Materials.Bismuth); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.coal", true, 60, 100, 24, Materials.Coal); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.iron", true, 40, 80, 16, Materials.Iron); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.lead", true, 40, 80, 16, Materials.Lead); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.zinc", true, 30, 60, 12, Materials.Zinc); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.gold", true, 20, 40, 8, Materials.Gold); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.silver", true, 20, 40, 8, Materials.Silver); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.nickel", true, 20, 40, 8, Materials.Nickel); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.lapis", true, 20, 40, 4, Materials.Lapis); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.diamond", true, 5, 10, 2, Materials.Diamond); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.redstone", true, 5, 20, 8, Materials.Redstone); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.platinum", true, 20, 40, 8, Materials.Platinum); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.iridium", true, 20, 40, 8, Materials.Iridium); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.netherquartz", true, 30, 120, 64, Materials.NetherQuartz); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.saltpeter", true, 10, 60, 8, Materials.Saltpeter); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sulfur_n", true, 10, 60, 32, Materials.Sulfur); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sulfur_o", true, 5, 15, 8, Materials.Sulfur); + + // Same for gems + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.emerald", true, 5, 250, 1, Materials.Emerald); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.ruby", true, 5, 250, 1, Materials.Ruby); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.sapphire", true, 5, 250, 1, Materials.Sapphire); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.greensapphire", true, 5, 250, 1, Materials.GreenSapphire); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.olivine", true, 5, 250, 1, Materials.Olivine); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.topaz", true, 5, 250, 1, Materials.Topaz); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.tanzanite", true, 5, 250, 1, Materials.Tanzanite); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.amethyst", true, 5, 250, 1, Materials.Amethyst); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.opal", true, 5, 250, 1, Materials.Opal); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.jasper", true, 5, 250, 1, Materials.Jasper); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.bluetopaz", true, 5, 250, 1, Materials.BlueTopaz); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.amber", true, 5, 250, 1, Materials.Amber); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.foolsruby", true, 5, 250, 1, Materials.FoolsRuby); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.garnetred", true, 5, 250, 1, Materials.GarnetRed); + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.garnetyellow", true, 5, 250, 1, Materials.GarnetYellow); + + // Parse all custom small ores + int f = 0; + for (int j = GregTech_API.sWorldgenFile.get("worldgen", "AmountOfCustomSmallOreSlots", 16); f < j; f++) + new GT_Worldgen_GT_Ore_SmallPieces_Space("ore.small.custom." + (f < 10 ? "0" : "") + f, false, 0, 0, 0, Materials._NULL); + + + // Register all well-known generators here, this time oreVeins + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.naquadah", false, 10, 60, 10, 5, 32, Materials.Naquadah, Materials.Naquadah, Materials.Naquadah, Materials.NaquadahEnriched); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.lignite", true, 50, 130, 160, 8, 32, Materials.Lignite, Materials.Lignite, Materials.Lignite, Materials.Coal); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.coal", true, 50, 80, 80, 6, 32, Materials.Coal, Materials.Coal, Materials.Coal, Materials.Lignite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.magnetite", true, 50, 120, 160, 3, 32, Materials.Magnetite, Materials.Magnetite, Materials.Iron, Materials.VanadiumMagnetite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.gold", true, 60, 80, 160, 3, 32, Materials.Magnetite, Materials.Magnetite, Materials.VanadiumMagnetite, Materials.Gold); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.iron", true, 10, 40, 120, 4, 24, Materials.BrownLimonite, Materials.YellowLimonite, Materials.BandedIron, Materials.Malachite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.cassiterite", true, 40, 120, 50, 5, 24, Materials.Tin, Materials.Tin, Materials.Cassiterite, Materials.Tin); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.tetrahedrite", true, 80, 120, 70, 4, 24, Materials.Tetrahedrite, Materials.Tetrahedrite, Materials.Copper, Materials.Stibnite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.netherquartz", true, 40, 80, 80, 5, 24, Materials.NetherQuartz, Materials.NetherQuartz, Materials.NetherQuartz, Materials.NetherQuartz); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.sulfur", true, 5, 20, 100, 5, 24, Materials.Sulfur, Materials.Sulfur, Materials.Pyrite, Materials.Sphalerite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.copper", true, 10, 30, 80, 4, 24, Materials.Chalcopyrite, Materials.Iron, Materials.Pyrite, Materials.Copper); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.bauxite", true, 50, 90, 80, 4, 24, Materials.Bauxite, Materials.Bauxite, Materials.Aluminium, Materials.Ilmenite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.salts", true, 50, 60, 50, 3, 24, Materials.RockSalt, Materials.Salt, Materials.Lepidolite, Materials.Spodumene); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.redstone", true, 10, 40, 60, 3, 24, Materials.Redstone, Materials.Redstone, Materials.Ruby, Materials.Cinnabar); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.soapstone", true, 10, 40, 40, 3, 16, Materials.Soapstone, Materials.Talc, Materials.Glauconite, Materials.Pentlandite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.nickel", true, 10, 40, 40, 3, 16, Materials.Garnierite, Materials.Nickel, Materials.Cobaltite, Materials.Pentlandite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.platinum", true, 40, 50, 5, 3, 16, Materials.Cooperite, Materials.Palladium, Materials.Platinum, Materials.Iridium); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.pitchblende", true, 10, 40, 40, 3, 16, Materials.Pitchblende, Materials.Pitchblende, Materials.Uranium, Materials.Uraninite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.plutonium", true, 20, 30, 10, 3, 16, Materials.Uraninite, Materials.Uraninite, Materials.Plutonium, Materials.Uranium); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.monazite", true, 20, 40, 30, 3, 16, Materials.Bastnasite, Materials.Bastnasite, Materials.Monazite, Materials.Neodymium); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.molybdenum", true, 20, 50, 5, 3, 16, Materials.Wulfenite, Materials.Molybdenite, Materials.Molybdenum, Materials.Powellite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.tungstate", true, 20, 50, 10, 3, 16, Materials.Scheelite, Materials.Scheelite, Materials.Tungstate, Materials.Lithium); + new GT_Worldgen_GT_Ore_L