Posted July 8, 201411 yr Hello modders, I need help with my mod. Can you read schematic files and generate them randomly in the world without converting schematic to java code ? Maybe it is good to read the schematic file into bytes and then set arrays or HashMaps ? Or best with inputStream? And how would you do it ? If you have an idea and a code for the beginning please help me. Thank you.
July 8, 201411 yr public Schematic get(String schemname){ try { InputStream is = this.getClass().getClassLoader().getResourceAsStream("assets/mymod/schem/"+schemname); NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is); short width = nbtdata.getShort("Width"); short height = nbtdata.getShort("Height"); short length = nbtdata.getShort("Length"); byte[] blocks = nbtdata.getByteArray("Blocks"); byte[] data = nbtdata.getByteArray("Data"); System.out.println("schem size:" + width + " x " + height + " x " + length); NBTTagList tileentities = nbtdata.getTagList("TileEntities", 10); is.close(); return new Schematic(tileentities, width, height, length, blocks, data); } catch (Exception e) { System.out.println("I can't load schematic, because " + e.toString()); return null; } } public class Schematic{ public NBTTagList tileentities; public short width; public short height; public short length; public byte[] blocks; public byte[] data; public Schematic(NBTTagList tileentities, short width, short height, short length, byte[] blocks, byte[] data){ this.tileentities = tileentities; this.width = width; this.height = height; this.length = length; this.blocks = blocks; this.data = data; } } And it's from my item code, maybe it can help you: public boolean onItemUse(ItemStack is, EntityPlayer placer, World world, int x, int y, int z, int side, float px, float py, float pz) { if(!world.isRemote && !blocked && delay<=0 && side == 1 && placer.capabilities.isCreativeMode){ blocked = true; delay = 20; int rotation = OtherUtils.getPlayerRotationSide(placer); SchemUtils.Schematic sh = sut.get(schematic); if(sh==null){ placer.addChatMessage(new ChatComponentText("Schematic is dead!")); this.setUnlocalizedName("builder_corrupt"); return false;} if(logBuilding)placer.addChatMessage(new ChatComponentText("Building started.")); int i = 0; for(int sy = 0; sy < sh.height; sy++) for(int sz = 0; sz < sh.length; sz++) for(int sx = 0; sx < sh.width; sx++){ Block b = Block.getBlockById(sh.blocks[i]); if(b!= Blocks.air) { int rx = SchemUtils.blockCoordsRotation(sx - this.getxShift(), sz, rotation)[0]; int rz = SchemUtils.blockCoordsRotation(sx - this.getxShift(), sz, rotation)[1]; world.setBlockToAir(x + rx, y + ylevel + sy, z + rz); world.setBlock(x+rx, y+ylevel+sy, z+rz, b, SchemUtils.rotateMeta(sh.blocks[i], sh.data[i], rotation ), 2); } i++; } if (sh.tileentities != null) { for (int i1 = 0; i1 < sh.tileentities.tagCount(); ++i1) { NBTTagCompound nbttagcompound4 = sh.tileentities.getCompoundTagAt(i1); TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound4); if (tileentity != null) { int[] conv2 = SchemUtils.blockCoordsRotation(tileentity.xCoord - this.getxShift(), tileentity.zCoord, rotation); tileentity.xCoord = x + conv2[0]; tileentity.yCoord += y+ylevel; tileentity.zCoord = z + conv2[1]; world.setTileEntity(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, tileentity); } } } if(logBuilding) placer.addChatMessage(new ChatComponentText("Building finished.")); blocked = false; return true; } return false; }
July 8, 201411 yr Author So in data[0] is the data (position, metadata) for the block from blocks[0] stored ?
July 9, 201411 yr Author So this would be right in the WorldGenerate method: for(int chanceForChuk = 0; chanceForChuk < 1; chanceForChuk++) { Schematic spring = SchematicLoader.get("spring"); int i = 0; for(int cy = 0; cy < spring.height; cy++) for(int cz = 0; cz < spring.length; cz++) for(int cx = 0; cx < spring.width; cx++){ Block b = Block.getBlockById(spring.blocks[i]); if(b!= Blocks.air) { world.setBlockToAir(cx , cy, cz); world.setBlock(cx, cy, cz, b, Integer.parseInt(String.valueOf(spring.data[i])), 2); } i++; } } Or would it be other if cx, cy, cz are my coordinates ? I am new with structure spawning in the world... Thanks for your help
July 9, 201411 yr Author Oh, forget my code, i just write before I test. I read your code carefully but because of your rotationthings i am not sure about it, so how do you can generate a structure with the Schematic and blocks[] and data[] ? I used Integer.parseINt(String.valueOf(spring.data)); because i needed an integer and Integer.something returns an integer, but i didn´t saw a byte - convert, so i tried to make first a string from the data stored in data and then I tried to get the value of this string.. Very complicated..
July 9, 201411 yr Your code is correct. And you can pass meta directly, byte normally casts to int (world.setBlock(cx, cy, cz, b, spring.data[і]), 2); ). And another thing. Schematic spring = SchematicLoader.get("spring"); Don't forget to add extention to filename if you didnt do it.
July 9, 201411 yr Author I get an error: my WorldGen code: package de.MhytRPG.www.worldgen; import java.util.Random; import cpw.mods.fml.common.IWorldGenerator; import de.MhytRPG.www.MhytRPG; import de.MhytRPG.www.structures.Schematic; import de.MhytRPG.www.structures.SchematicLoader; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenLiquids; import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGen 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); break; case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); break; case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); break; } } private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {} private void generateSurface(World world, Random rand, int chunkX, int chunkZ) { for(int k = 0; k < 10; k++){ int firstBlockXCoord = chunkX + rand.nextInt(16); int firstBlockYCoord = rand.nextInt(200); int firstBlockZCoord = chunkZ + rand.nextInt(16); (new WorldGenLiquids(MhytRPG.blockgoldenwater)).generate(world, rand, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord); } for(int chanceForChuk = 0; chanceForChuk < 1; chanceForChuk++) { Schematic spring = SchematicLoader.get("spring.schematic"); int firstBlockXCoord = chunkX + rand.nextInt(16); int firstBlockYCoord = rand.nextInt(200); int firstBlockZCoord = chunkZ + rand.nextInt(16); int i = 0; for(int cy = 0; cy < spring.height; cy++) for(int cz = 0; cz < spring.length; cz++) for(int cx = 0; cx < spring.width; cx++){ Block b = Block.getBlockById(spring.blocks[i]); if(b!= Blocks.air) { world.setBlockToAir(cx + firstBlockXCoord , cy + firstBlockYCoord, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + firstBlockYCoord, cz + firstBlockZCoord, b, spring.data[i] , 2); } i++; } } } private void generateNether(World world, Random rand, int chunkX, int chunkZ) {} } Description: Exception in server tick loop java.lang.NullPointerException: Exception in server tick loop at de.MhytRPG.www.worldgen.WorldGen.generateSurface(WorldGen.java:52) at de.MhytRPG.www.worldgen.WorldGen.generate(WorldGen.java:26) at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316) at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1163) at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79) at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) My Line 52 is: for(int cy = 0; cy < spring.height; cy++) I don´t really know why, is the spring.height = 0 ?
July 9, 201411 yr Your your schematic getter returns null. Search in log for "I can't load schematic, because ...".
July 9, 201411 yr Author I didn´t find it. My log (skip the errors with unable loading pngs, because it is something I forgot to add a texture.): [14:50:58] [main/INFO]: Setting user: ForgeDevName [14:50:58] [Client thread/INFO]: LWJGL Version: 2.9.1 [14:51:01] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:MhytRPG [14:51:02] [sound Library Loader/INFO]: Sound engine started [14:51:03] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas [14:51:03] [Client thread/ERROR]: Using missing texture, unable to load mhytrpg:textures/items/boundedChain.png java.io.FileNotFoundException: mhytrpg:textures/items/boundedChain.png at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:65) ~[FallbackResourceManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[simpleReloadableResourceManager.class:?] at net.minecraft.client.renderer.texture.TextureMap.loadTextureAtlas(TextureMap.java:126) [TextureMap.class:?] at net.minecraft.client.renderer.texture.TextureMap.loadTexture(TextureMap.java:91) [TextureMap.class:?] at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:89) [TextureManager.class:?] at net.minecraft.client.renderer.texture.TextureManager.loadTickableTexture(TextureManager.java:71) [TextureManager.class:?] at net.minecraft.client.renderer.texture.TextureManager.loadTextureMap(TextureManager.java:58) [TextureManager.class:?] at net.minecraft.client.Minecraft.startGame(Minecraft.java:593) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:941) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25] at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?] [14:51:03] [Client thread/INFO]: Created: 256x256 textures/items-atlas [14:51:03] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:MhytRPG [14:51:03] [Client thread/ERROR]: Using missing texture, unable to load mhytrpg:textures/items/boundedChain.png java.io.FileNotFoundException: mhytrpg:textures/items/boundedChain.png at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:65) ~[FallbackResourceManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[simpleReloadableResourceManager.class:?] at net.minecraft.client.renderer.texture.TextureMap.loadTextureAtlas(TextureMap.java:126) [TextureMap.class:?] at net.minecraft.client.renderer.texture.TextureMap.loadTexture(TextureMap.java:91) [TextureMap.class:?] at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:89) [TextureManager.class:?] at net.minecraft.client.renderer.texture.TextureManager.onResourceManagerReload(TextureManager.java:170) [TextureManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.notifyReloadListeners(SimpleReloadableResourceManager.java:134) [simpleReloadableResourceManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.reloadResources(SimpleReloadableResourceManager.java:118) [simpleReloadableResourceManager.class:?] at net.minecraft.client.Minecraft.refreshResources(Minecraft.java:653) [Minecraft.class:?] at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:303) [FMLClientHandler.class:?] at net.minecraft.client.Minecraft.startGame(Minecraft.java:596) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:941) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25] at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?] [14:51:03] [Client thread/INFO]: Created: 256x256 textures/items-atlas [14:51:03] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas [14:51:04] [sound Library Loader/INFO]: Sound engine started [14:51:05] [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press [14:51:06] [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press [14:51:07] [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press [14:51:07] [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press [14:51:08] [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press [14:51:08] [server thread/INFO]: Starting integrated minecraft server version 1.7.10 [14:51:08] [server thread/INFO]: Generating keypair [14:51:08] [server thread/INFO]: Converting map! [14:51:08] [server thread/INFO]: Scanning folders... [14:51:08] [server thread/INFO]: Total conversion count is 0 [14:51:09] [server thread/INFO]: Preparing start region for level 0 [14:51:09] [server thread/ERROR]: Encountered an unexpected exception java.lang.NullPointerException at de.MhytRPG.www.worldgen.WorldGen.generateSurface(WorldGen.java:47) ~[WorldGen.class:?] at de.MhytRPG.www.worldgen.WorldGen.generate(WorldGen.java:26) ~[WorldGen.class:?] at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) ~[GameRegistry.class:?] at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316) ~[ChunkProviderServer.class:?] at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1163) ~[Chunk.class:?] at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210) ~[ChunkProviderServer.class:?] at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151) ~[ChunkProviderServer.class:?] at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) ~[ChunkProviderServer.class:?] at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79) ~[integratedServer.class:?] at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?] [14:51:09] [server thread/ERROR]: This crash report has been saved to: C:\Users\Knirps\Desktop\forge 1.7.10\eclipse\.\crash-reports\crash-2014-07-09_14.51.09-server.txt
July 9, 201411 yr So i can't see the successful load message too (System.out.println("schem size:" + width + " x " + height + " x " + length).
July 9, 201411 yr Author I found a mistake, now there is an error : I can't load schematic because java.lang.NullPointerException with the same Errorcode.. My Schematic.java: package de.MhytRPG.www.structures; import net.minecraft.nbt.NBTTagList; public class Schematic{ public NBTTagList tileentities; public short width; public short height; public short length; public byte[] blocks; public byte[] data; public Schematic(NBTTagList tileentities, short width, short height, short length, byte[] blocks, byte[] data){ this.tileentities = tileentities; this.width = width; this.height = height; this.length = length; this.blocks = blocks; this.data = data; } } and my SchematicLoader.java : package de.MhytRPG.www.structures; import java.io.File; import java.io.InputStream; import de.MhytRPG.www.MhytRPG; import de.MhytRPG.www.structures.Schematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; public class SchematicLoader { public static Schematic get(String schemname){ try { InputStream is = Schematic.class.getClass().getClassLoader().getResourceAsStream("assets" + File.separator + MhytRPG.MODID + File.separator + "schematics" + File.separator + schemname +".schematic"); NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is); short width = nbtdata.getShort("Width"); short height = nbtdata.getShort("Height"); short length = nbtdata.getShort("Length"); byte[] blocks = nbtdata.getByteArray("Blocks"); byte[] data = nbtdata.getByteArray("Data"); System.out.println("schem size:" + width + " x " + height + " x " + length); NBTTagList tileentities = nbtdata.getTagList("TileEntities", 10); is.close(); return new Schematic(tileentities, width, height, length, blocks, data); } catch (Exception e) { System.out.println("I can't load schematic, because " + e.toString()); return null; } } } I splitted them and write it to public static Schematic... and changed the this. to Schematic. because the method need to performed with the Schematic.class So what I have done wrong ? EDIT : My location of schematic files: forge 1.7.10\src\main\resources\assets\mhytrpg\schematics
July 10, 201411 yr Maybe schematic is corrupt? If InputStream can't find file it throws FileNotFound exception. But in your case it's NullPointerException => CompressedStreamTools can't read stream correctly.
July 10, 201411 yr Author I tested it, if it throws a FileNotFoundException before I post this. I tried to import this schematic in WorldEdit and there is no error. So something other is going wrong. Do you know other programs with export something in the world to schematic ? Maybe WorldEdit mad something other in schematic so only WorldEdit can place them into the world ?
July 10, 201411 yr Replace InputStream is = Schematic.class.getClass().getClassLoader().getResourceAsStream("assets" + File.separator + MhytRPG.MODID + File.separator + "schematics" + File.separator + schemname +".schematic"); With String temp = "assets" + File.separator + MhytRPG.MODID + File.separator + "schematics" + File.separator + schemname +".schematic"; System.out.println("Trying to load " + temp); InputStream is = Schematic.class.getClass().getClassLoader().getResourceAsStream(temp); And look at log before crash.
July 10, 201411 yr Author Trying to load assets\mhytrpg\schematics\spring.schematic and same error (After first error i changed MODID to MODID.toLowercase() but the error was the same) I think now he didn´t found the schematic but didn´t throw a FileNotFound exception ( i tested it) EDIT: Here has to be the mistake after i added some more Sytem.Out.Println´s: package de.MhytRPG.www.structures; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import de.MhytRPG.www.MhytRPG; import de.MhytRPG.www.structures.Schematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; public class SchematicLoader { public static Schematic get(String schemname) { try { String temp = "assets" + File.separator + MhytRPG.MODID.toLowerCase() + File.separator + "schematics" + File.separator + schemname +".schematic"; System.out.println("Trying to load " + temp); InputStream is = Schematic.class.getClass().getClassLoader().getResourceAsStream(temp); //Is this Wrong ? NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is); //Or this ? System.out.println("First successfully"); // This doesn´t happen --- So the mistake is before ! short width = nbtdata.getShort("Width"); short height = nbtdata.getShort("Height"); short length = nbtdata.getShort("Length"); System.out.println("Second successfully"); byte[] blocks = nbtdata.getByteArray("Blocks"); byte[] data = nbtdata.getByteArray("Data"); System.out.println("Third successfully"); System.out.println("schem size:" + width + " x " + height + " x " + length); NBTTagList tileentities = nbtdata.getTagList("TileEntities", 10); is.close(); return new Schematic(tileentities, width, height, length, blocks, data); } catch (Exception e) { System.out.println("I can't load schematic, because " + e.toString()); return null; } } }
July 10, 201411 yr InputStream returns null because it can't find file. IDK. Recheck schematic path...
July 10, 201411 yr Author Path : C:\Users\user\Desktop\forge 1.7.10\src\main\resources\assets\mhytrpg\schematics\spring.schematic
July 10, 201411 yr I don't know what's wrong In my case it's works. https://gist.github.com/MultiMote/7242a27197cce7f17a7f https://gist.github.com/MultiMote/dee9b07369fa4ca40336 public static Item basebuilder2 = new BuilderItem("rotator.schematic", 0, 3, true).setTextureName("microz:builder").setUnlocalizedName("rotator"); http://up42.ru/u/p/_________________2014-07-10_17_02_35.png[/img] http://up42.ru/u/p/2014-07-10_17.19.11.png[/img]
July 10, 201411 yr Author I found the error: I forgot to declare SchematicLoader: private Schematicloader sl = new SchematicLoader(); Now I get no error but my world doesn´t load fast (takes more than 1 minutes with only one structure) How can I set my spawnrate lower or make Worldgenerating faster ? My Class: package de.MhytRPG.www.worldgen; import java.util.Random; import cpw.mods.fml.common.IWorldGenerator; import de.MhytRPG.www.MhytRPG; import de.MhytRPG.www.structures.SchematicLoader; import de.MhytRPG.www.structures.SchematicLoader.Schematic; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenLiquids; import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGen implements IWorldGenerator{ private SchematicLoader sl = new SchematicLoader(); @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); break; case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); break; case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); break; } } private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {} private void generateSurface(World world, Random rand, int chunkX, int chunkZ) { for(int k = 0; k < 10; k++){ int firstBlockXCoord = chunkX + rand.nextInt(16); int firstBlockYCoord = rand.nextInt(200); int firstBlockZCoord = chunkZ + rand.nextInt(16); (new WorldGenLiquids(MhytRPG.blockgoldenwater)).generate(world, rand, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord); } for(int k = 0; k < 10; k++) { Schematic spring = sl.get("spring"); int firstBlockXCoord = chunkX + rand.nextInt(16); int firstBlockYCoord = rand.nextInt(200); int firstBlockZCoord = chunkZ + rand.nextInt(16); int i = 0; for(int cy = 0; cy < spring.height; cy++) { for(int cz = 0; cz < spring.length; cz++) for(int cx = 0; cx < spring.width; cx++){ Block b = Block.getBlockById(spring.blocks[i]); if(b!= Blocks.air) { world.setBlockToAir(cx + firstBlockXCoord , cy + firstBlockYCoord, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + firstBlockYCoord, cz + firstBlockZCoord, b, spring.data[i] , 2); } i++; } } } } private void generateNether(World world, Random rand, int chunkX, int chunkZ) {} } Link to screenshot from world: http://prntscr.com/419ew9
July 10, 201411 yr Author I found a way: int chance = new Random().nextInt(100); if(int == 1) { do this } But how I can generate a spring half in the underground and half in the Overworld?
July 11, 201411 yr Author I solved this problems. But now I have some questions about my method to create a structure in the worl: My complet WorldGen.class : package de.MhytRPG.www.worldgen; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenLiquids; import cpw.mods.fml.common.IWorldGenerator; import de.MhytRPG.www.MhytRPG; import de.MhytRPG.www.structures.SchematicLoader; import de.MhytRPG.www.structures.SchematicLoader.Schematic; public class WorldGen implements IWorldGenerator{ private static SchematicLoader sl = new SchematicLoader(); @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); break; case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); break; case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); break; } } private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {} private void generateSurface(World world, Random rand, int chunkX, int chunkZ) { ArrayList<Block> normalList = new ArrayList<Block>(); normalList.add(Blocks.sand); normalList.add(Blocks.dirt); normalList.add(Blocks.stone); normalList.add(Blocks.grass); ArrayList<Block> normalListSpawner = new ArrayList<Block>(); normalListSpawner.add(Blocks.soul_sand); ArrayList<Block> normalListChest = new ArrayList<Block>(); normalListChest.add(Blocks.bedrock); ArrayList<Block> normalListSpinnwebs = new ArrayList<Block>(); normalListSpinnwebs.add(Blocks.end_portal_frame); ArrayList<Block> nothingBlocks = new ArrayList<Block>(); ArrayList<Item> noLoot = new ArrayList<Item>(); ArrayList<Integer> noStackSize = new ArrayList<Integer>(); ArrayList<Item> towerLoot = new ArrayList<Item>(); ArrayList<Integer> towerLootStackSize = new ArrayList<Integer>(); towerLoot.add(Items.potato); towerLootStackSize.add(5); towerLoot.add(Items.apple); towerLootStackSize.add(7); towerLoot.add(Items.arrow); towerLootStackSize.add(18); towerLoot.add(Items.iron_ingot); towerLootStackSize.add(9); towerLoot.add(Items.gold_nugget); towerLootStackSize.add(10); towerLoot.add(Items.ender_pearl); towerLootStackSize.add(3); towerLoot.add(Items.blaze_powder); towerLootStackSize.add(2); towerLoot.add(Items.spider_eye); towerLootStackSize.add(7); towerLoot.add(Items.rotten_flesh); towerLootStackSize.add(30); GeneralGenerateMethod(10, "spring", 0, 1, 12, true, chunkX, rand, chunkZ, world, normalList, false, nothingBlocks, false, nothingBlocks, false, nothingBlocks, noLoot, noStackSize); GeneralGenerateMethod(10, "tower", 0, -1, 50, true, chunkX, rand, chunkZ, world, normalList, true, normalListSpawner, true, normalListChest, true, normalListSpinnwebs, towerLoot, towerLootStackSize); } private void generateNether(World world, Random rand, int chunkX, int chunkZ) {} public static void GeneralGenerateMethod(int chance, String schemname, int where, int blockInUnderGround, int structureHigh, boolean structureWithAir, int chunkX, Random rand, int chunkZ, World world, ArrayList<Block> allowedBlocks, boolean SpawnerAcivate, ArrayList<Block> spawnerBlocks, boolean ChestWithRandomLoot, ArrayList<Block> chestBlocks, boolean randomSpinnwebs, ArrayList<Block> spinnwebsBlocks, ArrayList<Item> LootItems, ArrayList<Integer> LootMaxStackSize) { int chanceForSpawn = new Random().nextInt(chance); if(chanceForSpawn == 1) { int bcy = 0; Schematic schem = sl.get(schemname); int firstBlockXCoord = chunkX + rand.nextInt(16); int firstBlockZCoord = chunkZ + rand.nextInt(16); if(where == 0) { //where = 0 : spawn over ground ; where = 1 : spawn underground ; where = 2 : spawn only over water ; where = 3 : spawn on sea ground for(bcy = 256; bcy > 0; bcy--) { if(!world.getBlock(chunkX, bcy, chunkZ).equals(Blocks.air)) { if(allowedBlocks.contains(world.getBlock(chunkX, bcy, chunkZ))) { bcy = bcy - (blockInUnderGround + 1); break; } else { return; } } } } else if(where == 1) { for(bcy = 0; bcy < 256; bcy++) { if(world.getBlock(chunkX, bcy, chunkZ).equals(Blocks.air)) { bcy = (bcy-2)-structureHigh; break; } if(bcy == 240) { return; } } } else if(where == 2) { for(bcy = 256; bcy > 3; bcy--) { if(world.getBlock(chunkX, bcy, chunkZ).equals(Blocks.water)) { bcy = (bcy + 1) - blockInUnderGround; break; } if(bcy == 4) { return; } } } else if(where == 3) { for(bcy = 1; bcy < 256; bcy++) { if(world.getBlock(chunkX, bcy, chunkZ).equals(Blocks.water)) { bcy = bcy - blockInUnderGround; break; } if(bcy == 240) { return; } } } int i = 0; for(int cy = 0; cy < schem.height; cy++) { for(int cz = 0; cz < schem.length; cz++) { for(int cx = 0; cx < schem.width; cx++){ Block b = Block.getBlockById(schem.blocks[i]); if(b == Blocks.air) { if(structureWithAir == true) { world.setBlockToAir(cx + firstBlockXCoord , cy + bcy, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord, b, schem.data[i] , 2); i++; continue; } else if(structureWithAir == false) { continue; } } else if(spinnwebsBlocks.contains(b)) { if(randomSpinnwebs == true) { int ran = new Random().nextInt(4); if(ran <= 1) { world.setBlockToAir(cx + firstBlockXCoord , cy + bcy, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord, Blocks.web); i++; continue; } } else if(randomSpinnwebs == false) { continue; } } else if(spawnerBlocks.contains(b)) { if(SpawnerAcivate == true) { world.setBlockToAir(cx + firstBlockXCoord , cy + bcy, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord, Blocks.mob_spawner, schem.data[i] , 2); TileEntityMobSpawner spawner = (TileEntityMobSpawner)world.getTileEntity(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord); spawner.func_145881_a().setEntityName("Witch"); i++; continue; } else if(SpawnerAcivate == false) { continue; } } else if(chestBlocks.contains(b)) { if(ChestWithRandomLoot == true) { world.setBlockToAir(cx + firstBlockXCoord , cy + bcy, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord, Blocks.chest, schem.data[i], 2); TileEntityChest tec = (TileEntityChest) world.getTileEntity(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord); if(!tec.isInvalid()) { Block maybeChest1 = world.getBlock(cx + firstBlockXCoord + 1, cy + bcy, cz + firstBlockZCoord); Block maybeChest2 = world.getBlock(cx + firstBlockXCoord - 1, cy + bcy, cz + firstBlockZCoord); Block maybeChest3 = world.getBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord + 1); Block maybeChest4 = world.getBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord - 1); if(maybeChest1.equals(Blocks.chest) || maybeChest2.equals(Blocks.chest) || maybeChest3.equals(Blocks.chest) || maybeChest4.equals(Blocks.chest)) { int loot = (int) new Random().nextDouble()*10; for(int t = 0; t <= loot; t++) { int place = new Random().nextInt(27 + 27); int whichItem = new Random().nextInt(LootItems.size()); Item ranItem = LootItems.get(whichItem); int stackSize = new Random().nextInt(LootMaxStackSize.get(whichItem) + 1); ItemStack stack = new ItemStack(ranItem, stackSize); tec.setInventorySlotContents(place, stack); place = 0; continue; } i++; continue; } else if(!maybeChest1.equals(Blocks.chest) && !maybeChest2.equals(Blocks.chest) && !maybeChest3.equals(Blocks.chest) && !maybeChest4.equals(Blocks.chest)) { int loot = (int) new Random().nextDouble()*10; for(int t = 0; t <= loot; t++) { int place = new Random().nextInt(27); int whichItem = new Random().nextInt(LootItems.size()); Item ranItem = LootItems.get(whichItem); int stackSize = new Random().nextInt(LootMaxStackSize.get(whichItem) + 1); ItemStack stack = new ItemStack(ranItem, stackSize); tec.setInventorySlotContents(place, stack); place = 0; continue; } i++; continue; } } else if(tec.isInvalid()) { i++; continue; } } else if(ChestWithRandomLoot == false) { continue; } } else if(b != Blocks.air && !chestBlocks.contains(b) && !spawnerBlocks.contains(b) && !spinnwebsBlocks.contains(b)) { world.setBlockToAir(cx + firstBlockXCoord , cy + bcy, cz + firstBlockZCoord); world.setBlock(cx + firstBlockXCoord, cy + bcy, cz + firstBlockZCoord, b, schem.data[i] , 2); i++; continue; } } } } if (schem.tileentities != null) { for (int i1 = 0; i1 < schem.tileentities.tagCount(); ++i1) { NBTTagCompound nbttagcompound4 = schem.tileentities.getCompoundTagAt(i1); TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound4); if (tileentity != null) { tileentity.xCoord = tileentity.xCoord + firstBlockXCoord; tileentity.yCoord = tileentity.yCoord + bcy; tileentity.zCoord = tileentity.zCoord + firstBlockZCoord; world.setTileEntity(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, tileentity); } } } } } } This happens after I made a world : [18:03:07] [server thread/ERROR]: Encountered an unexpected exception java.lang.ArrayIndexOutOfBoundsException: 42 at net.minecraft.tileentity.TileEntityChest.setInventorySlotContents(TileEntityChest.java:129) ~[TileEntityChest.class:?] at de.MhytRPG.www.worldgen.WorldGen.GeneralGenerateMethod(WorldGen.java:223) ~[WorldGen.class:?] at de.MhytRPG.www.worldgen.WorldGen.generateSurface(WorldGen.java:89) ~[WorldGen.class:?] at de.MhytRPG.www.worldgen.WorldGen.generate(WorldGen.java:36) ~[WorldGen.class:?] at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) ~[GameRegistry.class:?] at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316) ~[ChunkProviderServer.class:?] at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1163) ~[Chunk.class:?] at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210) ~[ChunkProviderServer.class:?] at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151) ~[ChunkProviderServer.class:?] at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) ~[ChunkProviderServer.class:?] at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79) ~[integratedServer.class:?] at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?] [18:03:07] [server thread/ERROR]: This crash report has been saved to: C:\Users\Knirps\Desktop\forge-1.7.10-10.13.0.1179-src\eclipse\.\crash-reports\crash-2014-07-11_18.03.07-server.txt [18:03:07] [server thread/INFO] [FML]: Applying holder lookups [18:03:07] [server thread/INFO] [FML]: Holder lookups applied [18:03:07] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STARTING and forced into state SERVER_STOPPED. Errors may have been discarded. ---- Minecraft Crash Report ---- // Don't do that. Time: 11.07.14 18:03 Description: Exception in server tick loop java.lang.ArrayIndexOutOfBoundsException: 42 at net.minecraft.tileentity.TileEntityChest.setInventorySlotContents(TileEntityChest.java:129) at de.MhytRPG.www.worldgen.WorldGen.GeneralGenerateMethod(WorldGen.java:223) at de.MhytRPG.www.worldgen.WorldGen.generateSurface(WorldGen.java:89) at de.MhytRPG.www.worldgen.WorldGen.generate(WorldGen.java:36) at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316) at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1163) at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:315) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79) at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:455) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.7.0_25, Oracle Corporation Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 4092538560 bytes (3902 MB) / 4260102144 bytes (4062 MB) up to 4260102144 bytes (4062 MB) JVM Flags: 3 total; -Xincgc -Xmx4G -Xms4G AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.11.1179 Minecraft Forge 10.13.0.1179 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available FML{7.10.11.1179} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1179.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available Forge{10.13.0.1179} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1179.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available MhytRPG{1.0} [MhytRPG] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2014-07-11_18.03.07-server.txt AL lib: (EE) alc_cleanup: 1 device not closed 1. What is the problem with my chest system ? Also I want to know how I can add more loot items in a chest, because there is only one item in each chest. And there have to be more different items! But I don´t know what I had done wrong.. 2. And if a tower generate, the top is complet randomlly set ! But I want that only spinnwebs are generated randomly.. Thanks for your help!
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.