當前位置: 首頁>>代碼示例>>Java>>正文


Java InventoryBasic.getStackInSlot方法代碼示例

本文整理匯總了Java中net.minecraft.inventory.InventoryBasic.getStackInSlot方法的典型用法代碼示例。如果您正苦於以下問題:Java InventoryBasic.getStackInSlot方法的具體用法?Java InventoryBasic.getStackInSlot怎麽用?Java InventoryBasic.getStackInSlot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.inventory.InventoryBasic的用法示例。


在下文中一共展示了InventoryBasic.getStackInSlot方法的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);
			}
		}
	}
}
 
開發者ID:crazysnailboy,項目名稱:VillagerInventory,代碼行數:20,代碼來源:VillagerInventoryMod.java

示例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;
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:18,代碼來源:XUHelper.java

示例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;
}
 
開發者ID:MinecraftModDevelopmentMods,項目名稱:MMDLib-old,代碼行數:25,代碼來源:NBTUtils.java

示例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;
}
 
開發者ID:Darkhax-Minecraft,項目名稱:Bookshelf,代碼行數:34,代碼來源:NBTUtils.java

示例5: addToInventory

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
public static void addToInventory(ItemStack itemStack, InventoryBasic inventory) {
    if (itemStack != null && itemStack.stackSize != 0 && itemStack.getItem() != null) {
        int emptySlot = getFirstEmptyStack(inventory);

        if (itemStack.isItemDamaged()) {
            if (emptySlot > -1) {
                inventory.setInventorySlotContents(emptySlot, itemStack);
            }
        }
        else {
            int compatibleSlot = getExistingCompatibleStack(itemStack, inventory);
            if (compatibleSlot > -1) {
                ItemStack existingStack = inventory.getStackInSlot(compatibleSlot);
                existingStack.stackSize += itemStack.stackSize;
            }
            else if (emptySlot > -1) {
                inventory.setInventorySlotContents(emptySlot, itemStack);
            }
        }
    }
}
 
開發者ID:civilframe,項目名稱:TameHumans,代碼行數:22,代碼來源:InventoryUtils.java

示例6: 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);
	}
}
 
開發者ID:a1lic,項目名稱:McMod-CubicVillager,代碼行數:20,代碼來源:VillagerEvent.java

示例7: 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;
}
 
開發者ID:civilframe,項目名稱:TameHumans,代碼行數:10,代碼來源:InventoryUtils.java

示例8: 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;
}
 
開發者ID:civilframe,項目名稱:TameHumans,代碼行數:16,代碼來源:InventoryUtils.java

示例9: 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);
}
 
開發者ID:civilframe,項目名稱:TameHumans,代碼行數:16,代碼來源:InventoryUtils.java

示例10: onInventoryChanged

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * Called by InventoryBasic.onInventoryChanged() on a array that is never filled.
 */
@Override
public void onInventoryChanged(InventoryBasic p_76316_1_)
{
    int i = this.getMountArmorValue();
    boolean flag = this.isCamelSaddled();
    //this.func_110232_cE();

    if (this.ticksExisted > 20)
    {
    	if (!(p_76316_1_.getStackInSlot(0) == null)) {
    		if (p_76316_1_.getStackInSlot(0).getItem() ==Items.saddle){
            	this.setSaddled(true);
            	this.playSound("mob.horse.leather", 0.5F, 1.0F);
    		}        		
    	}else
		{
			this.setSaddled(false);
		}
    	
        if (i == 0 && i != this.getMountArmorValue())
        {
            this.playSound("mob.horse.armor", 0.5F, 1.0F);
        }
        else if (i != this.getMountArmorValue())
        {
            this.playSound("mob.horse.armor", 0.5F, 1.0F);
        }
    }
}
 
開發者ID:soultek101,項目名稱:projectzulu1.7.10,代碼行數:33,代碼來源:EntityCamel.java

示例11: inventoryToTag

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * InventoryBasicをNBTに変換する
 * @param inv InventoryBasic
 * @param tag 書き込むNBT
 */
public static void inventoryToTag(InventoryBasic inv, NBTTagList tag)
{
	int elements = inv.getSizeInventory();
	ItemStack[] _inv = new ItemStack[elements];
	for(int i = 0; i < elements; i++)
	{
		_inv[i] = inv.getStackInSlot(i);
	}
	VillagerData.inventoryToTag(_inv, tag);
}
 
開發者ID:a1lic,項目名稱:McMod-CubicVillager,代碼行數:16,代碼來源:VillagerData.java

示例12: updateTask

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * Updates the task
 */
