/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.ImmutableMap * com.mojang.serialization.MapCodec * org.jspecify.annotations.Nullable */ package net.minecraft.world.level.block; import com.google.common.collect.ImmutableMap; import com.mojang.serialization.MapCodec; import java.util.Map; import java.util.function.Function; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.stats.Stats; import net.minecraft.world.Containers; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.InsideBlockEffectApplier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; 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.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.HopperBlockEntity; 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.EnumProperty; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.level.redstone.Orientation; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; 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; import org.jspecify.annotations.Nullable; public class HopperBlock extends BaseEntityBlock { public static final MapCodec CODEC = HopperBlock.simpleCodec(HopperBlock::new); public static final EnumProperty FACING = BlockStateProperties.FACING_HOPPER; public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED; private final Function shapes; private final Map interactionShapes; public MapCodec codec() { return CODEC; } public HopperBlock(BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.DOWN)).setValue(ENABLED, true)); VoxelShape inside = Block.column(12.0, 11.0, 16.0); this.shapes = this.makeShapes(inside); this.interactionShapes = ImmutableMap.builderWithExpectedSize((int)5).putAll(Shapes.rotateHorizontal(Shapes.or(inside, Block.boxZ(4.0, 8.0, 10.0, 0.0, 4.0)))).put((Object)Direction.DOWN, (Object)inside).build(); } private Function makeShapes(VoxelShape inside) { VoxelShape spoutlessHopperOutline = Shapes.or(Block.column(16.0, 10.0, 16.0), Block.column(8.0, 4.0, 10.0)); VoxelShape spoutlessHopper = Shapes.join(spoutlessHopperOutline, inside, BooleanOp.ONLY_FIRST); Map spouts = Shapes.rotateAll(Block.boxZ(4.0, 4.0, 8.0, 0.0, 8.0), new Vec3(8.0, 6.0, 8.0).scale(0.0625)); return this.getShapeForEachState(state -> Shapes.or(spoutlessHopper, Shapes.join((VoxelShape)spouts.get(state.getValue(FACING)), Shapes.block(), BooleanOp.AND)), ENABLED); } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return this.shapes.apply(state); } @Override protected VoxelShape getInteractionShape(BlockState state, BlockGetter level, BlockPos pos) { return this.interactionShapes.get(state.getValue(FACING)); } @Override public BlockState getStateForPlacement(BlockPlaceContext context) { Direction direction = context.getClickedFace().getOpposite(); return (BlockState)((BlockState)this.defaultBlockState().setValue(FACING, direction.getAxis() == Direction.Axis.Y ? Direction.DOWN : direction)).setValue(ENABLED, true); } @Override public BlockEntity newBlockEntity(BlockPos worldPosition, BlockState blockState) { return new HopperBlockEntity(worldPosition, blockState); } @Override public @Nullable BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType type) { return level.isClientSide() ? null : HopperBlock.createTickerHelper(type, BlockEntityType.HOPPER, HopperBlockEntity::pushItemsTick); } @Override protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) { if (oldState.is(state.getBlock())) { return; } this.checkPoweredState(level, pos, state); } @Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { BlockEntity blockEntity; if (!level.isClientSide() && (blockEntity = level.getBlockEntity(pos)) instanceof HopperBlockEntity) { HopperBlockEntity hopper = (HopperBlockEntity)blockEntity; player.openMenu(hopper); player.awardStat(Stats.INSPECT_HOPPER); } return InteractionResult.SUCCESS; } @Override protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, @Nullable Orientation orientation, boolean movedByPiston) { this.checkPoweredState(level, pos, state); } private void checkPoweredState(Level level, BlockPos pos, BlockState state) { boolean shouldBeOn; boolean bl = shouldBeOn = !level.hasNeighborSignal(pos); if (shouldBeOn != state.getValue(ENABLED)) { level.setBlock(pos, (BlockState)state.setValue(ENABLED, shouldBeOn), 2); } } @Override protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel level, BlockPos pos, boolean movedByPiston) { Containers.updateNeighboursAfterDestroy(state, level, pos); } @Override protected boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override protected int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos, Direction direction) { return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); } @Override protected BlockState rotate(BlockState state, Rotation rotation) { return (BlockState)state.setValue(FACING, rotation.rotate(state.getValue(FACING))); } @Override protected BlockState mirror(BlockState state, Mirror mirror) { return state.rotate(mirror.getRotation(state.getValue(FACING))); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, ENABLED); } @Override protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier effectApplier, boolean isPrecise) { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof HopperBlockEntity) { HopperBlockEntity.entityInside(level, pos, state, entity, (HopperBlockEntity)blockEntity); } } @Override protected boolean isPathfindable(BlockState state, PathComputationType type) { return false; } }