Search in sources :

Example 1 with BottleItem

use of net.minecraft.world.item.BottleItem in project Create by Creators-of-Create.

the class FluidBottleItemHook method preventWaterBottlesFromCreatesFluids.

@SubscribeEvent
public static void preventWaterBottlesFromCreatesFluids(PlayerInteractEvent.RightClickItem event) {
    ItemStack itemStack = event.getItemStack();
    if (itemStack.isEmpty())
        return;
    if (!(itemStack.getItem() instanceof BottleItem))
        return;
    Level world = event.getWorld();
    Player player = event.getPlayer();
    HitResult raytraceresult = getPlayerPOVHitResult(world, player, ClipContext.Fluid.SOURCE_ONLY);
    if (raytraceresult.getType() != HitResult.Type.BLOCK)
        return;
    BlockPos blockpos = ((BlockHitResult) raytraceresult).getBlockPos();
    if (!world.mayInteract(player, blockpos))
        return;
    FluidState fluidState = world.getFluidState(blockpos);
    if (fluidState.is(FluidTags.WATER) && fluidState.getType().getRegistryName().getNamespace().equals(Create.ID)) {
        event.setCancellationResult(InteractionResult.PASS);
        event.setCanceled(true);
        return;
    }
    return;
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) Player(net.minecraft.world.entity.player.Player) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BottleItem(net.minecraft.world.item.BottleItem) FluidState(net.minecraft.world.level.material.FluidState) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 Player (net.minecraft.world.entity.player.Player)1 BottleItem (net.minecraft.world.item.BottleItem)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 FluidState (net.minecraft.world.level.material.FluidState)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1 HitResult (net.minecraft.world.phys.HitResult)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1