diff options
Diffstat (limited to 'src/main/java/gregtech/api/world')
4 files changed, 236 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/world/GT_Worldgen.java b/src/main/java/gregtech/api/world/GT_Worldgen.java new file mode 100644 index 0000000000..4e9ed6229b --- /dev/null +++ b/src/main/java/gregtech/api/world/GT_Worldgen.java @@ -0,0 +1,94 @@ +package gregtech.api.world; + +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import gregtech.api.GregTech_API; + +public abstract class GT_Worldgen { + + public final String mWorldGenName; + public final boolean mEnabled; + private final Map<String, Boolean> mDimensionMap = new ConcurrentHashMap<>(); + + @SuppressWarnings({ "unchecked", "rawtypes" }) // The adding of "this" needs a List<this> which does not exist + public GT_Worldgen(String aName, List aList, boolean aDefault) { + mWorldGenName = aName; + mEnabled = GregTech_API.sWorldgenFile.get("worldgen", mWorldGenName, aDefault); + if (mEnabled) aList.add(this); + } + + /** + * @param aWorld The World Object + * @param aRandom The Random Generator to use + * @param aBiome The Name of the Biome (always != null) + * @param aDimensionType The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End + * @param aChunkX xCoord of the Chunk + * @param aChunkZ zCoord of the Chunk + * @return if the Worldgeneration has been successfully completed + */ + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return false; + } + + public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, int seedX, int seedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return 4; // This is for the empty Orevein + } + + /** + * @param aWorld The World Object + * @param aRandom The Random Generator to use + * @param aBiome The Name of the Biome (always != null) + * @param aDimensionType The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End + * @param aChunkX xCoord of the Chunk + * @param aChunkZ zCoord of the Chunk + * @return if the Worldgeneration has been successfully completed + */ + public boolean executeCavegen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return false; + } + + /** + * + * @param aWorld The World Object + * @param aDimensionType The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End + * @param aAllowedDimensionType The Type of allowed Worldgeneration + * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether, + * Overworld, Twilight Forest and Deep Dark) + */ + public boolean isGenerationAllowed(World aWorld, int aDimensionType, int aAllowedDimensionType) { + return isGenerationAllowed(aWorld.provider.getDimensionName(), aDimensionType, aAllowedDimensionType); + } + + /** + * + * @param aDimName The Dimension Name + * @param aDimensionType The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End + * @param aAllowedDimensionType The Type of allowed Worldgeneration + * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether, + * Overworld, Twilight Forest and Deep Dark) + */ + public boolean isGenerationAllowed(String aDimName, int aDimensionType, int aAllowedDimensionType) { + if (!(aDimName.equalsIgnoreCase("Overworld") || aDimName.equalsIgnoreCase("Nether") + || aDimName.equalsIgnoreCase("The End") + || aDimName.equalsIgnoreCase("Twilight Forest") + || aDimName.equalsIgnoreCase("Underdark"))) return false; + + Boolean tAllowed = mDimensionMap.get(aDimName); + if (tAllowed == null) { + boolean tValue = GregTech_API.sWorldgenFile + .get("worldgen." + mWorldGenName, aDimName, aDimensionType == aAllowedDimensionType); + mDimensionMap.put(aDimName, tValue); + return tValue; + } + return tAllowed; + } +} diff --git a/src/main/java/gregtech/api/world/GT_Worldgen_Ore.java b/src/main/java/gregtech/api/world/GT_Worldgen_Ore.java new file mode 100644 index 0000000000..958adfad54 --- /dev/null +++ b/src/main/java/gregtech/api/world/GT_Worldgen_Ore.java @@ -0,0 +1,34 @@ +package gregtech.api.world; + +import java.util.ArrayList; +import java.util.Collection; + +import net.minecraft.block.Block; + +import gregtech.api.GregTech_API; + +public abstract class GT_Worldgen_Ore extends GT_Worldgen { + + public final int mBlockMeta, mAmount, mSize, mMinY, mMaxY, mProbability, mDimensionType; + public final Block mBlock; + public final Collection<String> mBiomeList; + public final boolean mAllowToGenerateinVoid; + private final String aTextWorldgen = "worldgen."; + + public GT_Worldgen_Ore(String aName, boolean aDefault, Block aBlock, int aBlockMeta, int aDimensionType, + int aAmount, int aSize, int aProbability, int aMinY, int aMaxY, Collection<String> aBiomeList, + boolean aAllowToGenerateinVoid) { + super(aName, GregTech_API.sWorldgenList, aDefault); + mDimensionType = aDimensionType; + mBlock = aBlock; + mBlockMeta = Math.min(Math.max(aBlockMeta, 0), 15); + mProbability = GregTech_API.sWorldgenFile.get(aTextWorldgen + mWorldGenName, "Probability", aProbability); + mAmount = GregTech_API.sWorldgenFile.get(aTextWorldgen + mWorldGenName, "Amount", aAmount); + mSize = GregTech_API.sWorldgenFile.get(aTextWorldgen + mWorldGenName, "Size", aSize); + mMinY = GregTech_API.sWorldgenFile.get(aTextWorldgen + mWorldGenName, "MinHeight", aMinY); + mMaxY = GregTech_API.sWorldgenFile.get(aTextWorldgen + mWorldGenName, "MaxHeight", aMaxY); + if (aBiomeList == null) mBiomeList = new ArrayList<>(); + else mBiomeList = aBiomeList; + mAllowToGenerateinVoid = aAllowToGenerateinVoid; + } +} diff --git a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java new file mode 100644 index 0000000000..900f7808b1 --- /dev/null +++ b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java @@ -0,0 +1,53 @@ +package gregtech.api.world; + +import java.util.Collection; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +public class GT_Worldgen_Ore_SingleBlock extends GT_Worldgen_Ore { + + public GT_Worldgen_Ore_SingleBlock(String aName, boolean aDefault, Block aBlock, int aBlockMeta, int aDimensionType, + int aAmount, int aSize, int aProbability, int aMinY, int aMaxY, Collection<String> aBiomeList, + boolean aAllowToGenerateinVoid) { + super( + aName, + aDefault, + aBlock, + aBlockMeta, + aDimensionType, + aAmount, + aSize, + aProbability, + aMinY, + aMaxY, + aBiomeList, + aAllowToGenerateinVoid); + } + + @Override + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + if (isGenerationAllowed(aWorld, aDimensionType, mDimensionType) + && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome)) + && (mProbability <= 1 || aRandom.nextInt(mProbability) == 0)) { + for (int i = 0; i < mAmount; i++) { + int tX = aChunkX + aRandom.nextInt(16), tY = mMinY + aRandom.nextInt(mMaxY - mMinY), + tZ = aChunkZ + aRandom.nextInt(16); + Block tBlock = aWorld.getBlock(tX, tY, tZ); + if (((mAllowToGenerateinVoid && aWorld.getBlock(tX, tY, tZ) + .isAir(aWorld, tX, tY, tZ)) + || (tBlock != null && (tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.stone) + || tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.end_stone) + || tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.netherrack))))) { + aWorld.setBlock(tX, tY, tZ, mBlock, mBlockMeta, 0); + } + } + return true; + } + return false; + } +} diff --git a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java new file mode 100644 index 0000000000..956cd0eb4c --- /dev/null +++ b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java @@ -0,0 +1,55 @@ +package gregtech.api.world; + +import java.util.Collection; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +public class GT_Worldgen_Ore_SingleBlock_UnderLava extends GT_Worldgen_Ore { + + public GT_Worldgen_Ore_SingleBlock_UnderLava(String aName, boolean aDefault, Block aBlock, int aBlockMeta, + int aDimensionType, int aAmount, int aSize, int aProbability, int aMinY, int aMaxY, + Collection<String> aBiomeList, boolean aAllowToGenerateinVoid) { + super( + aName, + aDefault, + aBlock, + aBlockMeta, + aDimensionType, + aAmount, + aSize, + aProbability, + aMinY, + aMaxY, + aBiomeList, + aAllowToGenerateinVoid); + } + + @Override + public boolean executeCavegen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + if (isGenerationAllowed(aWorld, aDimensionType, mDimensionType) + && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome)) + && (mProbability <= 1 || aRandom.nextInt(mProbability) == 0)) { + for (int i = 0; i < mAmount; i++) { + int tX = aChunkX + aRandom.nextInt(16), tY = mMinY + aRandom.nextInt(mMaxY - mMinY), + tZ = aChunkZ + aRandom.nextInt(16); + Block tBlock = aWorld.getBlock(tX, tY, tZ); + if (((mAllowToGenerateinVoid && aWorld.getBlock(tX, tY, tZ) + .isAir(aWorld, tX, tY, tZ)) + || (tBlock != null && (tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.stone) + || tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.end_stone) + || tBlock.isReplaceableOreGen(aWorld, tX, tY, tZ, Blocks.netherrack))))) { + if (aWorld.getBlock(tX, tY + 1, tZ) == Blocks.lava + || aWorld.getBlock(tX, tY, tZ) == Blocks.flowing_lava) + aWorld.setBlock(tX, tY, tZ, mBlock, mBlockMeta, 0); + } + } + return true; + } + return false; + } +} |