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

94 lines
3.5 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape SHAPE;
protected SignBlock(final Properties c) {
super(c);
}
@Override
public BlockState updateShape(final BlockState bvt1, final Direction fb, final BlockState bvt3, final LevelAccessor bhs, final BlockPos ew5, final BlockPos ew6) {
if (bvt1.<Boolean>getValue((Property<Boolean>)SignBlock.WATERLOGGED)) {
bhs.getLiquidTicks().scheduleTick(ew5, Fluids.WATER, Fluids.WATER.getTickDelay(bhs));
}
return super.updateShape(bvt1, fb, bvt3, bhs, ew5, ew6);
}
@Override
public VoxelShape getShape(final BlockState bvt, final BlockGetter bhb, final BlockPos ew, final CollisionContext csn) {
return SignBlock.SHAPE;
}
@Override
public boolean hasCustomBreakingProgress(final BlockState bvt) {
return true;
}
@Override
public boolean isPossibleToRespawnInThis() {
return true;
}
@Override
public BlockEntity newBlockEntity(final BlockGetter bhb) {
return new SignBlockEntity();
}
@Override
public boolean use(final BlockState bvt, final Level bhr, final BlockPos ew, final Player awg, final InteractionHand ahi, final BlockHitResult csd) {
if (bhr.isClientSide) {
return true;
}
final BlockEntity btw8 = bhr.getBlockEntity(ew);
if (btw8 instanceof SignBlockEntity) {
final SignBlockEntity bus9 = (SignBlockEntity)btw8;
final ItemStack bcj10 = awg.getItemInHand(ahi);
if (bcj10.getItem() instanceof DyeItem && awg.abilities.mayBuild) {
final boolean boolean11 = bus9.setColor(((DyeItem)bcj10.getItem()).getDyeColor());
if (boolean11 && !awg.isCreative()) {
bcj10.shrink(1);
}
}
return bus9.executeClickCommands(awg);
}
return false;
}
@Override
public FluidState getFluidState(final BlockState bvt) {
if (bvt.<Boolean>getValue((Property<Boolean>)SignBlock.WATERLOGGED)) {
return Fluids.WATER.getSource(false);
}
return super.getFluidState(bvt);
}
static {
WATERLOGGED = BlockStateProperties.WATERLOGGED;
SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 16.0, 12.0);
}
}