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

160 lines
8.3 KiB
Java

package com.dairymoose.modernlife.blocks;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
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.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
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.DoubleBlockHalf;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/MusicStandBlock.class */
public class MusicStandBlock extends Block {
protected static final VoxelShape SHAPE_NORTH = Block.box(3.0d, 0.0d, 11.0d, 13.0d, 16.0d, 16.0d);
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_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;
public MusicStandBlock(Properties p_i48413_1_) {
super(p_i48413_1_);
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.NORTH)).setValue(HALF, DoubleBlockHalf.LOWER));
}
public VoxelShape getShape(BlockState p_220053_1_, BlockGetter p_220053_2_, BlockPos p_220053_3_, CollisionContext p_220053_4_) {
Direction lvt_5_1_ = p_220053_1_.getValue(FACING);
switch (C00391.$SwitchMap$net$minecraft$core$Direction[lvt_5_1_.ordinal()]) {
case 1:
default:
return SHAPE_SOUTH;
case 2:
return SHAPE_EAST;
case 3:
return SHAPE_WEST;
case 4:
return SHAPE_NORTH;
}
}
/* renamed from: com.dairymoose.modernlife.blocks.MusicStandBlock$1 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/MusicStandBlock$1.class */
static /* synthetic */ class C00391 {
static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];
static {
try {
$SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 1;
} catch (NoSuchFieldError e) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 2;
} catch (NoSuchFieldError e2) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 3;
} catch (NoSuchFieldError e3) {
}
try {
$SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 4;
} catch (NoSuchFieldError e4) {
}
}
}
public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, LevelAccessor p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
Comparable comparable = (DoubleBlockHalf) p_196271_1_.getValue(HALF);
if (p_196271_2_.getAxis() == Direction.Axis.Y) {
if ((comparable == DoubleBlockHalf.LOWER) == (p_196271_2_ == Direction.UP)) {
return (!p_196271_3_.is(this) || p_196271_3_.getValue(HALF) == comparable) ? Blocks.AIR.defaultBlockState() : (BlockState) p_196271_1_.setValue(FACING, p_196271_3_.getValue(FACING));
}
}
return (comparable == DoubleBlockHalf.LOWER && p_196271_2_ == Direction.DOWN && !p_196271_1_.canSurvive(p_196271_4_, p_196271_5_)) ? Blocks.AIR.defaultBlockState() : super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
}
protected static void preventCreativeDropFromBottomPart(Level p_241471_0_, BlockPos p_241471_1_, BlockState p_241471_2_, Player p_241471_3_) {
DoubleBlockHalf doubleblockhalf = p_241471_2_.getValue(HALF);
if (doubleblockhalf == DoubleBlockHalf.UPPER) {
BlockPos blockpos = p_241471_1_.below();
BlockState blockstate = p_241471_0_.getBlockState(blockpos);
if (blockstate.getBlock() == p_241471_2_.getBlock() && blockstate.getValue(HALF) == DoubleBlockHalf.LOWER) {
p_241471_0_.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 35);
p_241471_0_.levelEvent(p_241471_3_, 2001, blockpos, Block.getId(blockstate));
}
}
}
public void playerWillDestroy(Level p_176208_1_, BlockPos p_176208_2_, BlockState p_176208_3_, Player p_176208_4_) {
if (!p_176208_1_.isClientSide && p_176208_4_.isCreative()) {
preventCreativeDropFromBottomPart(p_176208_1_, p_176208_2_, p_176208_3_, p_176208_4_);
}
super.playerWillDestroy(p_176208_1_, p_176208_2_, p_176208_3_, p_176208_4_);
}
public BlockState rotate(BlockState p_52790_, Rotation p_52791_) {
return (BlockState) p_52790_.setValue(FACING, p_52791_.rotate(p_52790_.getValue(FACING)));
}
public BlockState mirror(BlockState p_52787_, Mirror p_52788_) {
return p_52788_ == Mirror.NONE ? p_52787_ : p_52787_.rotate(p_52788_.getRotation(p_52787_.getValue(FACING)));
}
@Nullable
public BlockState getStateForPlacement(BlockPlaceContext p_196258_1_) {
BlockPos lvt_2_1_ = p_196258_1_.getClickedPos();
if (lvt_2_1_.getY() < p_196258_1_.getLevel().getMaxBuildHeight() && p_196258_1_.getLevel().getBlockState(lvt_2_1_.above()).canBeReplaced(p_196258_1_)) {
Level lvt_3_1_ = p_196258_1_.getLevel();
boolean z = lvt_3_1_.hasNeighborSignal(lvt_2_1_) || lvt_3_1_.hasNeighborSignal(lvt_2_1_.above());
return (BlockState) ((BlockState) defaultBlockState().setValue(FACING, p_196258_1_.getHorizontalDirection().getOpposite())).setValue(HALF, DoubleBlockHalf.LOWER);
}
return null;
}
public void setPlacedBy(Level p_180633_1_, BlockPos p_180633_2_, BlockState p_180633_3_, LivingEntity p_180633_4_, ItemStack p_180633_5_) {
p_180633_1_.setBlock(p_180633_2_.above(), (BlockState) p_180633_3_.setValue(HALF, DoubleBlockHalf.UPPER), 3);
}
public boolean canSurvive(BlockState p_196260_1_, LevelReader p_196260_2_, BlockPos p_196260_3_) {
BlockPos lvt_4_1_ = p_196260_3_.below();
BlockState lvt_5_1_ = p_196260_2_.getBlockState(lvt_4_1_);
return p_196260_1_.getValue(HALF) == DoubleBlockHalf.LOWER ? lvt_5_1_.isFaceSturdy(p_196260_2_, lvt_4_1_, Direction.UP) : lvt_5_1_.is(this);
}
public PushReaction getPistonPushReaction(BlockState p_149656_1_) {
return PushReaction.DESTROY;
}
@OnlyIn(Dist.CLIENT)
public long getSeed(BlockState p_209900_1_, BlockPos p_209900_2_) {
return Mth.getSeed(p_209900_2_.getX(), p_209900_2_.below(p_209900_1_.getValue(HALF) == DoubleBlockHalf.LOWER ? 0 : 1).getY(), p_209900_2_.getZ());
}
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_206840_1_) {
p_206840_1_.add(new Property[]{HALF, FACING});
}
}