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


Java ItemHandlerHelper.giveItemToPlayer方法代碼示例

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


在下文中一共展示了ItemHandlerHelper.giveItemToPlayer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onItemUse

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!(stack.getItem() instanceof MooncakeMold))
        return EnumActionResult.PASS;

    if (!stack.hasTagCompound())
        return EnumActionResult.PASS;

    if (world.getBlockState(pos).getBlock() == Blocks.IRON_BLOCK) {
        if (!stack.getTagCompound().hasKey("hitCount"))
            stack.getTagCompound().setInteger("hitCount", 0);
        stack.getTagCompound().setInteger("hitCount", stack.getTagCompound().getInteger("hitCount") + 1);

        if (stack.getTagCompound().getInteger("hitCount") >= 5) {
            ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(MooncakeConstants.RAW_MOONCAKE_ITEM, 1, stack.getTagCompound().getInteger("meta")));
            stack.setTagCompound(null);
        }

        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.PASS;
}
 
開發者ID:TeamCovertDragon,項目名稱:MooncakeCraft,代碼行數:26,代碼來源:MooncakeMold.java

示例2: onBlockActivated

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack stack = player.getHeldItem(hand);
	boolean isBlock = stack.getItem() instanceof ItemBlock && stack.getItem() != ModItems.ANGSTROM;
	if(!world.isRemote && isBlock) {
		//Replace
		ItemBlock item = (ItemBlock) stack.getItem();
		Block block = Block.getBlockFromItem(item);
		int meta = item.getMetadata(stack);
		IBlockState inState = block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, player, hand);
		world.setBlockState(pos, inState);
		block.onBlockPlacedBy(world, pos, inState, player, stack);
		SoundType sound = block.getSoundType(inState, world, pos, player);
		world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), sound.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F);
		//Exchange
		ItemStack drop = new ItemStack(Item.getItemFromBlock(this));
		ItemHandlerHelper.giveItemToPlayer(player, drop);
		if(!player.capabilities.isCreativeMode) {
			stack.shrink(1);
		}
	}
	return isBlock;
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:24,代碼來源:BlockAngstrom.java

示例3: enchantItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public boolean enchantItem(EntityPlayer playerIn, int id) {
	if(id == 256) {
		if(mercenary.getOwner() == playerIn) {
			ItemHandlerHelper.giveItemToPlayer(playerIn, new ItemStack(TF2weapons.itemTF2, 1, 2));
			this.mercenary.setOwner(null);
		}
		else if(mercenary.getOwnerId() == null && playerIn.inventory.hasItemStack(new ItemStack(TF2weapons.itemTF2, 1, 2))) {
			playerIn.inventory.clearMatchingItems(TF2weapons.itemTF2, 2, 1, null);
			this.mercenary.setOwner(playerIn);
		}
	}
	if(id == 257) {
		if(mercenary.getOwner() == playerIn) {
			playerIn.inventory.clearMatchingItems(TF2weapons.itemTF2, 2, 1, null);
			this.mercenary.setSharing(true);
		}
	}
	else if(id >= 260 && mercenary.getOwner() == playerIn) {
		int index = (id - 260) % EntityTF2Character.Order.values().length;
		this.mercenary.setOrder(Order.values()[index]);
	}
	return true;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:25,代碼來源:ContainerMercenary.java

示例4: entityJoinWorld

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@SubscribeEvent
public static void entityJoinWorld(EntityJoinWorldEvent event)
{
    Entity e = event.getEntity();
    if (e instanceof EntityPlayer && !e.getEntityWorld().isRemote)
    {
        for (String g : giveOnFirstJoin)
        {
            String tag = MODID + ":givenBook:" + g;
            if (!e.getTags().contains(tag))
            {
                ItemHandlerHelper.giveItemToPlayer((EntityPlayer) e, guidebook.of(new ResourceLocation(g)));
                e.addTag(tag);
            }
        }
    }
}
 
開發者ID:gigaherz,項目名稱:Guidebook,代碼行數:18,代碼來源:GuidebookMod.java

示例5: onItemUseFinish

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
	
	if (worldIn.isRemote) return stack;
	if (entityLiving instanceof EntityPlayer) {
		EntityPlayer entityplayer = (EntityPlayer)entityLiving;
		entityplayer.getFoodStats().addStats(this.amount, this.saturation);
           this.addEffects(stack, worldIn, entityplayer);
           entityplayer.addStat(StatList.getObjectUseStats(this));
 	     }
	EntityPlayer player = entityLiving instanceof EntityPlayer ? ((EntityPlayer) entityLiving) : null;
	if (!player.isCreative())
	{
		if (stack.getCount() <= 1)
		return this.getReturnStack();

		else
		{
			// this code should never run under normal circumstances
			ItemHandlerHelper.giveItemToPlayer(player, this.getReturnStack());
			stack.shrink(1);
		}
	}
	return stack;
}
 
開發者ID:TEAMModding,項目名稱:KalStuff,代碼行數:25,代碼來源:ItemDrink.java

