Jump to content

Recommended Posts

Posted

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.

Posted

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

 

Posted

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.

Posted

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.

Posted

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/

Posted

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.

Posted

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/

Posted

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.

Posted

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.

Posted

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!

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.