Posted August 12, 201411 yr Hi! How to? 1) Check block has sub-blocks or not? (like wood block) 2) If block has sub-blocks, how to iterate and get their?
August 12, 201411 yr The getSubBlocks() method should return a list of the variations on the block. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 13, 201411 yr Author I can't understand, how to correctly get the Block object from list. All my tries makes crash
August 13, 201411 yr What have you tried? Show us some code, please. 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.
August 13, 201411 yr Author i want to build array of all the Block objects with sub-blocks if block has it. if i build this array without sub-blocks, all my things are working fine. my code: int elementsCount = 0; public static void getBlockList(){ Iterator it = Block.blockRegistry.iterator(); for (boolean b=true; b==true; b=it.hasNext()){ Block block = (Block)it.next(); List list = new ArrayList(); block.getSubBlocks(Item.getItemFromBlock(block), null, list); System.out.println(list.size()); if (list.size()>1){ for (int i=0; i<list.size(); i++){ ItemStack stack = (ItemStack)list.get(i); blocks[elementsCount] = Block.getBlockFromItem(stack.getItem()); System.out.println(stack.getItem().getUnlocalizedName()); System.out.println(Block.getIdFromBlock(blocks[elementsCount])+" : "+blocks[elementsCount].getLocalizedName()); ++elementsCount; } } } } It's working, but blocks array is filling with the same blocks (not sub-blocks). E.G. wool block has 16 sub-blocks (aka sub-types) with different colors. But all 16 elements of my array is filling with only first type of wool (white wool). Same situation with wood, planks, saplings e.t.c. Is it fixable? and i also need to get localized names of each sub-block.
August 13, 201411 yr Okay first of all What is that for loop? Just use a while statement. Anyway, what are you trying to ACTUALLY do? What do you need this array for? And what do you mean by it not working? If it crashed, what was the crash report? 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.
August 13, 201411 yr Author Anyway, what are you trying to ACTUALLY do? What do you need this array for? I'm trying to build blocks list in my custom GUI to select block which i need to use in next operation. And what do you mean by it not working? If it crashed, what was the crash report? It's no crashes and no errors. sorry, i make tag mistake in my previous post. Answer is located in the and of previous post. But i repeat it: blocks array is filling with the same blocks (not sub-blocks). E.G. wool block has 16 sub-blocks (aka sub-types) with different colors. But all 16 elements of my array is filling with only first type of wool (white wool). Same situation with wood, planks, saplings e.t.c.
August 13, 201411 yr That's because the sub-blocks aren't actually blocks, they're ItemStacks with metadata values. If you want an array of blocks that have sub blocks, that's fine. But if you want to actually store all the actual sub blocks themselves, you're going to need an ItemStack array/list. 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.
August 13, 201411 yr I think there's a getLocalizedName method for every block. But if there isn't I'm pretty sure you can use StatCollector#translateToLocal or something 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.
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.