diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-12-15 16:11:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-15 16:11:54 +0100 |
commit | 128c74faa99dfef8d056c1d82c6e4388b9d470e8 (patch) | |
tree | 2c84162154ba681232f86dffd4106db530236814 /src/main/java/gtPlusPlus/australia/gen | |
parent | 47ce336f288a45aa3244c8ae1177499fa5080942 (diff) | |
parent | ff4b8c7068c2ea7d654e9beda00646d23e62b314 (diff) | |
download | GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.gz GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.bz2 GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.zip |
Merge pull request #65 from GTNewHorizons/unified-build-script2
Move sources and resources
Diffstat (limited to 'src/main/java/gtPlusPlus/australia/gen')
13 files changed, 3287 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_Australia_Ores.java b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_Australia_Ores.java new file mode 100644 index 0000000000..18f9e6684f --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_Australia_Ores.java @@ -0,0 +1,294 @@ +package gtPlusPlus.australia.gen.gt; + +import java.util.Hashtable; + +import gregtech.api.enums.Materials; + +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.everglades.object.BoxedQuad; + +public class WorldGen_Australia_Ores { + + /** + * Set Ore Types on by one. + */ + + private static final Material PYRITE = MaterialUtils.generateMaterialFromGtENUM(Materials.Pyrite); + private static final Material PYROPE = MaterialUtils.generateMaterialFromGtENUM(Materials.Pyrope); + private static final Material ALMANDINE = MaterialUtils.generateMaterialFromGtENUM(Materials.Almandine); + private static final Material RUBY = MaterialUtils.generateMaterialFromGtENUM(Materials.Ruby); + private static final Material CHALCOPYRITE = MaterialUtils.generateMaterialFromGtENUM(Materials.Chalcopyrite); + private static final Material TOPAZ = MaterialUtils.generateMaterialFromGtENUM(Materials.Topaz); + private static final Material SAPPHIRE_GREEN = MaterialUtils.generateMaterialFromGtENUM(Materials.GreenSapphire); + private static final Material SAPPHIRE_BLUE = MaterialUtils.generateMaterialFromGtENUM(Materials.Sapphire); + + + private static final Material EMERALD = MaterialUtils.generateMaterialFromGtENUM(Materials.Emerald); + private static final Material DIAMOND = MaterialUtils.generateMaterialFromGtENUM(Materials.Diamond); + private static final Material BANDED_IRON = MaterialUtils.generateMaterialFromGtENUM(Materials.BandedIron); + private static final Material LIM_YELLOW = MaterialUtils.generateMaterialFromGtENUM(Materials.YellowLimonite); + private static final Material LIM_BROWN = MaterialUtils.generateMaterialFromGtENUM(Materials.BrownLimonite); + private static final Material TETRAHEDRITE = MaterialUtils.generateMaterialFromGtENUM(Materials.Tetrahedrite); + private static final Material COAL = MaterialUtils.generateMaterialFromGtENUM(Materials.Coal); + private static final Material SHIT_COAL = MaterialUtils.generateMaterialFromGtENUM(Materials.Lignite); + private static final Material GRAPHITE = MaterialUtils.generateMaterialFromGtENUM(Materials.Graphite); + + + + public static WorldGen_GT_Australia_Ore_Layer BaseVein = new WorldGen_GT_Australia_Ore_Layer( + "veinA", + 0, 128, + 5, + 8, + 32, + ELEMENT.getInstance().IRON, + BANDED_IRON, + LIM_YELLOW, + TETRAHEDRITE); + + + + /** + * Custom ore Veins + */ + + public static WorldGen_GT_Australia_Ore_Layer Vein1 = new WorldGen_GT_Australia_Ore_Layer( + "vein1", + 0, 10, + 1, + 8, + 16, + EMERALD, + SHIT_COAL, + TOPAZ, + DIAMOND); + + public static WorldGen_GT_Australia_Ore_Layer Vein2 = new WorldGen_GT_Australia_Ore_Layer( + "vein2", + 0, 128, + 20, + 16, + 64, + COAL, + COAL, + SHIT_COAL, + SHIT_COAL); + + public static WorldGen_GT_Australia_Ore_Layer Vein3 = new WorldGen_GT_Australia_Ore_Layer( + "vein3", + 0, 128, + 5, + 8, + 32, + ELEMENT.getInstance().IRON, + ELEMENT.getInstance().TIN, + ELEMENT.getInstance().GOLD, + ELEMENT.getInstance().LEAD); + + public static WorldGen_GT_Australia_Ore_Layer Vein4 = new WorldGen_GT_Australia_Ore_Layer( + "vein4", + 0, 128, + 5, + 8, + 32, + ELEMENT.getInstance().GOLD, + ELEMENT.getInstance().COPPER, + ELEMENT.getInstance().COBALT, + ALMANDINE); + + + + public static WorldGen_GT_Australia_Ore_Layer Vein5 = new WorldGen_GT_Australia_Ore_Layer( + "vein5", + 0, 128, + 15, + 8, + 16, + PYRITE, + PYROPE, + LIM_YELLOW, + CHALCOPYRITE); + + public static WorldGen_GT_Australia_Ore_Layer Vein6 = new WorldGen_GT_Australia_Ore_Layer( + "vein6", + 0, 128, + 5, + 8, + 32, + LIM_BROWN, + SAPPHIRE_GREEN, + ELEMENT.getInstance().IRON, + ELEMENT.getInstance().COPPER); + + public static WorldGen_GT_Australia_Ore_Layer Vein7 = new WorldGen_GT_Australia_Ore_Layer( + "vein7", + 0, 128, + 5, + 8, + 32, + GRAPHITE, + RUBY, + LIM_YELLOW, + ELEMENT.getInstance().NICKEL); + + public static WorldGen_GT_Australia_Ore_Layer Vein8 = new WorldGen_GT_Australia_Ore_Layer( + "vein8", + 0, 128, + 5, + 8, + 32, + ELEMENT.getInstance().IRON, + SAPPHIRE_BLUE, + LIM_YELLOW, + GRAPHITE); + + + + + /*public static WorldGen_GT_Australia_Ore_Layer Vein9 = new WorldGen_GT_Australia_Ore_Layer( + "vein9", + 10, 30, + 20, + 4, + 64, + ORES.LANTHANITE_CE, + FLUORIDES.FLUORITE, + PLATINUM, + ORES.FLORENCITE); + public static WorldGen_GT_Australia_Ore_Layer Vein10 = new WorldGen_GT_Australia_Ore_Layer( + "vein10", + 20, 50, + 20, + 8, + 32, + ORES.GEIKIELITE, + ORES.YTTROCERITE, + ORES.LANTHANITE_LA, + BAUXITE); + public static WorldGen_GT_Australia_Ore_Layer Vein11 = new WorldGen_GT_Australia_Ore_Layer( + "vein11", + 30, 70, + 20, + 5, + 64, + FLUORIDES.FLUORITE, + SAPPHIRE_BLUE, + ORES.ZIRCON, + ORES.CRYOLITE); + public static WorldGen_GT_Australia_Ore_Layer Vein12 = new WorldGen_GT_Australia_Ore_Layer( + "vein12", + 40, 80, + 20, + 8, + 32, + ORES.CERITE, + SAPPHIRE_GREEN, + CHALCOPYRITE, + ORES.HIBONITE); + + *//** + * Best Rarest Veins 2017 + *//* + + public static WorldGen_GT_Australia_Ore_Layer Vein13 = new WorldGen_GT_Australia_Ore_Layer( + "vein13", + 5, 15, + 5, + 5, + 16, + ORES.CRYOLITE, + NAQPLUS, + NAQUADRIA, + ORES.FLORENCITE); + + public static WorldGen_GT_Australia_Ore_Layer Vein14 = new WorldGen_GT_Australia_Ore_Layer( + "vein14", + 10, 20, + 8, + 3, + 16, + URNAIUM235, + PLUTONIUM, + OSMIUM, + AMETHYST); + + public static WorldGen_GT_Australia_Ore_Layer Vein15 = new WorldGen_GT_Australia_Ore_Layer( + "vein15", + 5, 25, + 5, + 6, + 24, + ORES.FLUORCAPHITE, + BISMUTH, + ORES.GADOLINITE_CE, + ORES.GADOLINITE_Y); + + public static WorldGen_GT_Australia_Ore_Layer Vein16 = new WorldGen_GT_Australia_Ore_Layer( + "vein16", + 0, 25, + 4, + 6, + 32, + ORES.YTTROCERITE, + ORES.LEPERSONNITE, + INFUSEDGOLD, + FLUORIDES.FLUORITE); + + public static WorldGen_GT_Australia_Ore_Layer Vein17 = new WorldGen_GT_Australia_Ore_Layer( + "vein17", + 10, 35, + 4, + 5, + 32, + ORES.FLORENCITE, + URNAIUM235, + ORES.SAMARSKITE_YB, + ORES.POLYCRASE); + public static WorldGen_GT_Australia_Ore_Layer Vein18 = new WorldGen_GT_Australia_Ore_Layer( + "vein18", + 15, 40, + 4, + 4, + 64, + ORES.GADOLINITE_CE, + ORES.GADOLINITE_Y, + ORES.AGARDITE_LA, + ORES.AGARDITE_CD);*/ + + + + + public static Hashtable<Long, WorldGen_GT_Australia_Ore_Layer> validOreveins = new Hashtable<Long, WorldGen_GT_Australia_Ore_Layer>( + 1024); + + + public static volatile BoxedQuad<Integer, Integer, Integer, Integer> OreVein1 = new BoxedQuad<Integer, Integer, Integer, Integer>(null, null, null, null); + + static long ID = 0; + public static void generateValidOreVeins(){ + validOreveins.put(ID++, BaseVein); + + validOreveins.put(ID++, Vein1); + validOreveins.put(ID++, Vein2); + validOreveins.put(ID++, Vein3); + validOreveins.put(ID++, Vein4); + validOreveins.put(ID++, Vein5); + validOreveins.put(ID++, Vein6); + validOreveins.put(ID++, Vein7); + validOreveins.put(ID++, Vein8); + + /*validOreveins.put(ID++, Vein9); + validOreveins.put(ID++, Vein10); + validOreveins.put(ID++, Vein11); + validOreveins.put(ID++, Vein12); + validOreveins.put(ID++, Vein13); + validOreveins.put(ID++, Vein14); + validOreveins.put(ID++, Vein15); + validOreveins.put(ID++, Vein16); + validOreveins.put(ID++, Vein17); + validOreveins.put(ID++, Vein18);*/ + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia.java b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia.java new file mode 100644 index 0000000000..93d5524a66 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia.java @@ -0,0 +1,48 @@ +package gtPlusPlus.australia.gen.gt; + +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 gtPlusPlus.australia.GTplusplus_Australia; + +public abstract class WorldGen_GT_Australia { + public final String mWorldGenName; + public final boolean mEnabled; + private final Map<String, Boolean> mDimensionMap = new ConcurrentHashMap<String, Boolean>(); + + public WorldGen_GT_Australia(String aName, List aList, boolean aDefault) { + this.mWorldGenName = aName; + this.mEnabled = GTplusplus_Australia.sCustomWorldgenFile.get("worldgen", this.mWorldGenName, aDefault); + if (this.mEnabled) { + aList.add(this); + } + + } + + public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return false; + } + + public boolean executeCavegen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, + int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return false; + } + + public boolean isGenerationAllowed(World aWorld, int aDimensionType, int aAllowedDimensionType) { + String aDimName = aWorld.provider.getDimensionName(); + Boolean tAllowed = (Boolean) this.mDimensionMap.get(aDimName); + if (tAllowed == null) { + boolean tValue = GTplusplus_Australia.sCustomWorldgenFile.get("worldgen.dimensions." + this.mWorldGenName, aDimName, + aDimensionType == aAllowedDimensionType); + this.mDimensionMap.put(aDimName, Boolean.valueOf(tValue)); + return tValue; + } else { + return tAllowed.booleanValue(); + } + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Base.java b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Base.java new file mode 100644 index 0000000000..917c1eb746 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Base.java @@ -0,0 +1,471 @@ +package gtPlusPlus.australia.gen.gt; + +import java.util.*; + +import cpw.mods.fml.common.IWorldGenerator; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.feature.WorldGenMinable; + +import gregtech.api.util.GT_Log; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.random.XSTR; +import gtPlusPlus.australia.dimension.Dimension_Australia; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.xmod.gregtech.HANDLER_GT; + +public class WorldGen_GT_Australia_Base implements IWorldGenerator { + + /** + * Class Variables + */ + + /** + * Control percentage of filled 3x3 chunks. Lower number means less oreveins + * spawn + */ + public static int oreveinPercentage; + /** + * Control number of attempts to find a valid orevein. Generally this + * maximum limit isn't hit, selecting a vein is cheap + */ + public static int oreveinAttempts; + /** + * Control number of attempts to place a valid orevein. If a vein wasn't + * placed due to height restrictions, completely in the water, etc, another + * attempt is tried. + */ + public static int oreveinMaxPlacementAttempts; + /** + * Debug parameter for world generation. Tracks chunks added/removed from + * run queue. + */ + public static boolean debugWorldGen = false; + /** + * Try re-implement Richard Hendrick's Chunk by Chunk Ore Generation from + * his GT5u fork. + */ + + public static List<Runnable> mList = new ArrayList<Runnable>(); + public static HashSet<Long> ProcChunks = new HashSet<Long>(); + // This is probably not going to work. Trying to create a fake orevein to + // put into hashtable when there will be no ores in a vein. + public static WorldGen_GT_Australia_Ore_Layer noOresInVein = new WorldGen_GT_Australia_Ore_Layer("vein0", 0, 255, 0, 0, + 0, ELEMENT.getInstance().IRON, ELEMENT.getInstance().GOLD, ELEMENT.getInstance().LEAD, ELEMENT.getInstance().TIN); + + public static Hashtable<Long, WorldGen_GT_Australia_Ore_Layer> validOreveins = new Hashtable<Long, WorldGen_GT_Australia_Ore_Layer>( + 1024); + + public boolean mIsGenerating = false; + public static final Object listLock = new Object(); + // private static boolean gcAsteroids = true; + + public WorldGen_GT_Australia_Base() { + if (debugWorldGen) { + GT_Log.out.println("GTPP_Worldgenerator created"); + } + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, + IChunkProvider chunkProvider) { + if (world.provider.dimensionId == Dimension_Australia.DIMID) { + generateSafely(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider); + } + } + + public synchronized void generateSafely(Random random, int chunkX, int chunkZ, World world, + IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + int xDim = Dimension_Australia.DIMID; + switch (world.provider.dimensionId) { + case -1: // Nether + // generateNether(world, random, chunkX * 16, chunkZ * 16); + break; + case 0: // Overworld + // generateSurface(world, random, chunkX * 16, chunkZ * 16); + break; + case 1: // End + // generateEnd(world, random, chunkX * 16, chunkZ * 16); + break; + default: // Any other dimension + if (world.provider.dimensionId != xDim) { + break; + } + else { + generateEverglades(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider); + break; + } + } + } + + private synchronized void generateEverglades(Random aRandom, int aX, int aZ, World aWorld, + IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + Logger.WARNING("Trying to Generate Dimension."); + synchronized (listLock) { + Logger.WARNING("Locked List addition."); + if (WorldGen_GT_Australia_Base.mList.add(new WorldGenContainer(new XSTR(Math.abs(aRandom.nextInt()) + 1), aX, aZ, + Dimension_Australia.DIMID, + aWorld, aChunkGenerator, aChunkProvider, + aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName))){ + Logger.WARNING("Locked List addition. Success."); + } + else { + Logger.WARNING("Locked List addition. Fail."); + } + if (debugWorldGen) + GT_Log.out.println("ADD WorldSeed:" + aWorld.getSeed() + " DimId" + aWorld.provider.dimensionId + + " chunk x:" + aX + " z:" + aZ + " SIZE: " + WorldGen_GT_Australia_Base.mList.size()); + } + + if (!this.mIsGenerating) { + Logger.WARNING("Is not generating."); + this.mIsGenerating = true; + Logger.WARNING("Setting Generation to true."); + int mList_sS = WorldGen_GT_Australia_Base.mList.size(); + mList_sS = Math.min(mList_sS, 3); // Run a maximum of 3 chunks at a + // time through worldgen. Extra + // chunks get done later. + for (int i = 0; i < mList_sS; i++) { + WorldGenContainer toRun = (WorldGenContainer) WorldGen_GT_Australia_Base.mList.get(0); + if (debugWorldGen) + GT_Log.out.println("RUN WorldSeed:" + aWorld.getSeed() + " DimId" + aWorld.provider.dimensionId + + " chunk x:" + toRun.mX + " z:" + toRun.mZ + " SIZE: " + WorldGen_GT_Australia_Base.mList.size() + + " i: " + i); + synchronized (listLock) { + Logger.WARNING("Locked List Removal."); + WorldGen_GT_Australia_Base.mList.remove(0); + } + toRun.run(); + } + this.mIsGenerating = false; + Logger.WARNING("Is Generating now set to false.."); + } + } + + public void generateOre(Block block, World world, Random random, int chunk_x, int chunk_z, int maxX, int maxZ, + int maxVeinSize, int chancesToSpawn, int minY, int maxY, Block generateIn) { + int heightRange = maxY - minY; + WorldGenMinable worldgenminable = new WorldGenMinable(block, maxVeinSize, generateIn); + for (int k1 = 0; k1 < chancesToSpawn; ++k1) { + int xrand = random.nextInt(16); + int yrand = random.nextInt(heightRange) + minY; + int zrand = random.nextInt(16); + worldgenminable.generate(world, random, chunk_x + xrand, yrand, chunk_z + zrand); + } + } + + public static class WorldGenContainer implements Runnable { + public final Random mRandom; + public final int mX; + public final int mZ; + public final int mDimensionType; + public final World mWorld; + public final IChunkProvider mChunkGenerator; + public final IChunkProvider mChunkProvider; + public final String mBiome; + + // Local class to track which orevein seeds must be checked when doing + // chunkified worldgen + class NearbySeeds { + public int mX; + public int mZ; + + NearbySeeds(int x, int z) { + this.mX = x; + this.mZ = z; + } + }; + + public static ArrayList<NearbySeeds> seedList = new ArrayList<NearbySeeds>(); + + // aX and aZ are now the by-chunk X and Z for the chunk of interest + public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, + IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) { + this.mRandom = aRandom; + this.mX = aX; + this.mZ = aZ; + this.mDimensionType = aDimensionType; + this.mWorld = aWorld; + this.mChunkGenerator = aChunkGenerator; + this.mChunkProvider = aChunkProvider; + this.mBiome = aBiome; + } + + public void worldGenFindVein(int oreseedX, int oreseedZ) { + // Explanation of oreveinseed implementation. + // (long)this.mWorld.getSeed()<<16) Deep Dark does two oregen + // passes, one with getSeed set to +1 the original world seed. This + // pushes that +1 off the low bits of oreseedZ, so that the hashes + // are far apart for the two passes. + // ((this.mWorld.provider.dimensionId & 0xffL)<<56) Puts the + // dimension in the top bits of the hash, to make sure to get unique + // hashes per dimension + // ((long)oreseedX & 0x000000000fffffffL) << 28) Puts the chunk X in + // the bits 29-55. Cuts off the top few bits of the chunk so we have + // bits for dimension. + // ( (long)oreseedZ & 0x000000000fffffffL )) Puts the chunk Z in the + // bits 0-27. Cuts off the top few bits of the chunk so we have bits + // for dimension. + long oreveinSeed = (this.mWorld.getSeed() << 16) ^ ((this.mWorld.provider.dimensionId & 0xffL) << 56 + | ((oreseedX & 0x000000000fffffffL) << 28) | (oreseedZ & 0x000000000fffffffL)); // Use + // an + // RNG + // that + // is + // identical + // every + // time + // it + // is + // called + // for + // this + // oreseed. + XSTR oreveinRNG = new XSTR(oreveinSeed); + int oreveinPercentageRoll = oreveinRNG.nextInt(100); // Roll the + // dice, see + // if we get + // an + // orevein + // here at + // all + int noOrePlacedCount = 0; + String tDimensionName = ""; + if (debugWorldGen) { + tDimensionName = this.mWorld.provider.getDimensionName(); + } + + if (debugWorldGen){ + GT_Log.out.println(" Finding oreveins for oreveinSeed=" + oreveinSeed + " mX=" + this.mX + " mZ=" + + this.mZ + " oreseedX=" + oreseedX + " oreseedZ=" + oreseedZ + " worldSeed=" + + this.mWorld.getSeed()); + } + + Logger.WARNING("[World Generation Debug] !validOreveins.containsKey(oreveinSeed) | oreveinSeed: "+oreveinSeed); + // Search for a valid orevein for this dimension + if (!validOreveins.containsKey(oreveinSeed)) { + + + Logger.WARNING("[World Generation Debug] oreveinPercentageRoll < oreveinPercentage? "+((oreveinPercentageRoll < oreveinPercentage))); + Logger.WARNING("[World Generation Debug] WorldGen_GT_Ore_Layer.sWeight > 0? "+(WorldGen_GT_Australia_Ore_Layer.sWeight > 0)); + Logger.WARNING("[World Generation Debug] WorldGen_GT_Ore_Layer.sList.size() > 0? "+(WorldGen_GT_Australia_Ore_Layer.sList.size() > 0)); + if ((oreveinPercentageRoll < oreveinPercentage) && (WorldGen_GT_Australia_Ore_Layer.sWeight > 0) + && (WorldGen_GT_Australia_Ore_Layer.sList.size() > 0)) { + int placementAttempts = 0; + boolean oreveinFound = false; + int i; + for (i = 0; (i < oreveinAttempts) && (!oreveinFound) + && (placementAttempts < oreveinMaxPlacementAttempts); i++) { + Logger.WARNING("[World Generation Debug] i: "+i); + Logger.WARNING("[World Generation Debug] placementAttempts: "+placementAttempts); + Logger.WARNING("[World Generation Debug] oreveinAttempts: "+oreveinAttempts); + Logger.WARNING("[World Generation Debug] (placementAttempts < oreveinMaxPlacementAttempts): "+(placementAttempts < oreveinMaxPlacementAttempts)); + Logger.WARNING("[World Generation Debug] oreveinFound: "+oreveinFound); + int tRandomWeight = oreveinRNG.nextInt(WorldGen_GT_Australia_Ore_Layer.sWeight); + for (WorldGen_GT_Australia_Ore_Layer tWorldGen : WorldGen_GT_Australia_Ore_Layer.sList) { + Logger.WARNING("[World Generation Debug] Iterating sList - Size: "+WorldGen_GT_Australia_Ore_Layer.sList.size()); + tRandomWeight -= (tWorldGen).mWeight; + if (tRandomWeight <= 0) { + try { + // Adjust the seed so that this layer has a + // series of unique random numbers. + // Otherwise multiple attempts at this same + // oreseed will get the same offset and X/Z + // values. If an orevein failed, any orevein + // with the + // same minimum heights would fail as well. + // This prevents that, giving each orevein a + // unique height each pass through here. + int placementResult = tWorldGen.executeWorldgenChunkified(this.mWorld, + new XSTR(oreveinSeed ^ (Block.getIdFromBlock(tWorldGen.mPrimaryMeta))), this.mBiome, + this.mDimensionType, this.mX * 16, this.mZ * 16, oreseedX * 16, + oreseedZ * 16, this.mChunkGenerator, this.mChunkProvider); + switch (placementResult) { + case WorldGen_GT_Australia_Ore_Layer.ORE_PLACED: + if (debugWorldGen) + GT_Log.out.println(" Added oreveinSeed=" + oreveinSeed + + " tries at oremix=" + i + " placementAttempts=" + + placementAttempts + " dimensionName=" + tDimensionName); + validOreveins.put(oreveinSeed, tWorldGen); + oreveinFound = true; + Logger.WARNING("[World Generation Debug] ORE_PLACED"); + break; + case WorldGen_GT_Australia_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER: + placementAttempts++; + Logger.WARNING("[World Generation Debug] NO_ORE_IN_BOTTOM_LAYER | Attempts: "+placementAttempts); + // SHould do retry in this case + // until out of chances + break; + case WorldGen_GT_Australia_Ore_Layer.NO_OVERLAP: + // Orevein didn't reach this chunk, + // can't add it yet to the hash + Logger.WARNING("[World Generation Debug] NO_OVERLAP"); + if (debugWorldGen) GT_Log.out.println( + " Added far oreveinSeed=" + oreveinSeed + " " + + ( tWorldGen).mWorldGenName + + " tries at oremix=" + i + + " placementAttempts=" + placementAttempts + + " dimensionName=" + tDimensionName + ); + validOreveins.put(oreveinSeed, tWorldGen); + oreveinFound = true; + break; + case WorldGen_GT_Australia_Ore_Layer.NO_OVERLAP_AIR_BLOCK: + if (debugWorldGen) GT_Log.out.println( + " No overlap and air block in test spot=" + oreveinSeed + " " + + ( tWorldGen).mWorldGenName + + " tries at oremix=" + i + + " placementAttempts=" + placementAttempts + + " dimensionName=" + tDimensionName + ); + // SHould do retry in this case until out of chances + Logger.WARNING("[World Generation Debug] NO_OVERLAP_AIR_BLOCK"); + placementAttempts++; + break; + } + break; // Try the next orevein + } + catch (Throwable e) { + if (debugWorldGen) + GT_Log.out.println("Exception occurred on oreVein" + tWorldGen + " oreveinSeed=" + + oreveinSeed + " mX=" + this.mX + " mZ=" + this.mZ + " oreseedX=" + + oreseedX + " oreseedZ=" + oreseedZ); + e.printStackTrace(GT_Log.err); + } + } + } + } + // Only add an empty orevein if are unable to place a vein + // at the oreseed chunk. + if ((!oreveinFound) && (this.mX == oreseedX) && (this.mZ == oreseedZ)) { + if (debugWorldGen) + GT_Log.out.println(" Empty oreveinSeed=" + oreveinSeed + " mX=" + this.mX + " mZ=" + this.mZ + + " oreseedX=" + oreseedX + " oreseedZ=" + oreseedZ + " tries at oremix=" + i + + " placementAttempts=" + placementAttempts + " dimensionName=" + tDimensionName); + validOreveins.put(oreveinSeed, noOresInVein); + } + } + else if (oreveinPercentageRoll >= oreveinPercentage) { + if (debugWorldGen) + GT_Log.out.println(" Skipped oreveinSeed=" + oreveinSeed + " mX=" + this.mX + " mZ=" + this.mZ + + " oreseedX=" + oreseedX + " oreseedZ=" + oreseedZ + " RNG=" + oreveinPercentageRoll + + " %=" + oreveinPercentage + " dimensionName=" + tDimensionName); + validOreveins.put(oreveinSeed, noOresInVein); + } + } + else { + // oreseed is located in the previously processed table + if (debugWorldGen) + GT_Log.out.print(" Valid oreveinSeed=" + oreveinSeed + " validOreveins.size()=" + + validOreveins.size() + " "); + WorldGen_GT_Australia_Ore_Layer tWorldGen = validOreveins.get(oreveinSeed); + oreveinRNG.setSeed(oreveinSeed ^ (Block.getIdFromBlock(tWorldGen.mPrimaryMeta))); // Reset + // RNG + // to + // only + // be + // based + // on + // oreseed + // X/Z + // and + // type + // of + // vein + int placementResult = tWorldGen.executeWorldgenChunkified(this.mWorld, oreveinRNG, this.mBiome, + this.mDimensionType, this.mX * 16, this.mZ * 16, oreseedX * 16, oreseedZ * 16, + this.mChunkGenerator, this.mChunkProvider); + switch (placementResult) { + case WorldGen_GT_Australia_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER: + if (debugWorldGen) + GT_Log.out.println(" No ore in bottom layer"); + break; + case WorldGen_GT_Australia_Ore_Layer.NO_OVERLAP: + if (debugWorldGen) + GT_Log.out.println(" No overlap"); + break; + } + } + } + + @Override + public void run() { + long startTime = System.nanoTime(); + int oreveinMaxSize; + + // Determine bounding box on how far out to check for oreveins + // affecting this chunk + // For now, manually reducing oreveinMaxSize when not in the + // Underdark for performance + if (this.mWorld.provider.getDimensionName().equals("Underdark")) { + oreveinMaxSize = 24; // Leave Deep Dark/Underdark max oregen at + // 32, instead of 64 + } + else { + oreveinMaxSize = 48; + } + + int wXbox = this.mX - (oreveinMaxSize / 16); + int eXbox = this.mX + (oreveinMaxSize / 16 + 1); // Need to add 1 + // since it is + // compared + // using a < + int nZbox = this.mZ - (oreveinMaxSize / 16); + int sZbox = this.mZ + (oreveinMaxSize / 16 + 1); + + // Search for orevein seeds and add to the list; + for (int x = wXbox; x < eXbox; x++) { + for (int z = nZbox; z < sZbox; z++) { + // Determine if this X/Z is an orevein seed + if (((Math.abs(x) % 3) == 1) && ((Math.abs(z) % 3) == 1)) { + if (debugWorldGen) + GT_Log.out.println("Adding seed x=" + x + " z=" + z); + seedList.add(new NearbySeeds(x, z)); + } + } + } + + // Now process each oreseed vs this requested chunk + for (; seedList.size() != 0; seedList.remove(0)) { + if (debugWorldGen) + GT_Log.out.println("Processing seed x=" + seedList.get(0).mX + " z=" + seedList.get(0).mZ); + worldGenFindVein(seedList.get(0).mX, seedList.get(0).mZ); + } + + long oregenTime = System.nanoTime(); + + // Do leftover worldgen for this chunk (GT_Stones and GT_small_ores) + try { + for (WorldGen_GT_Australia tWorldGen : HANDLER_GT.sWorldgenListAustralia) { + /* + * if (debugWorldGen) GT_Log.out.println( + * "tWorldGen.mWorldGenName="+tWorldGen.mWorldGenName ); + */ + tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX * 16, + this.mZ * 16, this.mChunkGenerator, this.mChunkProvider); + } + } + catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } + + long leftOverTime = System.nanoTime(); + + Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ); + if (tChunk != null) { + tChunk.isModified = true; + } + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + if (debugWorldGen) { + GT_Log.out.println(" Oregen took " + (oregenTime - startTime) + " Leftover gen took " + + (leftOverTime - oregenTime) + " Worldgen took " + duration + " nanoseconds"); + } + } + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java new file mode 100644 index 0000000000..a5e5f8b245 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/gt/WorldGen_GT_Australia_Ore_Layer.java @@ -0,0 +1,511 @@ +package gtPlusPlus.australia.gen.gt; + +import static gtPlusPlus.australia.gen.gt.WorldGen_GT_Australia_Base.debugWorldGen; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.util.GT_Log; +import gregtech.common.blocks.GT_Block_Ores; +import gregtech.common.blocks.GT_TileEntity_Ores; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.GTplusplus_Australia; +import gtPlusPlus.australia.dimension.Dimension_Australia; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; + +public class WorldGen_GT_Australia_Ore_Layer +extends WorldGen_GT_Australia { + public static ArrayList<WorldGen_GT_Australia_Ore_Layer> sList = new ArrayList<WorldGen_GT_Australia_Ore_Layer>(); + 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 Block mPrimaryMeta; + public Block mSecondaryMeta; + public Block mBetweenMeta; + public Block mSporadicMeta; + public final Material mPrimary; + public final Material mSecondary; + public final Material mBetween; + public final Material mSporadic; + + public static boolean mUpdated = CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK; + public static final Block mStoneTypes; + + //public final String mBiome; + public final String mRestrictBiome; + public final boolean mOverworld; + public final boolean mNether; + public final boolean mEnd; + public static final int WRONG_BIOME=0; + public static final int WRONG_DIMENSION=1; + public static final int NO_ORE_IN_BOTTOM_LAYER=2; + public static final int NO_OVERLAP=3; + public static final int ORE_PLACED=4; + public static final int NO_OVERLAP_AIR_BLOCK=5; + + //public final boolean mMoon; + //public final boolean mMars; + //public final boolean mAsteroid; + public final String aTextWorldgen = "worldgen."; + + static { + if (mUpdated) { + Object tempBlock = null; + try { + Field temp = ReflectionUtils.getField(GregTech_API.class, "sBlockStones"); + tempBlock = temp.get(null); + } + catch (IllegalArgumentException | IllegalAccessException e) {} + mStoneTypes = (Block) tempBlock; + } + else { + mStoneTypes = null; + } + } + + + public WorldGen_GT_Australia_Ore_Layer(String aName, int aMinY, int aMaxY, int aWeight, int aDensity, int aSize, Material aPrimary, Material aSecondary, Material aBetween, Material aSporadic) { + this(aName, true, aMinY, aMaxY, aWeight, aDensity, aSize, false, false, false, false, false, false, aPrimary, aSecondary, aBetween, aSporadic); + } + + + public WorldGen_GT_Australia_Ore_Layer(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity, int aSize, boolean aOverworld, boolean aNether, boolean aEnd, boolean GC_UNUSED1, boolean GC_UNUSED2, boolean GC_UNUSED3, Material aPrimary, Material aSecondary, Material aBetween, Material aSporadic) { + super(aName, sList, aDefault); + Logger.WARNING("Creating Ore Layer Object"); + this.mOverworld = GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Overworld", aOverworld); + this.mNether = GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Nether", aNether); + this.mEnd = GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "TheEnd", aEnd); + //this.mMoon = HANDLER_GT.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Moon", aMoon); + //this.mMars = HANDLER_GT.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Mars", aMars); + //this.mAsteroid = HANDLER_GT.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Asteroid", aAsteroid); + this.mMinY = 5; + short mMaxY = 14; + if (mMaxY < (this.mMinY + 7)) { + GT_Log.out.println( + "Oremix " + this.mWorldGenName + + " has invalid Min/Max heights!" + ); + mMaxY = (short) (this.mMinY + 7); + } + this.mMaxY = mMaxY; + this.mWeight = ((short) GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "RandomWeight", aWeight)); + this.mDensity = ((short) GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Density", aDensity)); + this.mSize = ((short) Math.max(1, GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "Size", aSize))); + this.mPrimary = aPrimary; + this.mSecondary = aSecondary; + this.mBetween = aBetween; + this.mSporadic = aSporadic; + this.mPrimaryMeta = aPrimary.getOreBlock(1); + this.mSecondaryMeta = aSecondary.getOreBlock(1); + this.mBetweenMeta = aBetween.getOreBlock(1); + this.mSporadicMeta = aSporadic.getOreBlock(1); + this.mRestrictBiome = GTplusplus_Australia.sCustomWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "RestrictToBiomeName", "None"); + + //if (mPrimaryMeta != -1 && GregTech_API.sGeneratedMaterials[(mPrimaryMeta % 1000)] == null) throw new IllegalArgumentException("A Material for the supplied ID " + mPrimaryMeta + " for " + mWorldGenName + " does not exist"); + //if (mSecondaryMeta != -1 && GregTech_API.sGeneratedMaterials[(mSecondaryMeta % 1000)] == null) throw new IllegalArgumentException("A Material for the supplied ID " + mSecondaryMeta + " for " + mWorldGenName + " does not exist"); + //if (mBetweenMeta != -1 && GregTech_API.sGeneratedMaterials[(mBetweenMeta % 1000)] == null) throw new IllegalArgumentException("A Material for the supplied ID " + mBetweenMeta + " for " + mWorldGenName + " does not exist"); + //if (mPrimaryMeta != -1 && GregTech_API.sGeneratedMaterials[(mSporadicMeta % 1000)] == null) throw new IllegalArgumentException("A Material for the supplied ID " + mSporadicMeta + " for " + mWorldGenName + " does not exist"); + + if (this.mEnabled) { + //GT_Achievements.registerOre(GregTech_API.sGeneratedMaterials[(mPrimaryMeta % 1000)], aMinY, aMaxY, aWeight, aOverworld, aNether, aEnd); + //GT_Achievements.registerOre(GregTech_API.sGeneratedMaterials[(mSecondaryMeta % 1000)], aMinY, aMaxY, aWeight, aOverworld, aNether, aEnd); + //GT_Achievements.registerOre(GregTech_API.sGeneratedMaterials[(mBetweenMeta % 1000)], aMinY, aMaxY, aWeight, aOverworld, aNether, aEnd); + //GT_Achievements.registerOre(GregTech_API.sGeneratedMaterials[(mSporadicMeta % 1000)], aMinY, aMaxY, aWeight, aOverworld, aNether, aEnd); + sWeight += this.mWeight; + } + } + + public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, int aSeedX, int aSeedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + + //Debug Handler + /** + * This handles Variables that are null during Init + */ + + if (this.mPrimaryMeta == Blocks.stone || this.mSecondaryMeta == Blocks.stone + || this.mBetweenMeta == Blocks.stone || this.mSporadicMeta == Blocks.stone){ + this.mPrimaryMeta = this.mPrimary.getOreBlock(1); + this.mSecondaryMeta = this.mSecondary.getOreBlock(1); + this.mBetweenMeta = this.mBetween.getOreBlock(1); + this.mSporadicMeta = this.mSporadic.getOreBlock(1); + Logger.WARNING("[Vein Generator] An Ore in a Vein had defaulted back to a default value, so they have now been reset to correct values."); + } + + if( mWorldGenName.equals("vein0") ) { + if (debugWorldGen) GT_Log.out.println( + " NoOresInVein-vein0" + ); + // This is a special empty orevein + Logger.WARNING("[World Generation Debug] Special Empty Vein placed."); + return ORE_PLACED; + } + if (aDimensionType != Dimension_Australia.DIMID) { + /* // Debug code, but spams log + if (debugWorldGen) { + GT_Log.out.println( + "Wrong dimension" + ); + } + */ + Logger.WARNING("[World Generation Debug] Wrong dimension."); + return WRONG_DIMENSION; + } + if (!this.mRestrictBiome.equals("None") && !(this.mRestrictBiome.equals(aBiome))) { + return WRONG_BIOME; + } + int[] placeCount=new int[4]; + + int tMinY = mMinY + aRandom.nextInt(mMaxY - mMinY - 5); + // Determine West/East ends of orevein + int wXVein = aSeedX - aRandom.nextInt(mSize); // West side + int eXVein = aSeedX + 16 + aRandom.nextInt(mSize); + // Limit Orevein to only blocks present in current chunk + int wX = Math.max( wXVein, aChunkX + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int eX = Math.min( eXVein, aChunkX + 2 + 16); + if (wX >= eX) { //No overlap between orevein and this chunk exists in X + Block tBlock = aWorld.getBlock(aChunkX + 8, tMinY, aChunkZ + 8); + if (tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.stone) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.netherrack) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.end_stone) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, GregTech_API.sBlockGranites) || + (mUpdated && tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, mStoneTypes)) ) { + // Didn't reach, but could have placed. Save orevein for future use. + return NO_OVERLAP; + } else { + // Didn't reach, but couldn't place in test spot anywys, try for another orevein + return NO_OVERLAP_AIR_BLOCK; + } + } + // Determine North/Sound ends of orevein + int nZVein = aSeedZ - aRandom.nextInt(mSize); + int sZVein = aSeedZ + 16 + aRandom.nextInt(mSize); + + int nZ = Math.max(nZVein, aChunkZ + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int sZ = Math.min(sZVein, aChunkZ + 2 + 16); + if (nZ >= sZ) { //No overlap between orevein and this chunk exists in Z + Block tBlock = aWorld.getBlock(aChunkX + 8, tMinY, aChunkZ + 8); + if (tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.stone) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.netherrack) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, Blocks.end_stone) || + tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, GregTech_API.sBlockGranites) || + (mUpdated && tBlock.isReplaceableOreGen(aWorld, aChunkX+8, tMinY, aChunkZ + 8, mStoneTypes)) ) { + // Didn't reach, but could have placed. Save orevein for future use. + return NO_OVERLAP; + } else { + // Didn't reach, but couldn't place in test spot anywys, try for another orevein + return NO_OVERLAP_AIR_BLOCK; + } + + } + + if (debugWorldGen) { + String tDimensionName = aWorld.provider.getDimensionName(); + GT_Log.out.print( + "Trying Orevein:" + this.mWorldGenName + + " Dimension=" + tDimensionName + + " mX="+aChunkX/16+ + " mZ="+aChunkZ/16+ + " oreseedX="+ aSeedX/16 + + " oreseedZ="+ aSeedZ/16 + + " cY="+tMinY + ); + } + // Adjust the density down the more chunks we are away from the oreseed. The 5 chunks surrounding the seed should always be max density due to truncation of Math.sqrt(). + int localDensity = (Math.max(1, this.mDensity / ((int)Math.sqrt(2 + Math.pow(aChunkX/16 - aSeedX/16, 2) + Math.pow(aChunkZ/16 - aSeedZ/16, 2))))); + + // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll 1 pass through the loop + // Now we do bottom-level-first oregen, and work our way upwards. + int level = tMinY - 1; //Dunno why, but the first layer is actually played one below tMinY. Go figure. + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta != null) ) { + if (setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { + placeCount[1]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta != null) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + /*if ((placeCount[1]+placeCount[3])==0) { + if (debugWorldGen) GT_Log.out.println( + " No ore in bottom layer" + ); + return NO_ORE_IN_BOTTOM_LAYER; // Exit early, didn't place anything in the bottom layer + }*/ + Logger.WARNING("[World Generation Debug] Trying to set Ores?"); + for (level = tMinY; level < (tMinY-1+3); level++) { + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta != null) ) { + if (setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { + placeCount[1]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta != null) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + } + // Low Middle layer is between + sporadic + // level should be = tMinY-1+3 from end of for loop + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mBetweenMeta != null) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { + placeCount[2]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta != null) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + // High Middle layer is between + primary + sporadic + level++; // Increment level to next layer + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mBetweenMeta != null) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { + placeCount[2]++; + } + } + else if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta != null) ) { + if (setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { + placeCount[0]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta != null) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + // Top two layers are primary + sporadic + level++; // Increment level to next layer + for( ; level < (tMinY + 6); level++){ // should do two layers + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta != null) ) { + if (setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { + placeCount[0]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta != null) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + } + if (debugWorldGen) { + String tDimensionName = aWorld.provider.getDimensionName(); + GT_Log.out.println( + "Generated Orevein:" + this.mWorldGenName + + " Dimension=" + tDimensionName + + " mX="+aChunkX/16+ + " mZ="+aChunkZ/16+ + " oreseedX="+ aSeedX/16 + + " oreseedZ="+ aSeedZ/16 + + " cY="+tMinY+ + " wXVein" + wXVein + + " eXVein" + eXVein + + " nZVein" + nZVein + + " sZVein" + sZVein + + " locDen=" + localDensity + + " Den=" + this.mDensity + + " Sec="+placeCount[1]+ + " Spo="+placeCount[3]+ + " Bet="+placeCount[2]+ + " Pri="+placeCount[0] + ); + } + // Something (at least the bottom layer must have 1 block) must have been placed, return true + return ORE_PLACED; + } + + private String fString = "unset", ore1String = "unset", ore2String = "unset", ore3String = "unset", ore4String = "unset"; + Map<Materials, String> gtOreMap = new HashMap<Materials, String>(); + + @SuppressWarnings("deprecation") + public boolean setOreBlock(World aWorld, int aX, int aY, int aZ, Block aMetaData, boolean isSmallOre, + boolean air) { + if (!air) { + aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); + } + + //Set GT ORE + if (aMetaData instanceof GT_Block_Ores){ + if (ore1String.equals("unset")) { + ore1String = Utils.sanitizeString(this.mPrimary.getLocalizedName().toLowerCase()); + } + if (ore2String.equals("unset")) { + ore2String = Utils.sanitizeString(this.mSecondaryMeta.getLocalizedName().toLowerCase()); + } + if (ore3String.equals("unset")) { + ore3String = Utils.sanitizeString(this.mBetweenMeta.getLocalizedName().toLowerCase()); + } + if (ore4String.equals("unset")) { + ore4String = Utils.sanitizeString(this.mSporadicMeta.getLocalizedName().toLowerCase()); + } + + if (this.mPrimaryMeta == aMetaData){ + for (Materials f : Materials.values()){ + if (!gtOreMap.containsKey(f)) { + gtOreMap.put(f, Utils.sanitizeString(f.name().toLowerCase())); + } + fString = gtOreMap.get(f); + if (fString.contains(ore1String)){ + int r = f.mMetaItemSubID; + if (setOreBlock(aWorld, aX, aY, aZ, r, false)){ + Logger.WARNING("[World Generation Debug] Set "+f.mDefaultLocalName+" Ore at X: "+aX+" | Y: "+aY+" | Z: "+aZ); + return true; + } + } + } + } + if (this.mSecondaryMeta == aMetaData){ + for (Materials f : Materials.values()){ + if (!gtOreMap.containsKey(f)) { + gtOreMap.put(f, Utils.sanitizeString(f.name().toLowerCase())); + } + fString = gtOreMap.get(f); + if (fString.contains(ore2String)){ + int r = f.mMetaItemSubID; + if (setOreBlock(aWorld, aX, aY, aZ, r, false)){ + Logger.WARNING("[World Generation Debug] Set "+f.mDefaultLocalName+" Ore at X: "+aX+" | Y: "+aY+" | Z: "+aZ); + return true; + } + } + } + } + if (this.mBetweenMeta == aMetaData){ + for (Materials f : Materials.values()){ + if (!gtOreMap.containsKey(f)) { + gtOreMap.put(f, Utils.sanitizeString(f.name().toLowerCase())); + } + fString = gtOreMap.get(f); + if (fString.contains(ore3String)){ + int r = f.mMetaItemSubID; + if (setOreBlock(aWorld, aX, aY, aZ, r, false)){ + Logger.WARNING("[World Generation Debug] Set "+f.mDefaultLocalName+" Ore at X: "+aX+" | Y: "+aY+" | Z: "+aZ); + return true; + } + } + } + } + if (this.mSporadicMeta == aMetaData){ + for (Materials f : Materials.values()){ + if (!gtOreMap.containsKey(f)) { + gtOreMap.put(f, Utils.sanitizeString(f.name().toLowerCase())); + } + fString = gtOreMap.get(f); + if (fString.contains(ore4String)){ + int r = f.mMetaItemSubID; + if (setOreBlock(aWorld, aX, aY, aZ, r, false)){ + Logger.WARNING("[World Generation Debug] Set "+f.mDefaultLocalName+" Ore at X: "+aX+" | Y: "+aY+" | Z: "+aZ); + return true; + } + } + } + } + + } + + Block tBlock = aWorld.getBlock(aX, aY, aZ); + Block tOreBlock = aMetaData; + int BlockMeta = aWorld.getBlockMetadata(aX, aY, aZ); + String BlockName = tBlock.getUnlocalizedName(); + if ( + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone) || + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.sand) || + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.dirt) || + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTech_API.sBlockGranites) || + (mUpdated && tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, mStoneTypes)) ||/* + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Dimension_Everglades.blockSecondLayer) || + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Dimension_Everglades.blockMainFiller) || + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Dimension_Everglades.blockSecondaryFiller) ||*/ + tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.sandstone)) { + + if (aWorld.setBlock(aX, aY, aZ, tOreBlock, 0, 3)){ + Logger.WARNING("[World Generation Debug] Set "+tOreBlock.getLocalizedName()+" at X: "+aX+" | Y: "+aY+" | Z: "+aZ); + return true; + } + } + return false; + } + + + private boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int mMetaItemSubID, boolean useless){ + + //Get Class and Methods + Method setOres = null; + boolean is08 = !CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK; + + //GT 5.08 + if (is08){ + try { + setOres = GT_TileEntity_Ores.class.getDeclaredMethod("setOreBlock", World.class, int.class, int.class, int.class, int.class); + } + catch (NoSuchMethodException | SecurityException e) { + + } + } + //GT 5.09 + else { + try { + setOres = GT_TileEntity_Ores.class.getDeclaredMethod("setOreBlock", World.class, int.class, int.class, int.class, int.class, boolean.class); + } + catch (NoSuchMethodException | SecurityException e) { + + } + } + + try { + if (is08 && setOres != null){ + setOres.invoke(null, aWorld, aX, aY, aZ, mMetaItemSubID); + } + else if (!is08 && setOres != null){ + setOres.invoke(null, aWorld, aX, aY, aZ, mMetaItemSubID, useless); + } + else { + return false; + }} + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + + } + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java b/src/main/java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java new file mode 100644 index 0000000000..8fc6940242 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/MapGenExtendedVillage.java @@ -0,0 +1,265 @@ +package gtPlusPlus.australia.gen.map; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.GTplusplus_Australia; + +import java.util.Map.Entry; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.gen.structure.MapGenStructure; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.StructureStart; +import net.minecraft.world.gen.structure.StructureVillagePieces; + +public class MapGenExtendedVillage extends MapGenStructure +{ + /** A list of all the biomes villages can spawn in. */ + public static List<BiomeGenBase> villageSpawnBiomes = Arrays.asList(new BiomeGenBase[] {GTplusplus_Australia.Australian_Desert_Biome_3, GTplusplus_Australia.Australian_Plains_Biome, GTplusplus_Australia.Australian_Forest_Biome, GTplusplus_Australia.Australian_Outback_Biome}); + /** World terrain type, 0 for normal, 1 for flat map */ + private int terrainType; + private int field_82665_g; + private int field_82666_h; + + public MapGenExtendedVillage(){ + this.field_82665_g = 8; + this.field_82666_h = 4; + } + + public MapGenExtendedVillage(Map<?, ?> p_i2093_1_){ + this(); + Iterator<?> iterator = p_i2093_1_.entrySet().iterator(); + + Logger.INFO("Created Extended Village Object."); + + while (iterator.hasNext()) + { + Entry<?, ?> entry = (Entry<?, ?>)iterator.next(); + + if (((String)entry.getKey()).equals("size")) + { + this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.terrainType, 0); + } + else if (((String)entry.getKey()).equals("distance")) + { + this.field_82665_g = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_82665_g, this.field_82666_h + 1); + } + } + } + + public String func_143025_a() + { + return "ExtendedVillage"; + } + + protected boolean canSpawnStructureAtCoords(int p_75047_1_, int p_75047_2_) + { + + + int k = p_75047_1_; + int l = p_75047_2_; + + if (p_75047_1_ < 0) + { + p_75047_1_ -= this.field_82665_g - 1; + } + + if (p_75047_2_ < 0) + { + p_75047_2_ -= this.field_82665_g - 1; + } + + int i1 = p_75047_1_ / this.field_82665_g; + int j1 = p_75047_2_ / this.field_82665_g; + Random random = this.worldObj.setRandomSeed(i1, j1, 10387312); + i1 *= this.field_82665_g; + j1 *= this.field_82665_g; + i1 += random.nextInt(this.field_82665_g - this.field_82666_h); + j1 += random.nextInt(this.field_82665_g - this.field_82666_h); + + if (k == i1 && l == j1) + { + boolean flag = this.worldObj.getWorldChunkManager().areBiomesViable(k * 16 + 8, l * 16 + 8, 0, villageSpawnBiomes); + + if (flag) + { + Logger.INFO("Found viable biome(s) for custom village"); + return true; + } + } + + return false; + } + + protected StructureStart getStructureStart(int p_75049_1_, int p_75049_2_) + { + return new MapGenExtendedVillage.Start(this.worldObj, this.rand, p_75049_1_, p_75049_2_, this.terrainType); + } + + public static class Start extends StructureStart + { + /** well ... thats what it does */ + private boolean hasMoreThanTwoComponents; + + public Start() { + } + + public Start(World p_i2092_1_, Random p_i2092_2_, int p_i2092_3_, int p_i2092_4_, int p_i2092_5_) + { + super(p_i2092_3_, p_i2092_4_); + Logger.INFO("Trying to Start Village Builder."); + List<?> list = StructureVillagePieces.getStructureVillageWeightedPieceList(p_i2092_2_, p_i2092_5_); + StructureVillagePieces.Start start = new StructureVillagePieces.Start(p_i2092_1_.getWorldChunkManager(), 0, p_i2092_2_, (p_i2092_3_ << 4) + 2, (p_i2092_4_ << 4) + 2, list, p_i2092_5_); + this.components.add(start); + start.buildComponent(start, this.components, p_i2092_2_); + List<?> list1 = start.field_74930_j; + List<?> list2 = start.field_74932_i; + int l; + Logger.INFO("List1: "+list1.size()+" | List2: "+list2.size()); + + while (!list1.isEmpty() || !list2.isEmpty()) + { + Logger.INFO("Iterating non empty list."); + StructureComponent structurecomponent; + + if (list1.isEmpty()) + { + l = p_i2092_2_.nextInt(list2.size()); + structurecomponent = (StructureComponent)list2.remove(l); + structurecomponent.buildComponent(start, this.components, p_i2092_2_); + } + else + { + l = p_i2092_2_.nextInt(list1.size()); + structurecomponent = (StructureComponent)list1.remove(l); + structurecomponent.buildComponent(start, this.components, p_i2092_2_); + } + } + Logger.INFO("Finished iterating lists, updating bounding box for structure."); + + this.updateBoundingBox(); + l = 0; + Iterator iterator = this.components.iterator(); + + while (iterator.hasNext()) + { + Logger.INFO("Iterating Components."); + StructureComponent structurecomponent1 = (StructureComponent)iterator.next(); + + if (!(structurecomponent1 instanceof StructureVillagePieces.Road)) + { + ++l; + } + } + + Logger.INFO("hasMoreThanTwoComponents? "+(l > 2)); + this.hasMoreThanTwoComponents = l > 2; + } + + /** + * currently only defined for Villages, returns true if Village has more than 2 non-road components + */ + public boolean isSizeableStructure() + { + //return this.hasMoreThanTwoComponents; + return true; + } + + public void func_143022_a(NBTTagCompound p_143022_1_) + { + super.func_143022_a(p_143022_1_); + p_143022_1_.setBoolean("Valid", this.hasMoreThanTwoComponents); + } + + public void func_143017_b(NBTTagCompound p_143017_1_) + { + super.func_143017_b(p_143017_1_); + this.hasMoreThanTwoComponents = p_143017_1_.getBoolean("Valid"); + } + } + + /** + * Generates structures in specified chunk next to existing structures. Does *not* generate StructureStarts. + */ + @Override + public boolean generateStructuresInChunk(World p_75051_1_, Random p_75051_2_, int p_75051_3_, int p_75051_4_){ + //Logger.INFO("Try generate Structs in chunk."); + this.callPrivateFunction1(p_75051_1_); + int k = (p_75051_3_ << 4) + 8; + int l = (p_75051_4_ << 4) + 8; + boolean flag = false; + Iterator iterator = this.structureMap.values().iterator(); + + //Logger.INFO("Iteration Size: "+this.structureMap.values().size()); + while (iterator.hasNext()) + { + //Logger.INFO("Iterating."); + StructureStart structurestart = (StructureStart)iterator.next(); + + if (structurestart.isSizeableStructure() && (structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15) || structurestart.getBoundingBox().intersectsWith(k, l, k - 15, l - 15))) + { + Logger.INFO("Iterating. 2"); + structurestart.generateStructure(p_75051_1_, p_75051_2_, new StructureBoundingBox(k, l, k + 15, l + 15)); + flag = true; + this.callPrivateFunction2(structurestart.func_143019_e(), structurestart.func_143018_f(), structurestart); + } + /* else { + Logger.INFO("Iterating. 3"); + Logger.INFO("structurestart.isSizeableStructure()? "+structurestart.isSizeableStructure()); + Logger.INFO("structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15)? "+(structurestart.getBoundingBox().intersectsWith(k, l, k + 15, l + 15) || structurestart.getBoundingBox().intersectsWith(k, l, k - 15, l - 15))); + Logger.INFO("K: "+k+" | L: "+l); + Logger.INFO("structure bounding box info: x-:"+structurestart.getBoundingBox().minX+" y-:"+structurestart.getBoundingBox().minY+" x+:"+structurestart.getBoundingBox().maxX+" y+:"+structurestart.getBoundingBox().maxY); + }*/ + } + + return flag; + } + + Method mMethod1; + Method mMethod2; + private boolean callPrivateFunction1(World aWorld) { + if (mMethod1 == null) { + try { + mMethod1 = MapGenStructure.class.getDeclaredMethod("func_143027_a", World.class); + } catch (NoSuchMethodException | SecurityException e) { + return false; + } + } + if (mMethod1 != null) { + try { + //Logger.INFO("Invoking func_143027_a"); + mMethod1.invoke(this, aWorld); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + return false; + } + + private boolean callPrivateFunction2(int aInt1, int aInt2, StructureStart aStruct) { + if (mMethod2 == null) { + try { + mMethod2 = MapGenStructure.class.getDeclaredMethod("func_143026_a", int.class, int.class, StructureStart.class); + } catch (NoSuchMethodException | SecurityException e) { + return false; + } + } + if (mMethod2 != null) { + try { + Logger.INFO("Invoking func_143026_a"); + mMethod2.invoke(this, aInt1, aInt2, aStruct); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + return false; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/australia/gen/map/MapGenLargeRavine.java b/src/main/java/gtPlusPlus/australia/gen/map/MapGenLargeRavine.java new file mode 100644 index 0000000000..0eab94c5d1 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/MapGenLargeRavine.java @@ -0,0 +1,217 @@ +package gtPlusPlus.australia.gen.map; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.block.Block; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.gen.MapGenRavine; + +public class MapGenLargeRavine extends MapGenRavine { + private float[] field_75046_d = new float[1024]; + + @Override + protected void func_151540_a(long aSeed, int var1, int var2, Block[] aBlocksInChunkOrPassedIn, double p_151540_6_, + double p_151540_8_, double p_151540_10_, float p_151540_12_, float p_151540_13_, float p_151540_14_, + int possibleCurrentY, int possibleMaxY, double p_151540_17_) { + Random random = CORE.RANDOM; + //gtPlusPlus.api.objects.Logger.WORLD("Generating Large Ravine. 1"); + this.range *= 2; + double d4 = (double) (var1 * 24 + 16); + double d5 = (double) (var2 * 24 + 16); + float f3 = 0.0F; + float f4 = 0.0F; + + if (possibleMaxY <= 25) { + int j1 = Math.min(this.range * 16 - 32, 200); + possibleMaxY = j1 - random.nextInt(j1 / 4); + } + + boolean possibleIsUnderGroundFlag = false; + + if (possibleCurrentY <= -1) { + possibleCurrentY = possibleMaxY / 3; + possibleIsUnderGroundFlag = true; + } + + float f5 = 1.0F; + + for (int k1 = 0; k1 < 256; ++k1) { + if (k1 == 0 || random.nextInt(3) == 0) { + f5 = 1.0F + random.nextFloat() * random.nextFloat() * 1.0F; + } + + this.field_75046_d[k1] = f5 * f5; + } + + for (; possibleCurrentY < possibleMaxY; ++possibleCurrentY) { + double d12 = 3.5D + (double) (MathHelper.sin((float) possibleCurrentY * CORE.PI / (float) possibleMaxY) + * p_151540_12_ * 1.0F); + double d6 = d12 * p_151540_17_; + d12 *= (double) random.nextFloat() * 0.55D + 0.75D; + d6 *= (double) random.nextFloat() * 0.55D + 0.75D; + float f6 = MathHelper.cos(p_151540_14_); + float f7 = MathHelper.sin(p_151540_14_); + p_151540_6_ += (double) (MathHelper.cos(p_151540_13_) * f6); + p_151540_8_ += (double) f7; + p_151540_10_ += (double) (MathHelper.sin(p_151540_13_) * f6); + p_151540_14_ *= 1.7F; + p_151540_14_ += f4 * 0.25F; + p_151540_13_ += f3 * 0.25F; + f4 *= 0.8F; + f3 *= 0.5F; + f4 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2.0F; + f3 += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4.0F; + + if (possibleIsUnderGroundFlag || random.nextInt(4) != 0) { + double d7 = p_151540_6_ - d4; + double d8 = p_151540_10_ - d5; + double d9 = (double) (possibleMaxY - possibleCurrentY); + double d10 = (double) (p_151540_12_ + 2.0F + 16.0F); + + if (d7 * d7 + d8 * d8 - d9 * d9 > d10 * d10) { + return; + } + + if (p_151540_6_ >= d4 - 16.0D - d12 * 2.0D && p_151540_10_ >= d5 - 16.0D - d12 * 2.0D + && p_151540_6_ <= d4 + 16.0D + d12 * 2.0D && p_151540_10_ <= d5 + 16.0D + d12 * 2.0D) { + int i4 = MathHelper.floor_double(p_151540_6_ - d12) - var1 * 16 - 1; + int l1 = MathHelper.floor_double(p_151540_6_ + d12) - var1 * 16 + 1; + int j4 = MathHelper.floor_double(p_151540_8_ - d6) - 1; + int i2 = MathHelper.floor_double(p_151540_8_ + d6) + 1; + int k4 = MathHelper.floor_double(p_151540_10_ - d12) - var2 * 16 - 1; + int j2 = MathHelper.floor_double(p_151540_10_ + d12) - var2 * 16 + 1; + + if (i4 < 0) { + i4 = 0; + } + + if (l1 > 16) { + l1 = 16; + } + + if (j4 < 1) { + j4 = 1; + } + + if (i2 > 248) { + i2 = 248; + } + + if (k4 < 0) { + k4 = 0; + } + + if (j2 > 16) { + j2 = 16; + } + + boolean flag2 = false; + int k2; + int j3; + + for (k2 = i4; !flag2 && k2 < l1; ++k2) { + for (int l2 = k4; !flag2 && l2 < j2; ++l2) { + for (int i3 = i2 + 1; !flag2 && i3 >= j4 - 1; --i3) { + j3 = (k2 * 16 + l2) * 256 + i3; + + if (i3 >= 0 && i3 < 256) { + Block block = aBlocksInChunkOrPassedIn[j3]; + + if (isOceanBlock(aBlocksInChunkOrPassedIn, j3, k2, i3, l2, var1, var2)) { + flag2 = true; + } + + if (i3 != j4 - 1 && k2 != i4 && k2 != l1 - 1 && l2 != k4 && l2 != j2 - 1) { + i3 = j4; + } + } + } + } + } + + if (!flag2) { + for (k2 = i4; k2 < l1; ++k2) { + double d13 = ((double) (k2 + var1 * 16) + 0.5D - p_151540_6_) / d12; + + for (j3 = k4; j3 < j2; ++j3) { + double d14 = ((double) (j3 + var2 * 16) + 0.5D - p_151540_10_) / d12; + int k3 = (k2 * 16 + j3) * 256 + i2; + boolean flag = false; + + if (d13 * d13 + d14 * d14 < 1.0D) { + for (int l3 = i2 - 1; l3 >= j4; --l3) { + double d11 = ((double) l3 + 0.5D - p_151540_8_) / d6; + + if ((d13 * d13 + d14 * d14) * (double) this.field_75046_d[l3] + + d11 * d11 / 6.0D < 1.0D) { + Block block1 = aBlocksInChunkOrPassedIn[k3]; + + if (checkIfTopBlock(aBlocksInChunkOrPassedIn, k3, k2, l3, j3, var1, var2)) { + flag = true; + } + + Logger.WORLD("Generating Large Ravine. 2"); + digBlock(aBlocksInChunkOrPassedIn, k3, k2, l3, j3, var1, var2, flag); + } + + --k3; + } + } + } + } + + if (possibleIsUnderGroundFlag) { + break; + } + } + } + } + } + } + + // generate? + @Override + protected void func_151538_a(World p_151538_1_, int p_151538_2_, int p_151538_3_, int chunkX, int chunkZ, + Block[] blocks) { + if (this.rand.nextInt(50) == 0) { + double d0 = (double) (p_151538_2_ * 16 + this.rand.nextInt(16)); + double d1 = (double) (this.rand.nextInt(this.rand.nextInt(40) + 8) + 20); + double d2 = (double) (p_151538_3_ * 16 + this.rand.nextInt(16)); + byte b0 = 1; + + for (int i1 = 0; i1 < b0; ++i1) { + float f = this.rand.nextFloat() * (float) Math.PI * 2.0F; + float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F / 8.0F; + float f2 = (this.rand.nextFloat() * 2.0F + this.rand.nextFloat()) * 2.0F; + this.func_151540_a(this.rand.nextLong(), chunkX, chunkZ, blocks, d0, d1, d2, f2, f, f1, 0, 0, 3.0D); + } + } + } + + private static Method isTopBlock; + + // Determine if the block at the specified location is the top block for the + // biome, we take into account + private synchronized boolean checkIfTopBlock(Block[] data, int index, int x, int y, int z, int chunkX, int chunkZ) { + try { + if (isTopBlock == null) { + isTopBlock = MapGenRavine.class.getDeclaredMethod("isTopBlock", Block[].class, int.class, int.class, + int.class, int.class, int.class, int.class); + } + if (isTopBlock != null) { + return (boolean) isTopBlock.invoke(this, data, index, x, y, z, chunkX, chunkZ); + } else { + return false; + } + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException n) { + return false; + } + } + +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/australia/gen/map/component/AustraliaComponent.java b/src/main/java/gtPlusPlus/australia/gen/map/component/AustraliaComponent.java new file mode 100644 index 0000000000..b6b83d997b --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/component/AustraliaComponent.java @@ -0,0 +1,196 @@ +package gtPlusPlus.australia.gen.map.component; + +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityDispenser; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraftforge.common.ChestGenHooks; + +public class AustraliaComponent extends StructureComponent { + public AustraliaComponent() { + } + + public AustraliaComponent(int direction, Random random, int x, int z, int dimX, int dimY, int dimZ) { + super(direction); + this.coordBaseMode = direction; + this.boundingBox = calcBox(direction, x + (16 - dimX) / 2, 64, z + (16 - dimZ) / 2, dimX, dimY, dimZ, 0); + } + + public boolean addComponentParts(World world, Random random) { + return true; + } + + protected void func_151554_b(World par1World, Block par2, int par3, int par4, int par5, int par6, + StructureBoundingBox par7StructureBoundingBox) { + int j1 = getXWithOffset(par4, par6); + int k0 = getYWithOffset(par5); + int k1 = k0; + int l1 = getZWithOffset(par4, par6); + if (par7StructureBoundingBox.isVecInside(j1, k1, l1)) { + if (par1World.isAirBlock(j1, k1, l1)) { + return; + } + k1--; + while (((par1World.isAirBlock(j1, k1, l1)) || (!par1World.getBlock(j1, k1, l1).getMaterial().isSolid()) + || (par1World.getBlock(j1, k1, l1) == Blocks.ice)) && (k1 > 1)) { + par1World.setBlock(j1, k1, l1, par2, par3, 2); + + k1--; + } + } + } + + protected void clearCurrentPositionBlocksUpwards(World par1World, int par2, int par3, int par4, + StructureBoundingBox par5StructureBoundingBox) { + int l = getXWithOffset(par2, par4); + int i1 = getYWithOffset(par3); + int j1 = getZWithOffset(par2, par4); + if (par5StructureBoundingBox.isVecInside(l, i1, j1)) { + int i = 0; + for (;;) { + i++; + if (((i >= 20) && (par1World.isAirBlock(l, i1, j1))) || (i1 >= 255)) { + break; + } + par1World.setBlock(l, i1, j1, Blocks.air, 0, 2); + i1++; + } + } + } + + protected boolean isWaterBelow(World par1World, int par4, int par5, int par6, + StructureBoundingBox par7StructureBoundingBox) { + int j1 = getXWithOffset(par4, par6); + int k1 = getYWithOffset(par5); + int l1 = getZWithOffset(par4, par6); + for (int i = 0; i < 10; i++) { + Material material = par1World.getBlock(j1, k1, l1).getMaterial(); + if ((material.isLiquid()) || (material == Material.ice)) { + return true; + } + if (!par1World.isAirBlock(j1, k1, l1)) { + return false; + } + } + return false; + } + + public void setDispenser(int x, int y, int z, Random random, World world, int facing) { + int i1 = getXWithOffset(x, z); + int j1 = getYWithOffset(y); + int k1 = getZWithOffset(x, z); + + world.setBlock(i1, j1, k1, Blocks.dispenser, facing, 0); + TileEntity tileDispenser = world.getTileEntity(i1, j1, k1); + if ((tileDispenser != null) && ((tileDispenser instanceof TileEntityDispenser))) { + ChestGenHooks info = ChestGenHooks.getInfo("mineshaftCorridor"); + WeightedRandomChestContent.generateChestContents(random, info.getItems(random), + (TileEntityDispenser) tileDispenser, info.getCount(random)); + } else { + Logger.WARNING("Failed to fetch dispenser entity at (" + i1 + ", " + j1 + ", " + k1 + ")"); + } + } + + protected void setSpawner(int x, int y, int z, String mobName, World world) { + int i1 = getXWithOffset(x, z); + int j1 = getYWithOffset(y); + int k1 = getZWithOffset(x, z); + + world.setBlock(i1, j1, k1, Blocks.mob_spawner, 0, 2); + TileEntity tileSpawner = world.getTileEntity(i1, j1, k1); + if ((tileSpawner != null) && ((tileSpawner instanceof TileEntityMobSpawner))) { + ((TileEntityMobSpawner) tileSpawner).func_145881_a().setEntityName(mobName); + } else { + Logger.WARNING("Failed to fetch mob spawner entity at (" + i1 + ", " + j1 + ", " + k1 + ")"); + } + } + + protected void setFurnace(int x, int y, int z, World world) { + int i1 = getXWithOffset(x, z); + int j1 = getYWithOffset(y); + int k1 = getZWithOffset(x, z); + + world.setBlock(i1, j1, k1, Blocks.furnace, getMetadataWithOffset(Blocks.piston, 3), 2); + } + + protected void placeAirBlockAtPos(int x, int y, int z, StructureBoundingBox bounds, World world) { + placeBlockAtCurrentPosition(world, Blocks.air, 0, x, y, z, bounds); + } + + protected void place(Block block, int meta, int x, int y, int z, StructureBoundingBox bounds, World world) { + placeBlockAtCurrentPosition(world, block, meta, x, y, z, bounds); + } + + protected StructureBoundingBox calcBox(int direction, int x, int y, int z, int xLength, int height, int zLength, + int xShift) { + int minX = 0; + int maxX = 0; + int minY = y; + int maxY = y + height; + int minZ = 0; + int maxZ = 0; + switch (direction) { + case 0: + minX = x - xShift; + maxX = x - xShift + xLength; + minZ = z; + maxZ = z + zLength; + break; + case 1: + minX = x - zLength; + maxX = x; + minZ = z - xShift; + maxZ = z - xShift + xLength; + break; + case 2: + minX = x - xShift; + maxX = x - xShift + xLength; + minZ = z - zLength; + maxZ = z; + break; + case 3: + minX = x; + maxX = x + zLength; + minZ = z - xShift; + maxZ = z - xShift + xLength; + } + return new StructureBoundingBox(minX, minY, minZ, maxX, maxY, maxZ); + } + + protected int calcGroundHeight(World world, StructureBoundingBox boundingBox) { + int height = 0; + int count = 0; + for (int z = boundingBox.minZ; z <= boundingBox.maxZ; z++) { + for (int x = boundingBox.minX; x <= boundingBox.maxX; x++) { + if (boundingBox.isVecInside(x, 64, z)) { + height += Math.max(world.getTopSolidOrLiquidBlock(x, z), world.provider.getAverageGroundLevel()); + count++; + } + } + } + if (count == 0) { + return -1; + } + return height / count; + } + + protected void func_143012_a(NBTTagCompound nbttagcompound) { + } + + protected void func_143011_b(NBTTagCompound nbttagcompound) { + } + + public boolean addComponentParts(World world, Random random, StructureBoundingBox structureboundingbox) { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentHut.java b/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentHut.java new file mode 100644 index 0000000000..1f5dd59667 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentHut.java @@ -0,0 +1,474 @@ +package gtPlusPlus.australia.gen.map.component; + +import java.util.Random; + +import gtPlusPlus.api.interfaces.IGeneratorWorld; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.GTplusplus_Australia; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.plugin.villagers.entity.EntityNativeAustralian; +import net.minecraft.block.Block; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.gen.structure.StructureBoundingBox; + +public class ComponentHut extends AustraliaComponent { + public static final int DIM_X = 7; + public static final int DIM_Y = 10; + public static final int DIM_Z = 7; + + public ComponentHut() { + } + + public ComponentHut(int direction, Random random, int x, int z) { + super(direction, random, x, z, 7, 10, 7); + } + + public boolean addComponentParts(World world, Random random) { + + BiomeGenBase biom = world.getBiomeGenForCoords(getXWithOffset(0, 0), getZWithOffset(0, 0)); + int groundAvg = calcGroundHeight(world, this.boundingBox); + if (groundAvg < 0) { + return true; + } + this.boundingBox.offset(0, groundAvg - this.boundingBox.maxY + 10 - 1, 0); + if ((isWaterBelow(world, 0, -1, 0, this.boundingBox)) || (isWaterBelow(world, 0, -1, 6, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 0, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 6, this.boundingBox))) { + return false; + } + + Block aWall1, aWall2, aRoof, aFloor; + + if (biom.biomeID == GTplusplus_Australia.Australian_Desert_Biome_3.biomeID) { + aWall1 = Blocks.sand; + aWall2 = Blocks.sandstone; + aRoof = Blocks.sandstone; + aFloor = Blocks.sandstone; + } + else if (biom.biomeID == GTplusplus_Australia.Australian_Outback_Biome.biomeID) { + aWall1 = Blocks.clay; + aWall2 = Blocks.hardened_clay; + aRoof = Blocks.hardened_clay; + aFloor = Blocks.stained_hardened_clay; + } + else { + aWall1 = Blocks.sand; + aWall2 = Blocks.sandstone; + aRoof = Blocks.sandstone; + aFloor = Blocks.sandstone; + } + + //Empty Area + fillWithAir(world, this.boundingBox, 0, 1, 0, 6, 9, 6); + + //Build Floor + fillWithMetadataBlocks(world, this.boundingBox, 0, 0, 0, 6, 0, 6, aFloor, 0, aFloor, 1, false); + + //Layer 2 + int dir = MathUtils.randInt(0, 3); + + //Door First + if (dir == 0) { + placeDoorAtCurrentPosition( + world, this.boundingBox, random, 0, 1, 3, getMetadataWithOffset(Blocks.wooden_door, 1)); + } + else if (dir == 1) { + placeDoorAtCurrentPosition( + world, this.boundingBox, random, 3, 1, 6, getMetadataWithOffset(Blocks.wooden_door, 1)); + } + else if (dir == 2) { + placeDoorAtCurrentPosition( + world, this.boundingBox, random, 6, 1, 3, getMetadataWithOffset(Blocks.wooden_door, 1)); + } + else { + placeDoorAtCurrentPosition( + world, this.boundingBox, random, 3, 1, 0, getMetadataWithOffset(Blocks.wooden_door, 1)); + } + + //Layer 1 + //Wall Top + place(aWall1, 0, 0, 1, 2, this.boundingBox, world); + if (dir != 0) place(aWall1, 0, 0, 1, 3, this.boundingBox, world); + place(aWall1, 0, 0, 1, 4, this.boundingBox, world); + //Wall Right + place(aWall1, 0, 2, 1, 6, this.boundingBox, world); + if (dir != 1) place(aWall2, 0, 3, 1, 6, this.boundingBox, world); + place(aWall1, 0, 4, 1, 6, this.boundingBox, world); + //Wall Bottom + place(aWall2, 0, 6, 1, 4, this.boundingBox, world); + if (dir != 2) place(aWall1, 0, 6, 1, 3, this.boundingBox, world); + place(aWall1, 0, 6, 1, 2, this.boundingBox, world); + //Wall Left + place(aWall1, 0, 4, 1, 0, this.boundingBox, world); + if (dir != 3) place(aWall1, 0, 3, 1, 0, this.boundingBox, world); + place(aWall2, 0, 2, 1, 0, this.boundingBox, world); + //Corners + place(aWall1, 0, 1, 1, 5, this.boundingBox, world); + place(aWall2, 0, 5, 1, 5, this.boundingBox, world); + place(aWall1, 0, 5, 1, 1, this.boundingBox, world); + place(aWall1, 0, 1, 1, 1, this.boundingBox, world); + + + //Wall Top + place(aWall1, 0, 0, 2, 2, this.boundingBox, world); + //place(aWall1, 0, 0, 2, 3, this.boundingBox, world); + place(aWall2, 0, 0, 2, 4, this.boundingBox, world); + + //Wall Right + place(aWall2, 0, 2, 2, 6, this.boundingBox, world); + //place(aWall1, 0, 3, 2, 6, this.boundingBox, world); + place(aWall1, 0, 4, 2, 6, this.boundingBox, world); + + //Wall Bottom + place(aWall1, 0, 6, 2, 4, this.boundingBox, world); + //place(aWall1, 0, 6, 2, 3, this.boundingBox, world); + place(aWall2, 0, 6, 2, 2, this.boundingBox, world); + + //Wall Left + place(aWall1, 0, 4, 2, 0, this.boundingBox, world); + //place(aWall2, 0, 4, 2, 0, this.boundingBox, world); + place(aWall1, 0, 2, 2, 0, this.boundingBox, world); + + //Corners + place(aWall1, 0, 1, 2, 5, this.boundingBox, world); + place(aWall1, 0, 5, 2, 5, this.boundingBox, world); + place(aWall2, 0, 5, 2, 1, this.boundingBox, world); + place(aWall2, 0, 1, 2, 1, this.boundingBox, world); + + //Layer 3 + //Wall Top + place(aWall2, 0, 0, 3, 2, this.boundingBox, world); + place(aWall1, 0, 0, 3, 3, this.boundingBox, world); + place(aWall1, 0, 0, 3, 4, this.boundingBox, world); + //Wall Right + place(aWall1, 0, 2, 3, 6, this.boundingBox, world); + place(aWall1, 0, 3, 3, 6, this.boundingBox, world); + place(aWall1, 0, 4, 3, 6, this.boundingBox, world); + //Wall Bottom + place(aWall1, 0, 6, 3, 4, this.boundingBox, world); + place(aWall2, 0, 6, 3, 3, this.boundingBox, world); + place(aWall1, 0, 6, 3, 2, this.boundingBox, world); + //Wall Left + place(aWall1, 0, 4, 3, 0, this.boundingBox, world); + place(aWall2, 0, 3, 3, 0, this.boundingBox, world); + place(aWall1, 0, 2, 3, 0, this.boundingBox, world); + //Corners + place(aWall1, 0, 1, 3, 5, this.boundingBox, world); + place(aWall2, 0, 5, 3, 5, this.boundingBox, world); + place(aWall1, 0, 5, 3, 1, this.boundingBox, world); + place(aWall1, 0, 1, 3, 1, this.boundingBox, world); + + //Roof + //Roof 1 Top + place(aRoof, 0, 1, 4, 2, this.boundingBox, world); + place(aRoof, 0, 1, 4, 3, this.boundingBox, world); + place(aRoof, 0, 1, 4, 4, this.boundingBox, world); + //Roof 1 Right + place(aRoof, 0, 2, 4, 5, this.boundingBox, world); + place(aRoof, 0, 3, 4, 5, this.boundingBox, world); + place(aRoof, 0, 4, 4, 5, this.boundingBox, world); + //Roof 1 Bottom + place(aRoof, 0, 5, 4, 4, this.boundingBox, world); + place(aRoof, 0, 5, 4, 3, this.boundingBox, world); + place(aRoof, 0, 5, 4, 2, this.boundingBox, world); + //Roof 1 Left + place(aRoof, 0, 4, 4, 1, this.boundingBox, world); + place(aRoof, 0, 3, 4, 1, this.boundingBox, world); + place(aRoof, 0, 2, 4, 1, this.boundingBox, world); + + //Roof 2 Top + place(aRoof, 0, 2, 5, 2, this.boundingBox, world); + place(aRoof, 0, 2, 5, 3, this.boundingBox, world); + place(aRoof, 0, 2, 5, 4, this.boundingBox, world); + + //Roof 2 Right + //place(aWall1, 0, 2, 5, 4, this.boundingBox, world); + place(aRoof, 0, 3, 5, 4, this.boundingBox, world); + //place(aWall1, 0, 4, 5, 4, this.boundingBox, world); + + //Roof 2 Bottom + place(aRoof, 0, 4, 5, 4, this.boundingBox, world); + place(aRoof, 0, 4, 5, 3, this.boundingBox, world); + place(aRoof, 0, 4, 5, 2, this.boundingBox, world); + + //Roof 2 Left + //place(aWall1, 0, 4, 5, 2, this.boundingBox, world); + place(aRoof, 0, 3, 5, 2, this.boundingBox, world); + //place(aWall1, 0, 2, 5, 2, this.boundingBox, world); + + //Roof 3 Top + place(Blocks.glowstone, 0, 3, 5, 3, this.boundingBox, world); + /* + int logID = MathUtils.randInt(0, 1); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 1, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 2, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 3, 1, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 1, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 2, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 3, 5, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 1, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 2, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 3, 1, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 1, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 2, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 3, 5, this.boundingBox, world); + + int meta = (this.coordBaseMode == 3) || (this.coordBaseMode == 1) ? 4 : 8; + + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 2, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 3, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 4, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 2, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 3, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 4, this.boundingBox, world); + + for (int x = -2; x < 9; x++) { + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 3, 0, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 4, 1, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 2, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 3, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 4, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 4, 5, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 3, 6, this.boundingBox, world); + } + + int glassMeta = Math.min(16, (coordBaseMode+MathUtils.randInt(0, 8))); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 2, 2, 1, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 2, 2, 5, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 4, 2, 5, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 0, 2, 3, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 6, 2, 3, this.boundingBox, world); + + placeDoorAtCurrentPosition(world, this.boundingBox, random, 4, 1, 1, + getMetadataWithOffset(Blocks.wooden_door, 1)); + + place(Blocks.leaves, MathUtils.randInt(0, 3), 1, 1, 4, this.boundingBox, world); + place(Blocks.torch, 0, 1, 2, 3, this.boundingBox, world); + place(Blocks.torch, 0, 3, 2, 2, this.boundingBox, world); + if (!this.hasMadeChest) { + int ic = getYWithOffset(0); + int jc = getXWithOffset(7, 1); + int kc = getZWithOffset(7, 1); + if (this.boundingBox.isVecInside(jc, ic, kc)) { + this.hasMadeChest = true; + generateStructureChestContents(world, this.boundingBox, random, 1, 1, 2, shackChestContents, + 1 + random.nextInt(3)); + } + }*/ + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 7; j++) { + clearCurrentPositionBlocksUpwards(world, j, 6, i, this.boundingBox); + func_151554_b(world, aFloor, 0, j, 0, i, this.boundingBox); + } + } + spawnNatives(world, this.boundingBox, 4, 1, 3, MathUtils.randInt(3, 5)); + + return true; + + /* + BiomeGenBase biom = world.getBiomeGenForCoords(getXWithOffset(0, 0), getZWithOffset(0, 0)); + int groundAvg = calcGroundHeight(world, this.boundingBox); + if (groundAvg < 0) { + return true; + } + this.boundingBox.offset(0, groundAvg - this.boundingBox.maxY + 10 - 1, 0); + if ((isWaterBelow(world, 0, -1, 0, this.boundingBox)) || (isWaterBelow(world, 0, -1, 6, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 0, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 6, this.boundingBox))) { + return false; + } + Block groundID = Blocks.grass; + Block undergroundID = Blocks.dirt; + if (biom.biomeID == GTplusplus_Australia.Australian_Desert_Biome_3.biomeID) { + groundID = Blocks.sand; + undergroundID = Blocks.sand; + } + else if (biom.biomeID == GTplusplus_Australia.Australian_Outback_Biome.biomeID) { + groundID = Blocks.hardened_clay; + undergroundID = Blocks.stained_hardened_clay; + } + + + fillWithAir(world, this.boundingBox, 0, 1, 0, 6, 9, 6); + fillWithMetadataBlocks(world, this.boundingBox, 0, 0, 1, 6, 1, 5, Blocks.dirt, 0, Blocks.dirt, 1, false); + fillWithMetadataBlocks(world, this.boundingBox, 0, 2, 1, 6, 3, 5, Blocks.cobblestone, 0, Blocks.cobblestone, 0, false); + fillWithAir(world, this.boundingBox, 1, 1, 2, 5, 3, 4); + + int logID = MathUtils.randInt(0, 1); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 1, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 2, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 3, 1, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 1, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 2, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 3, 5, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 1, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 2, 1, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 3, 1, this.boundingBox, world); + + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 1, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 2, 5, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 3, 5, this.boundingBox, world); + + int meta = (this.coordBaseMode == 3) || (this.coordBaseMode == 1) ? 4 : 8; + + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 2, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 3, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 0, 4, 4, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 2, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 3, this.boundingBox, world); + place(Blocks.dirt, MathUtils.randInt(0, 1), 6, 4, 4, this.boundingBox, world); + + for (int x = -2; x < 9; x++) { + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 3, 0, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 4, 1, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 2, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 3, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 5, 4, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 4, 5, this.boundingBox, world); + place(Blocks.leaves, MathUtils.randInt(0, 3), x, 3, 6, this.boundingBox, world); + } + + int glassMeta = Math.min(16, (coordBaseMode+MathUtils.randInt(0, 8))); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 2, 2, 1, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 2, 2, 5, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 4, 2, 5, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 0, 2, 3, this.boundingBox, world); + if (MathUtils.randInt(0, 5) > 4) + place(Blocks.stained_glass, glassMeta, 6, 2, 3, this.boundingBox, world); + + placeDoorAtCurrentPosition(world, this.boundingBox, random, 4, 1, 1, + getMetadataWithOffset(Blocks.wooden_door, 1)); + + place(Blocks.leaves, MathUtils.randInt(0, 3), 1, 1, 4, this.boundingBox, world); + place(Blocks.torch, 0, 1, 2, 3, this.boundingBox, world); + place(Blocks.torch, 0, 3, 2, 2, this.boundingBox, world); + if (!this.hasMadeChest) { + int ic = getYWithOffset(0); + int jc = getXWithOffset(7, 1); + int kc = getZWithOffset(7, 1); + if (this.boundingBox.isVecInside(jc, ic, kc)) { + this.hasMadeChest = true; + generateStructureChestContents(world, this.boundingBox, random, 1, 1, 2, shackChestContents, + 1 + random.nextInt(3)); + } + } + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 7; j++) { + clearCurrentPositionBlocksUpwards(world, j, 6, i, this.boundingBox); + func_151554_b(world, undergroundID, 0, j, 0, i, this.boundingBox); + } + } + spawnNatives(world, this.boundingBox, 4, 1, 3, MathUtils.randInt(3, 5)); + + return true; + */} + + private int nativesSpawned = 0; + + private void spawnNatives(World par1World, StructureBoundingBox par2StructureBoundingBox, int par3, int par4, + int par5, int maxSpawned) { + if (this.nativesSpawned < maxSpawned) { + for (int i1 = this.nativesSpawned; i1 < maxSpawned; i1++) { + int j1 = getXWithOffset(par3 + i1, par5); + int k1 = getYWithOffset(par4); + int l1 = getZWithOffset(par3 + i1, par5); + if (!par2StructureBoundingBox.isVecInside(j1, k1, l1)) { + break; + } + if (par1World.rand.nextInt(MathUtils.randInt(3, 5)) != 0) { + EntityNativeAustralian entityvillager = new EntityNativeAustralian(par1World); + entityvillager.func_110163_bv(); + entityvillager.setLocationAndAngles(j1 + 0.5D, k1, l1 + 0.5D, 0.0F, 0.0F); + par1World.spawnEntityInWorld(entityvillager); + this.nativesSpawned += 1; + } + } + } + } + + public static final WeightedRandomChestContent[] shackChestContents = { + new WeightedRandomChestContent(Items.glass_bottle, 0, 1, 1, 10), + new WeightedRandomChestContent(Items.bread, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.apple, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.cooked_fished, 0, 1, 3, 10), + new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.sapling), 1, 1, 1, 15), + // new WeightedRandomChestContent(Witchery.Items.GENERIC, + // Witchery.Items.GENERIC.itemRowanBerries.damageValue, 1, 2, 10), + new WeightedRandomChestContent(Items.iron_shovel, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_pickaxe, 0, 1, 1, 5) }; + private boolean hasMadeChest; + private static final String CHEST_KEY = "AUSShackChest"; + + protected void func_143012_a(NBTTagCompound par1NBTTagCompound) { + super.func_143012_a(par1NBTTagCompound); + par1NBTTagCompound.setBoolean("AUSShackChest", this.hasMadeChest); + par1NBTTagCompound.setInteger("AUSWCount", this.nativesSpawned); + } + + protected void func_143011_b(NBTTagCompound par1NBTTagCompound) { + super.func_143011_b(par1NBTTagCompound); + this.hasMadeChest = par1NBTTagCompound.getBoolean("AUSShackChest"); + if (par1NBTTagCompound.hasKey("AUSWCount")) { + this.nativesSpawned = par1NBTTagCompound.getInteger("AUSWCount"); + } else { + this.nativesSpawned = 0; + } + } + + public static class WorldHandlerHut implements IGeneratorWorld { + private final double chance; + private final int range; + + public WorldHandlerHut(double chance) { + this.chance = chance; + this.range = 400; + } + + public int getExtentX() { + return 7; + } + + public int getExtentZ() { + return 7; + } + + public int getRange() { + return this.range; + } + + public boolean generate(World world, Random random, int x, int z) { + if ((MathUtils.randInt(0, 100) < (this.chance/5))) { + int direction = MathUtils.randInt(0, 3); + new ComponentHut(direction, random, x, z).addComponentParts(world, random); + Logger.WORLD("NativeHut x: " + x + " | z: " + z + " | Dir: " + direction); + return true; + } + return false; + } + + public void initiate() { + } + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentShack.java b/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentShack.java new file mode 100644 index 0000000000..e3f501468b --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/component/ComponentShack.java @@ -0,0 +1,279 @@ +package gtPlusPlus.australia.gen.map.component; + +import java.util.Random; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gtPlusPlus.api.interfaces.IGeneratorWorld; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.australia.GTplusplus_Australia; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.gen.structure.StructureBoundingBox; + +public class ComponentShack extends AustraliaComponent { + public static final int DIM_X = 9; + public static final int DIM_Y = 10; + public static final int DIM_Z = 9; + + public ComponentShack() { + } + + public ComponentShack(int direction, Random random, int x, int z) { + super(direction, random, x, z, DIM_X, DIM_Y, DIM_Z); + } + + public boolean addComponentParts(World world, Random random) { + BiomeGenBase biom = world.getBiomeGenForCoords(getXWithOffset(0, 0), getZWithOffset(0, 0)); + int groundAvg = calcGroundHeight(world, this.boundingBox); + if (groundAvg < 0) { + return true; + } + this.boundingBox.offset(0, groundAvg - this.boundingBox.maxY + 10 - 1, 0); + if ((isWaterBelow(world, 0, -1, 0, this.boundingBox)) || (isWaterBelow(world, 0, -1, 6, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 0, this.boundingBox)) + || (isWaterBelow(world, 6, -1, 6, this.boundingBox))) { + return false; + } + Block mStone; + Block groundID = Blocks.grass; + Block undergroundID = Blocks.dirt; + if (biom.biomeID == GTplusplus_Australia.Australian_Desert_Biome_3.biomeID) { + groundID = Blocks.sand; + undergroundID = Blocks.sand; + mStone = Blocks.sandstone; + } + else if (biom.biomeID == GTplusplus_Australia.Australian_Outback_Biome.biomeID) { + groundID = Blocks.hardened_clay; + undergroundID = Blocks.stained_hardened_clay; + mStone = Blocks.stained_hardened_clay; + } + else { + mStone = Blocks.stonebrick; + } + + int mWoodType = MathUtils.randInt(0, 5); + int logID; + Block mWoodenStairs; + Block mLog; + if (mWoodType == 1) { + mWoodenStairs = Blocks.spruce_stairs; + logID = 1; + } + else if (mWoodType == 2) { + mWoodenStairs = Blocks.birch_stairs; + logID = 2; + + } + else if (mWoodType == 3) { + mWoodenStairs = Blocks.jungle_stairs; + logID = 3; + } + else if (mWoodType == 4) { + mWoodenStairs = Blocks.acacia_stairs; + logID = 0; + } + else if (mWoodType == 5) { + mWoodenStairs = Blocks.dark_oak_stairs; + logID = 1; + } + else { + mWoodenStairs = Blocks.oak_stairs; + logID = 0; + } + if (mWoodType >= 4) { + mLog = Blocks.log2; + } + else { + mLog = Blocks.log; + } + + int mStoneMeta = MathUtils.randInt(0, mStone == Blocks.stained_hardened_clay ? 15 : mStone == Blocks.sandstone ? 2 : 3); + + fillWithAir(world, this.boundingBox, 0, 1, 0, 7, 7, 4); + fillWithMetadataBlocks(world, this.boundingBox, 1, 0, 1, 7, 1, 5, mStone, mStoneMeta, mStone, mStoneMeta, false); + fillWithMetadataBlocks(world, this.boundingBox, 1, 2, 1, 7, 3, 5, Blocks.planks, mWoodType, Blocks.planks, mWoodType, false); + fillWithAir(world, this.boundingBox, 2, 1, 2, 6, 3, 4); + + place(mLog, logID, 1, 1, 1, this.boundingBox, world); + place(mLog, logID, 1, 2, 1, this.boundingBox, world); + place(mLog, logID, 1, 3, 1, this.boundingBox, world); + + place(mLog, logID, 1, 1, 5, this.boundingBox, world); + place(mLog, logID, 1, 2, 5, this.boundingBox, world); + place(mLog, logID, 1, 3, 5, this.boundingBox, world); + + place(mLog, logID, 7, 1, 1, this.boundingBox, world); + place(mLog, logID, 7, 2, 1, this.boundingBox, world); + place(mLog, logID, 7, 3, 1, this.boundingBox, world); + + place(mLog, logID, 7, 1, 5, this.boundingBox, world); + place(mLog, logID, 7, 2, 5, this.boundingBox, world); + place(mLog, logID, 7, 3, 5, this.boundingBox, world); + + int meta = (this.coordBaseMode == 3) || (this.coordBaseMode == 1) ? 4 : 8; + + place(mLog, logID, 1, 4, 2, this.boundingBox, world); + place(mLog, logID, 1, 4, 3, this.boundingBox, world); + place(mLog, logID, 1, 4, 4, this.boundingBox, world); + place(mLog, logID, 7, 4, 2, this.boundingBox, world); + place(mLog, logID, 7, 4, 3, this.boundingBox, world); + place(mLog, logID, 7, 4, 4, this.boundingBox, world); + + for (int x = 0; x < 9; x++) { + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 3), x, 3, 0, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 3), x, 4, 1, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 3), x, 5, 2, this.boundingBox, world); + place(Blocks.planks, mWoodType, x, 5, 3, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 2), x, 5, 4, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 2), x, 4, 5, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(Blocks.oak_stairs, 2), x, 3, 6, this.boundingBox, world); + } + + int glassMeta = Math.min(16, (coordBaseMode+MathUtils.randInt(0, 8))); + + place(Blocks.stained_glass_pane, glassMeta, 3, 2, 1, this.boundingBox, world); + place(Blocks.stained_glass_pane, glassMeta, 3, 2, 5, this.boundingBox, world); + place(Blocks.stained_glass_pane, glassMeta, 5, 2, 5, this.boundingBox, world); + place(Blocks.stained_glass_pane, glassMeta, 1, 2, 3, this.boundingBox, world); + place(Blocks.stained_glass_pane, glassMeta, 7, 2, 3, this.boundingBox, world); + + placeDoorAtCurrentPosition(world, this.boundingBox, random, 5, 1, 1, + getMetadataWithOffset(Blocks.wooden_door, 1)); + + place(Blocks.redstone_lamp, mWoodType, 2, 1, 4, this.boundingBox, world); + place(Blocks.redstone_torch, 0, 2, 2, 4, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(mWoodenStairs, 1), 2, 1, 3, this.boundingBox, world); + place(mWoodenStairs, getMetadataWithOffset(mWoodenStairs, 3), 3, 1, 4, this.boundingBox, world); + place(Blocks.fence, 0, 3, 1, 3, this.boundingBox, world); + place(Blocks.heavy_weighted_pressure_plate, 0, 3, 2, 3, this.boundingBox, world); + if (!this.hasMadeChest) { + int ic = getYWithOffset(0); + int jc = getXWithOffset(7, 1); + int kc = getZWithOffset(7, 1); + if (this.boundingBox.isVecInside(jc, ic, kc)) { + this.hasMadeChest = true; + generateStructureChestContents(world, this.boundingBox, random, 2, 1, 2, shackChestContents, + 1 + random.nextInt(3)); + } + } + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + clearCurrentPositionBlocksUpwards(world, j, 6, i, this.boundingBox); + func_151554_b(world, undergroundID, 0, j, 0, i, this.boundingBox); + } + } + spawnNatives(world, this.boundingBox, 3, 2, 3, MathUtils.randInt(3, 5)); + + return true; + } + + private int nativesSpawned = 0; + + private void spawnNatives(World par1World, StructureBoundingBox par2StructureBoundingBox, int par3, int par4, + int par5, int maxSpawned) { + if (this.nativesSpawned < maxSpawned) { + for (int i1 = this.nativesSpawned; i1 < maxSpawned; i1++) { + int j1 = getXWithOffset(par3 + i1, par5); + int k1 = getYWithOffset(par4); + int l1 = getZWithOffset(par3 + i1, par5); + if (!par2StructureBoundingBox.isVecInside(j1, k1, l1)) { + break; + } + if (par1World.rand.nextInt(MathUtils.randInt(1, 3)) != 0) { + EntityVillager entityvillager = new EntityVillager(par1World, 7736+(MathUtils.randInt(0, 1))); + entityvillager.func_110163_bv(); + entityvillager.setLocationAndAngles(j1 + 0.5D, k1, l1 + 0.5D, 0.0F, 0.0F); + par1World.spawnEntityInWorld(entityvillager); + this.nativesSpawned += 1; + } + } + } + } + + //Min, max, Weight + public static final WeightedRandomChestContent[] shackChestContents = { + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("dustIron", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 9), 50), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("dustCopper", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 6), 50), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("dustTin", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 6), 50), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("dustGold", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 3), 30), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("dustSilver", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 3), 30), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("gemDiamond", MathUtils.randInt(1, 2)), 0, MathUtils.randInt(1, 2), 5), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("gemEmerald", MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 5), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("gemRuby", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 4), 15), + new WeightedRandomChestContent(ItemUtils.getItemStackOfAmountFromOreDict("gemSapphire", MathUtils.randInt(1, 4)), 0, MathUtils.randInt(1, 4), 15), + new WeightedRandomChestContent(ItemUtils.getSimpleStack(CI.electricMotor_LV, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 5), + new WeightedRandomChestContent(ItemUtils.getSimpleStack(CI.electricPiston_LV, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 5), + new WeightedRandomChestContent(ItemUtils.getSimpleStack(CI.robotArm_LV, MathUtils.randInt(1, 2)), 0, MathUtils.randInt(1, 2), 2), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.cableGt01, Materials.Copper, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 25), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.cableGt01, Materials.Tin, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 25), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.wireGt01, Materials.Copper, MathUtils.randInt(2, 5)), 0, MathUtils.randInt(2, 5), 35), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.wireGt01, Materials.Tin, MathUtils.randInt(2, 5)), 0, MathUtils.randInt(2, 5), 35), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.pipeSmall, Materials.Copper, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 25), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.pipeSmall, Materials.Bronze, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 15), + new WeightedRandomChestContent(ItemUtils.getGregtechOreStack(OrePrefixes.pipeTiny, Materials.Steel, MathUtils.randInt(1, 3)), 0, MathUtils.randInt(1, 3), 5), + }; + + private boolean hasMadeChest; + private static final String CHEST_KEY = "AUSShackChest"; + + protected void func_143012_a(NBTTagCompound par1NBTTagCompound) { + super.func_143012_a(par1NBTTagCompound); + par1NBTTagCompound.setBoolean("AUSShackChest", this.hasMadeChest); + par1NBTTagCompound.setInteger("AUSWCount", this.nativesSpawned); + } + + protected void func_143011_b(NBTTagCompound par1NBTTagCompound) { + super.func_143011_b(par1NBTTagCompound); + this.hasMadeChest = par1NBTTagCompound.getBoolean("AUSShackChest"); + if (par1NBTTagCompound.hasKey("AUSWCount")) { + this.nativesSpawned = par1NBTTagCompound.getInteger("AUSWCount"); + } else { + this.nativesSpawned = 0; + } + } + + public static class WorldHandlerShack implements IGeneratorWorld { + private final double chance; + private final int range; + + public WorldHandlerShack(double chance) { + this.chance = chance; + this.range = 400; + } + + public int getExtentX() { + return 7; + } + + public int getExtentZ() { + return 7; + } + + public int getRange() { + return this.range; + } + + public boolean generate(World world, Random random, int x, int z) { + if ((MathUtils.randInt(0, 100) < (this.chance/5))) { + int direction = MathUtils.randInt(0, 3); + new ComponentShack(direction, random, x, z).addComponentParts(world, random); + Logger.WORLD("NativeShack x: " + x + " | z: " + z + " | dir: " + direction); + return true; + } + return false; + } + + public void initiate() { + } + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/map/structure/StructureManager.java b/src/main/java/gtPlusPlus/australia/gen/map/structure/StructureManager.java new file mode 100644 index 0000000000..b3238a5903 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/structure/StructureManager.java @@ -0,0 +1,20 @@ +package gtPlusPlus.australia.gen.map.structure; + +import gtPlusPlus.australia.gen.map.MapGenExtendedVillage; +import gtPlusPlus.australia.gen.map.structure.type.ComponentVillageBank; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.world.gen.structure.MapGenStructureIO; + +public class StructureManager { + + public static void registerVillageComponents() { + try { + //Register Village + MapGenStructureIO.registerStructure(MapGenExtendedVillage.Start.class, "ExtendedVillage"); + + //Register Structures within village + MapGenStructureIO.func_143031_a(ComponentVillageBank.class, CORE.MODID+":"+"Bank"); + } catch (Throwable e) {} + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java b/src/main/java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java new file mode 100644 index 0000000000..5b7017aaf0 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/map/structure/type/ComponentVillageBank.java @@ -0,0 +1,175 @@ +package gtPlusPlus.australia.gen.map.structure.type; + +import static net.minecraftforge.common.ChestGenHooks.VILLAGE_BLACKSMITH; + +import java.util.List; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.StructureComponent; +import net.minecraft.world.gen.structure.StructureVillagePieces; +import net.minecraft.world.gen.structure.StructureVillagePieces.House2; +import net.minecraftforge.common.ChestGenHooks; + +public class ComponentVillageBank extends House2 { + + /** List of items that Village's Blacksmith chest can contain. */ + public static final WeightedRandomChestContent[] villageBlacksmithChestContents = new WeightedRandomChestContent[] { + new WeightedRandomChestContent(Items.diamond, 0, 1, 3, 3), + new WeightedRandomChestContent(Items.iron_ingot, 0, 1, 5, 10), + new WeightedRandomChestContent(Items.gold_ingot, 0, 1, 3, 5), + new WeightedRandomChestContent(Items.bread, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.apple, 0, 1, 3, 15), + new WeightedRandomChestContent(Items.iron_pickaxe, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_sword, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_chestplate, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_helmet, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_leggings, 0, 1, 1, 5), + new WeightedRandomChestContent(Items.iron_boots, 0, 1, 1, 5), + new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.obsidian), 0, 3, 7, 5), + new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.sapling), 0, 3, 7, 5), + new WeightedRandomChestContent(Items.saddle, 0, 1, 1, 3), + new WeightedRandomChestContent(Items.iron_horse_armor, 0, 1, 1, 1), + new WeightedRandomChestContent(Items.golden_horse_armor, 0, 1, 1, 1), + new WeightedRandomChestContent(Items.diamond_horse_armor, 0, 1, 1, 1) + }; + + private boolean hasMadeChest; + + public ComponentVillageBank() { + Logger.INFO("Created a Bank."); + } + + public ComponentVillageBank(StructureVillagePieces.Start aStart, int p_i2103_2_, Random aRand, + StructureBoundingBox aBox, int aCoordBaseMode) { + super(aStart, p_i2103_2_, aRand, aBox, aCoordBaseMode); + this.coordBaseMode = aCoordBaseMode; + this.boundingBox = aBox; + } + + public static StructureVillagePieces.House2 func_74915_a(StructureVillagePieces.Start p_74915_0_, List p_74915_1_, + Random p_74915_2_, int p_74915_3_, int p_74915_4_, int p_74915_5_, int p_74915_6_, int p_74915_7_) { + StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p_74915_3_, + p_74915_4_, p_74915_5_, 0, 0, 0, 10, 6, 7, p_74915_6_); + Logger.INFO("12334453"); + return canVillageGoDeeper(structureboundingbox) + && StructureComponent.findIntersecting(p_74915_1_, structureboundingbox) == null + ? new StructureVillagePieces.House2(p_74915_0_, p_74915_7_, p_74915_2_, structureboundingbox, + p_74915_6_) + : null; + } + + protected void func_143012_a(NBTTagCompound aNBT) { + super.func_143012_a(aNBT); + aNBT.setBoolean("Chest", this.hasMadeChest); + } + + protected void func_143011_b(NBTTagCompound aNBT) { + super.func_143011_b(aNBT); + this.hasMadeChest = aNBT.getBoolean("Chest"); + } + + /** + * second Part of Structure generating, this for example places Spiderwebs, Mob + * Spawners, it closes Mineshafts at the end, it adds Fences... + */ + public boolean addComponentParts(World aWorld, Random aRand, StructureBoundingBox aBox) { + if (this.field_143015_k < 0) { + this.field_143015_k = this.getAverageGroundLevel(aWorld, aBox); + + if (this.field_143015_k < 0) { + return true; + } + + this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 6 - 1, 0); + } + + this.fillWithBlocks(aWorld, aBox, 0, 1, 0, 9, 4, 6, Blocks.air, Blocks.air, false); + this.fillWithBlocks(aWorld, aBox, 0, 0, 0, 9, 0, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.fillWithBlocks(aWorld, aBox, 0, 4, 0, 9, 4, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.fillWithBlocks(aWorld, aBox, 0, 5, 0, 9, 5, 6, Blocks.stone_slab, Blocks.stone_slab, false); + this.fillWithBlocks(aWorld, aBox, 1, 5, 1, 8, 5, 5, Blocks.air, Blocks.air, false); + this.fillWithBlocks(aWorld, aBox, 1, 1, 0, 2, 3, 0, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 0, 0, 4, 0, Blocks.log, Blocks.log, false); + this.fillWithBlocks(aWorld, aBox, 3, 1, 0, 3, 4, 0, Blocks.log, Blocks.log, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 6, 0, 4, 6, Blocks.log, Blocks.log, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.planks, 0, 3, 3, 1, aBox); + this.fillWithBlocks(aWorld, aBox, 3, 1, 2, 3, 3, 2, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 4, 1, 3, 5, 3, 3, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 0, 1, 1, 0, 3, 5, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 1, 1, 6, 5, 3, 6, Blocks.planks, Blocks.planks, false); + this.fillWithBlocks(aWorld, aBox, 5, 1, 0, 5, 3, 0, Blocks.fence, Blocks.fence, false); + this.fillWithBlocks(aWorld, aBox, 9, 1, 0, 9, 3, 0, Blocks.fence, Blocks.fence, false); + this.fillWithBlocks(aWorld, aBox, 6, 1, 4, 9, 4, 6, Blocks.cobblestone, Blocks.cobblestone, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.flowing_lava, 0, 7, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.flowing_lava, 0, 8, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.iron_bars, 0, 9, 2, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.iron_bars, 0, 9, 2, 4, aBox); + this.fillWithBlocks(aWorld, aBox, 7, 2, 4, 8, 2, 5, Blocks.air, Blocks.air, false); + this.placeBlockAtCurrentPosition(aWorld, Blocks.cobblestone, 0, 6, 1, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.furnace, 0, 6, 2, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.furnace, 0, 6, 3, 3, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.double_stone_slab, 0, 8, 1, 1, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 0, 2, 2, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 0, 2, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 2, 2, 6, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.glass_pane, 0, 4, 2, 6, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.fence, 0, 2, 1, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.wooden_pressure_plate, 0, 2, 2, 4, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.planks, 0, 1, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.oak_stairs, + this.getMetadataWithOffset(Blocks.oak_stairs, 3), 2, 1, 5, aBox); + this.placeBlockAtCurrentPosition(aWorld, Blocks.oak_stairs, + this.getMetadataWithOffset(Blocks.oak_stairs, 1), 1, 1, 4, aBox); + int i; + int j; + + if (!this.hasMadeChest) { + i = this.getYWithOffset(1); + j = this.getXWithOffset(5, 5); + int k = this.getZWithOffset(5, 5); + + if (aBox.isVecInside(j, i, k)) { + this.hasMadeChest = true; + this.generateStructureChestContents(aWorld, aBox, aRand, 5, 1, 5, + ChestGenHooks.getItems(VILLAGE_BLACKSMITH, aRand), + ChestGenHooks.getCount(VILLAGE_BLACKSMITH, aRand)); + } + } + + for (i = 6; i <= 8; ++i) { + if (this.getBlockAtCurrentPosition(aWorld, i, 0, -1, aBox).getMaterial() == Material.air && this + .getBlockAtCurrentPosition(aWorld, i, -1, -1, aBox).getMaterial() != Material.air) { + this.placeBlockAtCurrentPosition(aWorld, Blocks.stone_stairs, + this.getMetadataWithOffset(Blocks.stone_stairs, 3), i, 0, -1, aBox); + } + } + + for (i = 0; i < 7; ++i) { + for (j = 0; j < 10; ++j) { + this.clearCurrentPositionBlocksUpwards(aWorld, j, 6, i, aBox); + this.func_151554_b(aWorld, Blocks.cobblestone, 0, j, -1, i, aBox); + } + } + + this.spawnVillagers(aWorld, aBox, 7, 1, 1, 1); + return true; + } + + /** + * Returns the villager type to spawn in this component, based on the number of + * villagers already spawned. + */ + protected int getVillagerType(int p_74888_1_) { + return 7735; + } + +} diff --git a/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianOre.java b/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianOre.java new file mode 100644 index 0000000000..9adb84eef2 --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianOre.java @@ -0,0 +1,87 @@ +package gtPlusPlus.australia.gen.world; + +import java.util.Random; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class WorldGenAustralianOre extends WorldGenerator { + + private Block mOreToSpawn; + private int numberOfBlocks; + private Block mBlockToReplace; + private int mineableBlockMeta; + + public WorldGenAustralianOre(Block aBlock, int aNumber) { + this(aBlock, aNumber, Blocks.stone); + this.mineableBlockMeta = 0; + } + + public WorldGenAustralianOre(Block aBlock, int aNumber, Block aReplace) { + this.mOreToSpawn = aBlock; + this.numberOfBlocks = aNumber; + this.mBlockToReplace = aReplace; + } + + public WorldGenAustralianOre(Block block, int meta, int number, Block target) { + this(block, number, target); + this.mineableBlockMeta = meta; + } + + + + public boolean generate(World aWorld, Random aRand, int aX, int aY, int aZ) { + float f = MathUtils.randFloat(0f, 1.5f) * CORE.PI; + double d0 = (double) ((float) (aX + 8) + MathHelper.sin(f) * (float) this.numberOfBlocks / 8.0F); + double d1 = (double) ((float) (aX + 8) - MathHelper.sin(f) * (float) this.numberOfBlocks / 8.0F); + double d2 = (double) ((float) (aZ + 8) + MathHelper.cos(f) * (float) this.numberOfBlocks / 8.0F); + double d3 = (double) ((float) (aZ + 8) - MathHelper.cos(f) * (float) this.numberOfBlocks / 8.0F); + double d4 = (double) (aY + aRand.nextInt(MathUtils.randInt(3, 6)) - 2); + double d5 = (double) (aY + aRand.nextInt(MathUtils.randInt(3, 6)) - 2); + + for (int aOreGenerated = 0; aOreGenerated <= this.numberOfBlocks; ++aOreGenerated) { + double d6 = d0 + (d1 - d0) * (double) aOreGenerated / (double) this.numberOfBlocks; + double d7 = d4 + (d5 - d4) * (double) aOreGenerated / (double) this.numberOfBlocks; + double d8 = d2 + (d3 - d2) * (double) aOreGenerated / (double) this.numberOfBlocks; + double d9 = aRand.nextDouble() * (double) this.numberOfBlocks / 16.0D; + double d10 = (double) (MathHelper.sin((float) aOreGenerated * CORE.PI / (float) this.numberOfBlocks) + 1.0F) + * d9 + 1.0D; + double d11 = (double) (MathHelper.sin((float) aOreGenerated * CORE.PI / (float) this.numberOfBlocks) + 1.0F) + * d9 + 1.0D; + int i1 = MathHelper.floor_double(d6 - d10 / 2.0D); + int j1 = MathHelper.floor_double(d7 - d11 / 2.0D); + int k1 = MathHelper.floor_double(d8 - d10 / 2.0D); + int l1 = MathHelper.floor_double(d6 + d10 / 2.0D); + int i2 = MathHelper.floor_double(d7 + d11 / 2.0D); + int j2 = MathHelper.floor_double(d8 + d10 / 2.0D); + + for (int k2 = i1; k2 <= l1; ++k2) { + double d12 = ((double) k2 + 0.5D - d6) / (d10 / 2.0D); + + if (d12 * d12 < 1.0D) { + for (int l2 = j1; l2 <= i2; ++l2) { + double d13 = ((double) l2 + 0.5D - d7) / (d11 / 2.0D); + + if (d12 * d12 + d13 * d13 < 1.0D) { + for (int i3 = k1; i3 <= j2; ++i3) { + double d14 = ((double) i3 + 0.5D - d8) / (d10 / 2.0D); + + if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D && aWorld.getBlock(k2, l2, i3) + .isReplaceableOreGen(aWorld, k2, l2, i3, mBlockToReplace)) { + aWorld.setBlock(k2, l2, i3, this.mOreToSpawn, mineableBlockMeta, 2); + } + } + } + } + } + } + } + + return true; + } +}
\ No newline at end of file diff --git a/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianTrees.java b/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianTrees.java new file mode 100644 index 0000000000..f3529aff0b --- /dev/null +++ b/src/main/java/gtPlusPlus/australia/gen/world/WorldGenAustralianTrees.java @@ -0,0 +1,250 @@ +package gtPlusPlus.australia.gen.world; + +import java.util.Random; + +import gtPlusPlus.core.util.math.MathUtils; +import net.minecraft.block.Block; +import net.minecraft.block.BlockSapling; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.util.Direction; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraftforge.common.util.ForgeDirection; + +public class WorldGenAustralianTrees extends WorldGenTrees { + + /** The minimum height of a generated tree. */ + private final int minHeight; + /** True if this tree should grow Vines. */ + private final boolean growVines; + /** The metadata value of the wood to use in tree generation. */ + private final int woodMeta; + /** The metadata value of the leaves to use in tree generation. */ + private final int leavesMeta; + + public WorldGenAustralianTrees(boolean p_i2027_1_) { + this(p_i2027_1_, 4, false); + } + + public WorldGenAustralianTrees(boolean p_i2028_1_, int aMinHeight, boolean aVinesGrow) { + super(p_i2028_1_, aMinHeight, 0, 0, aVinesGrow); + this.minHeight = aMinHeight; + this.woodMeta = 0; + this.leavesMeta = 0; + this.growVines = aVinesGrow; + } + + public boolean generate(World aWorld, Random aRand, int aX, int aY, int aZ) { + int aActualMinHeight = MathUtils.randInt(4, 8) + this.minHeight; + boolean flag = true; + + if (aY >= 1 && aY + aActualMinHeight + 1 <= 256) { + byte b0; + int k1; + Block block; + + for (int i1 = aY; i1 <= aY + 1 + aActualMinHeight; ++i1) { + b0 = 1; + + if (i1 == aY) { + b0 = 0; + } + + if (i1 >= aY + 1 + aActualMinHeight - 2) { + b0 = 2; + } + + for (int j1 = aX - b0; j1 <= aX + b0 && flag; ++j1) { + for (k1 = aZ - b0; k1 <= aZ + b0 && flag; ++k1) { + if (i1 >= 0 && i1 < 256) { + block = aWorld.getBlock(j1, i1, k1); + + if (!this.isReplaceable(aWorld, j1, i1, k1)) { + flag = false; + } + } else { + flag = false; + } + } + } + } + + if (!flag) { + return false; + } else { + Block block2 = aWorld.getBlock(aX, aY - 1, aZ); + boolean isSoil = true; + for (int gh = 0; gh < 5; gh++) { + int xMod, zMod; + if (gh == 0) { + xMod = 1; + zMod = 0; + } + else if (gh == 1) { + xMod = 0; + zMod = 1; + } + else if (gh == 2) { + xMod = -1; + zMod = 0; + } + else if (gh == 3) { + xMod = 0; + zMod = -1; + } + else { + xMod = 0; + zMod = 0; + } + block2 = aWorld.getBlock(aX+xMod, aY - 1, aZ+zMod); + if (block2 == Blocks.air || !block2.canSustainPlant(aWorld, aX+xMod, aY - 1, aZ+zMod, ForgeDirection.UP, (BlockSapling) Blocks.sapling)) { + isSoil = false; + break; + } + } + + if (isSoil && aY < 256 - aActualMinHeight - 1) { + block2.onPlantGrow(aWorld, aX, aY - 1, aZ, aX, aY, aZ); + b0 = 5; + byte b1 = 0; + int l1; + int i2; + int j2; + int i3; + + for (k1 = aY - b0 + aActualMinHeight; k1 <= aY + aActualMinHeight; ++k1) { + i3 = k1 - (aY + aActualMinHeight); + l1 = b1 + 3 - i3 / 2; + + for (i2 = aX - l1; i2 <= aX + l1; ++i2) { + j2 = i2 - aX; + + for (int k2 = aZ - l1; k2 <= aZ + l1; ++k2) { + int l2 = k2 - aZ; + + if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || aRand.nextInt(2) != 0 && i3 != 0) { + Block block1 = aWorld.getBlock(i2, k1, k2); + + if (block1.isAir(aWorld, i2, k1, k2) || block1.isLeaves(aWorld, i2, k1, k2)) { + this.setBlockAndNotifyAdequately(aWorld, i2, k1, k2, Blocks.leaves, + this.leavesMeta); + } + } + } + } + } + + for (k1 = 0; k1 < aActualMinHeight; ++k1) { + block = aWorld.getBlock(aX, aY + k1, aZ); + + if (block.isAir(aWorld, aX, aY + k1, aZ) || block.isLeaves(aWorld, aX, aY + k1, aZ)) { + + //Set Middle Trunk + this.setBlockAndNotifyAdequately(aWorld, aX, aY + k1, aZ, Blocks.log, this.woodMeta); + //Set Sides + if (k1 < (aActualMinHeight - 2)) { + if (aWorld.isAirBlock(aX+1, aY + k1, aZ) || block.isLeaves(aWorld, aX+1, aY + k1, aZ)) this.setBlockAndNotifyAdequately(aWorld, aX+1, aY + k1, aZ, Blocks.log, this.woodMeta); + if (aWorld.isAirBlock(aX-1, aY + k1, aZ) || block.isLeaves(aWorld, aX-1, aY + k1, aZ)) this.setBlockAndNotifyAdequately(aWorld, aX-1, aY + k1, aZ, Blocks.log, this.woodMeta); + if (aWorld.isAirBlock(aX, aY + k1, aZ+1) || block.isLeaves(aWorld, aX, aY + k1, aZ+1)) this.setBlockAndNotifyAdequately(aWorld, aX, aY + k1, aZ+1, Blocks.log, this.woodMeta); + if (aWorld.isAirBlock(aX, aY + k1, aZ-1) || block.isLeaves(aWorld, aX, aY + k1, aZ-1)) this.setBlockAndNotifyAdequately(aWorld, aX, aY + k1, aZ-1, Blocks.log, this.woodMeta); + } + + if (this.growVines && k1 > 0) { + if (aRand.nextInt(3) > 0 && aWorld.isAirBlock(aX - 1, aY + k1, aZ)) { + this.setBlockAndNotifyAdequately(aWorld, aX - 1, aY + k1, aZ, Blocks.vine, 8); + } + + if (aRand.nextInt(3) > 0 && aWorld.isAirBlock(aX + 1, aY + k1, aZ)) { + this.setBlockAndNotifyAdequately(aWorld, aX + 1, aY + k1, aZ, Blocks.vine, 2); + } + + if (aRand.nextInt(3) > 0 && aWorld.isAirBlock(aX, aY + k1, aZ - 1)) { + this.setBlockAndNotifyAdequately(aWorld, aX, aY + k1, aZ - 1, Blocks.vine, 1); + } + + if (aRand.nextInt(3) > 0 && aWorld.isAirBlock(aX, aY + k1, aZ + 1)) { + this.setBlockAndNotifyAdequately(aWorld, aX, aY + k1, aZ + 1, Blocks.vine, 4); + } + } + } + } + + if (this.growVines) { + for (k1 = aY - 3 + aActualMinHeight; k1 <= aY + aActualMinHeight; ++k1) { + i3 = k1 - (aY + aActualMinHeight); + l1 = 2 - i3 / 2; + + for (i2 = aX - l1; i2 <= aX + l1; ++i2) { + for (j2 = aZ - l1; j2 <= aZ + l1; ++j2) { + if (aWorld.getBlock(i2, k1, j2).isLeaves(aWorld, i2, k1, j2)) { + if (aRand.nextInt(4) == 0 + && aWorld.getBlock(i2 - 1, k1, j2).isAir(aWorld, i2 - 1, k1, j2)) { + this.growVines(aWorld, i2 - 1, k1, j2, 8); + } + + if (aRand.nextInt(4) == 0 + && aWorld.getBlock(i2 + 1, k1, j2).isAir(aWorld, i2 + 1, k1, j2)) { + this.growVines(aWorld, i2 + 1, k1, j2, 2); + } + + if (aRand.nextInt(4) == 0 + && aWorld.getBlock(i2, k1, j2 - 1).isAir(aWorld, i2, k1, j2 - 1)) { + this.growVines(aWorld, i2, k1, j2 - 1, 1); + } + + if (aRand.nextInt(4) == 0 + && aWorld.getBlock(i2, k1, j2 + 1).isAir(aWorld, i2, k1, j2 + 1)) { + this.growVines(aWorld, i2, k1, j2 + 1, 4); + } + } + } + } + } + + if (aRand.nextInt(5) == 0 && aActualMinHeight > 5) { + for (k1 = 0; k1 < 2; ++k1) { + for (i3 = 0; i3 < 4; ++i3) { + if (aRand.nextInt(4 - k1) == 0) { + l1 = aRand.nextInt(3); + this.setBlockAndNotifyAdequately(aWorld, + aX + Direction.offsetX[Direction.rotateOpposite[i3]], aY + aActualMinHeight - 5 + k1, + aZ + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, + l1 << 2 | i3); + } + } + } + } + } + + return true; + } else { + return false; + } + } + } else { + return false; + } + } + + /** + * Grows vines downward from the given block for a given length. Args: World, x, + * starty, z, vine-length + */ + private void growVines(World p_76529_1_, int p_76529_2_, int p_76529_3_, int p_76529_4_, int p_76529_5_) { + this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_); + int i1 = 4; + + while (true) { + --p_76529_3_; + + if (!p_76529_1_.getBlock(p_76529_2_, p_76529_3_, p_76529_4_).isAir(p_76529_1_, p_76529_2_, p_76529_3_, + p_76529_4_) || i1 <= 0) { + return; + } + + this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_); + --i1; + } + } +}
\ No newline at end of file |