Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.x] Check block has sub-blocks or not


BlackCrafer666
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Is there a way to "override" an entity's texture to something else without creating a "dummy" item when using ThrownItemRenderer? I tried creating a Renderer that extends it with a ResourceLocation override but this does not change the entity's 2D texture. Any help would be appreciated. Render class: public class BulletEntityRenderer extends ThrownItemRenderer { private static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MOD_ID, "textures/entity/bullet.png"); public BulletEntityRenderer(EntityRendererProvider.Context context) { super(context); } @Override public ResourceLocation getTextureLocation(Entity entity) { return TEXTURE; } } Render registry: public class ModRender { public static void registerRender() { EntityRenderers.register(ExampleMod.BULLET, BulletEntityRenderer::new); } } Entity class: public class BulletEntity extends ThrowableItemProjectile { private float damage = 12.0F; private int pierceLevel = 0; private int ticksAlive = 0; private final int lifespan = 60; public BulletEntity(EntityType<BulletEntity> type, Level world) { super(type, world); } public BulletEntity(Player player, Level world, float damage, int pierceLevel) { super(ExampleMod.BULLET, player, world); this.damage = damage; this.pierceLevel = pierceLevel; this.setNoGravity(true); } public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) { return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile(); } public void tick() { super.tick(); Vec3 vec3d = this.getDeltaMovement(); double d1 = vec3d.x; double d2 = vec3d.y; double d0 = vec3d.z; if (this.isInWater()) { this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } else { this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } if (ticksAlive > lifespan) { this.discard(); } ticksAlive++; } @Override protected void onHitEntity(EntityHitResult hitResult) { LivingEntity target = (LivingEntity) hitResult.getEntity(); Entity shooter = getOwner(); double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel)); double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue(); float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25)); target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage); } @Override public Item getDefaultItem() { return ModItems.BULLET; } }
    • Which version of Forge did you use? Post debug log
    • delete this client config file
    • Latest minecraft most viewed youtube video! Here's the link : https://shrinke.me/SCMUI
    • Latest minecraft most viewed youtube video! Here's the link : https://shrinke.me/SCMUI  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.