package net.minecraft.world;

import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import java.util.Random;

public class Containers {
    private static final Random RANDOM;
    
    public static void dropContents(final Level bjw, final BlockPos fk, final Container aje) {
        dropContents(bjw, fk.getX(), fk.getY(), fk.getZ(), aje);
    }
    
    public static void dropContents(final Level bjw, final Entity akq, final Container aje) {
        dropContents(bjw, akq.getX(), akq.getY(), akq.getZ(), aje);
    }
    
    private static void dropContents(final Level bjw, final double double2, final double double3, final double double4, final Container aje) {
        for (int integer9 = 0; integer9 < aje.getContainerSize(); ++integer9) {
            dropItemStack(bjw, double2, double3, double4, aje.getItem(integer9));
        }
    }
    
    public static void dropContents(final Level bjw, final BlockPos fk, final NonNullList<ItemStack> fy) {
        fy.forEach(ben -> dropItemStack(bjw, fk.getX(), fk.getY(), fk.getZ(), ben));
    }
    
    public static void dropItemStack(final Level bjw, final double double2, final double double3, final double double4, final ItemStack ben) {
        final double double5 = EntityType.ITEM.getWidth();
        final double double6 = 1.0 - double5;
        final double double7 = double5 / 2.0;
        final double double8 = Math.floor(double2) + Containers.RANDOM.nextDouble() * double6 + double7;
        final double double9 = Math.floor(double3) + Containers.RANDOM.nextDouble() * double6;
        final double double10 = Math.floor(double4) + Containers.RANDOM.nextDouble() * double6 + double7;
        while (!ben.isEmpty()) {
            final ItemEntity awb21 = new ItemEntity(bjw, double8, double9, double10, ben.split(Containers.RANDOM.nextInt(21) + 10));
            final float float22 = 0.05f;
            awb21.setDeltaMovement(Containers.RANDOM.nextGaussian() * 0.05000000074505806, Containers.RANDOM.nextGaussian() * 0.05000000074505806 + 0.20000000298023224, Containers.RANDOM.nextGaussian() * 0.05000000074505806);
            bjw.addFreshEntity(awb21);
        }
    }
    
    static {
        RANDOM = new Random();
    }
}
