本文整理匯總了Java中net.minecraft.inventory.InventoryBasic.getSizeInventory方法的典型用法代碼示例。如果您正苦於以下問題:Java InventoryBasic.getSizeInventory方法的具體用法?Java InventoryBasic.getSizeInventory怎麽用?Java InventoryBasic.getSizeInventory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.inventory.InventoryBasic
的用法示例。
在下文中一共展示了InventoryBasic.getSizeInventory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onEntityDeath
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
@SubscribeEvent
public static void onEntityDeath(LivingDeathEvent event)
{
// if villager death drops are enabled, if the newly dead entity is a villager, and that villager was killed by a player...
if ((ModConfiguration.enableDeathDrops) && (event.getEntityLiving() instanceof EntityVillager) && (event.getSource().getTrueSource() instanceof EntityPlayerMP))
{
// iterate through the itemstacks in the villager's inventory
InventoryBasic inventory = ((EntityVillager)event.getEntityLiving()).getVillagerInventory();
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
// remove the stack from the inventory and spawn it in the world
ItemStack stack = inventory.getStackInSlot(i);
if (stack != ItemStack.EMPTY)
{
event.getEntityLiving().entityDropItem(stack, 0.0F);
}
}
}
}
示例2: writeInventoryBasicToNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static NBTTagCompound writeInventoryBasicToNBT(final NBTTagCompound tag, final InventoryBasic inventoryBasic) {
if (inventoryBasic.hasCustomInventoryName()) {
tag.setString("CustomName", inventoryBasic.getInventoryName());
}
final NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < inventoryBasic.getSizeInventory(); ++i) {
final ItemStack stackInSlot = inventoryBasic.getStackInSlot(i);
if (stackInSlot != null) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte)i);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag((NBTBase)itemTag);
}
}
tag.setTag("Items", (NBTBase)nbttaglist);
return tag;
}
示例3: writeInventoryToNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
* Writes an inventory to an NBTTagCompound. Can be used to save an inventory in a
* TileEntity, or perhaps an ItemStack.
*
* @param tag: The NBTTagCompound to write the inventory to.
* @param inventory: The inventory to write to the NBTTagCompound.
* @return NBTTagCompound: The same NBTTagCompound that was passed to this method.
*/
public static NBTTagCompound writeInventoryToNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (inventory.hasCustomName())
tag.setString("CustomName", inventory.getName());
final NBTTagList nbttaglist = new NBTTagList();
for (int slotCount = 0; slotCount < inventory.getSizeInventory(); slotCount++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotCount);
if (stackInSlot != null) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte) slotCount);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag(itemTag);
}
}
tag.setTag("Items", nbttaglist);
return tag;
}
示例4: writeInventoryToNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
* Writes an inventory to an NBTTagCompound. Can be used to save an inventory in a
* TileEntity, or perhaps an ItemStack.
*
* @param tag: The NBTTagCompound to write the inventory to.
* @param inventory: The inventory to write to the NBTTagCompound.
* @return NBTTagCompound: The same NBTTagCompound that was passed to this method.
*/
public static NBTTagCompound writeInventoryToNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (inventory.hasCustomName()) {
tag.setString("CustomName", inventory.getName());
}
final NBTTagList nbttaglist = new NBTTagList();
for (int slotCount = 0; slotCount < inventory.getSizeInventory(); slotCount++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotCount);
if (!stackInSlot.isEmpty()) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte) slotCount);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag(itemTag);
}
}
tag.setTag("Items", nbttaglist);
return tag;
}
示例5: readInventoryFromNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
* Reads an inventory from an NBTTagCompound. Can be used to load an Inventory from a
* TileEntity or perhaps an ItemStak.
*
* @param tag: The NBTTagCompound to read the inventory data from.
* @param inventory: The inventory to set all of the inventory data to.
* @return InventoryBasic: The same instance of InventoryBasic that was passed to this
* method.
*/
public static InventoryBasic readInventoryFromNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (tag.hasKey("CustomName", 8)) {
inventory.setCustomName(tag.getString("CustomName"));
}
final NBTTagList items = tag.getTagList("Items", 10);
for (int storedCount = 0; storedCount < items.tagCount(); storedCount++) {
final NBTTagCompound itemTag = items.getCompoundTagAt(storedCount);
final int slotCount = itemTag.getByte("Slot") & 0xFF;
if (slotCount >= 0 && slotCount < inventory.getSizeInventory()) {
inventory.setInventorySlotContents(slotCount, new ItemStack(itemTag));
}
}
return inventory;
}
示例6: countPossibleRecipes
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public int countPossibleRecipes(IInventory inventory)
{
InventoryBasic basic = new InventoryBasic("basic", false, inventory.getSizeInventory());
for (int i = 0; i < basic.getSizeInventory(); i++)
if(inventory.getStackInSlot(i) != null)
basic.setInventorySlotContents(i, inventory.getStackInSlot(i).copy());
searched.clear();
ArrayList<RecipeOverflow> overflow = new ArrayList<RecipeOverflow>();
int ammount = 0;
ConsumeResult result = consumeRecipe(basic, input, overflow, new SearchLimiter());
while(result != null)
{
overflow.addAll(result.overflow);
ammount++;
result = consumeRecipe(basic, input, overflow, new SearchLimiter());
searched.clear();
}
searched.clear();
return ammount;
}
示例7: dropInventory
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
private static void dropInventory(List<EntityItem> drops, EntityVillager villager)
{
// 村人自身のインベントリの內容をドロップ
// InventoryBasicもIterableにしてくれ~
InventoryBasic inv = villager.getVillagerInventory();
final int invElements = inv.getSizeInventory();
for(int i = 0; i < invElements; i++)
{
// スロットごとにItemStackがないか確認
ItemStack stack = inv.getStackInSlot(i);
if(stack == null)
{
continue;
}
// ItemStackがあればそれをドロップアイテムとして登録
EntityItem entityDropItem = new EntityItem(villager.world, villager.posX, villager.posY + 1, villager.posZ, stack);
drops.add(entityDropItem);
}
}
示例8: readInventoryBasicFromNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static NBTTagCompound readInventoryBasicFromNBT(final NBTTagCompound tag, final InventoryBasic inventoryBasic) {
if (tag.hasKey("CustomName", 8)) {
inventoryBasic.func_110133_a(tag.getString("CustomName"));
}
final NBTTagList items = tag.getTagList("Items", 10);
for (int i = 0; i < items.tagCount(); ++i) {
final NBTTagCompound itemTag = items.getCompoundTagAt(i);
final int j = itemTag.getByte("Slot") & 0xFF;
if (j >= 0 && j < inventoryBasic.getSizeInventory()) {
inventoryBasic.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(itemTag));
}
}
return tag;
}
示例9: getCurrentBaubles
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static IInventory getCurrentBaubles(IBaublesItemHandler baubles)
{
InventoryBasic basic = new InventoryBasic("CurrentBaubles", false, baubles.getSlots());
for (int i=0; i < basic.getSizeInventory(); i++)
{
basic.setInventorySlotContents(i, baubles.getStackInSlot(i));
}
return basic;
}
示例10: readInventoryFromNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
* Reads an inventory from an NBTTagCompound. Can be used to load an Inventory from a
* TileEntity or perhaps an ItemStak.
*
* @param tag: The NBTTagCompound to read the inventory data from.
* @param inventory: The inventory to set all of the inventory data to.
* @return InventoryBasic: The same instance of InventoryBasic that was passed to this
* method.
*/
public static InventoryBasic readInventoryFromNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (tag.hasKey("CustomName", 8))
inventory.setCustomName(tag.getString("CustomName"));
final NBTTagList items = tag.getTagList("Items", 10);
for (int storedCount = 0; storedCount < items.tagCount(); storedCount++) {
final NBTTagCompound itemTag = items.getCompoundTagAt(storedCount);
final int slotCount = itemTag.getByte("Slot") & 0xFF;
if (slotCount >= 0 && slotCount < inventory.getSizeInventory())
inventory.setInventorySlotContents(slotCount, ItemStack.loadItemStackFromNBT(itemTag));
}
return inventory;
}
示例11: openPotionGui
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
private void openPotionGui(EntityPlayerMP player, PacketCustom packet) {
InventoryBasic b = new InventoryBasic("potionStore", true, 9);
for (int i = 0; i < b.getSizeInventory(); i++) {
b.setInventorySlotContents(i, packet.readItemStack());
}
ServerUtils.openSMPContainer(player, new ContainerPotionCreator(player.inventory, b), (player1, windowId) -> {
PacketCustom packet1 = new PacketCustom(channel, 24);
packet1.writeByte(windowId);
packet1.sendToPlayer(player1);
});
}
示例12: getFirstEmptyStack
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
private static int getFirstEmptyStack(InventoryBasic inventory) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) == null) {
return i;
}
}
return -1;
}
示例13: getExistingCompatibleStack
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
private static int getExistingCompatibleStack(ItemStack itemStack, InventoryBasic inventory) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack existingStack = inventory.getStackInSlot(i);
if (existingStack != null
&& existingStack.getItem() == itemStack.getItem()
&& existingStack.isStackable()
&& existingStack.stackSize + itemStack.stackSize <= existingStack.getMaxStackSize()
&& existingStack.stackSize < inventory.getInventoryStackLimit()
&& (!existingStack.getHasSubtypes() || existingStack.getItemDamage() == itemStack.getItemDamage())
&& ItemStack.areItemStackTagsEqual(existingStack, itemStack)) {
return i;
}
}
return -1;
}
示例14: writeToNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static void writeToNBT(NBTTagCompound ntb, InventoryBasic inventory) {
NBTTagList nbtTagList = new NBTTagList();
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack != null) {
NBTTagCompound nbtItem = new NBTTagCompound();
nbtItem.setByte("Slot", (byte) i);
stack.writeToNBT(nbtItem);
nbtTagList.appendTag(nbtItem);
}
}
ntb.setTag(NTB_INVENTORY_TAG, nbtTagList);
}
示例15: readFromNBT
import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static void readFromNBT(NBTTagCompound ntb, InventoryBasic inventory) {
NBTTagList nbtTagList = ntb.getTagList(NTB_INVENTORY_TAG, 10);
for (int i = 0; i < nbtTagList.tagCount(); ++i) {
NBTTagCompound ntbItem = nbtTagList.getCompoundTagAt(i);
int j = ntbItem.getByte("Slot") & 255;
if (j >= 0 && j < inventory.getSizeInventory()) {
inventory.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(ntbItem));
}
}
}