223 lines
12 KiB
Java
223 lines
12 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.core.CustomBlocks;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.stream.Stream;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.util.StringRepresentable;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Mirror;
|
|
import net.minecraft.world.level.block.Rotation;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.material.Material;
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RampBlock.class */
|
|
public class RampBlock extends Block {
|
|
protected static final VoxelShape SHAPE_WEST = Shapes.or(Block.box(0.0d, 0.0d, 0.0d, 16.0d, 1.0d, 16.0d), new VoxelShape[]{Block.box(0.0d, 1.0d, 0.0d, 15.0d, 2.0d, 16.0d), Block.box(0.0d, 2.0d, 0.0d, 14.0d, 3.0d, 16.0d), Block.box(0.0d, 3.0d, 0.0d, 13.0d, 4.0d, 16.0d), Block.box(0.0d, 4.0d, 0.0d, 12.0d, 5.0d, 16.0d), Block.box(0.0d, 5.0d, 0.0d, 11.0d, 6.0d, 16.0d), Block.box(0.0d, 6.0d, 0.0d, 10.0d, 7.0d, 16.0d), Block.box(0.0d, 7.0d, 0.0d, 9.0d, 8.0d, 16.0d), Block.box(0.0d, 8.0d, 0.0d, 8.0d, 9.0d, 16.0d), Block.box(0.0d, 9.0d, 0.0d, 7.0d, 10.0d, 16.0d), Block.box(0.0d, 10.0d, 0.0d, 6.0d, 11.0d, 16.0d), Block.box(0.0d, 11.0d, 0.0d, 5.0d, 12.0d, 16.0d), Block.box(0.0d, 12.0d, 0.0d, 4.0d, 13.0d, 16.0d), Block.box(0.0d, 13.0d, 0.0d, 3.0d, 14.0d, 16.0d), Block.box(0.0d, 14.0d, 0.0d, 2.0d, 15.0d, 16.0d), Block.box(0.0d, 15.0d, 0.0d, 1.0d, 16.0d, 16.0d)}).optimize();
|
|
protected static final VoxelShape SHAPE_NORTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST);
|
|
protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH);
|
|
protected static final VoxelShape SHAPE_SOUTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_EAST);
|
|
protected static final VoxelShape SHAPE_EAST_CORNER = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(-0.75d, 0.0d, 0.0d, 16.0d, 1.0d, 16.0d), Block.box(0.5d, 1.0d, 0.0d, 16.0d, 2.0d, 15.0d), Block.box(1.5d, 2.0d, 0.0d, 16.0d, 3.0d, 14.0d), Block.box(2.5d, 3.0d, 0.0d, 16.0d, 4.0d, 13.0d), Block.box(3.5d, 4.0d, 0.0d, 16.0d, 5.0d, 12.0d), Block.box(4.5d, 5.0d, 0.0d, 16.0d, 6.0d, 11.0d), Block.box(5.5d, 6.0d, 0.0d, 16.0d, 7.0d, 10.0d), Block.box(6.5d, 7.0d, 0.0d, 16.0d, 8.0d, 9.0d), Block.box(7.5d, 8.0d, 0.0d, 16.0d, 9.0d, 8.0d), Block.box(8.5d, 9.0d, 0.0d, 16.0d, 10.0d, 7.0d), Block.box(9.5d, 10.0d, 0.0d, 16.0d, 11.0d, 6.0d), Block.box(10.5d, 11.0d, 0.0d, 16.0d, 12.0d, 5.0d), Block.box(11.5d, 12.0d, 0.0d, 16.0d, 13.0d, 4.0d), Block.box(12.5d, 13.0d, 0.0d, 16.0d, 14.0d, 3.0d), Block.box(13.5d, 14.0d, 0.0d, 16.0d, 15.0d, 2.0d)}).reduce((v1, v2) -> {
|
|
return Shapes.join(v1, v2, BooleanOp.OR);
|
|
}).get();
|
|
protected static final VoxelShape SHAPE_SOUTH_CORNER = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_EAST_CORNER);
|
|
protected static final VoxelShape SHAPE_WEST_CORNER = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_CORNER);
|
|
protected static final VoxelShape SHAPE_NORTH_CORNER = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_CORNER);
|
|
protected static final Map<Direction, VoxelShape> SHAPE_MAP;
|
|
protected static final Map<Direction, VoxelShape> SHAPE_MAP_CORNER;
|
|
public static final EnumProperty<Direction> FACING;
|
|
public static final EnumProperty<PartType> PART;
|
|
|
|
static {
|
|
Map<Direction, VoxelShape> shapes = new HashMap<>();
|
|
shapes.put(Direction.EAST, SHAPE_EAST);
|
|
shapes.put(Direction.SOUTH, SHAPE_SOUTH);
|
|
shapes.put(Direction.WEST, SHAPE_WEST);
|
|
shapes.put(Direction.NORTH, SHAPE_NORTH);
|
|
SHAPE_MAP = Collections.unmodifiableMap(shapes);
|
|
Map<Direction, VoxelShape> shapes2 = new HashMap<>();
|
|
shapes2.put(Direction.EAST, SHAPE_EAST_CORNER);
|
|
shapes2.put(Direction.SOUTH, SHAPE_SOUTH_CORNER);
|
|
shapes2.put(Direction.WEST, SHAPE_WEST_CORNER);
|
|
shapes2.put(Direction.NORTH, SHAPE_NORTH_CORNER);
|
|
SHAPE_MAP_CORNER = Collections.unmodifiableMap(shapes2);
|
|
FACING = BlockStateProperties.HORIZONTAL_FACING;
|
|
PART = EnumProperty.create("part", PartType.class);
|
|
}
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RampBlock$PartType.class */
|
|
public enum PartType implements StringRepresentable {
|
|
straight,
|
|
corner;
|
|
|
|
public String getSerializedName() {
|
|
return name().toLowerCase();
|
|
}
|
|
}
|
|
|
|
public RampBlock() {
|
|
super(Properties.of(Material.WOOD).sound(SoundType.WOOD).strength(1.0f));
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.EAST)).setValue(PART, PartType.straight));
|
|
}
|
|
|
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
|
return (BlockState) state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
|
}
|
|
|
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
|
return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
|
}
|
|
|
|
public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
|
|
if (this.material.isFlammable()) {
|
|
return 20;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
|
|
if (this.material.isFlammable()) {
|
|
return 5;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public RampBlock(Properties props) {
|
|
super(props);
|
|
registerDefaultState((BlockState) this.stateDefinition.any().setValue(FACING, Direction.EAST));
|
|
}
|
|
|
|
public void stepOn(Level p_176199_1_, BlockPos p_176199_2_, BlockState state, Entity entity) {
|
|
if (p_176199_1_.getBlockState(p_176199_2_).is(CustomBlocks.BLOCK_PAVED_ROAD_RAMP.get())) {
|
|
PavedRoadBlock.steppedOn(entity);
|
|
}
|
|
}
|
|
|
|
public boolean useShapeForLightOcclusion(BlockState p_220074_1_) {
|
|
return true;
|
|
}
|
|
|
|
private boolean isOpposite(BlockState first, BlockState second) {
|
|
if (first.getBlock() == second.getBlock() && first.getValue(PART) == second.getValue(PART) && first.getValue(FACING) == second.getValue(FACING).getOpposite()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private BlockState setPartType(LevelAccessor world, BlockState state, BlockPos pos) {
|
|
BlockState nRamp = world.getBlockState(pos.relative(Direction.NORTH));
|
|
BlockState eRamp = world.getBlockState(pos.relative(Direction.EAST));
|
|
BlockState sRamp = world.getBlockState(pos.relative(Direction.SOUTH));
|
|
BlockState wRamp = world.getBlockState(pos.relative(Direction.WEST));
|
|
boolean hasNramp = nRamp.is(this);
|
|
boolean hasEramp = eRamp.is(this);
|
|
boolean hasSramp = sRamp.is(this);
|
|
boolean hasWramp = wRamp.is(this);
|
|
int adjacentRampCount = (hasNramp ? 1 : 0) + (hasEramp ? 1 : 0) + (hasSramp ? 1 : 0) + (hasWramp ? 1 : 0);
|
|
BlockState forwardState = world.getBlockState(pos.relative(state.getValue(FACING)));
|
|
if (adjacentRampCount >= 2) {
|
|
if (hasSramp && hasWramp && !isOpposite(state, forwardState)) {
|
|
state = (BlockState) ((BlockState) state.setValue(PART, PartType.corner)).setValue(FACING, Direction.WEST);
|
|
} else if (hasSramp && hasEramp && !isOpposite(state, forwardState)) {
|
|
state = (BlockState) ((BlockState) state.setValue(PART, PartType.corner)).setValue(FACING, Direction.SOUTH);
|
|
} else if (hasNramp && hasWramp && !isOpposite(state, forwardState)) {
|
|
state = (BlockState) ((BlockState) state.setValue(PART, PartType.corner)).setValue(FACING, Direction.NORTH);
|
|
} else if (hasNramp && hasEramp && !isOpposite(state, forwardState)) {
|
|
state = (BlockState) ((BlockState) state.setValue(PART, PartType.corner)).setValue(FACING, Direction.EAST);
|
|
}
|
|
} else {
|
|
if (state.getValue(PART) == PartType.corner) {
|
|
boolean cornerAdjustment = false;
|
|
if (hasNramp && nRamp.getValue(PART) == PartType.corner) {
|
|
cornerAdjustment = true;
|
|
if (nRamp.getValue(FACING) == Direction.WEST) {
|
|
state = (BlockState) state.setValue(FACING, Direction.WEST);
|
|
} else {
|
|
state = (BlockState) state.setValue(FACING, Direction.EAST);
|
|
}
|
|
}
|
|
if (hasEramp && eRamp.getValue(PART) == PartType.corner) {
|
|
cornerAdjustment = true;
|
|
if (eRamp.getValue(FACING) == Direction.NORTH) {
|
|
state = (BlockState) state.setValue(FACING, Direction.NORTH);
|
|
} else {
|
|
state = (BlockState) state.setValue(FACING, Direction.SOUTH);
|
|
}
|
|
}
|
|
if (hasSramp && sRamp.getValue(PART) == PartType.corner) {
|
|
cornerAdjustment = true;
|
|
if (sRamp.getValue(FACING) == Direction.EAST) {
|
|
state = (BlockState) state.setValue(FACING, Direction.EAST);
|
|
} else {
|
|
state = (BlockState) state.setValue(FACING, Direction.WEST);
|
|
}
|
|
}
|
|
if (hasWramp && wRamp.getValue(PART) == PartType.corner) {
|
|
cornerAdjustment = true;
|
|
if (wRamp.getValue(FACING) == Direction.EAST) {
|
|
state = (BlockState) state.setValue(FACING, Direction.NORTH);
|
|
} else {
|
|
state = (BlockState) state.setValue(FACING, Direction.SOUTH);
|
|
}
|
|
}
|
|
if (!cornerAdjustment) {
|
|
if (hasNramp) {
|
|
state = (BlockState) state.setValue(FACING, nRamp.getValue(FACING));
|
|
}
|
|
if (hasEramp) {
|
|
state = (BlockState) state.setValue(FACING, eRamp.getValue(FACING));
|
|
}
|
|
if (hasSramp) {
|
|
state = (BlockState) state.setValue(FACING, sRamp.getValue(FACING));
|
|
}
|
|
if (hasWramp) {
|
|
state = (BlockState) state.setValue(FACING, wRamp.getValue(FACING));
|
|
}
|
|
}
|
|
}
|
|
state = (BlockState) state.setValue(PART, PartType.straight);
|
|
}
|
|
return state;
|
|
}
|
|
|
|
public BlockState updateShape(BlockState state, Direction p_196271_2_, BlockState p_196271_3_, LevelAccessor world, BlockPos pos, BlockPos p_196271_6_) {
|
|
return setPartType(world, state, pos);
|
|
}
|
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(new Property[]{FACING, PART});
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState p_220053_1_, BlockGetter p_220053_2_, BlockPos p_220053_3_, CollisionContext p_220053_4_) {
|
|
if (p_220053_1_.getValue(PART) == PartType.corner) {
|
|
VoxelShape result = SHAPE_MAP_CORNER.get(p_220053_1_.getValue(FACING));
|
|
return result == null ? SHAPE_EAST_CORNER : result;
|
|
}
|
|
VoxelShape result2 = SHAPE_MAP.get(p_220053_1_.getValue(FACING));
|
|
return result2 == null ? SHAPE_EAST : result2;
|
|
}
|
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
return setPartType(context.getLevel(), (BlockState) defaultBlockState().setValue(FACING, context.getHorizontalDirection()), context.getClickedPos());
|
|
}
|
|
}
|