minecraft-source/src/net/minecraft/world/level/block/PumpkinBlock.java

55 lines
2.6 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Items;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
public class PumpkinBlock extends StemGrownBlock {
protected PumpkinBlock(final Properties c) {
super(c);
}
@Override
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
final ItemStack bek8 = ayg.getItemInHand(ajh);
if (bek8.getItem() == Items.SHEARS) {
if (!bjt.isClientSide) {
final Direction fp9 = cvd.getDirection();
final Direction fp10 = (fp9.getAxis() == Direction.Axis.Y) ? ayg.getDirection().getOpposite() : fp9;
bjt.playSound(null, fk, SoundEvents.PUMPKIN_CARVE, SoundSource.BLOCKS, 1.0f, 1.0f);
bjt.setBlock(fk, ((AbstractStateHolder<O, BlockState>)Blocks.CARVED_PUMPKIN.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)CarvedPumpkinBlock.FACING, fp10), 11);
final ItemEntity avy11 = new ItemEntity(bjt, fk.getX() + 0.5 + fp10.getStepX() * 0.65, fk.getY() + 0.1, fk.getZ() + 0.5 + fp10.getStepZ() * 0.65, new ItemStack(Items.PUMPKIN_SEEDS, 4));
avy11.setDeltaMovement(0.05 * fp10.getStepX() + bjt.random.nextDouble() * 0.02, 0.05, 0.05 * fp10.getStepZ() + bjt.random.nextDouble() * 0.02);
bjt.addFreshEntity(avy11);
bek8.<Player>hurtAndBreak(1, ayg, ayg -> ayg.broadcastBreakEvent(ajh));
}
return InteractionResult.SUCCESS;
}
return super.use(byg, bjt, fk, ayg, ajh, cvd);
}
@Override
public StemBlock getStem() {
return (StemBlock)Blocks.PUMPKIN_STEM;
}
@Override
public AttachedStemBlock getAttachedStem() {
return (AttachedStemBlock)Blocks.ATTACHED_PUMPKIN_STEM;
}
}