本文整理匯總了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;
}
}
}
}
}
示例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);
}
}
}
示例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);
}