Posted June 25, 20205 yr Hello, I am looking to change the behavior of water and lava blocks, basically I want to make so that the lava doesn't burn the player and that water burns the player. I found that the line that handles lava burning is in the onEntityCollision method on the FlowingFluidBlock class: public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) { if (this.fluid.isIn(FluidTags.LAVA)) { entityIn.setInLava(); } } the method checks if the fluid is lava, so I tought that I could create a class that extends this one and modify only that method. But I can't seem to be able to re-define the lava and water blocks on the Blocks class. (I am using reflection to do that, since the fields are final). Field lavafield = Blocks.class.getDeclaredField("LAVA"); // LAVA field from Blocks (THIS IS WHERE THE EXCEPTION OCCURS) Field waterfield = Blocks.class.getDeclaredField("WATER"); // WATER field from Blocks Field modifiersField = Field.class.getDeclaredField("modifiers"); // modifiers of a field modifiersField.setAccessible(true); // make modifiers public modifiersField.setInt(lavafield, lavafield.getModifiers() & ~Modifier.FINAL); // set LAVA public modifiersField.setInt(waterfield, waterfield.getModifiers() & ~Modifier.FINAL); // set WATER public lavafield.set(null, register("lava", new PatchedFlowingFluidBlock(Fluids.LAVA, Block.Properties.create(Material.LAVA).doesNotBlockMovement().tickRandomly().hardnessAndResistance(100.0F).lightValue(15).noDrops()))); // Redefine the block with the "patched" FlowingFluidBlock that checks for water to burn. waterfield.set(null, register("water", new PatchedFlowingFluidBlock(Fluids.WATER, Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops()))); // The same as the line before This is my new onEntityCollision: @Override public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) { if (this.getFluid().isIn(FluidTags.WATER)) { entityIn.setInLava(); } } This approach doesn't work (It gives a NoSuchFieldException in the first line, idk why) and also I believe it is very hacky because is uses reflection, modifying final fields and using deprecated methods. Is there a better/easier way to do this? Edited June 25, 20205 yr by Taimander
June 25, 20205 yr Author @diesieben07 Oh thank you very much. I didn't know tags existed haha. I was overcomplicating everything, this is much easier.
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.