示例6: onContainerClosed

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public void onContainerClosed(EntityPlayer playerIn)
{
    super.onContainerClosed(playerIn);

    if (!this.world.isRemote)
    {
        for (int i = 0; i < 9; ++i)
        {
            ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);

            if (itemstack.getCount() > 0)
            {
                ItemHandlerHelper.giveItemToPlayer(playerIn, itemstack);
            }
        }
    }
}
 
開發者ID:gigaherz,項目名稱:Ender-Rift,代碼行數:19,代碼來源:ContainerCraftingBrowser.java

示例7: takeItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
default void takeItem(EntityPlayer player) {
	ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
	if(hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
		IItemHandler handler = getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
		if(handler == null) return;

		ItemStack contained = handler.extractItem(0, Integer.MAX_VALUE, false);
		if(stack.isEmpty()) {
			player.setHeldItem(EnumHand.MAIN_HAND, contained);
		} else {
			ItemHandlerHelper.giveItemToPlayer(player, contained);
		}
	}
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:15,代碼來源:IQuantumTile.java

示例8: onBlockActivated

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {

	TileEntity te = world.getTileEntity(pos);
	if (te != null && te instanceof TileArtisia && hand == EnumHand.MAIN_HAND) {
		if (((TileArtisia)te).getItem() != null && !world.isRemote) {
			ItemStack tilestack = ((TileArtisia)te).getItem().copy();
			((TileArtisia)te).setItem(null);
			ItemHandlerHelper.giveItemToPlayer(player, tilestack);
		}
		((TileArtisia)te).markBlockForUpdate();
	}
	return false;
}
 
開發者ID:bafomdad,項目名稱:uniquecrops,代碼行數:15,代碼來源:Artisia.java

示例9: magnetItems

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public static void magnetItems(World world, EntityPlayer player, List<ItemStack> items)
{
	for (ItemStack item : items)
	{
		ItemHandlerHelper.giveItemToPlayer(player, item);
	}
}
 
開發者ID:murapix,項目名稱:Inhuman-Resources,代碼行數:8,代碼來源:ItemMagnet.java

示例10: onBlockActivated

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

	ItemStack heldItem = playerIn.getHeldItem(hand);

	if (!worldIn.isRemote) {
		TileAssemblyTable table = getTE(worldIn, pos);

		if (table.behavior != null) {
			boolean allowedToEdit = table.behavior.canEditItems(table.inventory, table.output, table.craftingTime);
			if (allowedToEdit)
				table.behavior = null;
			else return true;
		}

		if (table.output.getStackInSlot(0).isEmpty()) {
			ItemHandlerHelper.giveItemToPlayer(playerIn, table.output.extractItem(0, 64, false));
			playerIn.openContainer.detectAndSendChanges();
		} else if (!heldItem.isEmpty()) {
			ItemStack stack = heldItem.copy();
			stack.setCount(1);
			ItemStack insert = ItemHandlerHelper.insertItem(table.inventory, stack, false);
			if (insert.isEmpty())
				heldItem.setCount(heldItem.getCount() - 1);
			playerIn.openContainer.detectAndSendChanges();
		} else if (CapsUtils.getOccupiedSlotCount(table.inventory) > 0) {
			ItemHandlerHelper.giveItemToPlayer(playerIn, table.inventory.extractItem(CapsUtils.getLastOccupiedSlot(table.inventory), 1, false));
			playerIn.openContainer.detectAndSendChanges();
		}
		table.markDirty();
	}
	return true;
}
 
開發者ID:TeamWizardry,項目名稱:TMT-Refraction,代碼行數:34,代碼來源:BlockAssemblyTable.java

示例11: finishSeeds

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private static void finishSeeds(EntityItemPickupEvent event, EntityItem entity, EntityPlayer player, @Nonnull ItemStack leftover) {
    entity.setDead();
    event.setCanceled(true);
    player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.world.rand.nextFloat() - player.world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    if (!leftover.isEmpty()) {
        ItemHandlerHelper.giveItemToPlayer(player, leftover);
    }
}
 
開發者ID:GirafiStudios,項目名稱:Culinary-Cultivation,代碼行數:9,代碼來源:ItemSeedBag.java

示例12: onItemUseFinish

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
	
	if (worldIn.isRemote) return stack;
	if (entityLiving instanceof EntityPlayer) {
		EntityPlayer entityplayer = (EntityPlayer)entityLiving;
		entityplayer.getFoodStats().addStats(this.getAmount(), this.getSaturation());
           this.addEffects(stack, worldIn, entityplayer);
           entityplayer.addStat(StatList.getObjectUseStats(this));
 	     }
	
	EntityPlayer player = entityLiving instanceof EntityPlayer ? ((EntityPlayer) entityLiving) : null;
	System.out.println(player);
	if (!player.capabilities.isCreativeMode)
	{
		if (stack.attemptDamageItem(1, new Random()))
		{
			if (stack.getCount() <= 1)
				return this.getReturnStack();
			
			else
			{
				// this code should never run under normal circumstances
				ItemHandlerHelper.giveItemToPlayer(player, this.getReturnStack());
				stack.shrink(1);
				stack.getItem().setDamage(stack, 0);;
			}
		}
	}
	return stack;
}
 
