Jump to content

[1.12.2] getMaterial and actual state


Pyre540

Recommended Posts

Hello,

I am extending vanilla redstone wire block that it has additional property - Color. The color value is stored in tileEntity since metadata is used to store redstone power value. Of course I override getActualState method to return state with color.

//getColor method retrieves color from tileEntity
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){
    state = super.getActualState(state, worldIn, pos);
    return state.withProperty(COLOR, getColor(worldIn, pos));
}

 

Blocks of different colors have different properties/behavior. One of them is that the blue colored block is not washed away by water. I achieved this by returning the appropriate material based on the state of the block.

@SuppressWarnings("deprecation")
@Override
public Material getMaterial(IBlockState state) {
    return state.getValue(COLOR) == WATERPROOF_COLOR ? ModMaterials.CIRCUITS_WATERPROOF : super.getMaterial(state);
}

 

The problem is that the passed state argument does not use getActualState method but World#getBlockState that only returns the metadata-based state, so after reloading the world this state contains the default color.

It is unfortunate that the getMaterial method does not take World and BlockPos as its parameters like for example getExplosionResistance method.

 

@Override
public float getExplosionResistance(World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion) {
    return getColor(world, pos) == EXPLOSION_PROOF_COLOR ? EXPLOSION_PROOF_BLOCK_RESISTANCE : super.getExplosionResistance(world, pos, exploder, explosion);
}

 

Is there a way for the getMaterial method to use the "actual" state? Or is there, for example, any event that I can use to prevent block being removed by water?

Link to comment
Share on other sites

38 minutes ago, Pyre540 said:

 

 Is there a way for the getMaterial method to use the "actual" state?

Not exactly, what it looks like you will have to do is. In your TEs class override onLoad and change the blockstate there and tell the client it has changed. Or, and this might be the more elegant solution, maybe override getExtendedState and see if that does what you need to do.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, V0idWa1k3r said:

getExtendedState is only used when rendering the block. It is only ever called in BlockRendererDispatcher#renderBlock and ForgeHooksClient.getDamageModel.

Ok, didn't know its call hierarchy, trying to help while I'm away from home.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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



×
×
  • Create New...

Important Information

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