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


Java InventoryHelper.spawnItemStack方法代码示例

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


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

示例1: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    TileEntity tile = worldIn.getTileEntity(pos);

    if (tile != null)
    {
        IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (itemHandler != null)
        {
            for (int i = 0; i < itemHandler.getSlots(); i++)
            {
                ItemStack stack = itemHandler.getStackInSlot(i);
                if (!stack.isEmpty())
                {
                    InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
                }
            }
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:24,代码来源:BlockMixin.java

示例2: onBlockActivated

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	ItemStack item = playerIn.getHeldItem(hand);
	TileEntity tileEntity = worldIn.getTileEntity(pos);
	if(tileEntity instanceof BaseTileEntityHarshenSingleItemInventory)
		if(((BaseTileEntityHarshenSingleItemInventory)tileEntity).canAddItem() && Item.getItemFromBlock(Blocks.AIR) != item.getItem())
		{
			int i =  item.getCount() - 1;
			if(((BaseTileEntityHarshenSingleItemInventory)tileEntity).setItem(item))
				playerIn.setHeldItem(hand, new ItemStack(item.getItem(), i, item.getMetadata(), item.serializeNBT()));
		}
		else if (!((BaseTileEntityHarshenSingleItemInventory) tileEntity).canAddItem())
		{
			ItemStack stack = ((BaseTileEntityHarshenSingleItemInventory)tileEntity).getItem();
			((BaseTileEntityHarshenSingleItemInventory)tileEntity).setItemAir();
			if(!worldIn.isRemote)
				InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY() + 0.7f, pos.getZ(), stack);
		}

	return true;
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:23,代码来源:BaseBlockHarshenSingleInventory.java

示例3: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityInfusionAltar te = (TileEntityInfusionAltar) world.getTileEntity(pos);
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	for (int i = 0; i < cap.getSlots(); ++i)
	{
		ItemStack itemstack = cap.getStackInSlot(i);

		if (!itemstack.isEmpty())
		{
			InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
		}
	}

	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:19,代码来源:BlockInfusionAltar.java

示例4: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityAnimusMaterializer te = (TileEntityAnimusMaterializer) world.getTileEntity(pos);
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	for (int i = 0; i < cap.getSlots(); ++i)
	{
		ItemStack itemstack = cap.getStackInSlot(i);

		if (!itemstack.isEmpty())
		{
			InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
		}
	}

	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:19,代码来源:BlockAnimusMaterializer.java

示例5: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityAnalyzer te = (TileEntityAnalyzer) world.getTileEntity(pos);

	if (!te.getStack(0).isEmpty())
	{
		InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), te.getStack(0).copy());
	}

	if (!te.getStack(1).isEmpty())
	{
		InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), te.getStack(1).copy());
	}
	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:17,代码来源:BlockAnalyzer.java

示例6: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityInfernalSmelter te = (TileEntityInfernalSmelter) world.getTileEntity(pos);
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	for (int i = 0; i < cap.getSlots(); ++i)
	{
		ItemStack itemstack = cap.getStackInSlot(i);

		if (!itemstack.isEmpty())
		{
			InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
		}
	}

	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:18,代码来源:BlockInfernalSmelter.java

示例7: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityWritingDesk te = (TileEntityWritingDesk) world.getTileEntity(pos);
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	for (int i = 0; i < cap.getSlots(); ++i)
	{
		ItemStack itemstack = cap.getStackInSlot(i);

		if (!itemstack.isEmpty())
		{
			InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
		}
	}

	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:19,代码来源:BlockWritingDesk.java

