diff options
Diffstat (limited to 'src/main/java/bloodasp/galacticgreg')
33 files changed, 4501 insertions, 0 deletions
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..02f45a1187 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/GalacticGreg.java @@ -0,0 +1,111 @@ +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<GT_Worldgen_GT_Ore_SmallPieces_Space> smallOreWorldgenList = new ArrayList(); + public static final List<GT_Worldgen_GT_Ore_Layer_Space> 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(); + } + else + GalacticGreg.Logger.error("GalacticGreg will NOT continue to load. Please read the warnings and configure your config file!"); + 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<ModDBMDef> singleToList(ModDBMDef pDef) + { + List<ModDBMDef> tLst = new ArrayList<ModDBMDef>(); + 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: <ModID>_<Name you give here as arg0>_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_Layer_Space("ore.mix.sapphire", true, 10, 40, 60, 3, 16, Materials.Almandine, Materials.Pyrope, Materials.Sapphire, Materials.GreenSapphire); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.manganese", true, 20, 30, 20, 3, 16, Materials.Grossular, Materials.Spessartine, Materials.Pyrolusite, Materials.Tantalite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.quartz", true, 40, 80, 60, 3, 16, Materials.Quartzite, Materials.Barite, Materials.CertusQuartz, Materials.CertusQuartz); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.diamond", true, 5, 20, 40, 2, 16, Materials.Graphite, Materials.Graphite, Materials.Diamond, Materials.Coal); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.olivine", true, 10, 40, 60, 3, 16, Materials.Bentonite, Materials.Magnesite, Materials.Olivine, Materials.Glauconite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.apatite", true, 40, 60, 60, 3, 16, Materials.Apatite, Materials.Apatite, Materials.Phosphorus, Materials.Phosphate); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.galena", true, 30, 60, 40, 5, 16, Materials.Galena, Materials.Galena, Materials.Silver, Materials.Lead); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.lapis", true, 20, 50, 40, 5, 16, Materials.Lazurite, Materials.Sodalite, Materials.Lapis, Materials.Calcite); + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.beryllium", true, 5, 30, 30, 3, 16, Materials.Beryllium, Materials.Beryllium, Materials.Emerald, Materials.Thorium); + + // Parse all custom ore veins + int i = 0; + for (int j = GregTech_API.sWorldgenFile.get("worldgen", "AmountOfCustomLargeVeinSlots", 16); i < j; i++) { + new GT_Worldgen_GT_Ore_Layer_Space("ore.mix.custom." + (i < 10 ? "0" : "") + i, false, 0, 0, 0, 0, 0, Materials._NULL, Materials._NULL, Materials._NULL, Materials._NULL); + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java b/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java new file mode 100644 index 0000000000..901a94e270 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/AsteroidBlockComb.java @@ -0,0 +1,74 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +/** + * Class for a bit more advanced combinations for Asteroids, which supports Custom Blocks as base material + * and Values required to generate Gregtech ores + */ +public class AsteroidBlockComb extends BlockMetaComb { + private final GTOreTypes _mGTOreMaterial; + + /** + * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block + * for the asteroid material + * @param pOreType The GregTech oreType + * @param pBlock Your block + */ + public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock) { + super(pBlock, 0); + _mGTOreMaterial = pOreType; + } + + /** + * Create an advanced definition which uses the GregTech-OreType values for ores, and your own definition of Block + * for the asteroid material + * @param pOreType The GregTech oreType + * @param pBlock Your block + * @param pMeta The metavalue for your block (If required) + */ + public AsteroidBlockComb(GTOreTypes pOreType, Block pBlock, int pMeta) { + super(pBlock, pMeta); + _mGTOreMaterial = pOreType; + } + + /** + * Create a simple definition which uses the GregTech-OreType values for both asteroidStone and ores + * @param pOreType The GregTech oreType + */ + public AsteroidBlockComb(GTOreTypes pOreType) { + super(pOreType.getBlock(), pOreType.getMeta()); + _mGTOreMaterial = pOreType; + } + + /**Internal function + * + * @return The GT Material for the oregen + */ + public GTOreTypes getOreMaterial() { + return _mGTOreMaterial; + } + + @Override + public boolean equals(Object other) + { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof AsteroidBlockComb))return false; + AsteroidBlockComb otherObj = (AsteroidBlockComb)other; + + boolean tFlag = true; + String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); + String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); + if (!otherName.equals(thisName)) + tFlag = false; + + if (!(otherObj.getMeta() == this.getMeta())) + tFlag = false; + + if (!(otherObj.getOreMaterial() == this.getOreMaterial())) + tFlag = false; + + return tFlag; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java b/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java new file mode 100644 index 0000000000..3c98223774 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/BlockMetaComb.java @@ -0,0 +1,45 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; + +/** + * Class used for Simple Block - Meta constructs + */ +public class BlockMetaComb { + private int mMeta; + private Block mBlock; + + /** Creates a simple instance for a block that has no meta value + * @param pBlock The Block in question. 0 is used as meta + */ + public BlockMetaComb(Block pBlock) + { + this(pBlock, 0); + } + + /** Creates a simple instance for a block with a meta value + * @param pBlock The Block in question + * @param pMeta The MetaValue in question ([block]:[meta]) + */ + public BlockMetaComb(Block pBlock, int pMeta) + { + mMeta = pMeta; + mBlock = pBlock; + } + + /**Internal function + * + * @return The metadata for this block + */ + public int getMeta() { + return mMeta; + } + + /**Internal function + * + * @return The block + */ + public Block getBlock() { + return mBlock; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/Enums.java b/src/main/java/bloodasp/galacticgreg/api/Enums.java new file mode 100644 index 0000000000..9109d375bc --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/Enums.java @@ -0,0 +1,62 @@ +package bloodasp.galacticgreg.api; + +public class Enums { + public enum SpaceObjectType + { + OreAsteroid, + NonOreSchematic + } + + public enum TargetBlockPosition + { + Invalid, + AsteroidInnerCore, + AsteroidCore, + AsteroidShell, + StructureBlock + } + + public enum AllowedBlockPosition + { + AsteroidInnerCore, + AsteroidCore, + AsteroidShell, + AsteroidCoreAndShell + } + + public enum AirReplaceRule + { + NeverReplaceAir, + AllowReplaceAir, + OnlyReplaceAir + } + + public enum ReplaceState + { + Unknown, + Airblock, + CanReplace, + CannotReplace + } + + public enum DimensionType + { + /** + * The Dimension is a void dimension and asteroids shall be generated. They will randomly spawn bewteen 0 and 250 + * Additional config values will be generated in worldconfig + */ + Asteroid, + + /** + * The Dimension is a planet, and only ores shall be generated in the ground + */ + Planet, + + /** + * The Dimension is a special dim where Asteroids *and* ores shall spawn. + * Additional config values will be generated in worldconfig + */ + AsteroidAndPlanet + } + +} diff --git a/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java b/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java new file mode 100644 index 0000000000..0106cd0e6e --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/GTOreTypes.java @@ -0,0 +1,69 @@ +package bloodasp.galacticgreg.api; + +import gregtech.api.GregTech_API; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; + +/** + * Representation of the various GregTech ores, with their counterpart in VanillaBlocks, and + * the OreOffset that is required to generate the proper ores + */ +public enum GTOreTypes { + /** + * The Definition for Gregtech's RedGranite + **/ + RedGranite(4000, GregTech_API.sBlockGranites, 8, 3), + /** + * The Definition for Gregtech's BlackGranite + */ + BlackGranite(3000, GregTech_API.sBlockGranites, 0, 3), + /** + * The Definition for EndStone + */ + EndStone(2000, Blocks.end_stone, 0, 0), + /** + * The Definition for Netherrack + */ + Netherrack(1000, Blocks.netherrack, 0, 0), // Unsure about blockupdate value! + /** + * The Definition for SmallOres (And BlockType Stone) + */ + SmallOres(16000, Blocks.stone, 0, 0), // Unsure about blockupdate value! + /** + * The Definition for Ores (And BlockType Stone) + */ + NormalOres(0, Blocks.stone, 0, 0); // Unsure about blockupdate value! + + + private int _mOffset; + private Block _mStoneBlock; + private int _mBlockMeta; + private int _mUpdateMode; + + private GTOreTypes(int pOffset, Block pBlock, int pMeta, int pUpdateMode) + { + _mOffset = pOffset; + _mStoneBlock = pBlock; + _mBlockMeta = pMeta; + _mUpdateMode = pUpdateMode; + } + + public Block getBlock() + { + return _mStoneBlock; + } + + public int getMeta() + { + return _mBlockMeta; + } + + public int getOffset() + { + return _mOffset; + } + + public int getUpdateMode() { + return _mUpdateMode; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java b/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java new file mode 100644 index 0000000000..b51e5facb3 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/ISpaceObjectGenerator.java @@ -0,0 +1,51 @@ +package bloodasp.galacticgreg.api; + +import java.util.List; + +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import net.minecraft.util.Vec3; + +public interface ISpaceObjectGenerator { + Vec3 getCenterPoint(); + /** + * Set the center-point of the object to generate, by providing X, Y and Z directly + * @param pX + * @param pY + * @param pZ + */ + void setCenterPoint(int pX, int pY, int pZ); + + /** + * Set the center-point of the object to generate, by providing a Vec3 instance + * @param pCenter + */ + void setCenterPoint(Vec3 pCenter); + List<StructureInformation> getStructure(); + + /** + * Calculate the structure + * Called after randomize() + */ + void calculate(); + + /** + * Randomize the structure. + * Called before calculate() + * @param pSizeMin The minimum size for the structure. It is up to you how you handle this value. it's what the user sets in his config file + * @param pSizeMax The maximum size for the structure. It is up to you how you handle this value. it's what the user sets in his config file + */ + void randomize(int pSizeMin, int pSizeMax); + + /** + * Define the type of the generator. OreAsteroid will be used to spawn ores at given coordinates, + * where NonOreSchematic will use the Blocks provided in the structural information to generate your structure + * @return + */ + SpaceObjectType getType(); + + + /** + * This function is called every time the generator shall be reset in order to generate a blank, new structure + */ + void reset(); +} diff --git a/src/main/java/bloodasp/galacticgreg/api/ModContainer.java b/src/main/java/bloodasp/galacticgreg/api/ModContainer.java new file mode 100644 index 0000000000..9cea43b754 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/ModContainer.java @@ -0,0 +1,91 @@ +package bloodasp.galacticgreg.api; + +import java.util.ArrayList; +import java.util.List; + +/** + * Defines a Mod where this Generator shall be active. + * Note: This will only work (obviously) for Dimensions where either: + * - Gregtech has a hook in the OreGen + * or + * - For mods which are addons to GalactiCraft + * + */ +public class ModContainer { + private String _mModName; + private List<ModDimensionDef> _mDimensionLookup; + private boolean _mEnabled = false; + + + /**Internal function + * + * @return The state if the Registry could find the mod or not + */ + public boolean getEnabled() + { + return _mEnabled; + } + + /** Internal function + * + * Never set this to true. This is an internal marker which is set by the registry if the mod could be found or not + * @param pEnabled + */ + public void setEnabled(boolean pEnabled) + { + _mEnabled = pEnabled; + } + + + /** + * Define a new Mod where GT OreGen shall be enabled + * @param pModName The modID. Make sure to use the proper mod-id, or it won't load correctly + */ + public ModContainer(String pModName) + { + _mModName = pModName; + _mDimensionLookup = new ArrayList<ModDimensionDef>(); + } + + + /** Internal function + * + * @return The mods name + */ + public String getModName() + { + return _mModName; + } + + /** Internal function + * + * @return The list of attached dimensions for this mod + */ + public List<ModDimensionDef> getDimensionList() + { + return _mDimensionLookup; + } + + /** + * Adds a new dimension to this modcontainer. + * Make sure you've added all blocks there first + * @param pDimDef The dimension definition to be added + * @return true if it could be added, false if not + */ + public boolean addDimensionDef(ModDimensionDef pDimDef) + { + for (ModDimensionDef mdd : _mDimensionLookup) + { + if (mdd.getChunkProviderName().equals(pDimDef.getChunkProviderName())) + { + // Cannot add DimensionDefinition; The Given chunk-provider name is already taken! + return false; + } + } + + // Set the parent modName of this dimension. This will finalize it + pDimDef.setParentModName(_mModName); + _mDimensionLookup.add(pDimDef); + return true; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java b/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java new file mode 100644 index 0000000000..453909a919 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/ModDBMDef.java @@ -0,0 +1,154 @@ +package bloodasp.galacticgreg.api; + +import net.minecraft.block.Block; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.ReplaceState; + +/** + * Mod "Dimension Block Meta Definition" + * Defines the Block-Meta combination for Blocks that can be replaced by the oregen. + * + */ +public class ModDBMDef { + + private String _targetBlockName; + private int _targetMeta; + private boolean _canAlwaysReplace; + + public String getBlockName() { return _targetBlockName; } + public int getMeta() { return _targetMeta; } + public boolean getCanAlwaysReplace() { return _canAlwaysReplace; } + + /**Internal function + * + * Check if the given Block is equal to the block in this instance + * @param pBlock the Block in question + * @return + */ + public ReplaceState blockEquals(Block pBlock) + { + if (pBlock == null) + return ReplaceState.Unknown; + + if (Block.blockRegistry.getNameForObject(pBlock).equals(_targetBlockName)) + return ReplaceState.CanReplace; + else + return ReplaceState.CannotReplace; + } + + /**Internal function + * + * Check if the given Block is equal to the block in this instance and matches the metadata + * @param pBlock the block in question + * @param pMeta the metadata in question + * @return + */ + public ReplaceState blockEquals(Block pBlock, int pMeta) + { + ReplaceState tFlag = ReplaceState.Unknown; + if (blockEquals(pBlock) == ReplaceState.CanReplace) + { + if (pMeta == _targetMeta || _canAlwaysReplace) + tFlag = ReplaceState.CanReplace; + else + tFlag = ReplaceState.CannotReplace; + } + + return tFlag; + } + + @Override + public boolean equals(Object other) + { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof ModDBMDef))return false; + ModDBMDef otherModDBMDef = (ModDBMDef)other; + return (otherModDBMDef._targetBlockName.equals(_targetBlockName) && otherModDBMDef._targetMeta == _targetMeta); + } + + + /** Create a new "Block that can be replaced by ores" definition. + * Meta defaults to 0 here + * @param pTargetBlockName The unlocalizedName of the block + */ + public ModDBMDef(String pTargetBlockName) + { + this(pTargetBlockName, 0, false); + } + + /** Create a new "Block that can be replaced by ores" definition + * @param pTargetBlockName The unlocalizedName of the block + * @param pMetaData The blocks metadata + */ + public ModDBMDef(String pTargetBlockName, int pMetaData) + { + this(pTargetBlockName, pMetaData, false); + } + + /** Create a new "Block that can be replaced by ores" definition + * @param pTargetBlock The instance of the block that can be replaced + * @param pMetaData The blocks metadata + */ + public ModDBMDef(Block pTargetBlock, int pMetaData) + { + this(Block.blockRegistry.getNameForObject(pTargetBlock), pMetaData, false); + } + + /** Create a new "Block that can be replaced by ores" definition. + * Meta defaults to 0 here + * @param pTargetBlock The instance of the block that can be replaced + */ + public ModDBMDef(Block pTargetBlock) + { + this(Block.blockRegistry.getNameForObject(pTargetBlock), 0, false); + } + + /** Create a new "Block that can be replaced by ores" definition + * @param pTargetBlock + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: [block]:* + */ + public ModDBMDef(Block pTargetBlock, boolean pCanAlwaysReplace) + { + this(Block.blockRegistry.getNameForObject(pTargetBlock), -1, pCanAlwaysReplace); + } + + /** Create a new "Block that can be replaced by ores" definition + * @param pTargetBlockName The unlocalizedName of the block + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: [block]:* + */ + public ModDBMDef(String pTargetBlockName, boolean pCanAlwaysReplace) + { + this(pTargetBlockName, -1, false); + } + + /** Create a new "Block that can be replaced by ores" definition + * @param pTargetBlockName The unlocalizedName of the block + * @param pMetaData The blocks metadata + * @param pCanAlwaysReplace set to true if this block can always be replaced, regardless of it's metavalue. Like: [block]:* + */ + public ModDBMDef(String pTargetBlockName, int pMetaData, boolean pCanAlwaysReplace) + { + _targetBlockName = pTargetBlockName; + _targetMeta = pMetaData; + _canAlwaysReplace = pCanAlwaysReplace; + } + + /**Internal function + * Never run this function. It is used to update the blocks name when GalacticGreg is initializing its internal + * structures + * + * @param pParentModName The modname to be attached to the block-name + */ + public void updateBlockName(String pParentModName) + { + // Do we already have a FQBN? then do nothing + if (_targetBlockName.contains(":")) + { + GalacticGreg.Logger.trace("Not updating blockname, as it already contains a mods name: %s", _targetBlockName); + return; + } + GalacticGreg.Logger.trace("Updating blockname: Old: %s new: %s:%s", _targetBlockName, pParentModName, _targetBlockName); + _targetBlockName = String.format("%s:%s", pParentModName, _targetBlockName); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java b/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java new file mode 100644 index 0000000000..8c2ef5c3e8 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/ModDimensionDef.java @@ -0,0 +1,474 @@ +package bloodasp.galacticgreg.api; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.chunk.IChunkProvider; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.AirReplaceRule; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.Enums.ReplaceState; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; + +/** + * Class to define a Dimension. Supposed to be added to a ModContainer + */ +public class ModDimensionDef { + private static final String STR_NOTDEFINED = "iiznotdefined"; + private String _mDimensionName; + private String _mInternalDimIdentifier; + private String _mChunkProvider; + private AirReplaceRule _mDimAirSetting; + private ArrayList<ModDBMDef> _mReplaceableBlocks; + private DimensionType _mDimensionType; + + private List<ISpaceObjectGenerator> _mSpaceObjectsGenerators; + private List<ISpaceObjectGenerator> _mSpaceStructureGenerators; + + // Special Planets config settings + private int _mGroundOreMaxY = 64; + private int _mFloatingAsteroidsMinY = 128; + // ------ + + // Override for stonetype + private GTOreTypes _mStoneType; + + // Asteroid stuff + private List<AsteroidBlockComb> _mValidAsteroidMaterials; + private List<SpecialBlockComb> _mSpecialBlocksForAsteroids; + + private Random _mRandom = new Random(System.currentTimeMillis()); + + + /** Internal function + * @return A list of possible asteroid-mixes that shall be generated + */ + public List<AsteroidBlockComb> getValidAsteroidMaterials() + { + return _mValidAsteroidMaterials; + } + + // ================================================= + /** Internal function + * The only purpose of this functions is to get a default config value for this dim, that can be altered by + * the mod author which adds the dimension definition to his mod, but also provide the modpack-author/serveradmin + * to change these values aswell + */ + public int getPreConfiguratedGroundOreMaxY() + { + return _mGroundOreMaxY; + } + + /** Internal function + * The only purpose of this functions is to get a default config value for this dim, that can be altered by + * the mod author which adds the dimension definition to his mod, but also provide the modpack-author/serveradmin + * to change these values aswell + */ + public int getPreConfiguratedFloatingAsteroidMinY() + { + return _mFloatingAsteroidsMinY; + } + + /**Register new generator for objects in space. You can register as many as you want. + * If you don't register anything, no structures will generate and the default Asteroid-Generator will be used + * @param pSpaceObjectGenerator An instance of your own object generator + */ + public void registerSpaceObjectGenerator(ISpaceObjectGenerator pSpaceObjectGenerator) + { + SpaceObjectType tType = pSpaceObjectGenerator.getType(); + switch(tType) + { + case NonOreSchematic: + _mSpaceStructureGenerators.add(pSpaceObjectGenerator); + break; + case OreAsteroid: + _mSpaceObjectsGenerators.add(pSpaceObjectGenerator); + break; + default: + GalacticGreg.Logger.error("registerSpaceObjectGenerator() found unhandled generator type %s. Please report asap, the author was lazy!", tType.toString()); + break; + + } + } + + /**Internal function + * Return a random generator for space objects + */ + public ISpaceObjectGenerator getRandomSOGenerator(SpaceObjectType pTargetType) + { + ISpaceObjectGenerator tGen = null; + List<ISpaceObjectGenerator> tLst = null; + try + { + switch (pTargetType) + { + case NonOreSchematic: + tLst = _mSpaceStructureGenerators; + break; + case OreAsteroid: + tLst = _mSpaceObjectsGenerators; + break; + default: + break; + } + + if (tLst != null) + { + if (tLst.size() == 1) + tGen = tLst.get(0); + else if (tLst.size() > 1) + tGen = tLst.get(_mRandom.nextInt(tLst.size())); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + return tGen; + } + + /** + * Define the default values for the floating asteroids and the oregen here. + * As both generators run in the same dimension, and you probably don't want to + * have asteroids stuck in the ground, both generators are separated from each other. + * Basically, you can go with the default values. If you want to change them, make sure + * that pOregenMaxY is lower than pAsteroidMinY + * @param pOregenMaxY The maximum Y-height where ores will be allowed to spawn. Default: 64 + * @param pAsteroidMinY The minimum Y-height that has to be reached before asteroids will spawn. Default: 128 + * @throws IllegalArgumentException if the limits are invalid + * + */ + public void setAsteroidAndPlanetLimits(int pOregenMaxY, int pAsteroidMinY) + { + if (pOregenMaxY >= pAsteroidMinY) + throw new IllegalArgumentException("pOregenMaxY must be LOWER than pAsteroidMinY!"); + + _mFloatingAsteroidsMinY = pAsteroidMinY; + _mGroundOreMaxY = pOregenMaxY; + } + // ================================================= + + /**Internal function + * + * @return A list of all special blocks that shall be used to generate the asteroids. + */ + public List<SpecialBlockComb> getSpecialBlocksForAsteroids() + { + return _mSpecialBlocksForAsteroids; + } + + public List<ISpaceObjectGenerator> getSpaceObjectGenerators() + { + return _mSpaceObjectsGenerators; + } + + /**Internal function + * + * @return The type for this dimension + */ + public DimensionType getDimensionType() + { + return _mDimensionType; + } + + /** + * Set whether this DimensionDefinition defines an void-dimension that shall spawn asteroids instead of ores in stone + * @param pType The dimensiontype to be used + */ + public void setDimensionType(DimensionType pType) + { + _mDimensionType = pType; + } + + /**Internal function + * + * @return The configuration for AirBlocks + */ + public AirReplaceRule getAirSetting() + { + return _mDimAirSetting; + } + + /** + * Define how the oregen shall handle air-blocks. + * These settings should be pretty self-explandatory, but anyways: + * NeverReplaceAir: No matter what, if there is an Air-Block found, it will not replace it. + * AllowReplaceAir: This will generate Ores in Stones (defined by addBlockDefinition()) and air if found + * OnlyReplaceAir : This will not generate Ores in solid blocks, but only in air + * + * Note that "OnlyReplaceAir" is a special setting if you have a dimension that is not defined as "Asteroids" + * but you still need/want to generate ores in midair. + * @param pSetting + */ + public void setAirSetting(AirReplaceRule pSetting) + { + _mDimAirSetting = pSetting; + } + + /**Internal function + * + * @return The dimension identifier that is used internally to identify the dimension + */ + public String getDimIdentifier() + { + return _mInternalDimIdentifier; + } + + /** + * Set a manual override for ores that shall be generated. + * This setting is ignored if getIsAsteroidDimension() returns true + * + * For example, on GalactiCraft Mars, this value is set to GTOreTypes.RedGranite, because it matches the + * color better. If you don't set anything here, it will generate regular stone-ores. + * @param pOffset + */ + public void setStoneType(GTOreTypes pStoneType) + { + _mStoneType = pStoneType; + } + + /** Internal function + * + * @return The stone override for gregtech ores + */ + public GTOreTypes getStoneType() + { + return _mStoneType; + } + + /** Internal function + * + * @return The attached chunk-provider for this dimension + */ + public String getChunkProviderName() + { + return _mChunkProvider; + } + + /** + * Adds a new blockdefinition to this dimension. This block will then later be replaced by ores. + * You can add as many blocks as you want. Just don't add Blocks.Air, as there is another setting for allowing Air-Replacement + * @param pBlockDef + * @return + */ + public boolean addBlockDefinition(ModDBMDef pBlockDef) + { + if (_mReplaceableBlocks.contains(pBlockDef)) + { + GalacticGreg.Logger.error("Cannot add Block %s:%d, as it is already existing!", pBlockDef.getBlockName(), pBlockDef.getMeta()); + return false; + } + else + { + _mReplaceableBlocks.add(pBlockDef); + return true; + } + } + + /**Internal function + * + * @return The DimensionName in a Human-readable format + */ + public String getDimensionName() + { + return _mDimensionName; + } + + /**Internal function + * + * @return A list of all defined Blocks that can be replaced while generating ores + */ + public ArrayList<ModDBMDef> getReplaceableBlocks() + { + return _mReplaceableBlocks; + } + + /** Define a new dimension + * @param pDimensionName The human-readable. Spaces will be removed + * @param pChunkProvider The chunkprovider class that shall be observed for the oregen + */ + public ModDimensionDef(String pDimensionName, Class <? extends IChunkProvider> pChunkProvider) + { + this(pDimensionName, pChunkProvider.toString().substring(6), null); + } + + /** Define a new dimension + * @param pDimensionName The human-readable. Spaces will be removed + * @param pChunkProvider The chunkprovider class that shall be observed for the oregen + * @param pBlockDefinitions The list of predefined blocks to be replaced by ores + */ + public ModDimensionDef(String pDimensionName, Class <? extends IChunkProvider> pChunkProvider, List<ModDBMDef> pBlockDefinitions) + { + this(pDimensionName, pChunkProvider.toString().substring(6), pBlockDefinitions); + } + + /** Define a new dimension + * @param pDimensionName The human-readable DimensionName. Spaces will be removed + * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider + */ + public ModDimensionDef(String pDimensionName, String pChunkProviderName) + { + this(pDimensionName, pChunkProviderName, null); + } + + /** Define a new dimension + * @param pDimensionName The human-readable DimensionName. Spaces will be removed + * @param pChunkProviderName The human-readable, full-qualified classname for the chunkprovider + * @param pBlockDefinitions The list of predefined blocks to be replaced by ores + */ + public ModDimensionDef(String pDimensionName, String pChunkProviderName, List<ModDBMDef> pBlockDefinitions) + { + _mInternalDimIdentifier = STR_NOTDEFINED; + _mDimensionName = pDimensionName; + _mChunkProvider = pChunkProviderName; + + _mReplaceableBlocks = new ArrayList<ModDBMDef>(); + if (pBlockDefinitions != null) + _mReplaceableBlocks.addAll(pBlockDefinitions); + + _mValidAsteroidMaterials = new ArrayList<AsteroidBlockComb>(); + _mSpecialBlocksForAsteroids = new ArrayList<SpecialBlockComb>(); + _mSpaceObjectsGenerators = new ArrayList<ISpaceObjectGenerator>(); + _mSpaceStructureGenerators = new ArrayList<ISpaceObjectGenerator>(); + } + + /**Internal function + * + * Do not call this function by yourself. Ever. It will cause explosions, water to blood, death of firstborn,... + * Seriously, don't do it. + */ + protected void setParentModName(String pModName) + { + if (!_mInternalDimIdentifier.equals(STR_NOTDEFINED)) + return; // Don't update, we're already set + else + { + _mInternalDimIdentifier = String.format("%s_%s", pModName, _mDimensionName); + GalacticGreg.Logger.debug("Set Internal Identifier for Dimension %s to %s", _mDimensionName, _mInternalDimIdentifier); + } + } + + /**Internal function + * + * Check if pBlock can be replaced by an ore + * @param pBlock + * @param pMeta + * @return + */ + public ReplaceState getReplaceStateForBlock(Block pBlock, int pMeta) + { + ReplaceState tFlag = ReplaceState.Unknown; + + for (ModDBMDef pDef : _mReplaceableBlocks) + { + ReplaceState tResult = pDef.blockEquals(pBlock, pMeta); + if (tResult == ReplaceState.Unknown) + continue; + + if (tResult == ReplaceState.CanReplace) + { + GalacticGreg.Logger.trace("Targetblock found and metadata match. Replacement allowed"); + tFlag = ReplaceState.CanReplace; + } + else if (tResult == ReplaceState.CannotReplace) + { + GalacticGreg.Logger.trace("Targetblock found but metadata mismatch. Replacement denied"); + tFlag = ReplaceState.CannotReplace; + } + break; + } + + return tFlag; + } + + /**Internal function + * + * Randomly select one material out of all defined materials + * @return + */ + public AsteroidBlockComb getRandomAsteroidMaterial() + { + if (_mValidAsteroidMaterials.size() == 0) + return null; + + if (_mValidAsteroidMaterials.size() == 1) + return _mValidAsteroidMaterials.get(0); + else + { + return _mValidAsteroidMaterials.get(_mRandom.nextInt(_mValidAsteroidMaterials.size())); + } + } + + /**Internal function + * + * Randomly select one special block to be placed in the asteroids + * @return + */ + public SpecialBlockComb getRandomSpecialAsteroidBlock() + { + if (_mSpecialBlocksForAsteroids.size() == 0) + return null; + + if (_mSpecialBlocksForAsteroids.size() == 1) + return _mSpecialBlocksForAsteroids.get(0); + else + { + return _mSpecialBlocksForAsteroids.get(_mRandom.nextInt(_mSpecialBlocksForAsteroids.size())); + } + } + + /** + * Define the material the asteroid shall be made of. Limited to GT-Based Ores and their stones + * @param pMaterial + */ + public void addAsteroidMaterial(GTOreTypes pMaterial) + { + addAsteroidMaterial(new AsteroidBlockComb(pMaterial)); + } + + /** + * Define the material the asteroid shall be made of, more advanced option to specify your own blocks + * @param pMaterial + */ + public void addAsteroidMaterial(AsteroidBlockComb pBlockComb) { + if (_mValidAsteroidMaterials.contains(pBlockComb)) + return; + else + _mValidAsteroidMaterials.add(pBlockComb); + } + + /** + * Adds a new material for asteroid generation. These will spawn randomly in asteroids if enabled. + * You can basically add every block you can imagine. + * Be warned though, if you use Liquids (Water / Lava / ..), it can affect performance if the liquid + * is flowing down to the void. So make sure you define "AsteroidCore" as position + * @param pBlock Block-Meta Combination that shall be used + */ + public void addSpecialAsteroidBlock(SpecialBlockComb pBlock) { + if (_mSpecialBlocksForAsteroids.contains(pBlock)) + return; + else + _mSpecialBlocksForAsteroids.add(pBlock); + } + + /**Internal function + * Called when GalacticGreg will finalize all its internal structures. You should never call this yourself + */ + public void finalizeReplaceableBlocks(String pParentModName) + { + for (ModDBMDef rpb : _mReplaceableBlocks) + { + try + { + rpb.updateBlockName(pParentModName); + } + catch(Exception e) + { + GalacticGreg.Logger.error("Unable to finalize replaceable block with modname for block %s. Dimension %s will probably have problems generating ores", rpb.getBlockName(), _mDimensionName); + continue; + } + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java b/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java new file mode 100644 index 0000000000..857e379629 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/SpecialBlockComb.java @@ -0,0 +1,66 @@ +package bloodasp.galacticgreg.api; + +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; +import net.minecraft.block.Block; + +public class SpecialBlockComb extends BlockMetaComb { + private AllowedBlockPosition _mBlockPosition; + + /** Creates a simple instance for a block that has a meta value and a block position it is allowed to spawn + * @param pBlock The Block in question + * @param pMeta The meta value of the block + * @param pBlockPosition The position this block is allowed to generate + */ + public SpecialBlockComb(Block pBlock, int pMeta, AllowedBlockPosition pBlockPosition) { + super(pBlock, pMeta); + _mBlockPosition = pBlockPosition; + } + + /** Creates a simple instance for a block that has no meta value but a position it is allowed to spawn + * @param pBlock The Block in question. 0 is used as meta + * @param pBlockPosition The position this block is allowed to generate + */ + public SpecialBlockComb(Block pBlock, AllowedBlockPosition pBlockPosition) { + super(pBlock, 0); + _mBlockPosition = pBlockPosition; + } + + /** Creates a simple instance for a block that has no meta value and is allowed to spawn everywhere + * @param pBlock The Block in question. 0 is used as meta, and "CoreAndShell" is used as position + */ + public SpecialBlockComb(Block pBlock) { + super(pBlock, 0); + _mBlockPosition = AllowedBlockPosition.AsteroidCoreAndShell; + } + + /** Internal function + * @return The position the block is supposed to spawn at + */ + public AllowedBlockPosition getBlockPosition() + { + return _mBlockPosition; + } + + @Override + public boolean equals(Object other) + { + if (other == null) return false; + if (other == this) return true; + if (!(other instanceof SpecialBlockComb))return false; + SpecialBlockComb otherObj = (SpecialBlockComb)other; + + boolean tFlag = true; + String otherName = Block.blockRegistry.getNameForObject(otherObj.getBlock()); + String thisName = Block.blockRegistry.getNameForObject(this.getBlock()); + if (!otherName.equals(thisName)) + tFlag = false; + + if (!(otherObj.getMeta() == this.getMeta())) + tFlag = false; + + if (!(otherObj.getBlockPosition() == this.getBlockPosition())) + tFlag = false; + + return tFlag; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java b/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java new file mode 100644 index 0000000000..a053a9cbf6 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/api/StructureInformation.java @@ -0,0 +1,60 @@ +package bloodasp.galacticgreg.api; + +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import net.minecraft.util.Vec3; + +/** + * Structural information container. Holds X/Y/Z and block/meta information + */ +public class StructureInformation { + private Vec3 _mCoordinates; + private TargetBlockPosition _mBlockPosition; + private BlockMetaComb _mBlockMetaComb; + + public TargetBlockPosition getBlockPosition() + { + return _mBlockPosition; + } + + public int getX() + { + return (int) Math.round(_mCoordinates.xCoord); + } + + public int getY() + { + return (int) Math.round(_mCoordinates.yCoord); + } + + public int getZ() + { + return (int) Math.round(_mCoordinates.zCoord); + } + + public BlockMetaComb getBlock() + { + return _mBlockMetaComb; + } + + /** + * Init StructureInfo only with Coords and block position + * @param pCoordinates The coords in question + * @param pPosition The position-enum value + */ + public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition) { + this(pCoordinates, pPosition, null); + } + + /** + * Init StructureInfo with Coords, block position and a populated block/meta info + * @param pCoordinates The coords in question + * @param pPosition The position-enum value + * @param pTargetBlock The target block in question + */ + public StructureInformation(Vec3 pCoordinates, TargetBlockPosition pPosition, BlockMetaComb pTargetBlock) { + _mCoordinates = pCoordinates; + _mBlockPosition = pPosition; + _mBlockMetaComb = pTargetBlock; + } + +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java new file mode 100644 index 0000000000..9f337f945e --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java @@ -0,0 +1,81 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.io.File; + +import bloodasp.galacticgreg.GalacticGreg; +import net.minecraftforge.common.config.Configuration; + +/** + * config class to read/setup config files and folders + * @author Namikon + */ +public abstract class ConfigManager { + private File _mainconfigDir = null; + private File _blocksconfigDir = null; + private String _mModCollection = ""; + private String _mModID = ""; + + protected Configuration _mainConfig = null; + + protected File _mConfigBaseDirectory; + public boolean DoDebugMessages = false; + + protected abstract void PreInit(); + protected abstract void Init(); + protected abstract void PostInit(); + + + public ConfigManager(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) + { + _mModCollection = pModCollectionDirectory; + _mModID = pModID; + _mConfigBaseDirectory = pConfigBaseDirectory; + } + + /** + * Load/init the config file + * @return true/false if the load/init was successful or not + */ + public boolean LoadConfig() + { + try + { + InitConfigDirs(); + if (_mainConfig == null) + return false; + + PreInit(); + _mainConfig.load(); + Init(); + _mainConfig.save(); + PostInit(); + + return true; + } + catch (Exception e) + { + GalacticGreg.Logger.error("Unable to init config file"); + e.printStackTrace(); + return false; + } + } + + /** + * Search for required config-directory / file and create them if they can't be found + */ + private void InitConfigDirs() + { + GalacticGreg.Logger.debug("Checking/creating config folders"); + + _mainconfigDir = new File(String.format("%s%s%s", _mConfigBaseDirectory, File.separator, _mModCollection)); + + if(!_mainconfigDir.exists()) { + GalacticGreg.Logger.info("Config folder not found. Creating..."); + _mainconfigDir.mkdir(); + } + + File tRealConfigFile = new File(String.format("%s%s%s%s", _mainconfigDir, File.separator, _mModID, ".cfg")); + + _mainConfig = new Configuration(tRealConfigFile); + } +}
\ No newline at end of file diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java new file mode 100644 index 0000000000..e59c22e102 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java @@ -0,0 +1,19 @@ +package bloodasp.galacticgreg.auxiliary; + +/** + * Just a simple container to wrap 4 GT Ore-Meta ids into one var + */ +public class GTOreGroup { + public short PrimaryMeta; + public short SecondaryMeta; + public short SporadicBetweenMeta; + public short SporadicAroundMeta; + + public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) + { + PrimaryMeta = pPrimaryMeta; + SecondaryMeta = pSecondaryMeta; + SporadicBetweenMeta = pSporadicBetweenMeta; + SporadicAroundMeta = pSporadicAroundMeta; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java new file mode 100644 index 0000000000..f640f61193 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java @@ -0,0 +1,128 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.io.File; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.BlockMetaComb; +import cpw.mods.fml.common.registry.GameRegistry; + +public class GalacticGregConfig extends ConfigManager { + + public GalacticGregConfig(File pConfigBaseDirectory, + String pModCollectionDirectory, String pModID) { + super(pConfigBaseDirectory, pModCollectionDirectory, pModID); + + } + + public boolean ProfileOreGen; + public boolean ReportOreGenFailures; + public boolean PrintDebugMessagesToFMLLog; + public boolean PrintTraceMessagesToFMLLog; + + public boolean RegisterVanillaDim; + public boolean RegisterGalacticCraftCore; + public boolean RegisterGalacticCraftPlanets; + public boolean RegisterGalaxySpace; + public boolean LootChestsEnabled; + public boolean EnableAEExportCommand; + public boolean SchematicsEnabled; + public boolean ProperConfigured; + public String LootChestItemOverride; + public boolean QuietMode; + + public BlockMetaComb CustomLootChest; + + @Override + protected void PreInit() { + ProfileOreGen = false; + ReportOreGenFailures = false; + PrintDebugMessagesToFMLLog = false; + PrintTraceMessagesToFMLLog = false; + + LootChestsEnabled = true; + + RegisterVanillaDim = true; + RegisterGalacticCraftCore = true; + RegisterGalacticCraftPlanets = true; + RegisterGalaxySpace = true; + + // Default false, as it is WiP + EnableAEExportCommand = false; + SchematicsEnabled = false; + + ProperConfigured = false; + LootChestItemOverride = ""; + QuietMode = false; + } + + @Override + protected void Init() { + ProfileOreGen = _mainConfig.getBoolean("ProfileOreGen", "Debug", ProfileOreGen, "Enable to profile oregen and register the ingame command ggregprofiler"); + ReportOreGenFailures = _mainConfig.getBoolean("ReportOreGenFailures", "Debug", ReportOreGenFailures, "Report if a ore tileentity could not be placed"); + PrintDebugMessagesToFMLLog = _mainConfig.getBoolean("PrintDebugMessagesToFMLLog", "Debug", PrintDebugMessagesToFMLLog, "Enable debug output, not recommended for servers"); + PrintTraceMessagesToFMLLog = _mainConfig.getBoolean("PrintTraceMessagesToFMLLog", "Debug", PrintTraceMessagesToFMLLog, "Enable trace output. Warning: This will produce gazillions of log entries"); + QuietMode = _mainConfig.getBoolean("QuietMode", "Debug", QuietMode, "In quiet-mode only errors, warnings and fatals will be printed to the logfile/console"); + + RegisterVanillaDim = _mainConfig.getBoolean("RegisterVanillaDim", "BuildInMods", RegisterVanillaDim, "Enable to register the build-in dimension definition for TheEnd - Asteroids"); + RegisterGalacticCraftCore = _mainConfig.getBoolean("RegisterGalacticCraftCore", "BuildInMods", RegisterGalacticCraftCore, "Enable to register the build-in dimension definition for GalacticCraft Core (The moon)"); + RegisterGalacticCraftPlanets = _mainConfig.getBoolean("RegisterGalacticCraftPlanets", "BuildInMods", RegisterGalacticCraftPlanets, "Enable to register the build-in dimension definition for GalacticCraft Planets (Mars, asteroids)"); + RegisterGalaxySpace = _mainConfig.getBoolean("RegisterGalaxySpace", "BuildInMods", RegisterGalaxySpace, "Enable to register the build-in dimension definition for GalaxySpace by BlesseNtumble"); + + LootChestsEnabled = _mainConfig.getBoolean("LootChestsEnabled", "Extras", LootChestsEnabled, "Enables/disables the dungeon-chest generator system for asteroids. New config values will be generated if set to true"); + EnableAEExportCommand = _mainConfig.getBoolean("EnableAEExportCommand", "Extras", EnableAEExportCommand, "If set to true, you can export any structure stored on a AE2 spatial storage disk. (Can't be spawned yet, WiP). Requires SchematicsEnabled to be true"); + SchematicsEnabled = _mainConfig.getBoolean("SchematicsEnabled", "Extras", SchematicsEnabled, "Enable the experimental Schematics-handler to spawn exported schematics in dimensions. This is WiP, use at own risk"); + ProperConfigured = _mainConfig.getBoolean("IHaveConfiguredEverything", "main", ProperConfigured, "Set this to true to confirm that you've read the warnings about the massive change in WorldConfig.cfg and you backed-up / configured everything properly"); + LootChestItemOverride = _mainConfig.getString("CustomLootChest", "Extras", LootChestItemOverride, "Define the chest you wish to use as LootChest. use the <ModID>:<Name>:<meta> format or leave empty for the default Minecraft Chest"); + + GalacticGreg.Logger.setDebugOutput(PrintDebugMessagesToFMLLog); + GalacticGreg.Logger.setTraceOutput(PrintTraceMessagesToFMLLog); + GalacticGreg.Logger.setQuietMode(QuietMode); + } + + @Override + protected void PostInit() { + + } + + public boolean serverPostInit() + { + CustomLootChest = new BlockMetaComb(Blocks.chest); + try + { + if (LootChestItemOverride != "") + { + String[] args = LootChestItemOverride.split(":"); + String tMod; + String tName; + int tMeta; + + if (args.length >= 2) + { + tMod = args[0]; + tName = args[1]; + if (args.length == 3) + tMeta = Integer.parseInt(args[2]); + else + tMeta = 0; + + Block tBlock = GameRegistry.findBlock(tMod, tName); + if (tBlock != null) + { + GalacticGreg.Logger.debug("Found valid ChestOverride: %s. LootChest replaced", LootChestItemOverride); + CustomLootChest = new BlockMetaComb(tBlock, tMeta); + } + } + } + + return true; + } + catch (Exception e) + { + GalacticGreg.Logger.error("Unable to find custom chest override %s. Make sure item exists. Defaulting to Minecraft:chest", LootChestItemOverride); + e.printStackTrace(); + return false; + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java b/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java new file mode 100644 index 0000000000..4f6166e3eb --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java @@ -0,0 +1,250 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.ArrayList; + +import org.apache.logging.log4j.Level; + +import cpw.mods.fml.common.FMLLog; + +/** + * Generic LogHelper to print stuff to the console + * @author Namikon + */ +public final class LogHelper { + private ArrayList<String> _mReportedCategories = new ArrayList<String>(); + private boolean doDebugLogs = false; + private boolean doTraceLogs = false; + private boolean quietMode = false; + private String _mModID = ""; + + private final static String STR_NOCAT = "ihaznocathegory"; + private final static String STR_TOKEN_ONETIMEMESSAGE = " OTM"; + + public LogHelper(String pModID) + { + _mModID = pModID; + } + + /** If true, only error/fatal/warn messages will be printed + * @param pEnabled + */ + public void setQuietMode(boolean pEnabled) { + quietMode = pEnabled; + } + + + /** + * Enable/Disable debug logs + * @param pEnabled + */ + public void setDebugOutput(boolean pEnabled) + { + doDebugLogs = pEnabled; + } + + /** + * Enable/Disable trace logs + * @param pEnabled + */ + public void setTraceOutput(boolean pEnabled) + { + doTraceLogs = pEnabled; + } + + /** + * Resets all One-Time categories, so they will be displayed again + */ + public void ResetCategories() + { + _mReportedCategories = new ArrayList<String>(); + } + + /** + * Print a log-message with built-in String.format(x) support. This message will only appear once. usefull for + * error/warnings within loops + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param pLogLevel The logLevel for this message + * @param pMessage The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void log(String pCategory, Level pLogLevel, String pMessage, Object... args) + { + if (pLogLevel == Level.DEBUG && !doDebugLogs) + return; + + if (pLogLevel == Level.TRACE && !doTraceLogs) + return; + + if (pLogLevel != Level.ERROR && pLogLevel != Level.FATAL && pLogLevel != Level.WARN) + if (quietMode) + return; + + + String tt = ""; + if (!pCategory.equals(STR_NOCAT)) + { + tt = STR_TOKEN_ONETIMEMESSAGE; + if (_mReportedCategories.contains(pCategory)) + return; + else + { + _mReportedCategories.add(pCategory); + } + } + + FMLLog.log(_mModID.toUpperCase() + tt, pLogLevel, pMessage, args); + } + + + /** Prints a one-time message with Category ALL + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_all(String pCategory, String object, Object... args) + { + log(pCategory, Level.ALL, object, args); + } + + /** Prints a one-time message with Category DEBUG + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_debug(String pCategory, String object, Object... args) + { + log(pCategory, Level.DEBUG, object, args); + } + + /** Prints a one-time message with Category ERROR + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_error(String pCategory, String object, Object... args) + { + log(pCategory, Level.ERROR, object, args); + } + + /** Prints a one-time message with Category FATAL + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_fatal(String pCategory, String object, Object... args) + { + log(pCategory, Level.FATAL, object, args); + } + + /** Prints a one-time message with Category INFO + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_info(String pCategory, String object, Object... args) + { + log(pCategory, Level.INFO, object, args); + } + + /** Prints a one-time message with Category OFF + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_off(String pCategory, String object, Object... args) + { + log(pCategory, Level.OFF, object, args); + } + + /** Prints a one-time message with Category TRACE + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_trace(String pCategory, String object, Object... args) + { + log(pCategory, Level.TRACE, object, args); + } + + /** Prints a one-time message with Category WARN + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_warn(String pCategory, String object, Object... args) + { + log(pCategory, Level.WARN, object, args); + } + + /** Prints a message with Category ALL + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void all(String object, Object... args) + { + log(STR_NOCAT, Level.ALL, object, args); + } + + /** Prints a message with Category DEBUG + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void debug(String object, Object... args) + { + log(STR_NOCAT, Level.DEBUG, object, args); + } + + /** Prints a message with Category ERROR + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void error(String object, Object... args) + { + log(STR_NOCAT, Level.ERROR, object, args); + } + + /** Prints a message with Category FATAL + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void fatal(String object, Object... args) + { + log(STR_NOCAT, Level.FATAL, object, args); + } + + /** Prints a message with Category INFO + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void info(String object, Object... args) + { + log(STR_NOCAT, Level.INFO, object, args); + } + + /** Prints a message with Category OFF + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void off(String object, Object... args) + { + log(STR_NOCAT, Level.OFF, object, args); + } + + /** Prints a message with Category TRACE + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void trace(String object, Object... args) + { + log(STR_NOCAT, Level.TRACE, object, args); + } + + /** Prints a message with Category WARN + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void warn(String object, Object... args) + { + log(STR_NOCAT, Level.WARN, object, args); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java b/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java new file mode 100644 index 0000000000..07b6e58deb --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java @@ -0,0 +1,115 @@ +package bloodasp.galacticgreg.auxiliary; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +/** + * Method to easily send chat-messages to EntityPlayer + * @author Namikon + * + */ +public class PlayerChatHelper { + /** + * Meant for notifications that are being send to an admin/op + * Color will be GREEN + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(ICommandSender pCommandSender, String pMessage) + { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op + * Color will be RED + * @param pPlayer + * @param pMessage + */ + public static void SendError(ICommandSender pCommandSender, String pMessage) + { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op + * Color will be YELLOW + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(ICommandSender pCommandSender, String pMessage) + { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + + /** + * Meant for notifications that are being send to an admin/op + * Color will be GREEN + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op + * Color will be RED + * @param pPlayer + * @param pMessage + */ + public static void SendError(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op + * Color will be YELLOW + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op + * Color will be DARK_GREEN + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyPositive(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_GREEN + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op + * Color will be AQUA + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyNormal(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op + * Color will be DARK_PURPLE + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyWarning(EntityPlayer pPlayer, String pMessage) + { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + pMessage)); + } + + +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java b/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java new file mode 100644 index 0000000000..192fb07262 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java @@ -0,0 +1,87 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import bloodasp.galacticgreg.api.ModDimensionDef; + +/** + * A simple FIFO-storage for Long-values + * Will keep 50 values for each dimension in memory + * Doesn't need to be changed when adding new planets/mods + */ +public class ProfilingStorage { + private Map<String, List<Long>> mProfilingMap; + + public ProfilingStorage() + { + mProfilingMap = new HashMap<String, List<Long>>(); + } + + /** + * Add a new time to the list of pDimension. Will be ignored it tTotalTime == 0 + * @param pDimension + * @param tTotalTime + */ + public void AddTimeToList(ModDimensionDef pDimension, long pTotalTime) + { + try + { + if (pTotalTime == 0) + return; + + if(!mProfilingMap.containsKey(pDimension.getDimIdentifier())) + mProfilingMap.put(pDimension.getDimIdentifier(), new LinkedList<Long>()); + + LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); + + ll.addLast(pTotalTime); + + while(ll.size() > 50) + ll.removeFirst(); + } catch (Exception e) + { + // Just do nothing. profiling is for debug purposes only anyways... + } + } + + /** + * Return the average time required to execute the oregen in Dimension pDimension + * @param pDimension The DimensionType in question + * @return + */ + public long GetAverageTime(ModDimensionDef pDimension) + { + try + { + if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) + return -1; + + int tTotalVal = 0; + long tAverage = 0; + long tReturnVal = 0; + + LinkedList ll = (LinkedList) mProfilingMap.get(pDimension.getDimIdentifier()); + + if(ll != null) + { + Iterator<Long> qItr = ll.iterator(); + while(qItr.hasNext()) + { + tAverage += qItr.next(); + tTotalVal++; + } + + tReturnVal = (long)((float)(tAverage / tTotalVal)); + } + return tReturnVal; + } + catch (Exception e) + { + return -1; + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java b/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java new file mode 100644 index 0000000000..930b0d307c --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/command/AEStorageCommand.java @@ -0,0 +1,189 @@ +package bloodasp.galacticgreg.command; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import appeng.api.util.WorldCoord; +import appeng.items.storage.ItemSpatialStorageCell; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.auxiliary.PlayerChatHelper; +import bloodasp.galacticgreg.schematics.SpaceSchematic; +import bloodasp.galacticgreg.schematics.SpaceSchematicFactory; +import bloodasp.galacticgreg.schematics.SpaceSchematicHandler; + +/** + * This command allows to export any structure that has been stored inside a spatial storage cell + * to a xml file that can later be enabled for spawning in dimensions. + */ +public class AEStorageCommand implements ICommand { + private List aliases; + public AEStorageCommand() + { + this.aliases = new ArrayList(); + this.aliases.add("exportae"); + } + + @Override + public String getCommandName() + { + return "exportae"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) + { + return "exportae <structure name>"; + } + + @Override + public List getCommandAliases() + { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) + { + try + { + if (pCommandSender instanceof EntityPlayer) + { + if (pArgs.length < 1) + return; + + String tName = pArgs[0].toString(); + + EntityPlayer tEP = (EntityPlayer) pCommandSender; + // Check if item in hand is a spatial storage cell + ItemStack tIS = tEP.inventory.getCurrentItem(); + if (tIS.getItem() instanceof ItemSpatialStorageCell) + { + ItemSpatialStorageCell tCell = (ItemSpatialStorageCell) tIS.getItem(); + World tSpatialWorld = tCell.getWorld(tIS); + WorldCoord storedSize = tCell.getStoredSize(tIS); + + // Check if SSC is filled + if (storedSize.x == 0 || storedSize.y == 0 ||storedSize.z == 0) + { + PlayerChatHelper.SendError(pCommandSender, "Error: This spatial storage is empty"); + return; + } + + // Export structure + GalacticGreg.Logger.info("Creating Structure from Spatial AE drive. Dimensions: X [%d] Y [%d] Z [%d]", storedSize.x, storedSize.y, storedSize.z); + SpaceSchematic tSchematic = SpaceSchematicFactory.createSchematic(tName); + boolean tTEWarningSend = false; + + // Loop all 3 dimensions + for (int lX = 1; lX <= storedSize.x; lX++) { + for (int lY = 65; lY < 65 + storedSize.y; lY++) { + for (int lZ = 1; lZ <= storedSize.z; lZ++) { + + // Get the block + Block b = tSpatialWorld.getBlock(lX, lY, lZ); + // Get the meta + int bm = tSpatialWorld.getBlockMetadata(lX, lY, lZ); + + // Search for the blocks name + String tBlockName = Block.blockRegistry.getNameForObject(b); + + // Check if block is a tileentity + TileEntity bTE = tSpatialWorld.getTileEntity(lX, lY, lZ); + + String tMsg = String.format("[X-%d][Y-%d][Z-%d] ", lX, lY, lZ); + String nbtComp = ""; + // If block could be found... + if (b != null) + { + tMsg += tBlockName; + // If block is a TileEntity + if (bTE != null) + { + // Print a warning on the console + tMsg += " TE"; + GalacticGreg.Logger.warn("Warning: Found TileEntity at X[%d] Y[%d] Z[%d]. NBT States are not exported!", lX, lY, lZ); + if (!tTEWarningSend) + { + // Send a warning ingame, once per export command + tTEWarningSend = true; + PlayerChatHelper.SendWarn(pCommandSender, "TileEntity states are not exported!"); + } + + } + + // If the block is not air, add it to the structure + if (b != Blocks.air) + tSchematic.addStructureInfo(SpaceSchematicFactory.createStructureInfo(lX, lY, lZ, b, bm)); + } + } + } + } + + // Save structure to disk + if (!GalacticGreg.SchematicHandler.SaveSpaceStructure(tSchematic)) + { + // Something went wrong... + PlayerChatHelper.SendError(pCommandSender, "Something went wrong. Structure not saved"); + } + else + { + // All good, xml exported. Notify player that he needs to edit the file + PlayerChatHelper.SendInfo(pCommandSender, "Structure has been exported to " + tSchematic.getName() + ".xml. It contains " + tSchematic.coordInfo().size() + " Blocks"); + PlayerChatHelper.SendInfo(pCommandSender, "You have to edit the file before a reload will accept it!"); + } + } + else + PlayerChatHelper.SendError(pCommandSender, "Error: Item in your hand is not a spatial storage drive!"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) + { + // Command is only enabled for actual players and only if they are OP-ed + if(pCommandSender instanceof EntityPlayerMP) + { + EntityPlayerMP tEP = (EntityPlayerMP)pCommandSender; + return MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile()); + } + else + return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, + String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java b/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java new file mode 100644 index 0000000000..2626348da7 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/command/ProfilingCommand.java @@ -0,0 +1,100 @@ +package bloodasp.galacticgreg.command; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; + +/** + * Ingame command to get the average oregen time(s) for the active dimensions + * Doesn't need to be changed when adding new planets/mods + * + */ +public class ProfilingCommand implements ICommand { + private List aliases; + public ProfilingCommand() + { + this.aliases = new ArrayList(); + this.aliases.add("ggregprofiler"); + } + + @Override + public String getCommandName() + { + return "ggregprofiler"; + } + + @Override + public String getCommandUsage(ICommandSender pCommandSender) + { + return "ggregprofiler"; + } + + @Override + public List getCommandAliases() + { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender pCommandSender, String[] pArgs) + { + pCommandSender.addChatMessage(new ChatComponentText("Average OreGen times:")); + + + for (ModContainer mc : GalacticGregRegistry.getModContainers()) + { + String tModName = mc.getModName(); + for (ModDimensionDef mdd : mc.getDimensionList()) + { + long tTime = GalacticGreg.Profiler.GetAverageTime(mdd); + String tInfo; + if(tTime == -1) + tInfo = "N/A"; + else + tInfo = String.format("%d ms", tTime); + pCommandSender.addChatMessage(new ChatComponentText(String.format("%s (%s): %s", mdd.getDimIdentifier(), mdd.getDimensionName(), tInfo))); + } + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) + { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && !FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer()) + return true; + + if(pCommandSender instanceof EntityPlayerMP) + { + EntityPlayerMP tEP = (EntityPlayerMP)pCommandSender; + return MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile()); + } + return false; + } + + @Override + public int compareTo(Object o) { + return 0; + } + + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, + String[] p_71516_2_) { + return null; + } + + @Override + public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { + return false; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java b/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java new file mode 100644 index 0000000000..73f4a462b0 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicDimensionConfig.java @@ -0,0 +1,173 @@ +package bloodasp.galacticgreg.dynconfig; + +import gregtech.api.GregTech_API; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraftforge.common.ChestGenHooks; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; + +/** + * This dynamic config is different to the OreMix one. This is used/bound to the ModDimensionDef, + * and the OreMixWorldConfig is bound to the veins. Don't get confused! + * + */ +public class DynamicDimensionConfig { + public static class AsteroidConfig + { + public int MinSize; + public int MaxSize; + public int Probability; + public int OreChance; + public int OrePrimaryOffset; + public int SpecialBlockChance; + public int SmallOreChance; + public boolean ObeyHeightLimits; + public int OreGenMaxY; + public int FloatingAsteroidMinY; + public boolean HiddenOres; + public int LootChestChance; + public int LootChestTable; + public int NumLootItems; + public boolean RandomizeNumLootItems; + } + + private static Map<String, AsteroidConfig> _mDynamicAsteroidMap = new HashMap<String, AsteroidConfig>(); + + private static String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD) + { + return String.format("galacticgreg.asteroids.%s.%s", pMC.getModName(), pMDD.getDimensionName()); + } + + private static String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD, String pSubCat) + { + return String.format("%s.%s", getConfigKeyName(pMC, pMDD), pSubCat); + } + + public static AsteroidConfig getAsteroidConfig(ModDimensionDef pDimDef) + { + if (!_mDynamicAsteroidMap.containsKey(pDimDef.getDimIdentifier())) + return null; + else + return _mDynamicAsteroidMap.get(pDimDef.getDimIdentifier()); + } + + public static boolean InitDynamicConfig() + { + try + { + for (ModContainer mc : GalacticGregRegistry.getModContainers()) + { + if (!mc.getEnabled()) + continue; + + for (ModDimensionDef mdd : mc.getDimensionList()) + { + DimensionType dt = mdd.getDimensionType(); + if (dt == DimensionType.Asteroid || dt == DimensionType.AsteroidAndPlanet) + { + String tDimIdentifier = mdd.getDimIdentifier(); + if (_mDynamicAsteroidMap.containsKey(tDimIdentifier)) + GalacticGreg.Logger.warn("Found 2 Dimensions with the same Identifier! This should never happen, and you should report this to me. Identifier in question: %s", tDimIdentifier); + else + { + AsteroidConfig aConf = new AsteroidConfig(); + aConf.MinSize = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "SizeMin", 5); + aConf.MaxSize = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "SizeMax", 15); + aConf.Probability = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "Probability", 200); + aConf.SpecialBlockChance = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd), "SpecialBlockChance", 5); + + aConf.OreChance = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "orespawn"), "BaseOreChance", 5); + aConf.OrePrimaryOffset = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "orespawn"), "PrimaryToRareOreOffset", 5); + aConf.SmallOreChance = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "orespawn"), "SmallOreChance", 10); + aConf.ObeyHeightLimits = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "orespawn"), "ObeyHeightLimits", false); + aConf.HiddenOres = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "orespawn"), "OresOnlyInsideAsteroids", false); + + if (GalacticGreg.GalacticConfig.LootChestsEnabled) + { + aConf.LootChestChance = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "loot"), "LootChestChance", 1); + aConf.LootChestTable = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "loot"), "LootChestTable", 3); + aConf.NumLootItems = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "loot"), "LootChestItemCount", 10); + aConf.RandomizeNumLootItems = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "loot"), "RandomizeLootItemCount", true); + } + else + { + aConf.LootChestChance = 0; + aConf.LootChestTable = 1; + aConf.NumLootItems = 0; + aConf.RandomizeNumLootItems = false; + } + + if (dt == DimensionType.AsteroidAndPlanet) + { + int tDefaultMaxY = mdd.getPreConfiguratedGroundOreMaxY(); + int tDefaultMinY = mdd.getPreConfiguratedFloatingAsteroidMinY(); + aConf.OreGenMaxY = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "floating"), "OreGenMaxY", tDefaultMaxY); + aConf.FloatingAsteroidMinY = GregTech_API.sWorldgenFile.get(getConfigKeyName(mc, mdd, "floating"), "FloatingAsteroidMinY", tDefaultMinY); + } + + + if (aConf.MaxSize > 50) + GalacticGreg.Logger.warn("Asteroid-MaxSize for dimID [%s] is larger than 50. This might cause memory-problems, as the maximum asteroid size will be larger than 50*50*50 blocks", tDimIdentifier); + _mDynamicAsteroidMap.put(tDimIdentifier, aConf); + } + } + } + } + return true; + } + catch(Exception e) + { + e.printStackTrace(); + return false; + } + } + + /** + * Convert numbers to actual loot-table entries + * @param pACfg + * @return + */ + public static String getLootChestTable(AsteroidConfig pACfg) + { + String tLootTable = ChestGenHooks.MINESHAFT_CORRIDOR; + + switch(pACfg.LootChestTable) + { + case 2: + tLootTable = ChestGenHooks.PYRAMID_DESERT_CHEST; + break; + case 3: + tLootTable = ChestGenHooks.PYRAMID_JUNGLE_CHEST; + break; + case 4: + tLootTable = ChestGenHooks.PYRAMID_JUNGLE_DISPENSER; + break; + case 5: + tLootTable = ChestGenHooks.STRONGHOLD_CORRIDOR; + break; + case 6: + tLootTable = ChestGenHooks.STRONGHOLD_LIBRARY; + break; + case 7: + tLootTable = ChestGenHooks.STRONGHOLD_CROSSING; + break; + case 8: + tLootTable = ChestGenHooks.VILLAGE_BLACKSMITH; + break; + case 9: + tLootTable = ChestGenHooks.BONUS_CHEST; + break; + case 10: + tLootTable = ChestGenHooks.DUNGEON_CHEST; + break; + } + + return tLootTable; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java b/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java new file mode 100644 index 0000000000..846cb5616a --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/dynconfig/DynamicOreMixWorldConfig.java @@ -0,0 +1,95 @@ +package bloodasp.galacticgreg.dynconfig; + +import gregtech.api.GregTech_API; + +import java.util.HashMap; +import java.util.Map; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.registry.GalacticGregRegistry; + +/** + * This is the dynamic config class for every ore-vein that will generate config values according to the dimension and + * mod name + */ +public class DynamicOreMixWorldConfig { + private String _mWorldGenName; + private Map<String, Boolean> _mDynWorldConfigMap = null; + private final String _mConfigName; + + private String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD) + { + return getConfigKeyName(pMC, pMDD, ""); + } + + private String getConfigKeyName(ModContainer pMC, ModDimensionDef pMDD, String pAdditionalName) + { + String tRet = String.format("%s_%s", pMC.getModName(), pMDD.getDimensionName()); + if (pAdditionalName.length() > 1) + tRet = String.format("%s_%s", tRet, pAdditionalName); + + return tRet; + } + + /** + * Init a new dynamic config for a given world-generator + * @param pWorldGenName + */ + public DynamicOreMixWorldConfig(String pWorldGenName) + { + _mWorldGenName = pWorldGenName; + _mDynWorldConfigMap = new HashMap<String, Boolean>(); + _mConfigName = String.format("worldgen.%s", _mWorldGenName); + } + + /** + * Check if this OreGen is enabled for a given Dimension, represented by pMDD + * @param pMDD The dimension in question + * @return true or false if *this* oregen is enabled in the worldgen config + */ + public boolean isEnabledInDim(ModDimensionDef pMDD) + { + String tDimIdentifier = pMDD.getDimIdentifier(); + if (_mDynWorldConfigMap.containsKey(tDimIdentifier)) + return _mDynWorldConfigMap.get(tDimIdentifier); + else + return false; + } + + /** + * Initializes the dynamic oregen config. + * This must be called *AFTER* InitModContainers() has done its work + * @return true or false if the config init was successfull + */ + public boolean InitDynamicConfig() + { + try + { + for (ModContainer mc : GalacticGregRegistry.getModContainers()) + { + if (!mc.getEnabled()) + continue; + + for (ModDimensionDef mdd : mc.getDimensionList()) + { + String tDimIdentifier = mdd.getDimIdentifier(); + if (_mDynWorldConfigMap.containsKey(tDimIdentifier)) + GalacticGreg.Logger.error("Found 2 Dimensions with the same Identifier: %s Dimension will not generate Ores", tDimIdentifier); + else + { + boolean tFlag = GregTech_API.sWorldgenFile.get(_mConfigName, getConfigKeyName(mc, mdd), false); + _mDynWorldConfigMap.put(tDimIdentifier, tFlag); + } + } + } + return true; + } + catch(Exception e) + { + e.printStackTrace(); + return false; + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java b/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java new file mode 100644 index 0000000000..e4beaf1a7a --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/generators/GenEllipsoid.java @@ -0,0 +1,136 @@ +package bloodasp.galacticgreg.generators; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.StructureInformation; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +/** + * Simple ellipsoid-generator. Based on the formular created by Chrysator. + * Thanks for the help! + * + * Generates a simple ellipsoid with dynamic rotation, random size-values, random noise for the surface, etc. + * Can probably be tweaked even more, but works for now... + */ +public class GenEllipsoid implements ISpaceObjectGenerator { + private Vec3 _mEllipsoidCenter; + private Random _mRandom; + private List<StructureInformation> _mStructure; + + private double _mCoreDensity = 0.7D; + private double _mSineFactor = 0.05D; + private float _mRandomInfluence; + private float _mRandomAngleX; + private float _mRandomAngleY; + private float _mRandomAngleZ; + + private int _mSizeA; + private int _mSizeB; + private int _mSizeC; + + public GenEllipsoid() + { + reset(); + } + + @Override + public SpaceObjectType getType() { + return SpaceObjectType.OreAsteroid; + } + + @Override + public void randomize(int pSizeMin, int pSizeMax) + { + _mRandom = new Random(System.currentTimeMillis()); + _mRandomAngleX = (float) (_mRandom.nextFloat() * Math.PI); + _mRandomAngleY = (float) (_mRandom.nextFloat() * Math.PI); + _mRandomAngleZ = (float) (_mRandom.nextFloat() * Math.PI); + + _mRandomInfluence = _mRandom.nextFloat(); + + _mSizeA = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + _mSizeB = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + _mSizeC = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10; + } + + + @Override + public void setCenterPoint(int pX, int pY, int pZ) { + _mEllipsoidCenter = Vec3.createVectorHelper(pX, pY, pZ); + } + + @Override + public void setCenterPoint(Vec3 pCenter) + { + _mEllipsoidCenter = pCenter; + } + + @Override + public Vec3 getCenterPoint() + { + return _mEllipsoidCenter; + } + + @Override + public List<StructureInformation> getStructure() { + return _mStructure; + } + + @Override + public void calculate() + { + int Xmin = (int) (_mEllipsoidCenter.xCoord - _mSizeA); + int Xmax = (int) (_mEllipsoidCenter.xCoord + _mSizeA); + int Ymin = (int) (_mEllipsoidCenter.yCoord - _mSizeB); + int Ymax = (int) (_mEllipsoidCenter.yCoord + _mSizeB); + int Zmin = (int) (_mEllipsoidCenter.zCoord - _mSizeC); + int Zmax = (int) (_mEllipsoidCenter.zCoord + _mSizeC); + + for (int iX = Xmin; iX <= Xmax; iX++) { + for (int iY = Ymin; iY <= Ymax; iY++) { + for (int iZ = Zmin; iZ <= Zmax; iZ++) + { + double tmpX = Math.pow(_mEllipsoidCenter.xCoord - iX, 2) / Math.pow(_mSizeA, 2); + double tmpY = Math.pow(_mEllipsoidCenter.yCoord - iY, 2) / Math.pow(_mSizeB, 2); + double tmpZ = Math.pow(_mEllipsoidCenter.zCoord - iZ, 2) / Math.pow(_mSizeC, 2); + double val = (tmpX + tmpY + tmpZ); + + Vec3 tPoint = Vec3.createVectorHelper(iX, iY, iZ); + tPoint.rotateAroundX(_mRandomAngleX); + tPoint.rotateAroundY(_mRandomAngleY); + tPoint.rotateAroundZ(_mRandomAngleZ); + + TargetBlockPosition tbp = TargetBlockPosition.Invalid; + + if (val <= 0.01D) + tbp = TargetBlockPosition.AsteroidInnerCore; + + else if (val > 0.01D && val < _mCoreDensity) + tbp = TargetBlockPosition.AsteroidCore; + + else if (val >= _mCoreDensity && val <= (1.0D - (_mSineFactor * MathHelper.sin((iZ + iX + iY - _mRandom.nextFloat() * _mRandomInfluence))))) + tbp = TargetBlockPosition.AsteroidShell; + + if (tbp != TargetBlockPosition.Invalid) + _mStructure.add(new StructureInformation(Vec3.createVectorHelper(iX, iY, iZ), tbp)); + + } + } + } + } + + @Override + public void reset() { + _mStructure = new ArrayList<StructureInformation>(); + _mEllipsoidCenter = Vec3.createVectorHelper(0, 0, 0); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java b/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java new file mode 100644 index 0000000000..3a4d57a118 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/registry/GalacticGregRegistry.java @@ -0,0 +1,183 @@ +package bloodasp.galacticgreg.registry; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.world.chunk.IChunkProvider; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.DimensionType; +import bloodasp.galacticgreg.api.ModContainer; +import bloodasp.galacticgreg.api.ModDimensionDef; +import bloodasp.galacticgreg.dynconfig.DynamicDimensionConfig; +import bloodasp.galacticgreg.generators.GenEllipsoid; +import cpw.mods.fml.common.Loader; + +/** + * GalacticGregs registry + * + */ +public class GalacticGregRegistry { + private static final Map<String, ModContainer> _mModContainers = new HashMap<String, ModContainer>(); + public static final String DIM_UNKNOWN = "GGREG_DIMENSION_UNKNOWN"; + private static boolean _mInitializationDone = false; + + /** + * Register new ModContainer in the registry. Call this after you've populated it with Dimensions and Blocks + * Must be called from your own PreInit or Init event + * @param pModContainer + * @return + */ + public static boolean registerModContainer(ModContainer pModContainer) + { + if (_mInitializationDone) + { + GalacticGreg.Logger.warn("Initialization is already done, you can't add more ModContainers!"); + return false; + } + + if(_mModContainers.containsKey(pModContainer.getModName())) + { + GalacticGreg.Logger.warn("There is already a mod registered with that name: [%s]", pModContainer.getModName()); + return false; + } + else + { + GalacticGreg.Logger.info("Registered new mod to generate ores: [%s] Dimensions provided: [%d]", pModContainer.getModName(), pModContainer.getDimensionList().size()); + _mModContainers.put(pModContainer.getModName(), pModContainer); + return true; + } + } + + /** + * Lookup the registered dimensions and try to find the DimensionDefinition that has the ChunkProvider + * that we have here + * @param pChunkProvider + * @return + */ + public static ModDimensionDef getDimensionTypeByChunkGenerator(IChunkProvider pChunkProvider) + { + try + { + if (!_mInitializationDone) + return null; + + String tFQCPN = pChunkProvider.toString().split("@")[0]; + ModDimensionDef tReturnMDD = null; + + for (ModContainer mc : _mModContainers.values()) + { + for (ModDimensionDef mdd : mc.getDimensionList()) + { + if (mdd.getChunkProviderName().equals(tFQCPN)) + { + tReturnMDD = mdd; + break; + } + } + } + + return tReturnMDD; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + /** + * Get all registered modcontainers. Can only be done after the initialization process is done + * @return + */ + public static Collection<ModContainer> getModContainers() + { + if(!_mInitializationDone) + return null; + + return _mModContainers.values(); + } + + /** + * Initializes the Registry. Never do this in your code, GalacticGreg will crash if you do so + */ + public static boolean InitRegistry() + { + if (_mInitializationDone) // never run init twice! + return false; + + InitModContainers(); + + DynamicDimensionConfig.InitDynamicConfig(); + return true; + } + + /** + * Parse modcontainers and search for loaded mods. Enable found mods for generation + */ + private static void InitModContainers() + { + for (ModContainer mc : _mModContainers.values()) + { + if(!Loader.isModLoaded(mc.getModName()) && !mc.getModName().equalsIgnoreCase("vanilla")) + { + GalacticGreg.Logger.warn("Ignoring ModRegistration for OreGen: [%s], because mod is not loaded. Did you misspell the name?", mc.getModName()); + mc.setEnabled(false); + } + else + { + GalacticGreg.Logger.info("Mod [%s] is now enabled for OreGen by GalacticGreg", mc.getModName()); + mc.setEnabled(true); + for (ModDimensionDef md : mc.getDimensionList()) + { + GalacticGreg.Logger.info("ModID: [%s] DimName: [%s] ValidBlocks: [%d] Identifier: [%s] Generators: [%d]", mc.getModName(), md.getDimensionName(), md.getReplaceableBlocks().size(), md.getDimIdentifier(), md.getSpaceObjectGenerators().size()); + + // Register default generator if dimension is asteroid and no generator was added + if (md.getDimensionType() == DimensionType.AsteroidAndPlanet || md.getDimensionType() == DimensionType.Asteroid) + { + if (md.getSpaceObjectGenerators().size() == 0) + { + GalacticGreg.Logger.debug("No generators found, adding build-in ellipsoid generator"); + md.registerSpaceObjectGenerator(new GenEllipsoid()); + } + GalacticGreg.Logger.info("Asteroid-Enabled dimension. Registered Generators: [%d]", md.getSpaceObjectGenerators().size()); + } + + md.finalizeReplaceableBlocks(mc.getModName()); + } + } + } + _mInitializationDone = true; + } + + /** + * Returns ModContainer for given DimensionDefinition + * @param pDimensionDefinition + * @return + */ + public static ModContainer getModContainerForDimension(ModDimensionDef pDimensionDefinition) + { + if (!_mInitializationDone) + return null; + + try + { + for (ModContainer mc : _mModContainers.values()) + { + for (ModDimensionDef md : mc.getDimensionList()) + { + if (pDimensionDefinition.getDimIdentifier().equals(md.getDimIdentifier())) + { + return mc; + } + } + } + return null; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java new file mode 100644 index 0000000000..606f2318ad --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematic.java @@ -0,0 +1,107 @@ +package bloodasp.galacticgreg.schematics; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +import net.minecraft.block.Block; +import net.minecraft.util.Vec3; +import bloodasp.galacticgreg.api.StructureInformation; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. + * However, feel free to copy this code to your own mod to implement structures. If you have questions, find me on github + * and ask + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "SpaceSchematic") +public class SpaceSchematic { + @XmlAttribute(name = "enabled") + protected boolean _mStructureEnabled; + @XmlAttribute(name="centerX") + protected int _mCenterX; + @XmlAttribute(name="centerY") + protected int _mCenterY; + @XmlAttribute(name="centerZ") + protected int _mCenterZ; + + @XmlElement(name = "StructureName") + protected String _mStructureName; + + @XmlElement(name = "Rarity") + protected int _mRarity; + + @XmlElementWrapper(name = "Coords") + @XmlElement(name="block") + protected ArrayList<BaseStructureInfo> mStructureInfoList; + + public boolean isEnabled() + { + return _mStructureEnabled; + } + + public Vec3 getStructureCenter() + { + return Vec3.createVectorHelper(_mCenterX, _mCenterY, _mCenterZ); + } + + public int getRarity() + { + return _mRarity; + } + + public String getName() + { + return _mStructureName; + } + + public ArrayList<BaseStructureInfo> coordInfo() + { + if (mStructureInfoList == null) + mStructureInfoList = new ArrayList<BaseStructureInfo>(); + + return mStructureInfoList; + } + + public void addStructureInfo(StructureInformation pStrucInfo) + { + if (mStructureInfoList == null) + mStructureInfoList = new ArrayList<BaseStructureInfo>(); + mStructureInfoList.add(new BaseStructureInfo(pStrucInfo)); + } + + public static class BaseStructureInfo + { + @XmlAttribute(name = "X") + protected int posX; + @XmlAttribute(name = "Y") + protected int posY; + @XmlAttribute(name = "Z") + protected int posZ; + @XmlAttribute(name = "Block") + protected String blockName; + @XmlAttribute(name = "Meta") + protected int blockMeta; + + public BaseStructureInfo(StructureInformation pSI) + { + posX = pSI.getX(); + posY = pSI.getY(); + posZ = pSI.getZ(); + blockName = Block.blockRegistry.getNameForObject(pSI.getBlock().getBlock()); + blockMeta = pSI.getBlock().getMeta(); + } + + public Vec3 getVec3Pos() + { + return Vec3.createVectorHelper(posX, posY, posZ); + } + } +} diff --git a/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java new file mode 100644 index 0000000000..d2fdf7716e --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicFactory.java @@ -0,0 +1,34 @@ +package bloodasp.galacticgreg.schematics; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.Vec3; +import bloodasp.galacticgreg.api.Enums.AllowedBlockPosition; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.SpecialBlockComb; +import bloodasp.galacticgreg.api.StructureInformation; +import bloodasp.galacticgreg.schematics.SpaceSchematic.BaseStructureInfo; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. + * However, feel free to copy this code to your own mod to implement structures. If you have questions, find me on github + * and ask + */ +public class SpaceSchematicFactory { + public static SpaceSchematic createSchematic(String pName) + { + SpaceSchematic tSchem = new SpaceSchematic(); + tSchem._mStructureName = pName; + tSchem._mRarity = 100; + tSchem._mStructureEnabled = false; + + return tSchem; + } + + public static StructureInformation createStructureInfo(int pX, int pY, int pZ, Block pBlock, int pMeta) + { + StructureInformation si = new StructureInformation(Vec3.createVectorHelper(pX, pY, pZ), TargetBlockPosition.Invalid, new SpecialBlockComb(pBlock, pMeta, AllowedBlockPosition.AsteroidCoreAndShell)); + return si; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java new file mode 100644 index 0000000000..f44aaa4b88 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicHandler.java @@ -0,0 +1,206 @@ +package bloodasp.galacticgreg.schematics; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.apache.commons.io.FileUtils; + +import net.minecraft.util.Vec3; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.StructureInformation; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. + * However, feel free to copy this code to your own mod to implement structures. If you have questions, find me on github + * and ask + */ +public class SpaceSchematicHandler { + File _mConfigFolderName; + File _mSchematicsFolderName; + private List<SpaceSchematic> _mSpaceSchematics; + + public SpaceSchematicHandler(File pConfigFolder) + { + _mConfigFolderName = new File(String.format("%s/%s", pConfigFolder.toString(), GalacticGreg.NICE_MODID)); + _mSchematicsFolderName = new File(String.format("%s/schematics", _mConfigFolderName)); + + _mSpaceSchematics = new ArrayList<SpaceSchematic>(); + + if (!_mSchematicsFolderName.exists()) + _mSchematicsFolderName.mkdirs(); + } + + /** Get a random schematic to be placed. + * @return A schematic that can be spawned in space + */ + public SpaceSchematic getRandomSpaceSchematic() + { + int tRandomChance = GalacticGreg.GalacticRandom.nextInt(100); + List<Integer> tRandomIDs = new ArrayList<Integer>(); + SpaceSchematic tChoosenSchematic = null; + + if (_mSpaceSchematics == null) + return null; + + if (_mSpaceSchematics.size() == 0) + return null; + + if (_mSpaceSchematics.size() == 1) + { + tChoosenSchematic = _mSpaceSchematics.get(0); + if (tChoosenSchematic.getRarity() < tRandomChance) + tChoosenSchematic = null; + } + else + { + for (int i = 0; i < _mSpaceSchematics.size(); i++) + { + if (_mSpaceSchematics.get(i).getRarity() >= tRandomChance) + tRandomIDs.add(i); + } + } + + if (tRandomIDs.size() > 0) + { + int tRnd = GalacticGreg.GalacticRandom.nextInt(tRandomIDs.size()); + tChoosenSchematic = _mSpaceSchematics.get(tRandomIDs.get(tRnd)); + } + + return tChoosenSchematic; + } + + /** + * Try to reload the schematics. Will not change the list of currently loaded schematics if any errors + * are detected, except if you force it to do so + * @return + */ + public boolean reloadSchematics(boolean pForceReload) + { + try + { + Collection<File> structureFiles = FileUtils.listFiles(_mSchematicsFolderName, new String[] {"xml"}, false); + List<SpaceSchematic> tNewSpaceSchematics = new ArrayList<SpaceSchematic>(); + int tErrorsFound = 0; + + if (structureFiles.isEmpty()) + return true; + + for (File tSchematic : structureFiles) + { + try + { + SpaceSchematic tSchematicObj = LoadSpaceSchematic(tSchematic); + if (tSchematicObj != null) + tNewSpaceSchematics.add(tSchematicObj); + else + { + GalacticGreg.Logger.warn("Could not load Schematic %s. Please check the syntax", tSchematic); + tErrorsFound++; + } + } + catch (Exception e) + { + GalacticGreg.Logger.error("Error while loading Schematic %s", tSchematic); + e.printStackTrace(); + continue; + } + + } + + GalacticGreg.Logger.info("Successfully loaded %d Schematics", tNewSpaceSchematics.size()); + boolean tDoReplace = true; + + if(tErrorsFound > 0) + { + GalacticGreg.Logger.warn("Found %d errors while loading, not all schematics will be available"); + if (pForceReload) + GalacticGreg.Logger.info("Reload was forced, replacing currently active list with new one"); + else + { + GalacticGreg.Logger.warn("Nothing was replaced. Fix any errors and reload again"); + tDoReplace = false; + } + } + + if(tDoReplace) + _mSpaceSchematics = tNewSpaceSchematics; + + return true; + } + catch(Exception e) + { + e.printStackTrace(); + return false; + } + } + + /** + * Saves the schematic to disk. The schematics name will be used as filename + * @param pSchematic + * @return + */ + public boolean SaveSpaceStructure(SpaceSchematic pSchematic) + { + try + { + if (pSchematic.getName().length() < 1) + return false; + + JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class); + Marshaller jaxMarsh = tJaxbCtx.createMarshaller(); + jaxMarsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + jaxMarsh.marshal(pSchematic, new FileOutputStream(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematic.getName()), false)); + + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Load a schematic from disk by the schematic-name itself, without .xml or path + * @param pSchematicName + * @return + */ + public SpaceSchematic LoadSpaceSchematic(String pSchematicName) + { + return LoadSpaceSchematic(new File(String.format("%s/%s.xml", _mSchematicsFolderName, pSchematicName))); + } + + /** + * Load a schematic file from disk by providing the actual file-object + * @param pName + * @return + */ + public SpaceSchematic LoadSpaceSchematic(File pName) + { + SpaceSchematic tSchematic = null; + + try { + JAXBContext tJaxbCtx = JAXBContext.newInstance(SpaceSchematic.class); + if (!pName.exists()) + { + GalacticGreg.Logger.error("SchematicFile %s could not be found", pName); + return null; + } + + Unmarshaller jaxUnmarsh = tJaxbCtx.createUnmarshaller(); + tSchematic = (SpaceSchematic) jaxUnmarsh.unmarshal(pName); + + } catch (Exception e) { + e.printStackTrace(); + } + + return tSchematic; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java new file mode 100644 index 0000000000..d0fc1d68a3 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/schematics/SpaceSchematicWrapper.java @@ -0,0 +1,109 @@ +package bloodasp.galacticgreg.schematics; + +import java.util.ArrayList; +import java.util.List; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraft.util.Vec3; +import bloodasp.galacticgreg.GalacticGreg; +import bloodasp.galacticgreg.api.BlockMetaComb; +import bloodasp.galacticgreg.api.Enums.SpaceObjectType; +import bloodasp.galacticgreg.api.Enums.TargetBlockPosition; +import bloodasp.galacticgreg.api.ISpaceObjectGenerator; +import bloodasp.galacticgreg.api.StructureInformation; +import bloodasp.galacticgreg.schematics.SpaceSchematic.BaseStructureInfo; + +/** + * Class for XML Structure files. You only should edit/use this file/class if you want to add/fix stuff with + * GalacticGreg itself, and never if you're a mod developer and want to add support for GGreg to your mod. + * However, feel free to copy this code to your own mod to implement structures. If you have questions, find me on github + * and ask + */ +public class SpaceSchematicWrapper implements ISpaceObjectGenerator { + private SpaceSchematic _mSchematic; + private Vec3 _mCenter = Vec3.createVectorHelper(0, 0, 0); + private List<StructureInformation> _mFinalizedStructure; + + public SpaceSchematicWrapper(SpaceSchematic pSchematic) + { + _mSchematic = pSchematic; + } + + public boolean isCalculated() + { + return _mFinalizedStructure != null && _mFinalizedStructure.size() > 0; + } + + /** + * Recalculate the Structures position, center it around _mCenter + */ + private void RecalculatePosition() + { + _mFinalizedStructure = new ArrayList<StructureInformation>(); + + for (BaseStructureInfo bsi: _mSchematic.coordInfo()) + { + try + { + String tModID = bsi.blockName.split(":")[0]; + String tBlockName = bsi.blockName.split(":")[1]; + + Block tBlock = GameRegistry.findBlock(tModID, tBlockName); + if (tBlock != null) + { + BlockMetaComb bmc = new BlockMetaComb(tBlock, bsi.blockMeta); + Vec3 tCenteredPos = _mCenter.addVector(bsi.posX, bsi.posY, bsi.posZ); + StructureInformation tnewSI = new StructureInformation(tCenteredPos, TargetBlockPosition.StructureBlock, bmc); + _mFinalizedStructure.add(tnewSI); + } + else + GalacticGreg.Logger.warn("Block %s:%s could not be found. Schematic will be incomplete!", tModID, tBlockName); + } + catch (Exception e) + { + e.printStackTrace(); + GalacticGreg.Logger.error("Error while recalculating blocks position"); + } + } + } + + @Override + public Vec3 getCenterPoint() { + return _mCenter; + } + + @Override + public void setCenterPoint(int pX, int pY, int pZ) { + _mCenter = Vec3.createVectorHelper(pX, pY, pZ); + } + + @Override + public void setCenterPoint(Vec3 pCenter) { + _mCenter = pCenter; + } + + @Override + public List<StructureInformation> getStructure() { + return _mFinalizedStructure; + } + + @Override + public void calculate() { + RecalculatePosition(); + } + + @Override + public void randomize(int pSizeMin, int pSizeMax) {} + + @Override + public SpaceObjectType getType() { + return SpaceObjectType.NonOreSchematic; + } + + @Override + public void reset() { + + } + +} |