本文整理汇总了Java中net.minecraft.server.PlayerInventory类的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory类的具体用法?Java PlayerInventory怎么用?Java PlayerInventory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PlayerInventory类属于net.minecraft.server包,在下文中一共展示了PlayerInventory类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getType
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
public InventoryType getType() {
// Thanks to Droppers extending Dispensers, order is important.
if (inventory instanceof InventoryCrafting) {
return inventory.getSize() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
} else if (inventory instanceof PlayerInventory) {
return InventoryType.PLAYER;
} else if (inventory instanceof TileEntityDropper) {
return InventoryType.DROPPER;
} else if (inventory instanceof TileEntityDispenser) {
return InventoryType.DISPENSER;
} else if (inventory instanceof TileEntityFurnace) {
return InventoryType.FURNACE;
} else if (inventory instanceof ContainerEnchantTableInventory) {
return InventoryType.ENCHANTING;
} else if (inventory instanceof TileEntityBrewingStand) {
return InventoryType.BREWING;
} else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
} else if (inventory instanceof InventoryEnderChest) {
return InventoryType.ENDER_CHEST;
} else if (inventory instanceof InventoryMerchant) {
return InventoryType.MERCHANT;
} else if (inventory instanceof TileEntityBeacon) {
return InventoryType.BEACON;
} else if (inventory instanceof ContainerAnvilInventory) {
return InventoryType.ANVIL;
} else if (inventory instanceof IHopper) {
return InventoryType.HOPPER;
} else {
return InventoryType.CHEST;
}
}
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:33,代码来源:CraftInventory.java
示例2: setItem
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
@Override
public void setItem(int index, ItemStack item) {
super.setItem(index, item);
if (this.getHolder() == null) return;
EntityPlayer player = ((CraftPlayer) this.getHolder()).getHandle();
if (player.playerConnection == null) return;
// PacketPlayOutSetSlot places the items differently than setItem()
//
// Between, and including, index 9 (the first index outside of the hotbar) and index 35 (the last index before
// armor slots) both PacketPlayOutSetSlot and setItem() places the items in the player's inventory the same way.
// Index 9 starts at the upper left corner of the inventory and moves to the right as it increases. When it
// reaches the end of the line it goes back to the left side of the new line in the inventory. Basically, it
// follows the path your eyes would follow as you read a book.
//
// The player's hotbar is indexed 0-8 in setItem(). The order goes: 0-8 hotbar, 9-35 normal inventory, 36 boots,
// 37 leggings, 38 chestplate, and 39 helmet. For indexes > 39 an ArrayIndexOutOfBoundsException will be thrown.
//
// PacketPlayOutSetSlot works very differently. Slots 0-8 are as follows: 0 crafting output, 1-4 crafting input,
// 5 helmet, 6 chestplate, 7 leggings, and 8 boots. Then, 9-35 work exactly the same as setItem(). The hotbar
// for PacketPlayOutSetSlot starts at index 36, and continues to index 44. Items placed where index is < 0 or
// > 44 have no action. Basically, the upper part of the player's inventory (crafting area and armor slots) is
// the first "row" of 9 slots for PacketPlayOutSetSlot. From there the rows work as normal, from left to right
// all the way down, including the hotbar.
//
// With this in mind, we have to modify the index we give PacketPlayOutSetSlot to match the index we intended
// with setItem(). First, if the index is 0-8, we need to add 36, or 4 rows worth of slots, to the index. This
// will push the item down to the correct spot in the hotbar.
//
// Now when index is > 35 (if index > 39 an ArrayIndexOutOfBoundsException will be thrown, so we need not worry
// about it) then we need to reset the index, and then count backwards from the "top" of the inventory. That is
// to say, we first find (index - 36), which will give us the index required for the armor slots. Now, we need
// to reverse the order of the index from 8. That means we need 0 to correspond to 8, 1 to correspond to 7,
// 2 to correspond to 6, and 3 to correspond to 5. We do this simply by taking the result of (index - 36) and
// subtracting that value from 8.
if (index < PlayerInventory.getHotbarSize())
index = index + 36;
else if (index > 35)
index = 8 - (index - 36);
player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.defaultContainer.windowId, index, CraftItemStack.asNMSCopy(item)));
}
开发者ID:tgnmc,项目名称:Craftbukkit,代码行数:41,代码来源:CraftInventoryPlayer.java
示例3: getType
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
public InventoryType getType() {
// Thanks to Droppers extending Dispensers, order is important.
if (inventory instanceof InventoryCrafting) {
return inventory.getSize() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
} else if (inventory instanceof PlayerInventory) {
return InventoryType.PLAYER;
} else if (inventory instanceof TileEntityDropper) {
return InventoryType.DROPPER;
} else if (inventory instanceof TileEntityDispenser) {
return InventoryType.DISPENSER;
} else if (inventory instanceof TileEntityFurnace) {
return InventoryType.FURNACE;
} else if (this instanceof CraftInventoryEnchanting) {
return InventoryType.ENCHANTING;
} else if (inventory instanceof TileEntityBrewingStand) {
return InventoryType.BREWING;
} else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
} else if (inventory instanceof InventoryEnderChest) {
return InventoryType.ENDER_CHEST;
} else if (inventory instanceof InventoryMerchant) {
return InventoryType.MERCHANT;
} else if (inventory instanceof TileEntityBeacon) {
return InventoryType.BEACON;
} else if (this instanceof CraftInventoryAnvil) {
return InventoryType.ANVIL;
} else if (inventory instanceof IHopper) {
return InventoryType.HOPPER;
} else {
return InventoryType.CHEST;
}
}
开发者ID:tgnmc,项目名称:Craftbukkit,代码行数:33,代码来源:CraftInventory.java
示例4: CraftInventoryPlayer
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
public CraftInventoryPlayer(net.minecraft.server.PlayerInventory inventory) {
super(inventory);
}
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:4,代码来源:CraftInventoryPlayer.java
示例5: getInventory
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
@Override
public PlayerInventory getInventory() {
return (PlayerInventory) inventory;
}
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:5,代码来源:CraftInventoryPlayer.java
示例6: setHeldItemSlot
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
public void setHeldItemSlot(int slot) {
Validate.isTrue(slot >= 0 && slot < PlayerInventory.getHotbarSize(), "Slot is not between 0 and 8 inclusive");
this.getInventory().itemInHandIndex = slot;
((CraftPlayer) this.getHolder()).getHandle().playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(slot));
}
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:6,代码来源:CraftInventoryPlayer.java
示例7: setHeldItemSlot
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
public void setHeldItemSlot(int slot) {
Validate.isTrue(slot >= 0 && slot < PlayerInventory.getHotbarSize(), "Slot is not between 0 and 8 inclusive");
this.getInventory().itemInHandIndex = slot;
((CraftPlayer) this.getHolder()).getHandle().playerConnection.sendPacket(new Packet16BlockItemSwitch(slot));
}
开发者ID:AlmuraDev,项目名称:Almura-Server,代码行数:6,代码来源:CraftInventoryPlayer.java
示例8: setItem
import net.minecraft.server.PlayerInventory; //导入依赖的package包/类
@Override
public void setItem(int index, ItemStack item) {
super.setItem(index, item);
if (this.getHolder() == null) return;
EntityPlayer player = ((CraftPlayer) this.getHolder()).getHandle();
if (player.playerConnection == null) return;
// PacketPlayOutSetSlot places the items differently than setItem()
//
// Between, and including, index 9 (the first index outside of the hotbar) and index 35 (the last index before
// armor slots) both PacketPlayOutSetSlot and setItem() places the items in the player's inventory the same way.
// Index 9 starts at the upper left corner of the inventory and moves to the right as it increases. When it
// reaches the end of the line it goes back to the left side of the new line in the inventory. Basically, it
// follows the path your eyes would follow as you read a book.
//
// The player's hotbar is indexed 0-8 in setItem(). The order goes: 0-8 hotbar, 9-35 normal inventory, 36 boots,
// 37 leggings, 38 chestplate, and 39 helmet. For indexes > 39 an ArrayIndexOutOfBoundsException will be thrown.
//
// PacketPlayOutSetSlot works very differently. Slots 0-8 are as follows: 0 crafting output, 1-4 crafting input,
// 5 helmet, 6 chestplate, 7 leggings, and 8 boots. Then, 9-35 work exactly the same as setItem(). The hotbar
// for PacketPlayOutSetSlot starts at index 36, and continues to index 44. Items placed where index is < 0 or
// > 44 have no action. Basically, the upper part of the player's inventory (crafting area and armor slots) is
// the first "row" of 9 slots for PacketPlayOutSetSlot. From there the rows work as normal, from left to right
// all the way down, including the hotbar.
//
// With this in mind, we have to modify the index we give PacketPlayOutSetSlot to match the index we intended
// with setItem(). First, if the index is 0-8, we need to add 36, or 4 rows worth of slots, to the index. This
// will push the item down to the correct spot in the hotbar.
//
// Now when index is > 35 (if index > 39 an ArrayIndexOutOfBoundsException will be thrown, so we need not worry
// about it) then we need to reset the index, and then count backwards from the "top" of the inventory. That is
// to say, we first find (index - 36), which will give us the index required for the armor slots. Now, we need
// to reverse the order of the index from 8. That means we need 0 to correspond to 8, 1 to correspond to 7,
// 2 to correspond to 6, and 3 to correspond to 5. We do this simply by taking the result of (index - 36) and
// subtracting that value from 8.
if (index < PlayerInventory.getHotbarSize()) {
index += 36;
} else if (index > 39) {
index += 5; // Off hand
} else if (index > 35) {
index = 8 - (index - 36);
}
player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.defaultContainer.windowId, index, CraftItemStack.asNMSCopy(item)));
}
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:44,代码来源:CraftInventoryPlayer.java
注:本文中的net.minecraft.server.PlayerInventory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论