From 9796860f1eeae22c9413507e6bc0b065ef2f5f25 Mon Sep 17 00:00:00 2001 From: Forstride Date: Thu, 4 Jan 2024 07:02:17 -0500 Subject: [PATCH] Allowed canteens to take water from cauldrons (Closes #809) --- .../java/toughasnails/item/EmptyCanteenItem.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/toughasnails/item/EmptyCanteenItem.java b/common/src/main/java/toughasnails/item/EmptyCanteenItem.java index 49c3c8b1..a4e8c0ba 100644 --- a/common/src/main/java/toughasnails/item/EmptyCanteenItem.java +++ b/common/src/main/java/toughasnails/item/EmptyCanteenItem.java @@ -16,11 +16,12 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemUtils; -import net.minecraft.world.item.Vanishable; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LayeredCauldronBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -71,6 +72,18 @@ protected InteractionResultHolder fillCanteen(Level level, Player pla return InteractionResultHolder.success(this.replaceCanteen(stack, player, new ItemStack(getPurifiedWaterCanteen()))); } } + else if (state.getBlock() == Blocks.WATER_CAULDRON) + { + // Fill the canteen from water from a cauldron + int waterLevel = state.getValue(LayeredCauldronBlock.LEVEL); + + if (waterLevel > 0 && !level.isClientSide()) + { + level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0F, 1.0F); + LayeredCauldronBlock.lowerFillLevel(state, level, pos); + return InteractionResultHolder.success(this.replaceCanteen(stack, player, new ItemStack(getWaterCanteen()))); + } + } else if (level.getFluidState(pos).is(FluidTags.WATER)) { // Fill the canteen with water in the world