Pyre540 Posted October 19, 2018 Posted October 19, 2018 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? Quote
Animefan8888 Posted October 19, 2018 Posted October 19, 2018 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. Quote 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.
V0idWa1k3r Posted October 19, 2018 Posted October 19, 2018 12 minutes ago, Animefan8888 said: override getExtendedState getExtendedState is only used when rendering the block. It is only ever called in BlockRendererDispatcher#renderBlock and ForgeHooksClient.getDamageModel. Quote
Animefan8888 Posted October 19, 2018 Posted October 19, 2018 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. Quote 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.
Pyre540 Posted October 19, 2018 Author Posted October 19, 2018 3 hours ago, Animefan8888 said: In your TEs class override onLoad and change the blockstate there and tell the client it has changed. This seems to do the trick. Thanks Quote
Recommended Posts
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.