Manslaughter777 Posted November 9, 2014 Share Posted November 9, 2014 Im having the weidest problem generated 2 different types of trees in my dimension (metadata). I crash every time i make a new world for some reason. Now for some reason when i only generate 1 of the trees in works perfectly, but both, gives an error. TreeGen package com.manslaughter777.crystaldimension.world.gen; import java.util.Random; import com.manslaughter777.crystaldimension.Main; import com.manslaughter777.crystaldimension.world.gen.feature.WorldGenCrystalTrees; import com.manslaughter777.crystaldimension.world.gen.feature.WorldGenIlluminateTrees; import com.manslaughter777.crystaldimension.world.gen.feature.WorldGenOres; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenTrees; import cpw.mods.fml.common.IWorldGenerator; public class TreeGenerator implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { switch (world.provider.dimensionId) { case -1: generateNether(world, random, chunkX * 16, chunkZ * 16); case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); case 7: generateCrystal(world, random, chunkX * 16, chunkZ * 16); } } private void generateEnd(World world, Random random, int x, int z) { } private void generateSurface(World world, Random random, int x, int z) { } private void generateNether(World world, Random random, int x, int z) { } private void generateCrystal(World world, Random random, int x, int z) { BiomeGenBase biomeGenBase = world.getWorldChunkManager().getBiomeGenAt(x + 16, z + 16); if (biomeGenBase == Main.crystalBiome) this.addTreeSpawn(world, random, Main.log, Main.leaves, 0, 0, false, 5, 5, false, x, z, 16, 100, 16, 50); this.addTreeSpawn(world, random, Main.log, Main.leaves, 1, 1, false, 6, 8, false, x, z, 16, 120, 16, 30); /* for (int i = 0; i < 50; i++) { int x1 = x + random.nextInt(16); int y1 = random.nextInt(100); //How High? int z1 = z + random.nextInt(16); new WorldGenCrystalTrees(Main.log, Main.leaves, 0, 0, false, 5, 5, false).generate(world, random, x1, y1, z1); } */ } private void addTreeSpawn(World world, Random random, Block log, Block leaves, int metaLog, int metaLeaves, boolean doBlockNotify, int minTreeHeight, int randomTreeHeight, boolean vinesGrow, int xPos, int zPos, int maxX, int maxY, int maxZ, int chanceToSpawn) { for (int i = 0; i < chanceToSpawn; i++) { int posX = xPos + random.nextInt(maxX); //16 int posY = random.nextInt(maxY); int posZ = zPos + random.nextInt(maxZ); //16 (new WorldGenCrystalTrees(log, leaves, metaLog, metaLeaves, doBlockNotify, minTreeHeight, randomTreeHeight, vinesGrow)).generate(world, random, posX, posY, posZ); } } } WorldGenCrystalTrees package com.manslaughter777.crystaldimension.world.gen.feature; import java.util.Random; import com.manslaughter777.crystaldimension.Main; 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.WorldGenAbstractTree; import net.minecraftforge.common.util.ForgeDirection; public class WorldGenCrystalTrees extends WorldGenAbstractTree { private final int minTreeHeight; private final int randomTreeHeight; private final boolean vinesGrow; private final Block wood; private final Block leaves; private final int metaWood; private final int metaLeaves; public WorldGenCrystalTrees(Block wood, Block leaves, int metaWood, int metaLeaves) { this(wood, leaves, metaWood, metaLeaves, false, 4, 3, false); } public WorldGenCrystalTrees(Block wood, Block leaves, int metaWood, int metaLeaves, boolean doBlockNotify, int minTreeHeight, int randomTreeHeight, boolean vinesGrow) { super(doBlockNotify); this.wood = wood; this.leaves = leaves; this.minTreeHeight = minTreeHeight; this.randomTreeHeight = randomTreeHeight; this.metaWood = metaWood; this.metaLeaves = metaLeaves; this.vinesGrow = vinesGrow; } public boolean generate(World world, Random random, int x, int y, int z) { int l = random.nextInt(3) + this.minTreeHeight; boolean flag = true; if (y >= 1 && y + l + 1 <= 256) { byte b0; int k1; Block block; for (int i1 = y; i1 <= y + 1 + l; ++i1) { b0 = 1; if (i1 == y) { b0 = 0; } if (i1 >= y + 1 + l - 2) { b0 = 2; } for (int j1 = x - b0; j1 <= x + b0 && flag; ++j1) { for (k1 = z - b0; k1 <= z + b0 && flag; ++k1) { if (i1 >= 0 && i1 < 256) { block = world.getBlock(j1, i1, k1); //THIS IS WHERE THE ERROR CODE SAYS THERE IS SOMETHING WRONG if (!this.isReplaceable(world, j1, i1, k1)) { flag = false; } } else { flag = false; } } } } if (!flag) { return false; } else { Block block2 = world.getBlock(x, y - 1, z); boolean isSoil = block2.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, (BlockSapling)Main.sapling); if (isSoil && y < 256 - l - 1) { block2.onPlantGrow(world, x, y - 1, z, x, y, z); b0 = 3; byte b1 = 0; int l1; int i2; int j2; int i3; for (k1 = y - b0 + l; k1 <= y + l; ++k1) { i3 = k1 - (y + l); l1 = b1 + 1 - i3 / 2; for (i2 = x - l1; i2 <= x + l1; ++i2) { j2 = i2 - x; for (int k2 = z - l1; k2 <= z + l1; ++k2) { int l2 = k2 - z; if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || random.nextInt(2) != 0 && i3 != 0) { Block block1 = world.getBlock(i2, k1, k2); if (block1.isAir(world, i2, k1, k2) || block1.isLeaves(world, i2, k1, k2)) { this.setBlockAndNotifyAdequately(world, i2, k1, k2, Main.leaves, this.metaLeaves); } } } } } for (k1 = 0; k1 < l; ++k1) { block = world.getBlock(x, y + k1, z); if (block.isAir(world, x, y + k1, z) || block.isLeaves(world, x, y + k1, z)) { this.setBlockAndNotifyAdequately(world, x, y + k1, z, Main.log, this.metaWood); if (this.vinesGrow && k1 > 0) { if (random.nextInt(3) > 0 && world.isAirBlock(x - 1, y + k1, z)) { this.setBlockAndNotifyAdequately(world, x - 1, y + k1, z, Blocks.vine, ; } if (random.nextInt(3) > 0 && world.isAirBlock(x + 1, y + k1, z)) { this.setBlockAndNotifyAdequately(world, x + 1, y + k1, z, Blocks.vine, 2); } if (random.nextInt(3) > 0 && world.isAirBlock(x, y + k1, z - 1)) { this.setBlockAndNotifyAdequately(world, x, y + k1, z - 1, Blocks.vine, 1); } if (random.nextInt(3) > 0 && world.isAirBlock(x, y + k1, z + 1)) { this.setBlockAndNotifyAdequately(world, x, y + k1, z + 1, Blocks.vine, 4); } } } } if (this.vinesGrow) { for (k1 = y - 3 + l; k1 <= y + l; ++k1) { i3 = k1 - (y + l); l1 = 2 - i3 / 2; for (i2 = x - l1; i2 <= x + l1; ++i2) { for (j2 = z - l1; j2 <= z + l1; ++j2) { if (world.getBlock(i2, k1, j2).isLeaves(world, i2, k1, j2)) { if (random.nextInt(4) == 0 && world.getBlock(i2 - 1, k1, j2).isAir(world, i2 - 1, k1, j2)) { this.growVines(world, i2 - 1, k1, j2, ; } if (random.nextInt(4) == 0 && world.getBlock(i2 + 1, k1, j2).isAir(world, i2 + 1, k1, j2)) { this.growVines(world, i2 + 1, k1, j2, 2); } if (random.nextInt(4) == 0 && world.getBlock(i2, k1, j2 - 1).isAir(world, i2, k1, j2 - 1)) { this.growVines(world, i2, k1, j2 - 1, 1); } if (random.nextInt(4) == 0 && world.getBlock(i2, k1, j2 + 1).isAir(world, i2, k1, j2 + 1)) { this.growVines(world, i2, k1, j2 + 1, 4); } } } } } if (random.nextInt(5) == 0 && l > 5) { for (k1 = 0; k1 < 2; ++k1) { for (i3 = 0; i3 < 4; ++i3) { if (random.nextInt(4 - k1) == 0) { l1 = random.nextInt(3); this.setBlockAndNotifyAdequately(world, x + Direction.offsetX[Direction.rotateOpposite[i3]], y + l - 5 + k1, z + 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; } } } ERROR CODE (Seems to be line 81 of WorldGenCrystalTrees --- Minecraft Crash Report ---- // Why did you do that? Time: 9/11/14 6:53 PM Description: Exception getting block type in world java.lang.StackOverflowError: Exception getting block type in world at java.security.AccessController.doPrivileged(Native Method) at java.lang.ClassLoader.checkPackageAccess(Unknown Source) at net.minecraft.world.World.getBlock(World.java:389) at com.manslaughter777.crystaldimension.world.gen.feature.WorldGenCrystalTrees.generate(WorldGenCrystalTrees.java:81) at com.manslaughter777.crystaldimension.world.gen.TreeGenerator.addTreeSpawn(TreeGenerator.java:70) at com.manslaughter777.crystaldimension.world.gen.TreeGenerator.generateCrystal(TreeGenerator.java:52) at com.manslaughter777.crystaldimension.world.gen.TreeGenerator.generate(TreeGenerator.java:29) at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:314) at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1134) at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:208) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:149) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:119) at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:221) at net.minecraft.world.World.getChunkFromChunkCoords(World.java:479) at net.minecraft.world.World.getBlock(World.java:384) btw it repeats these lines about 100 times Quote Link to comment Share on other sites More sharing options...
gegy1000 Posted November 9, 2014 Share Posted November 9, 2014 https://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html Your code is probably getting into an infinite loop. Quote Link to comment Share on other sites More sharing options...
shieldbug1 Posted November 9, 2014 Share Posted November 9, 2014 Haven't looked into it, but from what it looks like, you're trying to get a block that hasn't generated yet. Minecraft then goes to generate the block, and in doing so, goes to call your class to generate. This results in an 'infinite loop'. Quote BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials. Link to comment Share on other sites More sharing options...
Manslaughter777 Posted November 9, 2014 Author Share Posted November 9, 2014 thanks guys, ill check it out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.