本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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);;
}
}
示例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);
}
示例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"));
}
}
}