Java Code Examples for net.minecraft.entity.player.EntityPlayer#getInventoryEnderChest()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#getInventoryEnderChest() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Moves as many items from the output slot to the owner's vanilla Ender Chest as possible.
 * Tries to first fill matching stacks to their max, then puts items into the first empty slot.
 * @return true if some items were moved
 */
private boolean moveItemsToEnderChest()
{
    if (this.getBaseItemHandler().getStackInSlot(SLOT_OUTPUT).isEmpty() ||
        this.ownerData == null || this.ownerData.getOwnerUUID() == null)
    {
        return false;
    }

    EntityPlayer player = this.getWorld().getPlayerEntityByUUID(this.ownerData.getOwnerUUID());

    if (player == null)
    {
        return false;
    }
    // Player is online

    ItemStack stack = this.getBaseItemHandler().extractItem(SLOT_OUTPUT, 64, false);

    if (stack.isEmpty())
    {
        return false;
    }

    int origSize = stack.getCount();
    IItemHandler inv = new InvWrapper(player.getInventoryEnderChest());
    stack = InventoryUtils.tryInsertItemStackToInventory(inv, stack);

    if (stack.isEmpty())
    {
        return true;
    }

    boolean movedItems = origSize != stack.getCount();
    this.getBaseItemHandler().insertItem(SLOT_OUTPUT, stack, false);

    return movedItems;
}
 
Example 2
public CraftHumanEntity(final CraftServer server, final EntityPlayer entity) {
    super(server, entity);
    mode = server.getDefaultGameMode();
    this.inventory = new CraftInventoryPlayer(entity.inventory);
    enderChest = new CraftInventory(entity.getInventoryEnderChest());
}
 
Example 3
/**
 * Returns the inventory that the selected Link Crystal in the given modular item is currently bound to,
 * or null in case of errors.
 */
@Nullable
public static IItemHandler getBoundInventory(ItemStack modularStack, EntityPlayer player, int chunkLoadDuration)
{
    if (modularStack.isEmpty() || (modularStack.getItem() instanceof IModular) == false)
    {
        return null;
    }

    IModular iModular = (IModular) modularStack.getItem();
    TargetData target = TargetData.getTargetFromSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL);

    if (target == null ||
        iModular.getSelectedModuleTier(modularStack, ModuleType.TYPE_LINKCRYSTAL) != ItemLinkCrystal.TYPE_BLOCK ||
        OwnerData.canAccessSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
    {
        return null;
    }

    // Bound to a vanilla Ender Chest
    if ("minecraft:ender_chest".equals(target.blockName))
    {
        return new InvWrapper(player.getInventoryEnderChest());
    }

    World targetWorld = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(target.dimension);

    if (targetWorld == null)
    {
        return null;
    }

    if (chunkLoadDuration > 0)
    {
        // Chunk load the target
        ChunkLoading.getInstance().loadChunkForcedWithPlayerTicket(player, target.dimension,
                target.pos.getX() >> 4, target.pos.getZ() >> 4, chunkLoadDuration);
    }

    TileEntity te = targetWorld.getTileEntity(target.pos);

    // Block has changed since binding, or does not have IItemHandler capability
    if (te == null || te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, target.facing) == false ||
        target.isTargetBlockUnchanged() == false)
    {
        // Remove the bind
        TargetData.removeTargetTagFromSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL);
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.bound.block.changed"), true);
        return null;
    }

    return te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, target.facing);
}