113 lines
5.5 KiB
Java
113 lines
5.5 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.util.Mth;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.level.Level;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
|
|
public class DoublePlantBlock extends BushBlock {
|
|
public static final EnumProperty<DoubleBlockHalf> HALF;
|
|
|
|
public DoublePlantBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<DoubleBlockHalf, DoubleBlockHalf>setValue(DoublePlantBlock.HALF, DoubleBlockHalf.LOWER));
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
final DoubleBlockHalf bzd8 = byg1.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF);
|
|
if (fp.getAxis() == Direction.Axis.Y && bzd8 == DoubleBlockHalf.LOWER == (fp == Direction.UP) && (byg3.getBlock() != this || byg3.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF) == bzd8)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
if (bzd8 == DoubleBlockHalf.LOWER && fp == Direction.DOWN && !byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final BlockPos fk3 = bcn.getClickedPos();
|
|
if (fk3.getY() < 255 && bcn.getLevel().getBlockState(fk3.above()).canBeReplaced(bcn)) {
|
|
return super.getStateForPlacement(bcn);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void setPlacedBy(final Level bjt, final BlockPos fk, final BlockState byg, final LivingEntity akw, final ItemStack bek) {
|
|
bjt.setBlock(fk.above(), ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<DoubleBlockHalf, DoubleBlockHalf>setValue(DoublePlantBlock.HALF, DoubleBlockHalf.UPPER), 3);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
if (byg.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF) == DoubleBlockHalf.UPPER) {
|
|
final BlockState byg2 = bjw.getBlockState(fk.below());
|
|
return byg2.getBlock() == this && byg2.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF) == DoubleBlockHalf.LOWER;
|
|
}
|
|
return super.canSurvive(byg, bjw, fk);
|
|
}
|
|
|
|
public void placeAt(final LevelAccessor bju, final BlockPos fk, final int integer) {
|
|
bju.setBlock(fk, ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<DoubleBlockHalf, DoubleBlockHalf>setValue(DoublePlantBlock.HALF, DoubleBlockHalf.LOWER), integer);
|
|
bju.setBlock(fk.above(), ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<DoubleBlockHalf, DoubleBlockHalf>setValue(DoublePlantBlock.HALF, DoubleBlockHalf.UPPER), integer);
|
|
}
|
|
|
|
@Override
|
|
public void playerDestroy(final Level bjt, final Player ayg, final BlockPos fk, final BlockState byg, @Nullable final BlockEntity bwi, final ItemStack bek) {
|
|
super.playerDestroy(bjt, ayg, fk, Blocks.AIR.defaultBlockState(), bwi, bek);
|
|
}
|
|
|
|
@Override
|
|
public void playerWillDestroy(final Level bjt, final BlockPos fk, final BlockState byg, final Player ayg) {
|
|
final DoubleBlockHalf bzd6 = byg.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF);
|
|
final BlockPos fk2 = (bzd6 == DoubleBlockHalf.LOWER) ? fk.above() : fk.below();
|
|
final BlockState byg2 = bjt.getBlockState(fk2);
|
|
if (byg2.getBlock() == this && byg2.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF) != bzd6) {
|
|
bjt.setBlock(fk2, Blocks.AIR.defaultBlockState(), 35);
|
|
bjt.levelEvent(ayg, 2001, fk2, Block.getId(byg2));
|
|
if (!bjt.isClientSide && !ayg.isCreative()) {
|
|
Block.dropResources(byg, bjt, fk, null, ayg, ayg.getMainHandItem());
|
|
Block.dropResources(byg2, bjt, fk2, null, ayg, ayg.getMainHandItem());
|
|
}
|
|
}
|
|
super.playerWillDestroy(bjt, fk, byg, ayg);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(DoublePlantBlock.HALF);
|
|
}
|
|
|
|
@Override
|
|
public OffsetType getOffsetType() {
|
|
return OffsetType.XZ;
|
|
}
|
|
|
|
@Override
|
|
public long getSeed(final BlockState byg, final BlockPos fk) {
|
|
return Mth.getSeed(fk.getX(), fk.below((int)((byg.<DoubleBlockHalf>getValue(DoublePlantBlock.HALF) != DoubleBlockHalf.LOWER) ? 1 : 0)).getY(), fk.getZ());
|
|
}
|
|
|
|
static {
|
|
HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;
|
|
}
|
|
}
|