当前位置: 首页>>代码示例>>Java>>正文


Java InventoryPlayer.setInventorySlotContents方法代码示例

本文整理汇总了Java中net.minecraft.entity.player.InventoryPlayer.setInventorySlotContents方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryPlayer.setInventorySlotContents方法的具体用法?Java InventoryPlayer.setInventorySlotContents怎么用?Java InventoryPlayer.setInventorySlotContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.entity.player.InventoryPlayer的用法示例。


在下文中一共展示了InventoryPlayer.setInventorySlotContents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeItemsFromPlayer

import net.minecraft.entity.player.InventoryPlayer; //导入方法依赖的package包/类
/**
 * Removes the given amount of items from the given player inventory. Scans through multiple inventory slots if needed.
 * 
 * @param inv - {@link net.minecraft.entity.player.InventoryPlayer Player inventory} to interact with.
 * @param item - {@link net.minecraft.item.Item Item type} to remove.
 * @param meta - Item metadata; set to {@code -1} to disregard item metadata.
 * @param qty - Number of items to remove.
 */
private static void removeItemsFromPlayer(InventoryPlayer inv, Item item, int meta, int qty){

	for(int i=0; i<inv.mainInventory.length; ++i){

		ItemStack stack = inv.mainInventory[i];
		if (stack == null) {
			continue;
		}

		if(stack.getItem().equals(item)){
			if(stack.getItemDamage() == meta || meta == -1){
				if(stack.stackSize <= qty){
					qty -= stack.stackSize;
					inv.removeStackFromSlot(i);
				}else{
					stack.stackSize -= qty;
					inv.setInventorySlotContents(i, stack);
					return;
				}
			}
		}
	}
}
 
开发者ID:DonBruce64,项目名称:OpenFlexiTrack,代码行数:32,代码来源:BlockSurveyFlag.java

示例2: combineSlots

import net.minecraft.entity.player.InventoryPlayer; //导入方法依赖的package包/类
static void combineSlots(EntityPlayerMP player, int dst, int add)
{
    InventoryPlayer inv = player.inventory;
    ItemStack dstStack = inv.getStackInSlot(dst);
    ItemStack addStack = inv.getStackInSlot(add);

    if (addStack == null)
        return;    // Combination is a no-op.

    if (dstStack == null)   // Do a straight move - nothing to combine with.
    {
        inv.setInventorySlotContents(dst, addStack);
        inv.setInventorySlotContents(add, null);
        return;
    }

    // Check we can combine. This logic comes from InventoryPlayer.storeItemStack():
    boolean itemsMatch = dstStack.getItem() == addStack.getItem();
    boolean dstCanStack = dstStack.isStackable() && dstStack.stackSize < dstStack.getMaxStackSize() && dstStack.stackSize < inv.getInventoryStackLimit();
    boolean subTypesMatch = !dstStack.getHasSubtypes() || dstStack.getMetadata() == addStack.getMetadata();
    boolean tagsMatch = ItemStack.areItemStackTagsEqual(dstStack, addStack);
    if (itemsMatch && dstCanStack && subTypesMatch && tagsMatch)
    {
        // We can combine, so figure out how much we have room for:
        int limit = Math.min(dstStack.getMaxStackSize(), inv.getInventoryStackLimit());
        int room = limit - dstStack.stackSize;
        if (addStack.stackSize > room)
        {
            // Not room for all of it, so shift across as much as possible.
            addStack.stackSize -= room;
            dstStack.stackSize += room;
        }
        else
        {
            // Room for the whole lot, so empty out the add slot.
            dstStack.stackSize += addStack.stackSize;
            inv.setInventorySlotContents(add, null);
        }
    }
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:41,代码来源:InventoryCommandsImplementation.java

示例3: swapSlots

import net.minecraft.entity.player.InventoryPlayer; //导入方法依赖的package包/类
static void swapSlots(EntityPlayerMP player, int lhs, int rhs)
{
    InventoryPlayer inv = player.inventory;
    ItemStack srcStack = inv.getStackInSlot(lhs);
    ItemStack dstStack = inv.getStackInSlot(rhs);
    inv.setInventorySlotContents(lhs, dstStack);
    inv.setInventorySlotContents(rhs, srcStack);
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:9,代码来源:InventoryCommandsImplementation.java


注:本文中的net.minecraft.entity.player.InventoryPlayer.setInventorySlotContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。