package com.dairymoose.modernlife.blocks;

import com.dairymoose.modernlife.blocks.gui.RadiatorScreen;
import com.dairymoose.modernlife.tileentities.RadiatorBlockEntity;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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.ItemStack;
import net.minecraft.world.item.TooltipFlag;
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.EntityBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
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.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
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;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RadiatorBlock.class */
public class RadiatorBlock extends Block implements SimpleWaterloggedBlock, EntityBlock {
    protected static final VoxelShape SHAPE_NORTH = Block.box(2.0d, 0.0d, 5.0d, 15.0d, 13.0d, 12.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 = BlockStateProperties.HORIZONTAL_FACING;
    public static final EnumProperty<HeatType> HEAT = EnumProperty.create("heat", HeatType.class);
    public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

    public RadiatorBlock() {
        super(Properties.of(Material.HEAVY_METAL).sound(SoundType.METAL).strength(3.5f, 10.0f).lightLevel(RadiatorBlock::getLightValueInternal));
        registerDefaultState((BlockState) ((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.NORTH)).setValue(HEAT, HeatType.off)).setValue(WATERLOGGED, Boolean.FALSE));
    }

    public boolean canSurvive(BlockState p_196260_1_, LevelReader p_196260_2_, BlockPos p_196260_3_) {
        return !p_196260_2_.isEmptyBlock(p_196260_3_.below());
    }

    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 FluidState getFluidState(BlockState p_204507_1_) {
        if (((Boolean) p_204507_1_.getValue(WATERLOGGED)).booleanValue()) {
            return Fluids.WATER.getSource(false);
        }
        return super.getFluidState(p_204507_1_);
    }

    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
        return ModernLifeUtil.createTickerHelper(type, RadiatorBlockEntity.RADIATOR, RadiatorBlockEntity::tick);
    }

    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
        return RadiatorBlockEntity.RADIATOR.create(pos, state);
    }

    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 (((Boolean) p_196271_1_.getValue(WATERLOGGED)).booleanValue()) {
            p_196271_4_.scheduleTick(p_196271_5_, Fluids.WATER, Fluids.WATER.getTickDelay(p_196271_4_));
        }
        return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.dairymoose.modernlife.blocks.RadiatorBlock$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RadiatorBlock$1.class */
    public class RunnableC00511 implements Runnable {
        final /* synthetic */ Level val$p_225533_2_;
        final /* synthetic */ BlockPos val$p_225533_3_;

        RunnableC00511(Level level, BlockPos blockPos) {
            p_225533_2_ = level;
            p_225533_3_ = blockPos;
        }

        @Override // java.lang.Runnable
        public void run() {
            RadiatorScreen screen = new RadiatorScreen(p_225533_2_, p_225533_3_);
            Minecraft.getInstance().setScreen(screen);
        }
    }

    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) {
            DistExecutor.runWhenOn(Dist.CLIENT, () -> {
                return new Runnable() { // from class: com.dairymoose.modernlife.blocks.RadiatorBlock.1
                    final /* synthetic */ Level val$p_225533_2_;
                    final /* synthetic */ BlockPos val$p_225533_3_;

                    RunnableC00511(Level p_225533_2_2, BlockPos p_225533_3_2) {
                        p_225533_2_ = p_225533_2_2;
                        p_225533_3_ = p_225533_3_2;
                    }

                    @Override // java.lang.Runnable
                    public void run() {
                        RadiatorScreen screen = new RadiatorScreen(p_225533_2_, p_225533_3_);
                        Minecraft.getInstance().setScreen(screen);
                    }
                };
            });
        }
        return InteractionResult.CONSUME;
    }

    public static int getLightValueInternal(BlockState state) {
        if (state.getValue(HEAT) == HeatType.low) {
            return 3;
        }
        if (state.getValue(HEAT) == HeatType.medium) {
            return 5;
        }
        if (state.getValue(HEAT) == HeatType.high) {
            return 7;
        }
        return 0;
    }

    public int getLightBlock(BlockState state, BlockGetter world, BlockPos pos) {
        return getLightValueInternal(state);
    }

    @OnlyIn(Dist.CLIENT)
    public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
        list.add(new TextComponent("Right click placed radiator to activate"));
    }

    @OnlyIn(Dist.CLIENT)
    public boolean isEmissiveRendering(BlockState blockState) {
        if (blockState.getValue(HEAT) == HeatType.low || blockState.getValue(HEAT) == HeatType.medium || blockState.getValue(HEAT) == HeatType.high) {
            return true;
        }
        return false;
    }

    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(new Property[]{FACING, HEAT, WATERLOGGED});
    }

    /* renamed from: com.dairymoose.modernlife.blocks.RadiatorBlock$2 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RadiatorBlock$2.class */
    static /* synthetic */ class C00522 {
        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 (C00522.$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;
        }
    }

    public BlockState getStateForPlacement(BlockPlaceContext context) {
        FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
        return (BlockState) ((BlockState) defaultBlockState().setValue(FACING, context.getHorizontalDirection())).setValue(WATERLOGGED, Boolean.valueOf(fluidState.getType() == Fluids.WATER));
    }

    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RadiatorBlock$HeatType.class */
    public enum HeatType implements StringRepresentable {
        off,
        low,
        medium,
        high;

        public String getSerializedName() {
            return name().toLowerCase();
        }
    }
}
