Posted October 12, 20169 yr I have a block called BlockFeliron. It contains 2 types : ORE and BLOCK i want a different hardness, resistance, soundtype for those both. How to i do this? i tried this: public class BlockFeliron extends Block implements IMetaBlockName{ public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockFeliron.EnumType.class); public BlockFeliron() { super(Material.ROCK); this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ORE)); if (this.getDefaultState() == this.getDefaultState().withProperty(TYPE, EnumType.ORE)){ setHardness(7.0F); setResistance(10.0F); setSoundType(SoundType.STONE); } if (this.getDefaultState() == this.getDefaultState().withProperty(TYPE, EnumType.BLOCK)){ setHardness(15.0F); setResistance(20.0F); setSoundType(SoundType.METAL); } setUnlocalizedName(References.temBlocks.FELIRON.getUnlocalizedName()); setRegistryName(References.temBlocks.FELIRON.getRegistryName()); setCreativeTab(Tem.blockstab); } It always takes the first settings, perhaps because it is the defaultstate Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
October 12, 20169 yr A Block can only have one default state. Any setter methods in Block will set that value to be used for every state of the block. Instead of calling the setter methods in the constructor, you need to override the getter methods to return the appropriate value based on the state they receive as an argument. The methods you need to override are Block#getBlockHardness , Block#getExplosionResistance(World, BlockPos, Entity, Explosion) and Block#getSoundType(IBlockState, World, BlockPos, Entity) . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
October 12, 20169 yr Author I have succeeded in applying the hardnes and resistance but not the soundtype: @Override public float getBlockHardness(IBlockState state, World worldIn, BlockPos pos){ float hardness=0F; if(state == state.withProperty(TYPE, EnumType.ORE)){ hardness=7.5F; } if(state == state.withProperty(TYPE, EnumType.BLOCK)){ hardness=15.0F; } return hardness; } @Override public float getExplosionResistance(World world, BlockPos pos, Entity entity, Explosion explosion){ float resistance=0F; IBlockState blockstate = world.getBlockState(pos); if (blockstate== blockstate.withProperty(TYPE, EnumType.ORE)){ resistance = 10.0F; } if (blockstate== blockstate.withProperty(TYPE, EnumType.BLOCK)){ resistance = 20.0F; } return resistance; } @Override public SoundType getSoundType(){ SoundType sound=null; IBlockState blockstate = (IBlockState) this.getBlockState(); if (blockstate == blockstate.withProperty(TYPE, EnumType.ORE)){ sound = SoundType.GROUND; } if (blockstate == blockstate.withProperty(TYPE, EnumType.BLOCK)){ sound = SoundType.STONE; } return sound ; } doing this getSoundType(IBlockState state, World world, BlockPos pos, Entity entity) gives me an error: The method getSoundType(IBlockState, World, BlockPos, Entity) of type BlockFeliron must override or implement a supertype method in the Block class from minecraft i find it like this getSoundType(), so i did this instead Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
October 12, 20169 yr If you get a blockstate from the world, check that it is still your block before you attempt to get your properties from it. Vanilla blocks don't have variable hardness etc, so Mojang doesn't necessarily make those methods safe for modders who do (and there have indeed been times past when deleting such a block could crash the game because getHardness was called on a block after it had been turned into air in the world). You will need to decide what your methods should return when they detect a blockstate mismatches. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
October 12, 20169 yr Vanilla blocks don't have variable hardness etc, so Mojang doesn't necessarily make those methods safe for modders who do Something something, this is why I have to try-catch a chunk of my code, because I specifically want to know what the hardness of a block (and its harvest tool/level) is without having a valid world position to look at (so I pass null for the world and catch the null pointer exception). Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 12, 20169 yr The Block#getSoundType overload I mentioned was added in Forge 1.10.2-12.18.1.2031. Update Forge to the latest or recommend version. Use IBlockState#getValue to get the value of a property. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
October 12, 20169 yr Author I have updated it to a newer version but now my workspace is empty! I still have all the data in the folder but in Eclipse it is empty. How do i get it back? Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
October 12, 20169 yr Try refreshing or rebuilding your project in Eclipse. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
October 12, 20169 yr Author Try refreshing or rebuilding your project in Eclipse. Thank you. I made a new workspace and after that i dragged my src folder to replace the new made src folder. Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
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.