125 lines
6.0 KiB
Java
125 lines
6.0 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
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.world.damagesource.DamageSource;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.level.Level;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class SweetBerryBushBlock extends BushBlock implements BonemealableBlock {
|
|
public static final IntegerProperty AGE;
|
|
private static final VoxelShape SAPLING_SHAPE;
|
|
private static final VoxelShape MID_GROWTH_SHAPE;
|
|
|
|
public SweetBerryBushBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)SweetBerryBushBlock.AGE, 0));
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCloneItemStack(final BlockGetter bjd, final BlockPos fk, final BlockState byg) {
|
|
return new ItemStack(Items.SWEET_BERRIES);
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
if (byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE) == 0) {
|
|
return SweetBerryBushBlock.SAPLING_SHAPE;
|
|
}
|
|
if (byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE) < 3) {
|
|
return SweetBerryBushBlock.MID_GROWTH_SHAPE;
|
|
}
|
|
return super.getShape(byg, bjd, fk, cvn);
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
super.tick(byg, xd, fk, random);
|
|
final int integer6 = byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE);
|
|
if (integer6 < 3 && random.nextInt(5) == 0 && xd.getRawBrightness(fk.above(), 0) >= 9) {
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)SweetBerryBushBlock.AGE, integer6 + 1), 2);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void entityInside(final BlockState byg, final Level bjt, final BlockPos fk, final Entity akn) {
|
|
if (!(akn instanceof LivingEntity) || akn.getType() == EntityType.FOX || akn.getType() == EntityType.BEE) {
|
|
return;
|
|
}
|
|
akn.makeStuckInBlock(byg, new Vec3(0.800000011920929, 0.75, 0.800000011920929));
|
|
if (!bjt.isClientSide && byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE) > 0 && (akn.xOld != akn.getX() || akn.zOld != akn.getZ())) {
|
|
final double double6 = Math.abs(akn.getX() - akn.xOld);
|
|
final double double7 = Math.abs(akn.getZ() - akn.zOld);
|
|
if (double6 >= 0.003000000026077032 || double7 >= 0.003000000026077032) {
|
|
akn.hurt(DamageSource.SWEET_BERRY_BUSH, 1.0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
final int integer8 = byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE);
|
|
final boolean boolean9 = integer8 == 3;
|
|
if (!boolean9 && ayg.getItemInHand(ajh).getItem() == Items.BONE_MEAL) {
|
|
return InteractionResult.PASS;
|
|
}
|
|
if (integer8 > 1) {
|
|
final int integer9 = 1 + bjt.random.nextInt(2);
|
|
Block.popResource(bjt, fk, new ItemStack(Items.SWEET_BERRIES, integer9 + (boolean9 ? 1 : 0)));
|
|
bjt.playSound(null, fk, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0f, 0.8f + bjt.random.nextFloat() * 0.4f);
|
|
bjt.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)SweetBerryBushBlock.AGE, 1), 2);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return super.use(byg, bjt, fk, ayg, ajh, cvd);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(SweetBerryBushBlock.AGE);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
|
|
return byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE) < 3;
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
|
|
final int integer6 = Math.min(3, byg.<Integer>getValue((Property<Integer>)SweetBerryBushBlock.AGE) + 1);
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)SweetBerryBushBlock.AGE, integer6), 2);
|
|
}
|
|
|
|
static {
|
|
AGE = BlockStateProperties.AGE_3;
|
|
SAPLING_SHAPE = Block.box(3.0, 0.0, 3.0, 13.0, 8.0, 13.0);
|
|
MID_GROWTH_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 16.0, 15.0);
|
|
}
|
|
}
|