Jump to content

Recommended Posts

Posted

Hi.

I wanted a custom hardness for my blocks. But when I break the block, instant crash.

All this blockstates thing is starting to look like a joke for me. Is it just good for anything but textures and models ?

This is the problem function, in my custom Block class. I don't get it. Everything I did here is really simple, I can't see why it can't work.

@Override
public float getBlockHardness(World world, BlockPos pos) {
	int meta = this.getMetaFromState(world.getBlockState(pos));
	switch (meta) {
	case 0:
		this.setHardness(3.0F);
	case 1:
		this.setHardness(4.5F);
	default:
		this.setHardness(1.5F);
	}
	return this.blockHardness;
}

Posted

Now it crashed immediately.

Here is the console of the session :

http://hastebin.com/efuguvariz.vhdl

 

I'm thinking to redesign the block as multiple blocks made of one class registered multiple times. The way vanilla Ores work, for example. It seems more suited when you want to define behaviours and not just simple "graphical" properties.

Posted

No need for a crash report. I ran into this one myself last week. Vanilla Minecraft has a bug on the client side that calls getHardness *after* breaking a block (it's doing some stat calculation the wrong way). By that time, the block has already been replaced by air.

 

Therefore, whenever *anyone* wants a block's effective mining hardness to vary according to metadata, the getHardness function must test for air and give the default hardness if that's so. Proceed with fetching metadata only if your own block type is still at pos.

 

Here's my Override:

  @Override
  public float getBlockHardness (World w, BlockPos pos) {
    float default_h = super.blockHardness;
    IBlockState bs = w.getBlockState (pos);                    // Vanilla code has a client side bug
    boolean alreadyBroken = (bs.getBlock () == Blocks.air);

    if (alreadyBroken) return default_h;                // Check for vanilla code bug and escape before...

    switch (this.getMetaFromState (bs)) {      // This would crash client-side after player breaks the wall
      case 8:
        return 5.0F;    // Iron wall
      case 9:           // Red Sandstone
      case 10:          // Chiseled Red Sandstone
      case 11:          // Glass
      case 12:          // Glowstone
      case 13:          // Sea-lantern
        return 1.0F;
      case 14:
      case 15:
        return 3.0F;    // diamond & emerald
      default:
        return default_h;
    }
  }

 

PS: I tried to report the bug to Mojang, but because none of the vanilla block types fall into the trap (yet), Mojang deleted the report instead of leaving a note to fix it when convenient. They'll suffer later, probably when it's *not* convenient.

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.

Posted

Ah yes, 1.8 - I had the same problem months ago when I updated and, after fixing it in a similar fashion to the above, totally forgot about it :P

PS: I tried to report the bug to Mojang, but because none of the vanilla block types fall into the trap (yet), Mojang deleted the report instead of leaving a note to fix it when convenient. They'll suffer later, probably when it's *not* convenient.

I've had the same experience - I reported one in 1.7.2 along with the fix for it, just a simple change x to y in the coordinates passed (they were passing x, x, z to getExplosionResistance). SIX months later, they close it saying it is no longer relevant because Blocks changed so much in 1.8. But in that time, they had 8 or so versions of 1.7 in which it could have been fixed -.-

 

Anyway, I no longer report bugs to them...

Posted

Anyway, I no longer report bugs to them...

 

Quite.

Took them freaking ages to fix the "save/load causes fireballs to get frozen in midair" bug.  As in, I reported it back in 1.6 and it got fixed in the last month.

 

And they still haven't fixed the "slabs on top of ice" issue ("floor Ypos, then subtract 1" rather than "ceiling Ypos, then subtract 1").

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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