minecraft-source/src/net/minecraft/world/Containers.java

52 lines
2.4 KiB
Java

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 bjt, final BlockPos fk, final Container ajb) {
dropContents(bjt, fk.getX(), fk.getY(), fk.getZ(), ajb);
}
public static void dropContents(final Level bjt, final Entity akn, final Container ajb) {
dropContents(bjt, akn.getX(), akn.getY(), akn.getZ(), ajb);
}
private static void dropContents(final Level bjt, final double double2, final double double3, final double double4, final Container ajb) {
for (int integer9 = 0; integer9 < ajb.getContainerSize(); ++integer9) {
dropItemStack(bjt, double2, double3, double4, ajb.getItem(integer9));
}
}
public static void dropContents(final Level bjt, final BlockPos fk, final NonNullList<ItemStack> fy) {
fy.forEach(bek -> dropItemStack(bjt, fk.getX(), fk.getY(), fk.getZ(), bek));
}
public static void dropItemStack(final Level bjt, final double double2, final double double3, final double double4, final ItemStack bek) {
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 (!bek.isEmpty()) {
final ItemEntity avy21 = new ItemEntity(bjt, double8, double9, double10, bek.split(Containers.RANDOM.nextInt(21) + 10));
final float float22 = 0.05f;
avy21.setDeltaMovement(Containers.RANDOM.nextGaussian() * 0.05000000074505806, Containers.RANDOM.nextGaussian() * 0.05000000074505806 + 0.20000000298023224, Containers.RANDOM.nextGaussian() * 0.05000000074505806);
bjt.addFreshEntity(avy21);
}
}
static {
RANDOM = new Random();
}
}