InventoryHelper .java

net.minecraft.inventory.InventoryHelper (class, 69 lines): members: dropInventoryItems, RANDOM. imports: EntityItem, NBTTagCompound, ItemStack.

net.minecraft.inventoryclass69 linescommon2.3 KB

API Surface (2)

void dropInventoryItems(World worldIn, BlockPos pos, IInventory inventory)
void dropInventoryItems(World worldIn, Entity entityAt, IInventory inventory)

Fields & Constants (1)

RANDOM

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

InventoryHelper.java69 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.inventory;
2
3
import java.util.Random;
4
import net.minecraft.entity.Entity;
5
import net.minecraft.entity.item.EntityItem;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.nbt.NBTTagCompound;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.world.World;
10
11
public class InventoryHelper
12
{
13
    private static final Random RANDOM = new Random();
14
15
    public static void dropInventoryItems(World worldIn, BlockPos pos, IInventory inventory)
16
    {
17
        dropInventoryItems(worldIn, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), inventory);
18
    }
19
20
    public static void dropInventoryItems(World worldIn, Entity entityAt, IInventory inventory)
21
    {
22
        dropInventoryItems(worldIn, entityAt.posX, entityAt.posY, entityAt.posZ, inventory);
23
    }
24
25
    private static void dropInventoryItems(World worldIn, double x, double y, double z, IInventory inventory)
26
    {
27
        for (int i = 0; i < inventory.getSizeInventory(); ++i)
28
        {
29
            ItemStack itemstack = inventory.getStackInSlot(i);
30
31
            if (itemstack != null)
32
            {
33
                spawnItemStack(worldIn, x, y, z, itemstack);
34
            }
35
        }
36
    }
37
38
    private static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack)
39
    {
40
        float f = RANDOM.nextFloat() * 0.8F + 0.1F;
41
        float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
42
        float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;
43
44
        while (stack.stackSize > 0)
45
        {
46
            int i = RANDOM.nextInt(21) + 10;
47
48
            if (i > stack.stackSize)
49
            {
50
                i = stack.stackSize;
51
            }
52
53
            stack.stackSize -= i;
54
            EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, new ItemStack(stack.getItem(), i, stack.getMetadata()));
55
56
            if (stack.hasTagCompound())
57
            {
58
                entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
59
            }
60
61
            float f3 = 0.05F;
62
            entityitem.motionX = RANDOM.nextGaussian() * (double)f3;
63
            entityitem.motionY = RANDOM.nextGaussian() * (double)f3 + 0.20000000298023224D;
64
            entityitem.motionZ = RANDOM.nextGaussian() * (double)f3;
65
            worldIn.spawnEntityInWorld(entityitem);
66
        }
67
    }
68
}
69

Deobfuscated MCP 1.8.9 source of InventoryHelper from Marcelektro/MavenMCP-1.8.9 (net/minecraft/inventory/InventoryHelper.java), stored verbatim.