Jump to content

MC 1.10+ How to set different hardness for different block type


Recommended Posts

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() {
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ORE));
        if (this.getDefaultState() == this.getDefaultState().withProperty(TYPE, EnumType.ORE)){
        if (this.getDefaultState() == this.getDefaultState().withProperty(TYPE, EnumType.BLOCK)){


It always takes the first settings, perhaps because it is the defaultstate

Link to comment
Share on other sites



can only have one default state. Any setter methods in


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#getExplosionResistance(World, BlockPos, Entity, Explosion)


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.

Link to comment
Share on other sites

I have succeeded in applying the hardnes and resistance but not the soundtype:


public float getBlockHardness(IBlockState state, World worldIn, BlockPos pos){
	float hardness=0F;
	if(state == state.withProperty(TYPE, EnumType.ORE)){
	if(state == state.withProperty(TYPE, EnumType.BLOCK)){
	return hardness;
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;
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites



overload I mentioned was added in Forge 1.10.2- Update Forge to the latest or recommend version.




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.

Link to comment
Share on other sites

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.



Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my arrow wont move at all it would stay mid air and show no collision   my Entity class: package net.jeezedboi.epicraft.entity.custom; import net.jeezedboi.epicraft.init.ModItems; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.IPacket; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; public class ExplosiveArrowEntity extends AbstractArrowEntity { // default constructor, required to register the entity public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, World world) { super(entityType, world); } public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, double x, double y, double z, World world) { super(entityType, x, y, z, world); } // the constructor used by the ArrowItem public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, LivingEntity shooter, World world) { super(entityType, shooter, world); } // the item stack to give the player when they walk over your arrow stuck in the ground @Override protected ItemStack getArrowStack() { return new ItemStack(ModItems.EXPLOSIVE_ARROW.get()); } @Override protected void onEntityHit(EntityRayTraceResult result) { super.onEntityHit(result); // this, x, y, z, explosionStrength, setsFires, breakMode (NONE, BREAK, DESTROY) this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); } // called each tick while in the ground @Override public void tick() { if (this.timeInGround > 60){ this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); this.remove(); } } // syncs to the client @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } } my item class :   package net.jeezedboi.epicraft.item.custom; import net.jeezedboi.epicraft.entity.custom.ExplosiveArrowEntity; import net.jeezedboi.epicraft.init.ModEntityTypes; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ArrowItem; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ExplosiveArrowItem extends ArrowItem { public ExplosiveArrowItem(Properties props) { super(props); } @Override public AbstractArrowEntity createArrow(World world, ItemStack ammoStack, LivingEntity shooter) { ExplosiveArrowEntity explosiveArrowEntity = new ExplosiveArrowEntity(ModEntityTypes.EXPLOSIVE_ARROW.get(), shooter, world); return explosiveArrowEntity; } } other stuffs: public static final RegistryObject<Item> EXPLOSIVE_ARROW = ITEMS.register("explosive_arrow", () -> new ExplosiveArrowItem(new Item.Properties().group(ModItemGroup.Epic_Items))); public static final RegistryObject<EntityType<ExplosiveArrowEntity>> EXPLOSIVE_ARROW = ENTITY_TYPES.register("explosive_arrow", () -> EntityType.Builder.create((EntityType.IFactory<ExplosiveArrowEntity>) ExplosiveArrowEntity::new, EntityClassification.MISC) .size(0.5F, 0.5F).build("explosive_arrow")); mappings channel: 'snapshot', version: '20210309-1.16.5'
    • may i ask what it was that fixed it, I'm having the same problem and its frustrating because I'm making an origin.
    • I need to accesses byPath field of net.minecraft.client.renderer.texture.TextureManager. As I found out I need to use accesstransformer.cfg file and make the field public via it. In this file field names look like f_<numbers>. And I was unable to figure out, how to get those. It seems like it is connected to something called mappings (thing left after Minecraft decompile process). How can I get such a name for a class field?
    • The game crashed whilst rendering overlay Error: java.lang.OutOfMemoryError: Java heap space Exit Code: -1   Crash Report:                                              Log: https://pastebin.com/9NMLr5bD       https://pastebin.com/av6Q2jCf Password: gpTq3Gvkc5                     qdF0BeJGYN   Any suggestions what should i do here?
  • Topics

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.