示例8: handle

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
protected void handle(final EntityPlayer sender)
{
    if (sender.inventoryContainer != null)
    {
        ItemStack stack = sender.openContainer.getSlot(slotID).getStack();

        if (stack.getItem() == QBarItems.MULTIBLOCK_BOX && stack.hasTagCompound())
        {
            NonNullList<ItemStack> items = NonNullList
                    .withSize(stack.getTagCompound().getTagList("Items", 10).tagCount(), ItemStack.EMPTY);
            ItemUtils.loadAllItems(stack.getTagCompound(), items);
            for (ItemStack item : items)
            {
                if (!sender.addItemStackToInventory(item))
                    InventoryHelper.spawnItemStack(sender.world, sender.posX, sender.posY, sender.posZ, item);
            }
            stack.setCount(0);
        }
    }
}
 
开发者ID:OPMCorp,项目名称:Qbar,代码行数:22,代码来源:MultiblockBoxPacket.java

示例9: onItemUse

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
	if (world.isRemote)
		return null;
	IFluidHandler h = FluidUtil.getFluidHandler(world, pos, side);
	if (h != null) {
		for (Entry<FluidStack, ItemStack> e : fluidToItem.entrySet()) {
			FluidStack drain = h.drain(new FluidStack(e.getKey(), e.getKey().amount), false);
			if (e.getKey().isFluidStackIdentical(drain)) {
				h.drain(drain, true);
				ItemStack s = e.getValue().copy();
				stack.shrink(1);
				player.setHeldItem(hand, stack);
				if (!player.inventory.addItemStackToInventory(s)) {
					InventoryHelper.spawnItemStack(world, player.posX, player.posY, player.posZ, s);
				}
				player.inventoryContainer.detectAndSendChanges();
				return EnumActionResult.SUCCESS;
			}
		}
	}
	return null;
}
 
开发者ID:tom5454,项目名称:Toms-Mod,代码行数:24,代码来源:TMResource.java

示例10: ejectContents

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
public void ejectContents(boolean ejectFuel)
{
	if(ejectFuel)
	{
		InventoryHelper.spawnItemStack(world, getPos().getX(), getPos().getY(), getPos().getZ(), this.getStackInSlot(FUEL_SLOT));
		this.setInventorySlotContents(FUEL_SLOT, ItemStack.EMPTY);
	}
	else
	{
		for(int i = TOOL_SLOT; i < this.getSizeInventory(); i++)
		{
			if(i == OUTPUT_SLOT && cookingTimer > 0)
			{
				continue;
			}
			InventoryHelper.spawnItemStack(world, getPos().getX(), getPos().getY(), getPos().getZ(), this.getStackInSlot(i));
			this.setInventorySlotContents(i, ItemStack.EMPTY);
		}
	}

}
 
开发者ID:Deadrik,项目名称:TFC2,代码行数:22,代码来源:TileFirepit.java

示例11: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter)world.getTileEntity(pos);
	if (tileEntityTeleporter != null)
	{
		tileEntityTeleporter.removeFromNetwork();

		if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
		{
			IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
			ItemStack stack = handler.getStackInSlot(0);
			if (!stack.isEmpty())
			{
				stack = stack.copy();
				InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack);
			}
		}
	}

	// super _must_ be called last because it removes the tile entity
	super.breakBlock(world, pos, state);
}
 
开发者ID:dyeo,项目名称:VanillaTeleporter,代码行数:24,代码来源:BlockTeleporter.java

示例12: breakBlockRecall

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
public void breakBlockRecall(World world, World nextWorld, BlockPos pos, BlockPos nextPos, IBlockState state, EntityPlayerMP player)
{
	TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter)world.getTileEntity(pos);
	if (tileEntityTeleporter != null)
	{
		tileEntityTeleporter.removeFromNetwork();

		if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
		{
			IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
			ItemStack stack = handler.getStackInSlot(0);
			if (!stack.isEmpty())
			{
				InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY()+1, nextPos.getZ(), stack);
			}
		}
	}

	InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY()+1, nextPos.getZ(), new ItemStack(ModBlocks.TELEPORTER,1,getMetaFromState(state)));
	world.setBlockToAir(pos);
	while(world.getTileEntity(pos) != null)
	{
		world.removeTileEntity(pos);
	}
}
 
