package com.dairymoose.modernlife.blocks; import com.dairymoose.modernlife.util.ModernLifeUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; 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.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock; 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.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/LightSwitchBlock.class */ public class LightSwitchBlock extends Block { protected static final VoxelShape SHAPE_SOUTH = Block.box(6.0d, 5.2d, 0.0d, 10.0d, 11.4d, 2.1d); protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH); protected static final VoxelShape SHAPE_NORTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST); protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH); public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public LightSwitchBlock() { super(Properties.of(Material.METAL).sound(SoundType.METAL).strength(2.0f, 0.0f)); registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.SOUTH)).setValue(POWERED, Boolean.FALSE)); } 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_) { if (p_196271_1_.getValue(FACING).getOpposite() == p_196271_2_ && !p_196271_1_.canSurvive(p_196271_4_, p_196271_5_)) { return Blocks.AIR.defaultBlockState(); } return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_); } 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 p_225533_4_, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) { if (p_225533_2_.isClientSide) { return InteractionResult.SUCCESS; } BlockState lvt_7_1_ = pull(p_225533_1_, p_225533_2_, p_225533_3_); float lvt_8_1_ = ((Boolean) lvt_7_1_.getValue(POWERED)).booleanValue() ? 0.6f : 0.5f; p_225533_2_.playSound((Player) null, p_225533_3_, SoundEvents.LEVER_CLICK, SoundSource.BLOCKS, 0.3f, lvt_8_1_); return InteractionResult.CONSUME; } public BlockState pull(BlockState p_226939_1_, Level p_226939_2_, BlockPos p_226939_3_) { BlockState p_226939_1_2 = (BlockState) p_226939_1_.m_61122_(POWERED); p_226939_2_.setBlock(p_226939_3_, p_226939_1_2, 3); updateNeighbours(p_226939_1_2, p_226939_2_, p_226939_3_); return p_226939_1_2; } public void onRemove(BlockState p_196243_1_, Level p_196243_2_, BlockPos p_196243_3_, BlockState p_196243_4_, boolean p_196243_5_) { if (!p_196243_5_ && !p_196243_1_.is(p_196243_4_.getBlock())) { if (((Boolean) p_196243_1_.getValue(POWERED)).booleanValue()) { updateNeighbours(p_196243_1_, p_196243_2_, p_196243_3_); } super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_, p_196243_4_, p_196243_5_); } } public int getSignal(BlockState p_180656_1_, BlockGetter p_180656_2_, BlockPos p_180656_3_, Direction p_180656_4_) { return ((Boolean) p_180656_1_.getValue(POWERED)).booleanValue() ? 15 : 0; } public int getDirectSignal(BlockState p_176211_1_, BlockGetter p_176211_2_, BlockPos p_176211_3_, Direction p_176211_4_) { return (((Boolean) p_176211_1_.getValue(POWERED)).booleanValue() && p_176211_1_.getValue(FACING) == p_176211_4_) ? 15 : 0; } private void updateNeighbours(BlockState p_196378_1_, Level p_196378_2_, BlockPos p_196378_3_) { p_196378_2_.updateNeighborsAt(p_196378_3_, this); p_196378_2_.updateNeighborsAt(p_196378_3_.relative(p_196378_1_.getValue(FACING).getOpposite()), this); } /* renamed from: com.dairymoose.modernlife.blocks.LightSwitchBlock$1 */ /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/LightSwitchBlock$1.class */ static /* synthetic */ class C00341 { 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) { switch (C00341.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) { case 1: return SHAPE_NORTH; case 2: return SHAPE_SOUTH; case 3: return SHAPE_EAST; case 4: return SHAPE_WEST; default: return SHAPE_NORTH; } } protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(new Property[]{FACING, POWERED}); } public boolean canSurvive(BlockState p_196260_1_, LevelReader p_196260_2_, BlockPos p_196260_3_) { return FaceAttachedHorizontalDirectionalBlock.canAttach(p_196260_2_, p_196260_3_, p_196260_1_.getValue(FACING).getOpposite()); } public BlockState getStateForPlacement(BlockPlaceContext context) { Direction[] var2 = context.getNearestLookingDirections(); for (Direction lvt_5_1_ : var2) { if (lvt_5_1_.getAxis() != Direction.Axis.Y) { BlockState lvt_6_2_ = (BlockState) defaultBlockState().setValue(FACING, lvt_5_1_.getOpposite()); if (lvt_6_2_.canSurvive(context.getLevel(), context.getClickedPos())) { return lvt_6_2_; } } } return defaultBlockState(); } }