public void updateTask()
{
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.theVillager.worldObj;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.field_179501_f == 0 && block instanceof BlockCrops && ((Integer)iblockstate.getValue(BlockCrops.AGE)).intValue() == 7)
        {
            world.destroyBlock(blockpos, true);
        }
        else if (this.field_179501_f == 1 && block == Blocks.air)
        {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                boolean flag = false;

                if (itemstack != null)
                {
                    if (itemstack.getItem() == Items.wheat_seeds)
                    {
                        world.setBlockState(blockpos, Blocks.wheat.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.potato)
                    {
                        world.setBlockState(blockpos, Blocks.potatoes.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.carrot)
                    {
                        world.setBlockState(blockpos, Blocks.carrots.getDefaultState(), 3);
                        flag = true;
                    }
                }

                if (flag)
                {
                    --itemstack.stackSize;

                    if (itemstack.stackSize <= 0)
                    {
                        inventorybasic.setInventorySlotContents(i, (ItemStack)null);
                    }

                    break;
                }
            }
        }

        this.field_179501_f = -1;
        this.runDelay = 10;
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:66,代碼來源:EntityAIHarvestFarmland.java

示例13: updateTask

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * Updates the task
 */
public void updateTask()
{
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.theVillager.world;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
        {
            world.destroyBlock(blockpos, true);
        }
        else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
        {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                boolean flag = false;

                if (!itemstack.func_190926_b())
                {
                    if (itemstack.getItem() == Items.WHEAT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.POTATO)
                    {
                        world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.CARROT)
                    {
                        world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
                        flag = true;
                    }
                }

                if (flag)
                {
                    itemstack.func_190918_g(1);

                    if (itemstack.func_190926_b())
                    {
                        inventorybasic.setInventorySlotContents(i, ItemStack.field_190927_a);
                    }

                    break;
                }
            }
        }

        this.currentTask = -1;
        this.runDelay = 10;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:71,代碼來源:EntityAIHarvestFarmland.java

示例14: updateTask

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * Updates the task
 */
public void updateTask()
{
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.theVillager.worldObj;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
        {
            world.destroyBlock(blockpos, true);
        }
        else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
        {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                boolean flag = false;

                if (itemstack != null)
                {
                    if (itemstack.getItem() == Items.WHEAT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.POTATO)
                    {
                        world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.CARROT)
                    {
                        world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
                        flag = true;
                    }
                }

                if (flag)
                {
                    --itemstack.stackSize;

                    if (itemstack.stackSize <= 0)
                    {
                        inventorybasic.setInventorySlotContents(i, (ItemStack)null);
                    }

                    break;
                }
            }
        }

        this.currentTask = -1;
        this.runDelay = 10;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:71,代碼來源:EntityAIHarvestFarmland.java

示例15: updateTask

import net.minecraft.inventory.InventoryBasic; //導入方法依賴的package包/類
/**
 * Updates the task
 */
public void updateTask()
{
    super.updateTask();

    if (this.interactionDelay > 0)
    {
        --this.interactionDelay;

        if (this.interactionDelay == 0)
        {
            InventoryBasic inventorybasic = this.villager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                ItemStack itemstack1 = null;

                if (itemstack != null)
                {
                    Item item = itemstack.getItem();

                    if ((item == Items.BREAD || item == Items.POTATO || item == Items.CARROT || item == Items.BEETROOT) && itemstack.stackSize > 3)
                    {
                        int l = itemstack.stackSize / 2;
                        itemstack.stackSize -= l;
                        itemstack1 = new ItemStack(item, l, itemstack.getMetadata());
                    }
                    else if (item == Items.WHEAT && itemstack.stackSize > 5)
                    {
                        int j = itemstack.stackSize / 2 / 3 * 3;
                        int k = j / 3;
                        itemstack.stackSize -= j;
                        itemstack1 = new ItemStack(Items.BREAD, k, 0);
                    }

                    if (itemstack.stackSize <= 0)
                    {
                        inventorybasic.setInventorySlotContents(i, (ItemStack)null);
                    }
                }

                if (itemstack1 != null)
                {
                    double d0 = this.villager.posY - 0.30000001192092896D + (double)this.villager.getEyeHeight();
                    EntityItem entityitem = new EntityItem(this.villager.worldObj, this.villager.posX, d0, this.villager.posZ, itemstack1);
                    float f = 0.3F;
                    float f1 = this.villager.rotationYawHead;
                    float f2 = this.villager.rotationPitch;
                    entityitem.motionX = (double)(-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
                    entityitem.motionZ = (double)(MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
                    entityitem.motionY = (double)(-MathHelper.sin(f2 * 0.017453292F) * 0.3F + 0.1F);
                    entityitem.setDefaultPickupDelay();
                    this.villager.worldObj.spawnEntityInWorld(entityitem);
                    break;
                }
            }
        }
    }
}
 
開發者ID:BlazeAxtrius,項目名稱:ExpandedRailsMod,代碼行數:63,代碼來源:EntityAIVillagerInteract.java


注:本文中的net.minecraft.inventory.InventoryBasic.getStackInSlot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。