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


Java ItemStack.copy方法代码示例

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


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

示例1: dropItemsFromInventory

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void dropItemsFromInventory(World world, BlockPos pos, CompatItemHandler inventoryItemHandler){
    for (int i = 0; i < inventoryItemHandler.getSlots(); i++) {
        ItemStack stack = inventoryItemHandler.getStackInSlot(i);
        if(!ItemStackTools.isEmpty(stack) && ItemStackTools.getStackSize(stack) != 0){
            float dX = world.rand.nextFloat()*0.8F+0.1F;
            float dY = world.rand.nextFloat()*0.8F+0.1F;
            float dZ = world.rand.nextFloat()*0.8F+0.1F;
            EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, stack.copy());
            float factor = 0.05F;
            entityItem.motionX = world.rand.nextGaussian()*factor;
            entityItem.motionY = world.rand.nextGaussian()*factor+0.2F;
            entityItem.motionZ = world.rand.nextGaussian()*factor;
            WorldTools.spawnEntity(world, entityItem);
        }
    }
}
 
开发者ID:MasterEric,项目名称:ChatBomb,代码行数:17,代码来源:ItemUtility.java

示例2: setDisplayedItemWithUpdate

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void setDisplayedItemWithUpdate(ItemStack stack, boolean p_174864_2_)
{
    if (!stack.func_190926_b())
    {
        stack = stack.copy();
        stack.func_190920_e(1);
        stack.setItemFrame(this);
    }

    this.getDataManager().set(ITEM, stack);
    this.getDataManager().setDirty(ITEM);

    if (!stack.func_190926_b())
    {
        this.playSound(SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, 1.0F, 1.0F);
    }

    if (p_174864_2_ && this.hangingPosition != null)
    {
        this.world.updateComparatorOutputLevel(this.hangingPosition, Blocks.AIR);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:23,代码来源:EntityItemFrame.java

示例3: attemptSmelting

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/** Attempt to smelt the given item.<br>
 * This returns instantly, callously disregarding such frivolous niceties as cooking times or the presence of a furnace.<br>
 * It will, however, consume fuel from the player's inventory.
 * @param player
 * @param input the raw ingredients we want to cook.
 * @return true if cooking was successful.
 */
public static boolean attemptSmelting(EntityPlayerMP player, ItemStack input)
{
    if (player == null || input == null)
        return false;
    List<ItemStack> ingredients = new ArrayList<ItemStack>();
    ingredients.add(input);
    ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(input);
    if (isOutput == null)
        return false;
    int cookingTime = 200;  // Seems to be hard-coded in TileEntityFurnace.
    if (playerHasIngredients(player, ingredients) && totalBurnTimeInInventory(player) >= cookingTime)
    {
        removeIngredientsFromPlayer(player, ingredients);
        burnInventory(player, cookingTime, input);

        ItemStack resultForInventory = isOutput.copy();
        ItemStack resultForReward = isOutput.copy();
        player.inventory.addItemStackToInventory(resultForInventory);
        RewardForCollectingItemImplementation.GainItemEvent event = new RewardForCollectingItemImplementation.GainItemEvent(resultForReward);
        MinecraftForge.EVENT_BUS.post(event);

        return true;
    }
    return false;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:33,代码来源:CraftingHelper.java

示例4: dropItemOrSelf

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void dropItemOrSelf(@Nullable Entity entityIn, boolean p_146065_2_)
{
    if (this.world.getGameRules().getBoolean("doEntityDrops"))
    {
        ItemStack itemstack = this.getDisplayedItem();

        if (entityIn instanceof EntityPlayer)
        {
            EntityPlayer entityplayer = (EntityPlayer)entityIn;

            if (entityplayer.capabilities.isCreativeMode)
            {
                this.removeFrameFromMap(itemstack);
                return;
            }
        }

        if (p_146065_2_)
        {
            this.entityDropItem(new ItemStack(Items.ITEM_FRAME), 0.0F);
        }

        if (!itemstack.func_190926_b() && this.rand.nextFloat() < this.itemDropChance)
        {
            itemstack = itemstack.copy();
            this.removeFrameFromMap(itemstack);
            this.entityDropItem(itemstack, 0.0F);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:31,代码来源:EntityItemFrame.java

示例5: C0EPacketClickWindow

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C0EPacketClickWindow(int windowId, int slotId, int usedButton, int mode, ItemStack clickedItem, short actionNumber)
{
    this.windowId = windowId;
    this.slotId = slotId;
    this.usedButton = usedButton;
    this.clickedItem = clickedItem != null ? clickedItem.copy() : null;
    this.actionNumber = actionNumber;
    this.mode = mode;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:10,代码来源:C0EPacketClickWindow.java

示例6: setSearchStack

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void setSearchStack(@Nonnull ItemStack stack) {
    if (!stack.isEmpty() && stackPredicate.test(stack)) {
        stack = stack.copy();
        stack.setCount(1);
        inventory.setStackInSlot(0, stack);
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:8,代码来源:GuiInventorySearcher.java

示例7: dropRecord

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void dropRecord(World worldIn, BlockPos pos, IBlockState state)
{
    if (!worldIn.isRemote)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof BlockJukebox.TileEntityJukebox)
        {
            BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox = (BlockJukebox.TileEntityJukebox)tileentity;
            ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();

            if (itemstack != null)
            {
                worldIn.playEvent(1010, pos, 0);
                worldIn.playRecord(pos, (SoundEvent)null);
                blockjukebox$tileentityjukebox.setRecord((ItemStack)null);
                float f = 0.7F;
                double d0 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
                double d1 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
                double d2 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
                ItemStack itemstack1 = itemstack.copy();
                EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, itemstack1);
                entityitem.setDefaultPickupDelay();
                worldIn.spawnEntityInWorld(entityitem);
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:29,代码来源:BlockJukebox.java

示例8: updateMachineTier

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void updateMachineTier(World world, EntityPlayer player, EnumHand hand, BlockPos pos, ItemStack stack) {
	if (stack.getItem() == ModItems.itemChip) {
		ChipTypes newType = ChipTypes.values()[stack.getItemDamage() % ChipTypes.values().length];
		ChipTypes currentType = (ChipTypes) world.getBlockState(pos).getValue(TYPE);
		IBlockState newState = world.getBlockState(pos).withProperty(TYPE, newType);
		if (newType.getID() > currentType.getID()) {
			world.setBlockState(pos, newState, 2);
		}
		ItemStack newStack = stack.copy();
		newStack.shrink(1);
		player.setHeldItem(hand, newStack);
		if (player.getHeldItem(hand).getCount() <= 0)
			player.setHeldItem(hand, ItemStack.EMPTY);
	}
}
 
开发者ID:IvanSteklow,项目名称:VanillaExtras,代码行数:16,代码来源:BlockMachine.java

示例9: C08PacketPlayerBlockPlacement

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C08PacketPlayerBlockPlacement(BlockPos positionIn, int placedBlockDirectionIn, ItemStack stackIn, float facingXIn, float facingYIn, float facingZIn)
{
    this.position = positionIn;
    this.placedBlockDirection = placedBlockDirectionIn;
    this.stack = stackIn != null ? stackIn.copy() : null;
    this.facingX = facingXIn;
    this.facingY = facingYIn;
    this.facingZ = facingZIn;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:10,代码来源:C08PacketPlayerBlockPlacement.java

示例10: dispense

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
protected void dispense(World worldIn, BlockPos pos)
{
    BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
    TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();

    if (tileentitydispenser != null)
    {
        int i = tileentitydispenser.getDispenseSlot();

        if (i < 0)
        {
            worldIn.playAuxSFX(1001, pos, 0);
        }
        else
        {
            ItemStack itemstack = tileentitydispenser.getStackInSlot(i);

            if (itemstack != null)
            {
                EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
                BlockPos blockpos = pos.offset(enumfacing);
                IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
                ItemStack itemstack1;

                if (iinventory == null)
                {
                    itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);

                    if (itemstack1 != null && itemstack1.stackSize <= 0)
                    {
                        itemstack1 = null;
                    }
                }
                else
                {
                    itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());

                    if (itemstack1 == null)
                    {
                        itemstack1 = itemstack.copy();

                        if (--itemstack1.stackSize <= 0)
                        {
                            itemstack1 = null;
                        }
                    }
                    else
                    {
                        itemstack1 = itemstack.copy();
                    }
                }

                tileentitydispenser.setInventorySlotContents(i, itemstack1);
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:58,代码来源:BlockDropper.java

示例11: addItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void addItem(EntityPlayer player, Entity_AA turret, ItemStack playerStack)
{
	int slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] == null)	// That spot is free
		{
			turret.storage[slot] = playerStack.copy();	// Stored
			if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
			
			if (playerStack.getItem() == Items.writable_book && AI_Targeting.isNameOnWhitelist(turret, Commands.cmdStayStationary))
			{
				//System.out.println("[ARMS ASSISTANT] Received a book with STAY command. Setting target position");
				turret.stationaryX = turret.posX;
				turret.stationaryY = turret.posY;
				turret.stationaryZ = turret.posZ;
			}
			
			// Informing the client about this change
			NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
					Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
			
			return;	// We're done here
		}
		// else, there's something in there
		
		slot += 1;
	}
	
	// No free spot found. What about existing ones?
	slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] != null)
		{				
			boolean skip = false;
			
			if (!(turret.storage[slot].getItem() instanceof _AmmoBase)) { skip = true; }	// Not ammunition, hm?
			
			if (turret.storage[slot].getItemDamage() < turret.storage[slot].getMaxDamage()) { skip = true; }	// Not empty
			
			if (!skip)
			{					
				// Has an empty magazine in there, so replacing that now
				dropSingleItem(turret, turret.storage[slot].copy());
				turret.storage[slot] = playerStack.copy();	// Stored
				
				if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
				
				// Informing the client about this change
				NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
						Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
				return;
			}
			// else, not a magazine
		}
		// else, no free spot found but this is null? Da fuq?
		
		slot += 1;
	}
}
 
开发者ID:Domochevsky,项目名称:minecraft-quiverbow,代码行数:64,代码来源:AI_Storage.java

示例12: transferStackInSlot

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(slotNumber);

	if(slot != null && slot.getHasStack()) {
		ItemStack slotStack = slot.getStack();
		itemstack = slotStack.copy();

		if(slotNumber == 5 || slotNumber == 6 || slotNumber == 7 || slotNumber == 8 || slotNumber == 9 || slotNumber == 10) {
			if(!this.mergeItemStack(slotStack, 11, 47, true)) {
				return null;
			}

			slot.onSlotChange(slotStack, itemstack);
		} else if(slotNumber != 0 && slotNumber != 1 && slotNumber != 2 && slotNumber != 3 && slotNumber != 4) {
			if(this.tileEntity.isItemUsedInRecipe(slotStack)) {
				if(!this.mergeItemStack(slotStack, 0, 3, false)) {
					return null;
				}
			} else if(TileEntityMachineRepairingForge.isItemFuelBurning(slotStack)) {
				if(!this.mergeItemStack(slotStack, 4, 5, false)) {
					return null;
				}
			} else if(TileEntityMachineRepairingForge.isItemFuelElectrical(slotStack)) {
				if(!this.mergeItemStack(slotStack, 3, 4, false)) {
					return null;
				}
			} else if(slotNumber >= 11 && slotNumber < 38) {
				if(!this.mergeItemStack(slotStack, 0, 2, false)) {
					return null;
				}
			} else if(slotNumber >= 38 && slotNumber < 47 && !this.mergeItemStack(slotStack, 0, 2, false)) {
				return null;
			}
		} else if(!this.mergeItemStack(slotStack, 11, 47, false)) {
			return null;
		}

		if(slotStack.stackSize == 0) {
			slot.putStack((ItemStack) null);
		} else {
			slot.onSlotChanged();
		}

		if(slotStack.stackSize == itemstack.stackSize) {
			return null;
		}

		slot.onPickupFromSlot(player, slotStack);
	}

	return itemstack;
}
 
开发者ID:viddeno,项目名称:Technical,代码行数:54,代码来源:ContainerMachine.java

示例13: C10PacketCreativeInventoryAction

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C10PacketCreativeInventoryAction(int slotIdIn, ItemStack stackIn)
{
    this.slotId = slotIdIn;
    this.stack = stackIn != null ? stackIn.copy() : null;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:6,代码来源:C10PacketCreativeInventoryAction.java

示例14: transferStackInSlot

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Take a stack from the specified inventory slot.
 */
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
    ItemStack itemstack = null;
    Slot slot = (Slot)this.inventorySlots.get(index);

    if (slot != null && slot.getHasStack())
    {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();

        if (index == 2)
        {
            if (!this.mergeItemStack(itemstack1, 3, 39, true))
            {
                return null;
            }

            slot.onSlotChange(itemstack1, itemstack);
        }
        else if (index != 0 && index != 1)
        {
            if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2, false))
            {
                return null;
            }
        }
        else if (!this.mergeItemStack(itemstack1, 3, 39, false))
        {
            return null;
        }

        if (itemstack1.stackSize == 0)
        {
            slot.putStack((ItemStack)null);
        }
        else
        {
            slot.onSlotChanged();
        }

        if (itemstack1.stackSize == itemstack.stackSize)
        {
            return null;
        }

        slot.onPickupFromSlot(playerIn, itemstack1);
    }

    return itemstack;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:54,代码来源:ContainerRepair.java

示例15: transferStackInSlot

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Take a stack from the specified inventory slot.
 */
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
    ItemStack itemstack = null;
    Slot slot = (Slot)this.inventorySlots.get(index);

    if (slot != null && slot.getHasStack())
    {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();

        if ((index < 0 || index > 2) && index != 3)
        {
            if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(itemstack1))
            {
                if (!this.mergeItemStack(itemstack1, 3, 4, false))
                {
                    return null;
                }
            }
            else if (ContainerBrewingStand.Potion.canHoldPotion(itemstack))
            {
                if (!this.mergeItemStack(itemstack1, 0, 3, false))
                {
                    return null;
                }
            }
            else if (index >= 4 && index < 31)
            {
                if (!this.mergeItemStack(itemstack1, 31, 40, false))
                {
                    return null;
                }
            }
            else if (index >= 31 && index < 40)
            {
                if (!this.mergeItemStack(itemstack1, 4, 31, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 4, 40, false))
            {
                return null;
            }
        }
        else
        {
            if (!this.mergeItemStack(itemstack1, 4, 40, true))
            {
                return null;
            }

            slot.onSlotChange(itemstack1, itemstack);
        }

        if (itemstack1.stackSize == 0)
        {
            slot.putStack((ItemStack)null);
        }
        else
        {
            slot.onSlotChanged();
        }

        if (itemstack1.stackSize == itemstack.stackSize)
        {
            return null;
        }

        slot.onPickupFromSlot(playerIn, itemstack1);
    }

    return itemstack;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:78,代码来源:ContainerBrewingStand.java


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