From c877016ac78732ab7d29b1d0207482d288df5343 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 8 Oct 2024 15:17:24 +0100 Subject: [PATCH] You can now soak clouds using bottles of water --- .../block/cloud/NaturalCloudBlock.java | 3 +- .../block/cloud/PoreousCloudBlock.java | 11 +++++++ .../block/cloud/PoreousCloudStairsBlock.java | 12 +++++++ .../unicopia/block/cloud/Soakable.java | 32 +++++++++++++------ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java index 27a569d9..e950ba4b 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java @@ -29,6 +29,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock { this.compactedBlock = compactedBlock; } + @Deprecated @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ItemStack stack = player.getStackInHand(hand); @@ -41,6 +42,6 @@ public class NaturalCloudBlock extends PoreousCloudBlock { return ActionResult.SUCCESS; } - return ActionResult.PASS; + return super.onUse(state, world, pos, player, hand, hit); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java index 15303184..171b8a9e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java @@ -7,9 +7,14 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.block.state.StateUtil; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; +import net.minecraft.world.World; public class PoreousCloudBlock extends CloudBlock implements Soakable { @Nullable @@ -20,6 +25,12 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable { this.soggyBlock = soggyBlock; } + @Deprecated + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + return Soakable.tryDepositMoisture(state, world, pos, player, hand, hit); + } + @Nullable @Override public BlockState getStateWithMoisture(BlockState state, int moisture) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudStairsBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudStairsBlock.java index 3ee498a1..2a8e4f81 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudStairsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudStairsBlock.java @@ -7,6 +7,12 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.block.state.StateUtil; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable { @@ -17,6 +23,12 @@ public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakabl this.soggyBlock = soggyBlock; } + @Deprecated + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + return Soakable.tryDepositMoisture(state, world, pos, player, hand, hit); + } + @Nullable @Override public BlockState getStateWithMoisture(BlockState state, int moisture) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java index d192c71d..44d6a95e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/Soakable.java @@ -9,8 +9,11 @@ import com.minelittlepony.unicopia.USounds; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsage; import net.minecraft.item.Items; import net.minecraft.particle.ParticleTypes; +import net.minecraft.potion.PotionUtil; +import net.minecraft.potion.Potions; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; @@ -50,15 +53,8 @@ public interface Soakable { static ActionResult tryCollectMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (state.getBlock() instanceof Soakable soakable) { ItemStack stack = player.getStackInHand(hand); - if (stack.getItem() == Items.GLASS_BOTTLE) { - if (!player.isCreative()) { - stack.split(1); - } - if (stack.isEmpty()) { - player.setStackInHand(hand, Items.POTION.getDefaultStack()); - } else { - player.giveItemStack(Items.POTION.getDefaultStack()); - } + if (stack.isOf(Items.GLASS_BOTTLE)) { + player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, Items.POTION.getDefaultStack(), false)); world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1); world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos); updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1); @@ -67,6 +63,24 @@ public interface Soakable { } } + return tryDepositMoisture(state, world, pos, player, hand, hit); + } + + static ActionResult tryDepositMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + if (state.getBlock() instanceof Soakable soakable) { + ItemStack stack = player.getStackInHand(hand); + if (soakable.getMoisture(state) < 7 + && stack.isOf(Items.POTION) + && PotionUtil.getPotion(stack) == Potions.WATER) { + player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, Items.GLASS_BOTTLE.getDefaultStack(), false)); + world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BUCKET_EMPTY, SoundCategory.NEUTRAL, 1, 1); + world.emitGameEvent(player, GameEvent.FLUID_PLACE, pos); + updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) + 1); + + return ActionResult.SUCCESS; + } + } + return ActionResult.PASS; }