開發者ID:TEAMModding,項目名稱:KalStuff,代碼行數:31,代碼來源:ItemSoda.java

示例13: clearCraftingGrid

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public void clearCraftingGrid(EntityPlayer playerIn)
{
    boolean isRemote = tile.getWorld().isRemote;

    if (!this.world.isRemote)
    {
        IItemHandler parent = tile.getCombinedInventory();

        for (int i = 0; i < 9; ++i)
        {
            ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i);

            if (!isRemote && itemstack.getCount() > 0)
            {
                ItemStack remaining = ItemStack.EMPTY;
                if (parent != null)
                    remaining = AutomationHelper.insertItems(parent, itemstack);

                if (remaining.getCount() > 0)
                {
                    ItemHandlerHelper.giveItemToPlayer(playerIn, remaining);

                    if (remaining.getCount() != itemstack.getCount())
                        tile.markDirty();
                }
                else
                {
                    tile.markDirty();
                }
            }
        }
    }

    if (isRemote)
    {
        EnderRiftMod.channel.sendToServer(new ClearCraftingGrid(windowId));
    }

    this.onCraftMatrixChanged(craftMatrix);
}
 
開發者ID:gigaherz,項目名稱:Ender-Rift,代碼行數:41,代碼來源:ContainerCraftingBrowser.java

示例14: onStrangeUpdate

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
public static void onStrangeUpdate(ItemStack stack, EntityLivingBase player) {
	int points = 0;
	if (stack.getItem() instanceof ItemMedigun) {
		points = stack.getTagCompound().getInteger("Ubercharges");
	} else if (stack.getItem() instanceof ItemCloak) {
		points = stack.getTagCompound().getInteger("CloakTicks") / 400;
	} else {
		points = stack.getTagCompound().getInteger("Kills");
		points += stack.getTagCompound().getInteger("PlayerKills") * 5;
	}
	int calculatedLevel = 0;

	if (points >= STRANGE_KILLS[STRANGE_KILLS.length - 1]) {
		calculatedLevel = STRANGE_KILLS.length - 1;
	} else {
		for (int i = 1; i < STRANGE_KILLS.length; i++)
			if (points < STRANGE_KILLS[i]) {
				calculatedLevel = i - 1;
				break;
			}
	}

	if (calculatedLevel > stack.getTagCompound().getInteger("StrangeLevel")) {
		stack.getTagCompound().setInteger("StrangeLevel", calculatedLevel);
		if(player instanceof EntityPlayer) {
			((EntityPlayer) player).addExperience(40 * calculatedLevel);
			ItemHandlerHelper.giveItemToPlayer((EntityPlayer) player, new ItemStack(TF2weapons.itemTF2, calculatedLevel<10?MathHelper.ceil(calculatedLevel/2f) : calculatedLevel - 5, 6));
			if(calculatedLevel == 20)
				ItemHandlerHelper.giveItemToPlayer((EntityPlayer) player, new ItemStack(TF2weapons.itemTF2, 2, 7));
		}
		/*final int level = calculatedLevel;
		if (player instanceof EntityPlayerMP) {
			((EntityPlayerMP) player).addStat(new Achievement(Integer.toString(player.getRNG().nextInt()), "strangeUp", 0, 0, stack, null) {
				@Override
				public ITextComponent getStatName() {
					return super.getStatName().appendText(STRANGE_TITLES[level]);
				}
			});
		}*/
	}
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:42,代碼來源:TF2EventsCommon.java

示例15: onItemRightClick

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemstack, World world, EntityPlayer player, EnumHand hand)
{
    FluidStack fluidStack = getFluid(itemstack);
    // empty bucket shouldn't exist, do nothing since it should be handled by the bucket event
    if (fluidStack == null)
    {
        return ActionResult.newResult(EnumActionResult.PASS, itemstack);
    }

    // clicked on a block?
    RayTraceResult mop = this.rayTrace(world, player, false);

    if(mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK)
    {
        return ActionResult.newResult(EnumActionResult.PASS, itemstack);
    }

    BlockPos clickPos = mop.getBlockPos();
    // can we place liquid there?
    if (world.isBlockModifiable(player, clickPos))
    {
        // the block adjacent to the side we clicked on
        BlockPos targetPos = clickPos.offset(mop.sideHit);

        // can the player place there?
        if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack))
        {
            // try placing liquid
            if (FluidUtil.tryPlaceFluid(player, player.getEntityWorld(), fluidStack, targetPos)
                    && !player.capabilities.isCreativeMode)
            {
                // success!
                player.addStat(StatList.getObjectUseStats(this));

                itemstack.stackSize--;
                ItemStack emptyStack = getEmpty() != null ? getEmpty().copy() : new ItemStack(this);

                // check whether we replace the item or add the empty one to the inventory
                if (itemstack.stackSize <= 0)
                {
                    return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack);
                }
                else
                {
                    // add empty bucket to player inventory
                    ItemHandlerHelper.giveItemToPlayer(player, emptyStack);
                    return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
                }
            }
        }
    }

    // couldn't place liquid there2
    return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:57,代碼來源:UniversalBucket.java


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