开发者ID:dyeo,项目名称:VanillaTeleporter,代码行数:26,代码来源:BlockTeleporter.java

示例13: doQuickMove

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
private void doQuickMove(int howMany, EntityPlayerMP player, ItemResource targetResource, ItemStorageListener listener)
{
    if(howMany == 0) return;
    int toMove = 0;
    try
    {
        toMove = LogisticsService.ITEM_SERVICE.executor.submit( () ->
        {
            return (int) listener.takeUpTo(targetResource, howMany, false, null);
        }, true).get();
    }
    catch (Exception e)
    {
        Log.error("Error in open container item handling", e);
    }
    
    if(toMove == 0) return;
    ItemStack newStack = targetResource.sampleItemStack();
    newStack.setCount(toMove);
    player.inventory.addItemStackToInventory(newStack);
    if(!newStack.isEmpty())
    {
        InventoryHelper.spawnItemStack(player.world, player.posX, player.posY, player.posZ, newStack);;
    }
}
 
开发者ID:grondag,项目名称:Hard-Science,代码行数:26,代码来源:PacketOpenContainerStorageInteraction.java

示例14: breakBlock

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{	
	BaseTileEntityHarshenSingleItemInventory te = (BaseTileEntityHarshenSingleItemInventory) worldIn.getTileEntity(pos);
	IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	if(!worldIn.isRemote)
		if(isBreakNBT(handler.getStackInSlot(0)))
		{
			ItemStackHandler handlerStack = new ItemStackHandler(1);
			handlerStack.setStackInSlot(0, handler.getStackInSlot(0));
			ItemStack stack = new ItemStack(this);
	        String stackName = "";
			NBTTagCompound nbttagcompound = new NBTTagCompound();
			if(handlerStack.getStackInSlot(0).getItem() != Items.AIR)
			{
		        nbttagcompound.setTag("ItemStackHandler", handlerStack.serializeNBT());
		        stackName +=  I18n.translateToLocal(handlerStack.getStackInSlot(0).getItem().getUnlocalizedName() + ".name");
			}
			addNBT(handler.getStackInSlot(0), nbttagcompound, worldIn, pos);
			if(!nbttagcompound.getKeySet().isEmpty() || !handlerStack.getStackInSlot(0).isEmpty())
			{
				stack.setTagCompound(nbttagcompound);
				stackName += extraName(nbttagcompound, handlerStack.getStackInSlot(0).getItem() != Items.AIR);
				stackName = stackName.equals("")? "�r" + getLocalizedName() : "�r" + getLocalizedName() + " (" + stackName + ")";
				stack.setStackDisplayName(stackName);
			}
			if(!creativeBreakMap.containsKey(pos) || !creativeBreakMap.get(pos))
				worldIn.spawnEntity(new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack));
			creativeBreakMap.remove(pos);
		}
		else
			InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(0));
	super.breakBlock(worldIn, pos, state);
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:36,代码来源:BaseBlockHarshenSingleInventory.java

示例15: onBlockHarvested

import net.minecraft.inventory.InventoryHelper; //导入方法依赖的package包/类
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
{
	if(player.capabilities.isCreativeMode)
	{
		super.onBlockHarvested(worldIn, pos, state, player);
		return;
	}
	ItemStack item = player.inventory.getCurrentItem();
	if(item.getItem() instanceof SoulHarsherPickaxe)
	{
		if(!worldIn.isRemote)
		{
			InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(HarshenItems.HARSHEN_SOUL_FRAGMENT));
			super.onBlockHarvested(worldIn, pos, state, player);
			player.sendMessage((ITextComponent) new TextComponentTranslation("message.success"));
		}	
	}
	else
	{
		player.attackEntityFrom(DamageSource.MAGIC, 21);
		if(!worldIn.isRemote)
		{
			player.sendMessage((ITextComponent) new TextComponentTranslation("message.failed"));
		}
	}

}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:29,代码来源:HarshenSoulOre.java


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