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

101 lines
4.2 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.pathfinder.PathComputationType;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.shapes.CollisionContext;
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.material.Fluids;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.StateDefinition;
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.BooleanProperty;
public class ConduitBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape SHAPE;
public ConduitBlock(final Properties c) {
super(c);
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)ConduitBlock.WATERLOGGED, true));
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(ConduitBlock.WATERLOGGED);
}
@Override
public BlockEntity newBlockEntity(final BlockGetter bjd) {
return new ConduitBlockEntity();
}
@Override
public RenderShape getRenderShape(final BlockState byg) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Override
public FluidState getFluidState(final BlockState byg) {
if (byg.<Boolean>getValue((Property<Boolean>)ConduitBlock.WATERLOGGED)) {
return Fluids.WATER.getSource(false);
}
return super.getFluidState(byg);
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (byg1.<Boolean>getValue((Property<Boolean>)ConduitBlock.WATERLOGGED)) {
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
}
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return ConduitBlock.SHAPE;
}
@Override
public void setPlacedBy(final Level bjt, final BlockPos fk, final BlockState byg, @Nullable final LivingEntity akw, final ItemStack bek) {
if (bek.hasCustomHoverName()) {
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
if (bwi7 instanceof BeaconBlockEntity) {
((BeaconBlockEntity)bwi7).setCustomName(bek.getHoverName());
}
}
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
final FluidState cog3 = bcn.getLevel().getFluidState(bcn.getClickedPos());
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)ConduitBlock.WATERLOGGED, cog3.is(FluidTags.WATER) && cog3.getAmount() == 8);
}
@Override
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
return false;
}
static {
WATERLOGGED = BlockStateProperties.WATERLOGGED;
SHAPE = Block.box(5.0, 5.0, 5.0, 11.0, 11.0, 11.0);
}
}