/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.logging.LogUtils * com.mojang.serialization.MapCodec * org.slf4j.Logger */ package net.minecraft.world.level.block; import com.mojang.logging.LogUtils; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.dispenser.BlockSource; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.core.dispenser.DispenseItemBehavior; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.DispenserBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.DispenserBlockEntity; import net.minecraft.world.level.block.entity.DropperBlockEntity; 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 org.slf4j.Logger; public class DropperBlock extends DispenserBlock { private static final Logger LOGGER = LogUtils.getLogger(); public static final MapCodec CODEC = DropperBlock.simpleCodec(DropperBlock::new); private static final DispenseItemBehavior DISPENSE_BEHAVIOUR = new DefaultDispenseItemBehavior(); public MapCodec codec() { return CODEC; } public DropperBlock(BlockBehaviour.Properties properties) { super(properties); } @Override protected DispenseItemBehavior getDispenseMethod(Level level, ItemStack itemStack) { return DISPENSE_BEHAVIOUR; } @Override public BlockEntity newBlockEntity(BlockPos worldPosition, BlockState blockState) { return new DropperBlockEntity(worldPosition, blockState); } @Override protected void dispenseFrom(ServerLevel level, BlockState state, BlockPos pos) { ItemStack remaining; DispenserBlockEntity blockEntity = level.getBlockEntity(pos, BlockEntityType.DROPPER).orElse(null); if (blockEntity == null) { LOGGER.warn("Ignoring dispensing attempt for Dropper without matching block entity at {}", (Object)pos); return; } BlockSource source = new BlockSource(level, pos, state, blockEntity); int slot = blockEntity.getRandomSlot(level.random); if (slot < 0) { level.levelEvent(1001, pos, 0); return; } ItemStack itemStack = blockEntity.getItem(slot); if (itemStack.isEmpty()) { return; } Direction direction = (Direction)level.getBlockState(pos).getValue(FACING); Container into = HopperBlockEntity.getContainerAt(level, pos.relative(direction)); if (into == null) { remaining = DISPENSE_BEHAVIOUR.dispense(source, itemStack); } else { remaining = HopperBlockEntity.addItem(blockEntity, into, itemStack.copyWithCount(1), direction.getOpposite()); if (remaining.isEmpty()) { remaining = itemStack.copy(); remaining.shrink(1); } else { remaining = itemStack.copy(); } } blockEntity.setItem(slot, remaining); } }