Posted February 16, 201411 yr I've been trying to generate blocks in my minecraft world using func_147465_d but all it does is put an air block at the spot, not the new kind of block I was generating. Note: I have registered my blocks and they do appear in the creative tab and can be placed from inventory. Thanks
February 17, 201411 yr You need to use the setBlock method: world.setBlock(x, y, z, block, meta, flag); Exactly the same as World.setBlockId from 1.6, but instead of an ID you have a Block instance. http://i.imgur.com/NdrFdld.png[/img]
February 17, 201411 yr Author I'm using forge 1.7.2-10.12.0.997. set block isn't a valid method name.
February 17, 201411 yr Why don't you update to the recommended version 1024? http://i.imgur.com/NdrFdld.png[/img]
February 17, 201411 yr Author I was following Wuppy29's tutorial, he had been using the version I listed above. I figured it should work if he was using it for his tutorials? I can upgrade and check it out when I get home.
February 18, 201411 yr Author So I updated to the recommended version. Apparently some methods and constants had their names changed. I'm not sure where to begin correcting that. Let alone see if my code works as expected.
February 18, 201411 yr Author Got all the method names straightened out, the mod loads again, but still doesn't place my block, just air.
February 18, 201411 yr What method are you using to place the block? (or best: give us the class you used to generate the block)
February 18, 201411 yr Author after updating to the latest version of forge, and fixing all the method names, this is what my code to place the block looks like. world.setBlock(...) is what I am using to place. package myMinecraftMod.tutorial.WorldGen; import java.util.Random; import myMinecraftMod.tutorial.Blocks.Cellulos; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGenBigNetherMushroom extends WorldGenerator { private int mushroomType = -1; private static final String __OBFID = "CL_00000415"; private Block mushBlock; public WorldGenBigNetherMushroom() { super(false); } public WorldGenBigNetherMushroom(int par1) { super(true); this.mushroomType = par1; } @Override public boolean generate(World world, Random random, int x, int y, int z) { //mushBlock=new Cellulos(); mushBlock=new Cellulos(Material.wood).setBlockName("cellulosblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)); int stalkHeight=random.nextInt(3)+10; for(int i=1;i<0+stalkHeight;i++) { world.setBlock(x,i,z,mushBlock,1,2); } return true; } }
February 18, 201411 yr Well you're creating a private Block just within that class, and you never register it to the game's registry... I suggest you follow some of Wuppy's tutorials on making a Block first, before you try to do world generation. http://i.imgur.com/NdrFdld.png[/img]
February 18, 201411 yr Author Seems to be the same format Wuppy used. http://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-2-more-modfile/
February 18, 201411 yr Seems to be the same format Wuppy used. http://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-2-more-modfile/ Yeah, no. Wuppy is not using dynamic blocks, he is assigning the blocks to static fields in his mod class, and notice he is registering each of them. You need to study his code better. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
February 19, 201411 yr Author Seems to be the same format Wuppy used. http://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-2-more-modfile/ Yeah, no. Wuppy is not using dynamic blocks, he is assigning the blocks to static fields in his mod class, and notice he is registering each of them. You need to study his code better. Right. He registers his blocks in his main mod file. Same as I did. I gave the wrong link anyway. His main mod file http://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-2-more-modfile/ registers the blocks. Then it registers a world generator. The world generator uses the EventManager class he defines. Here are the world generator and event manager http://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-6-generation-finishing-it-up/ In his event manager he calls the world generator. The world generator uses a new block as a prameter. Mine has no parameters. I generated a block and initialize it in the world generator. I don't see what difference that would make. But it appears that is the only difference.
February 20, 201411 yr Author Here's all the classes I think would matter. [code/] package myMinecraftMod.tutorial; import myMinecraftMod.tutorial.Blocks.Cellulos; import myMinecraftMod.tutorial.Items.CellulosItem; import myMinecraftMod.tutorial.Recipies.Crafting; import myMinecraftMod.tutorial.WorldGen.EventManager; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = Tutorial.MODID, version = Tutorial.VERSION) public class Tutorial { public static final String MODID = "tutorial"; public static final String VERSION = "1.0"; public static Item cellulosItem; public static Block cellulosBlock; public static Item cellulosplankItem; public static Block cellulosplankBlock; public EventManager eventManager; @EventHandler public void init(FMLInitializationEvent event) { } @EventHandler public void preInit(FMLPreInitializationEvent event) { //loads all new blocks/items cellulosBlock = new Cellulos(Material.wood).setBlockName("cellulosblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)); cellulosplankBlock = new Cellulos(Material.wood).setBlockName("cellulosplankblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)); GameRegistry.registerBlock(cellulosBlock,MODID +(cellulosBlock.getUnlocalizedName().substring(5))); GameRegistry.registerBlock(cellulosplankBlock,MODID +(cellulosplankBlock.getUnlocalizedName().substring(5))); cellulosplankItem = new CellulosItem().setUnlocalizedName("cellulosplankitem"); cellulosItem = new CellulosItem().setUnlocalizedName("cellulositem"); GameRegistry.registerItem(cellulosplankItem, "cellulosplankitem"); GameRegistry.registerItem(cellulosItem, "cellulositem"); myMinecraftMod.tutorial.Recipies.Crafting.loadRecipes(); eventManager=new EventManager(); GameRegistry.registerWorldGenerator(eventManager, 0); } @EventHandler public void postInit(FMLPostInitializationEvent event) { /** TODO Hack to get our textures for items and blocks to show, remove when the bug is * fixed in an update. If this is not done, then the player must manually refresh * the texture packs. */ } } [code/] package myMinecraftMod.tutorial.WorldGen; import java.util.Random; import myMinecraftMod.tutorial.Blocks.Cellulos; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenerator; import cpw.mods.fml.common.IWorldGenerator; public class EventManager implements IWorldGenerator{ 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); } } private void generateEnd(World world, Random random, int x, int z) { } private void generateSurface(World world, Random random, int chunk_X, int chunk_Z) { int x,z,y; int mushInChunk=random.nextInt(20); for(int j=0;j<mushInChunk;j++) { x=chunk_X+random.nextInt(16); z=chunk_Z+random.nextInt(16); Block block1,block2; for(int i=0;i<127;i++) { block1=world.getBlock(x,i,z); block2=world.getBlock(x,i+1,z); //if(!block1.isAir(world, x, i, z)&&block2.isAir(world, x, i+1, z)) //{ (new WorldGenBigNetherMushroom(new Cellulos(Material.wood).setBlockName("cellulosblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)))).generate(world,random,x,world.getTopSolidOrLiquidBlock(x, z),z); //} } } } private void generateNether(World world, Random random, int chunk_X, int chunk_Z) { int x,z,y; int mushInChunk=random.nextInt(5); for(int j=0;j<mushInChunk;j++) { x=chunk_X+random.nextInt(16); z=chunk_Z+random.nextInt(16); Block block1,block2; for(int i=0;i<127;i++) { block1=world.getBlock(x,i,z); block2=world.getBlock(x,i+1,z); if(!block1.isAir(world, x, i, z)&&block2.isAir(world, x, i+1, z)) { (new WorldGenBigNetherMushroom(new Cellulos(Material.wood).setBlockName("cellulosblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)))).generate(world,random,x,i,z); } } } } } [code] [code/] package myMinecraftMod.tutorial.WorldGen; import java.util.Random; import myMinecraftMod.tutorial.Blocks.Cellulos; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; public class WorldGenBigNetherMushroom extends WorldGenerator { private int mushroomType = -1; private static final String __OBFID = "CL_00000415"; private static Block mushBlock; public WorldGenBigNetherMushroom(Block block) { super(false); mushBlock=block; } public WorldGenBigNetherMushroom(Block block,int par1) { super(true); this.mushroomType = par1; mushBlock=block; } @Override public boolean generate(World world, Random random, int x, int y, int z) { //mushBlock=new Cellulos(); //mushBlock=new Cellulos(Material.wood).setBlockName("cellulosblock").setHardness(2.0F).setStepSound(new Block.SoundType("wood", 1.0F, 1.0F)); int stalkHeight=random.nextInt(3)+10; for(int i=1;i<0+stalkHeight;i++) { world.setBlock(x,i,z,mushBlock,1,2); } return true; } } [code] also here is my crafting code, which doesn't seem to load [code/] package myMinecraftMod.tutorial.Recipies; import myMinecraftMod.tutorial.Tutorial; import myMinecraftMod.tutorial.Blocks.Cellulos; import myMinecraftMod.tutorial.Blocks.CellulosPlank; import net.minecraft.enchantment.Enchantment; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import cpw.mods.fml.common.registry.GameRegistry; public class Crafting { public static void loadRecipes() { System.out.println("loading recipies for cellulos"); GameRegistry.addRecipe(new ItemStack(new CellulosPlank(),4), new Object[]{ "X", 'X', new Cellulos()}); } } [code]
February 20, 201411 yr Stop creating new blocks!!! Just reference the block you already created in your main mod: (new WorldGenBigNetherMushroom(Tutorial.cellulosBlock).generate(world,random,x,world.getTopSolidOrLiquidBlock(x, z),z); Why on earth would you create a new block each time? That makes no sense, and nowhere in Wuppy's code do I see him do that. http://i.imgur.com/NdrFdld.png[/img]
February 20, 201411 yr Look, OP. Doing it that way creates a huge chunk of memory in the dynamic heap (space in your RAM mamory) for every single 'new XYZ(...)' unless that class is trivial, which Block is not. About to time to fill one chunk of space with mushroom block, you have eaten up 16*16*(sizeof HugeMushRoomBlock) * height of blocks... Yeah, a couple chunks and you are done! So, like everyone says, "Don't do that." Learn to code the minecraft way. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
February 24, 201411 yr Author Bad way to code (Because of performance issues always making a new block instance) aside. What causes the blocks not to be there at all? That is the question I started this post about, and it is still unanswered.
February 24, 201411 yr Author It's not there because you cannot create blocks outside of preInit. Do not create a new block every time, like said many times above. Finally an answer! So they have to be loaded in the preInit AND called from there in each other class. This answer would have saved a lot of confusion had it come earlier.
February 25, 201411 yr Author Not really. No one explained why making a new block wouldn't work(which would have been helpful for learning). They just stated that it wouldn't. But it didn't help either. Even after calling Tutorial.celluloseBlock(), which was initiated in the preInit() method, instead of making a new block I still just have empty spaces. None of my blocks get generated in the world. I can still place them from creative mode though.
February 25, 201411 yr This is calling a method: Tutorial.celluloseBlock() This is referencing a static object: Tutorial.celluloseBlock If you don't understand the difference between that, then please go here and learn more about Java. I understand you are frustrated, but on the other hand, please understand that creating a Block is probably one of the most basic things you can do in a mod. Most 1.7 tutorials are about updating from 1.6 to 1.7, so if you don't understand how to create a basic block, I recommend you start off by modding a little for 1.6 first, just to get the hang of it, and then port your code over to 1.7 later on when you are more comfortable with not only Java, but Minecraft code in general. http://i.imgur.com/NdrFdld.png[/img]
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.