Jump to content

getting hardness from a block


winnetrie

Recommended Posts

i know with this :

setHardness(hardness);

I can set the hardness of a block, but what if i want to use the hardness from an other block.

Let's say from hardened clay.

 

How do i achieve this?

I tried with .blockHardness but that says "field not visible"

Link to comment
Share on other sites

The field

blockHardness

is

protected

, meaning only classes in the same package, OR sub-classes in other packages (classes that extend Block) can "see" this field.

 

This tells me that the class you are doing this in, is not a class extending

Block

.

What exactly are you trying to do?

Why do you need the

blockHardness

for a non-block class?

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

As i can see i am extending it:

 

public class BlockBrickedClay extends Block implements IMetaBlockName{

public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockBrickedClay.EnumType.class);
public BlockBrickedClay(Material material, float hardness, float resistance) {
	super(material);
        setHardness(hardness);
        setResistance(resistance);
        setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.WHITE));
        setUnlocalizedName(References.temBlocks.BRICKEDCLAY.getUnlocalizedName());
	setRegistryName(References.temBlocks.BRICKEDCLAY.getRegistryName());
	setCreativeTab(Tem.blockstab);
        
}
}

 

I am making a bricked version for the hardened clayblocks, just like you have bricked stone.

Now i instead of giving it manual the hardness, i want it to get it from the original hardened clayblock

 

Link to comment
Share on other sites

The field

blockHardness

is

protected

, meaning only classes in the same package, OR sub-classes in other packages (classes that extend Block) can "see" this field.

 

Subclasses in a different package to the parent class can only access

protected

fields and methods from the parent class on

this

, they can't access

protected

fields and methods on other instances.

 

Since you can't access the field, override the getter method instead:

Block#getBlockHardness

. Rather than calling this method on the other

Block

directly, call

IBlockState#getBlockHardness

on the state of the block you want to get the hardness for.

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

But .getBlockHardness is deprecated. Is there another way then?

 

Despite being deprecated, it's the correct method to override. See LexManos' post on this here.

 

Block#getBlockState

returns the

Block

's

BlockStateContainer

, which isn't what you need here. Use

Block#getDefaultState

to get the

Block

's default

IBlockState

, then call

IBlockState#withProperty

get an

IBlockState

with each property set to the appropriate value.

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 think you should be using

BlockStateContainer.getBlockHardness

, as that is what all the vanilla methods seem to call. Actually, most deprecated methods in the

Block

class are called by methods in

BlockStateContainer

.

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/

Link to comment
Share on other sites

I think you should be using

BlockStateContainer.getBlockHardness

, as that is what all the vanilla methods seem to call. Actually, most deprecated methods in the

Block

class are called by methods in

BlockStateContainer

.

 

There is no

BlockStateContainer#getBlockHardness

method because

BlockStateContainer

doesn't implement

IBlockState

itself, it contains the

Block

's valid

IBlockSate

s (hence the name).

 

There is a

BlockStateContainer.StateImplementation#getBlockHardness

method that implements

IBlockState#getBlockHardness

. You don't actually need to use the

BlockStateContainer.StateImplementation

class, you only need to use the

IBlockState

interface implemented by it.

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 think you should be using

BlockStateContainer.getBlockHardness

, as that is what all the vanilla methods seem to call. Actually, most deprecated methods in the

Block

class are called by methods in

BlockStateContainer

.

 

There is no

BlockStateContainer#getBlockHardness

method because

BlockStateContainer

doesn't implement

IBlockState

itself, it contains the

Block

's valid

IBlockSate

s (hence the name).

 

There is a

BlockStateContainer.StateImplementation#getBlockHardness

method that implements

IBlockState#getBlockHardness

. You don't actually need to use the

BlockStateContainer.StateImplementation

class, you only need to use the

IBlockState

interface implemented by it.

My bad, overlooked that it was in a nested class...

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/

Link to comment
Share on other sites

If your block is a variation of clay, then maybe you could extend BlockHardenedClay instead of extending Block?

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

Is there something wrong with using IBlockstate#getHardness(World, Pos) and passing null?

 

No vanilla block gives a damn about the world and pos values passed.  No really.  The IBlockState passes off the call to the block method:

 

    @Deprecated
    public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return this.blockHardness;
    }

 

Which is overriden by nothing.

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

If your block is a variation of clay, then maybe you could extend BlockHardenedClay instead of extending Block?

 

You have a point there, maybe i can try this.

The reason for what i try to do is because i think it looks nicer. It's not nessecary.

If i would create a lot of different blocks, i could use constants maybe.

An example i declare a constant as clayhardness and give it a value 10. So everytime i want to set a blocks hardness as hardened clay,

i fill in the clayhardness constant.

I think i have choices enough, but i do not understand all that blockstate stuff yet.

 

Thank you all!

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
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • DUTA89 agen slot online terbaik dan sering memberikan kemenangan kepada setiap member yang deposit diatas 50k dengan tidak klaim bonus sepeser pun.   Link daftar : https://heylink.me/DUTA89OFFICIAL/  
    • Hello All! Started a MC Eternal 1.6.2.2 server on Shockbyte hosting. The only other mod I added was betterfarmland v0.0.8BETA. Server is 16GB and Shockbyte wont tell me how many CPU cores i have.  We are having problems now when players log in it seems to crash the server. At other times it seems fine and we can have 3 people playing for hours at a time. Usually always when it does crash it is when someone logs in. Crash Reports Below. To the person who can post the fix I will reward $100 via Paypal.   ---- Minecraft Crash Report ---- // This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 2024-09-19 21:04:58 UTC Description: Exception in server tick loop java.lang.StackOverflowError     at net.minecraft.advancements.PlayerAdvancements.hasCompletedChildrenOrSelf(PlayerAdvancements.java:451)     at net.minecraft.advancements.PlayerAdvancements.shouldBeVisible(PlayerAdvancements.java:419)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:385)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.P  
    • It worked the first time but none of my friends and now me either could enter the server. internal exception: io.netty.handler.codec.DecoderException Unknown modifier tconstruct:soulbound
    • It worked the first time but none of my friends and now me either could enter the server. internal exception: io.netty.handler.codec.DecoderException Unknown modifier tconstruct:soulbound
    • It worked the first time but none of my friends and now me either could enter the server. internal exception: io.netty.handler.codec.DecoderException Unknown modifier tconstruct:soulbound
  • Topics

×
×
  • Create New...

Important Information

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