I'm currently trying to create an item that when you right-click a water source, it replaces the water source with an ice block. I can't quite figure out how to detect if the block I'm clicking on is water, or how to change it to ice.
So far this is all the code I have:
public ActionResultType onItemRightClick(ItemUseContext context) {
World world = context.getWorld();
PlayerEntity player = context.getPlayer();
Hand handIn = context.getHand();
BlockPos pos = context.getPos();
ItemStack itemstack = context.getItem();
if (world.getBlockState(pos) == Blocks.WATER.getDefaultState()) {
world.setBlockState(pos, Blocks.ICE.getDefaultState().getBlockState());
}
if (!player.abilities.isCreativeMode) {
itemstack.damageItem(1, player, (p_219998_1_) -> {
p_219998_1_.sendBreakAnimation(handIn);
});
}
return ActionResultType.SUCCESS;
}
Any help would be appreciated!