Fix up the Water Bowl

This commit is contained in:
Mrbysco 2024-03-11 22:36:25 +01:00
parent 8a16143e2f
commit 9f8523486c
2 changed files with 29 additions and 31 deletions

View file

@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
@ -27,14 +26,16 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
@ -42,28 +43,26 @@ public class ItemWaterBowl extends ItemBase {
public ItemWaterBowl() {
super(ActuallyItems.defaultProps().stacksTo(1));
//MinecraftForge.EVENT_BUS.register(this);
NeoForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent.RightClickItem event) {
if (event.getLevel() != null) {
if (CommonConfig.Other.WATER_BOWL.get()) {
if (!event.getItemStack().isEmpty() && event.getItemStack().getItem() == Items.BOWL) {
HitResult rayTrace = event.getEntity().pick(Util.getReachDistance(event.getEntity()), 1f, true);
if (rayTrace.getType() != HitResult.Type.BLOCK) {
if (event.getLevel() != null && CommonConfig.Other.WATER_BOWL.get()) {
if (!event.getItemStack().isEmpty() && event.getItemStack().is(Items.BOWL)) {
BlockHitResult trace = getPlayerPOVHitResult(
event.getLevel(), event.getEntity(), ClipContext.Fluid.SOURCE_ONLY //Using pick will also return flowing water
);
if (trace.getType() != HitResult.Type.BLOCK) {
return;
}
BlockHitResult trace = (BlockHitResult) rayTrace;
InteractionResultHolder<ItemStack> result = EventHooks.onBucketUse(event.getEntity(), event.getLevel(), event.getItemStack(), trace);
if (result == null) {
if (event.getEntity().mayUseItemAt(trace.getBlockPos().relative(trace.getDirection()), trace.getDirection(), event.getItemStack())) {
BlockState state = event.getLevel().getBlockState(trace.getBlockPos());
Block block = state.getBlock();
// TODO: Validate fluid check
if ((block == Blocks.WATER) && state.getValue(BlockStateProperties.LEVEL) == 0) {
if (state.getFluidState().is(Fluids.WATER) && state.getValue(BlockStateProperties.LEVEL) == 0) {
event.getEntity().playSound(SoundEvents.BUCKET_FILL, 1.0F, 1.0F);
if (!event.getLevel().isClientSide) {
@ -85,7 +84,6 @@ public class ItemWaterBowl extends ItemBase {
}
}
}
}
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {

View file

@ -371,7 +371,7 @@
"item.actuallyadditions.spawner_changer": "Spawner Changer (wip)",
"item.actuallyadditions.spawner_shard": "Spawner Shards (wip)",
"item.actuallyadditions.minecart_firework_box": "Firework Box Cart (wip)",
"item.actuallyadditions.water_bowl": "Bowl of Water (wip)",
"item.actuallyadditions.water_bowl": "Bowl of Water",
"item.actuallyadditions.filter": "Item Filter",
"item.actuallyadditions.biomass": "Biomass (wip)",
"item.actuallyadditions.biocoal": "Bio Coal (wip)",