ModernLifePatch/src-source/main/java/com/dairymoose/modernlife/blocks/SofaBlock.java
2024-10-26 09:40:21 +08:00

253 lines
13 KiB
Java

package com.dairymoose.modernlife.blocks;
import com.dairymoose.entity.DummyEntity;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import java.util.stream.Stream;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
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.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.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.BlockHitResult;
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/SofaBlock.class */
public class SofaBlock extends Block {
protected static final VoxelShape SHAPE_SOUTH_SINGLE = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(0.0d, 0.0d, 0.0d, 16.0d, 17.0d, 3.0d), Block.box(13.0d, 0.0d, 3.0d, 16.0d, 11.0d, 16.0d), Block.box(3.0d, 0.0d, 3.0d, 13.0d, 4.0d, 16.0d), Block.box(3.25d, 4.0d, 4.0d, 12.75d, 7.0d, 15.0d), Block.box(0.0d, 0.0d, 3.0d, 3.0d, 11.0d, 16.0d)}).reduce((v1, v2) -> {
return Shapes.join(v1, v2, BooleanOp.OR);
}).get();
protected static final VoxelShape SHAPE_WEST_SINGLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_SINGLE);
protected static final VoxelShape SHAPE_NORTH_SINGLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_SINGLE);
protected static final VoxelShape SHAPE_EAST_SINGLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_SINGLE);
protected static final VoxelShape SHAPE_SOUTH_MIDDLE = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(0.0d, 0.0d, 0.0d, 16.0d, 17.0d, 3.0d), Block.box(0.0d, 0.0d, 3.0d, 16.0d, 4.0d, 16.0d), Block.box(0.0d, 4.0d, 4.0d, 16.0d, 7.0d, 15.0d)}).reduce((v1, v2) -> {
return Shapes.join(v1, v2, BooleanOp.OR);
}).get();
protected static final VoxelShape SHAPE_WEST_MIDDLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_MIDDLE);
protected static final VoxelShape SHAPE_NORTH_MIDDLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_MIDDLE);
protected static final VoxelShape SHAPE_EAST_MIDDLE = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_MIDDLE);
protected static final VoxelShape SHAPE_SOUTH_LEFT = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(0.0d, 0.0d, 0.0d, 16.0d, 17.0d, 3.0d), Block.box(0.0d, 0.0d, 3.0d, 3.0d, 11.0d, 16.0d), Block.box(3.0d, 0.0d, 3.0d, 16.0d, 4.0d, 16.0d), Block.box(3.25d, 4.0d, 4.0d, 16.0d, 7.0d, 15.0d)}).reduce((v1, v2) -> {
return Shapes.join(v1, v2, BooleanOp.OR);
}).get();
protected static final VoxelShape SHAPE_WEST_LEFT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_LEFT);
protected static final VoxelShape SHAPE_NORTH_LEFT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_LEFT);
protected static final VoxelShape SHAPE_EAST_LEFT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_LEFT);
protected static final VoxelShape SHAPE_SOUTH_RIGHT = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(13.0d, 0.0d, 3.0d, 16.0d, 11.0d, 16.0d), Block.box(0.0d, 0.0d, 0.0d, 16.0d, 17.0d, 3.0d), Block.box(0.0d, 0.0d, 3.0d, 13.0d, 4.0d, 16.0d), Block.box(0.0d, 4.0d, 4.0d, 12.75d, 7.0d, 15.0d)}).reduce((v1, v2) -> {
return Shapes.join(v1, v2, BooleanOp.OR);
}).get();
protected static final VoxelShape SHAPE_WEST_RIGHT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_RIGHT);
protected static final VoxelShape SHAPE_NORTH_RIGHT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_RIGHT);
protected static final VoxelShape SHAPE_EAST_RIGHT = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_RIGHT);
protected static final VoxelShape SHAPE_SOUTH_CORNER = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(3.0d, 0.0d, 3.0d, 16.0d, 4.0d, 16.0d), Block.box(4.0d, 4.0d, 4.0d, 15.0d, 7.0d, 16.0d), Block.box(0.0d, 0.0d, 0.0d, 16.0d, 17.0d, 3.0d), Block.box(0.0d, 0.0d, 3.0d, 3.0d, 17.0d, 16.0d), Block.box(15.0d, 4.0d, 4.0d, 16.0d, 7.0d, 15.0d)}).reduce((v1, v2) -> {
return Shapes.join(v1, v2, BooleanOp.OR);
}).get();
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 VoxelShape SHAPE_EAST_CORNER = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_CORNER);
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<SofaType> TYPE = EnumProperty.create("type", SofaType.class);
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/SofaBlock$SofaType.class */
public enum SofaType implements StringRepresentable {
single,
middle,
left,
right,
corner;
public String getSerializedName() {
return name().toLowerCase();
}
}
public SofaBlock(Properties p_i48377_1_) {
super(p_i48377_1_);
registerDefaultState((BlockState) ((BlockState) getStateDefinition().any().setValue(FACING, Direction.NORTH)).setValue(TYPE, SofaType.single));
}
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 InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos p_225533_3_, Player player, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
if (!p_225533_2_.isClientSide) {
DummyEntity dummy = DummyEntity.getEntity(0.23f, p_225533_2_, p_225533_3_, false);
dummy.ride(player);
}
return InteractionResult.CONSUME;
}
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction newFacing = context.getHorizontalDirection().getOpposite();
BlockState state = getNewState(null, context.getLevel(), context.getClickedPos(), newFacing);
if (state == null) {
state = defaultBlockState();
}
return (BlockState) state.setValue(FACING, newFacing);
}
public BlockState updateShape(BlockState state, Direction dir, BlockState updater, LevelAccessor world, BlockPos pos, BlockPos updaterPos) {
return getNewState(state, world, pos, (Direction) state.getValue(FACING));
}
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(new Property[]{FACING, TYPE});
}
private BlockState getNewState(BlockState currentState, LevelAccessor world, BlockPos pos, Direction facing) {
BlockState adjacentSofa;
if (currentState == null) {
currentState = defaultBlockState();
}
BlockState cwState = world.getBlockState(pos.relative(facing.getClockWise()));
BlockState ccwState = world.getBlockState(pos.relative(facing.getCounterClockWise()));
BlockState frontState = world.getBlockState(pos.relative(facing));
int adjacentSofaCount = 0;
boolean cwSofa = cwState.is(this) && (cwState.getValue(FACING) == facing || cwState.getValue(TYPE) == SofaType.corner);
boolean ccwSofa = ccwState.is(this) && (ccwState.getValue(FACING) == facing || ccwState.getValue(TYPE) == SofaType.corner);
boolean frontSofa = frontState.is(this);
if (cwSofa) {
adjacentSofaCount = 0 + 1;
}
if (ccwSofa) {
adjacentSofaCount++;
}
if (adjacentSofaCount >= 2) {
return (BlockState) currentState.setValue(TYPE, SofaType.middle);
}
if (adjacentSofaCount == 1) {
if (frontSofa) {
if (cwState.is(this)) {
adjacentSofa = cwState;
} else {
adjacentSofa = ccwState;
}
if (adjacentSofa.getValue(FACING) == facing) {
Direction withDirection = facing;
if (adjacentSofa != ccwState) {
withDirection = (Direction) frontState.getValue(FACING);
}
return (BlockState) ((BlockState) currentState.setValue(TYPE, SofaType.corner)).setValue(FACING, withDirection);
}
}
if (cwSofa) {
return (BlockState) currentState.setValue(TYPE, SofaType.right);
}
if (ccwSofa) {
return (BlockState) currentState.setValue(TYPE, SofaType.left);
}
}
return (BlockState) currentState.setValue(TYPE, SofaType.single);
}
/* renamed from: com.dairymoose.modernlife.blocks.SofaBlock$1 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/SofaBlock$1.class */
static /* synthetic */ class C00571 {
static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];
static {
try {
$SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 1;
} catch (NoSuchFieldError e) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 2;
} catch (NoSuchFieldError e2) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 3;
} catch (NoSuchFieldError e3) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 4;
} catch (NoSuchFieldError e4) {
}
}
}
public VoxelShape getShape(BlockState bs, BlockGetter reader, BlockPos pos, CollisionContext sel) {
if (bs.getValue(TYPE) == SofaType.single) {
switch (C00571.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
case 1:
return SHAPE_NORTH_SINGLE;
case 2:
return SHAPE_SOUTH_SINGLE;
case 3:
return SHAPE_EAST_SINGLE;
case 4:
return SHAPE_WEST_SINGLE;
}
}
if (bs.getValue(TYPE) == SofaType.middle) {
switch (C00571.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
case 1:
return SHAPE_NORTH_MIDDLE;
case 2:
return SHAPE_SOUTH_MIDDLE;
case 3:
return SHAPE_EAST_MIDDLE;
case 4:
return SHAPE_WEST_MIDDLE;
}
}
if (bs.getValue(TYPE) == SofaType.left) {
switch (C00571.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
case 1:
return SHAPE_NORTH_LEFT;
case 2:
return SHAPE_SOUTH_LEFT;
case 3:
return SHAPE_EAST_LEFT;
case 4:
return SHAPE_WEST_LEFT;
}
}
if (bs.getValue(TYPE) == SofaType.right) {
switch (C00571.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
case 1:
return SHAPE_NORTH_RIGHT;
case 2:
return SHAPE_SOUTH_RIGHT;
case 3:
return SHAPE_EAST_RIGHT;
case 4:
return SHAPE_WEST_RIGHT;
}
}
if (bs.getValue(TYPE) == SofaType.corner) {
switch (C00571.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
case 1:
return SHAPE_NORTH_CORNER;
case 2:
return SHAPE_SOUTH_CORNER;
case 3:
return SHAPE_EAST_CORNER;
case 4:
return SHAPE_WEST_CORNER;
}
}
return SHAPE_NORTH_SINGLE;
}
}