94 lines
4.1 KiB
Java
94 lines
4.1 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.Util;
|
|
import com.google.common.collect.Maps;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import java.util.EnumMap;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import java.util.Map;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.core.Direction;
|
|
|
|
public class PipeBlock extends Block {
|
|
private static final Direction[] DIRECTIONS;
|
|
public static final BooleanProperty NORTH;
|
|
public static final BooleanProperty EAST;
|
|
public static final BooleanProperty SOUTH;
|
|
public static final BooleanProperty WEST;
|
|
public static final BooleanProperty UP;
|
|
public static final BooleanProperty DOWN;
|
|
public static final Map<Direction, BooleanProperty> PROPERTY_BY_DIRECTION;
|
|
protected final VoxelShape[] shapeByIndex;
|
|
|
|
protected PipeBlock(final float float1, final Properties c) {
|
|
super(c);
|
|
this.shapeByIndex = this.makeShapes(float1);
|
|
}
|
|
|
|
private VoxelShape[] makeShapes(final float float1) {
|
|
final float float2 = 0.5f - float1;
|
|
final float float3 = 0.5f + float1;
|
|
final VoxelShape cwc5 = Block.box(float2 * 16.0f, float2 * 16.0f, float2 * 16.0f, float3 * 16.0f, float3 * 16.0f, float3 * 16.0f);
|
|
final VoxelShape[] arr6 = new VoxelShape[PipeBlock.DIRECTIONS.length];
|
|
for (int integer7 = 0; integer7 < PipeBlock.DIRECTIONS.length; ++integer7) {
|
|
final Direction fp8 = PipeBlock.DIRECTIONS[integer7];
|
|
arr6[integer7] = Shapes.box(0.5 + Math.min(-float1, fp8.getStepX() * 0.5), 0.5 + Math.min(-float1, fp8.getStepY() * 0.5), 0.5 + Math.min(-float1, fp8.getStepZ() * 0.5), 0.5 + Math.max(float1, fp8.getStepX() * 0.5), 0.5 + Math.max(float1, fp8.getStepY() * 0.5), 0.5 + Math.max(float1, fp8.getStepZ() * 0.5));
|
|
}
|
|
final VoxelShape[] arr7 = new VoxelShape[64];
|
|
for (int integer8 = 0; integer8 < 64; ++integer8) {
|
|
VoxelShape cwc6 = cwc5;
|
|
for (int integer9 = 0; integer9 < PipeBlock.DIRECTIONS.length; ++integer9) {
|
|
if ((integer8 & 1 << integer9) != 0x0) {
|
|
cwc6 = Shapes.or(cwc6, arr6[integer9]);
|
|
}
|
|
}
|
|
arr7[integer8] = cwc6;
|
|
}
|
|
return arr7;
|
|
}
|
|
|
|
@Override
|
|
public boolean propagatesSkylightDown(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return this.shapeByIndex[this.getAABBIndex(byg)];
|
|
}
|
|
|
|
protected int getAABBIndex(final BlockState byg) {
|
|
int integer3 = 0;
|
|
for (int integer4 = 0; integer4 < PipeBlock.DIRECTIONS.length; ++integer4) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)PipeBlock.PROPERTY_BY_DIRECTION.get(PipeBlock.DIRECTIONS[integer4]))) {
|
|
integer3 |= 1 << integer4;
|
|
}
|
|
}
|
|
return integer3;
|
|
}
|
|
|
|
static {
|
|
DIRECTIONS = Direction.values();
|
|
NORTH = BlockStateProperties.NORTH;
|
|
EAST = BlockStateProperties.EAST;
|
|
SOUTH = BlockStateProperties.SOUTH;
|
|
WEST = BlockStateProperties.WEST;
|
|
UP = BlockStateProperties.UP;
|
|
DOWN = BlockStateProperties.DOWN;
|
|
PROPERTY_BY_DIRECTION = Util.<Map<Direction, BooleanProperty>>make(Maps.newEnumMap(Direction.class), enumMap -> {
|
|
enumMap.put(Direction.NORTH, PipeBlock.NORTH);
|
|
enumMap.put(Direction.EAST, PipeBlock.EAST);
|
|
enumMap.put(Direction.SOUTH, PipeBlock.SOUTH);
|
|
enumMap.put(Direction.WEST, PipeBlock.WEST);
|
|
enumMap.put(Direction.UP, PipeBlock.UP);
|
|
enumMap.put(Direction.DOWN, PipeBlock.DOWN);
|
|
});
|
|
}
|
|
}
|