minecraft-source/src/net/minecraft/world/item/WaterLilyBlockItem.java

70 lines
3.0 KiB
Java

package net.minecraft.world.item;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.Block;
public class WaterLilyBlockItem extends BlockItem {
public WaterLilyBlockItem(final Block bpe, final Properties a) {
super(bpe, a);
}
@Override
public InteractionResult useOn(final UseOnContext bfw) {
return InteractionResult.PASS;
}
@Override
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
final ItemStack bek5 = ayg.getItemInHand(ajh);
final HitResult cvf6 = Item.getPlayerPOVHitResult(bjt, ayg, ClipContext.Fluid.SOURCE_ONLY);
if (cvf6.getType() == HitResult.Type.MISS) {
return InteractionResultHolder.<ItemStack>pass(bek5);
}
if (cvf6.getType() == HitResult.Type.BLOCK) {
final BlockHitResult cvd7 = (BlockHitResult)cvf6;
final BlockPos fk8 = cvd7.getBlockPos();
final Direction fp9 = cvd7.getDirection();
if (!bjt.mayInteract(ayg, fk8) || !ayg.mayUseItemAt(fk8.relative(fp9), fp9, bek5)) {
return InteractionResultHolder.<ItemStack>fail(bek5);
}
final BlockPos fk9 = fk8.above();
final BlockState byg11 = bjt.getBlockState(fk8);
final Material cok12 = byg11.getMaterial();
final FluidState cog13 = bjt.getFluidState(fk8);
if ((cog13.getType() == Fluids.WATER || cok12 == Material.ICE) && bjt.isEmptyBlock(fk9)) {
bjt.setBlock(fk9, Blocks.LILY_PAD.defaultBlockState(), 11);
if (ayg instanceof ServerPlayer) {
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)ayg, fk9, bek5);
}
if (!ayg.abilities.instabuild) {
bek5.shrink(1);
}
ayg.awardStat(Stats.ITEM_USED.get(this));
bjt.playSound(ayg, fk8, SoundEvents.LILY_PAD_PLACE, SoundSource.BLOCKS, 1.0f, 1.0f);
return InteractionResultHolder.<ItemStack>success(bek5);
}
}
return InteractionResultHolder.<ItemStack>fail(bek5);
}
}