You can now soak clouds using bottles of water

This commit is contained in:
Sollace 2024-10-08 15:10:54 +01:00
parent 83458ef4d9
commit 65398db5af
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 47 additions and 10 deletions

View file

@ -59,6 +59,6 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
return ItemActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
} }
} }

View file

@ -12,9 +12,15 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BedBlock; import net.minecraft.block.BedBlock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
public class PoreousCloudBlock extends CloudBlock implements Soakable { public class PoreousCloudBlock extends CloudBlock implements Soakable {
private static final MapCodec<PoreousCloudBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( private static final MapCodec<PoreousCloudBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
@ -36,6 +42,11 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable {
return CODEC; return CODEC;
} }
@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryDepositMoisture(stack, state, world, pos, player, hand, hit);
}
@Nullable @Nullable
@Override @Override
public BlockState getStateWithMoisture(BlockState state, int moisture) { public BlockState getStateWithMoisture(BlockState state, int moisture) {

View file

@ -11,6 +11,13 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.StairsBlock; import net.minecraft.block.StairsBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable { public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable {
private static final MapCodec<PoreousCloudStairsBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( private static final MapCodec<PoreousCloudStairsBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
@ -31,6 +38,11 @@ public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakabl
return CODEC; return CODEC;
} }
@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryDepositMoisture(stack, state, world, pos, player, hand, hit);
}
@Nullable @Nullable
@Override @Override
public BlockState getStateWithMoisture(BlockState state, int moisture) { public BlockState getStateWithMoisture(BlockState state, int moisture) {

View file

@ -8,10 +8,14 @@ import com.mojang.serialization.Codec;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsage;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.potion.Potions;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@ -53,15 +57,8 @@ public interface Soakable {
static ItemActionResult tryCollectMoisture(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { static ItemActionResult tryCollectMoisture(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (state.getBlock() instanceof Soakable soakable) { if (state.getBlock() instanceof Soakable soakable) {
if (stack.getItem() == Items.GLASS_BOTTLE) { if (stack.isOf(Items.GLASS_BOTTLE)) {
if (!player.isCreative()) { player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, Items.POTION.getDefaultStack(), false));
stack.split(1);
}
if (stack.isEmpty()) {
player.setStackInHand(hand, Items.POTION.getDefaultStack());
} else {
player.giveItemStack(Items.POTION.getDefaultStack());
}
world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1); 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); world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1); updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1);
@ -70,6 +67,23 @@ public interface Soakable {
} }
} }
return tryDepositMoisture(stack, state, world, pos, player, hand, hit);
}
static ItemActionResult tryDepositMoisture(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (state.getBlock() instanceof Soakable soakable) {
if (soakable.getMoisture(state) < 7
&& stack.isOf(Items.POTION)
&& stack.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT).matches(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 ItemActionResult.SUCCESS;
}
}
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }