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


Java ItemStack.getMaxItemUseDuration方法代碼示例

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


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

示例1: getForce

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
/**
 * Get the initial velocity of the item
 */
public static double getForce(ItemStack itemStack) {
    double force = 0.D;
    switch (Item.getIdFromItem(itemStack.getItem())) {
        case 261: // bow
        {
            int duration = itemStack.getMaxItemUseDuration() - MC.player.getItemInUseCount();
            force = (double)duration / 20.0F;
            //   force = (force * force + force * 2.0F) / 3.0F;
            if (force > 1.0F)
                force = 1.0F;
            force *= 2d*1.5d;
            break;
        }
        case 332: // snowball
        case 344: // egg
        case 346: // fishing rod
        case 368: // ender pearl
            force = 1.5;
            break;
    }
    return force;
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:26,代碼來源:ProjectileUtils.java

示例2: setActiveHand

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
public void setActiveHand(EnumHand hand)
{
    ItemStack itemstack = this.getHeldItem(hand);

    if (!itemstack.func_190926_b() && !this.isHandActive())
    {
        this.activeItemStack = itemstack;
        this.activeItemStackUseCount = itemstack.getMaxItemUseDuration();

        if (!this.world.isRemote)
        {
            int i = 1;

            if (hand == EnumHand.OFF_HAND)
            {
                i |= 2;
            }

            this.dataManager.set(HAND_STATES, Byte.valueOf((byte)i));
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:23,代碼來源:EntityLivingBase.java

示例3: transformEatFirstPerson

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
private void transformEatFirstPerson(float p_187454_1_, EnumHandSide p_187454_2_, ItemStack p_187454_3_)
{
    float f = (float)this.mc.player.getItemInUseCount() - p_187454_1_ + 1.0F;
    float f1 = f / (float)p_187454_3_.getMaxItemUseDuration();

    if (f1 < 0.8F)
    {
        float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);
        GlStateManager.translate(0.0F, f2, 0.0F);
    }

    float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
    int i = p_187454_2_ == EnumHandSide.RIGHT ? 1 : -1;
    GlStateManager.translate(f3 * 0.6F * (float)i, f3 * -0.5F, f3 * 0.0F);
    GlStateManager.rotate((float)i * f3 * 90.0F, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
    GlStateManager.rotate((float)i * f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:19,代碼來源:ItemRenderer.java

示例4: transformEatFirstPerson

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
private void transformEatFirstPerson(float p_187454_1_, EnumHandSide p_187454_2_, ItemStack p_187454_3_)
{
    float f = (float)this.mc.thePlayer.getItemInUseCount() - p_187454_1_ + 1.0F;
    float f1 = f / (float)p_187454_3_.getMaxItemUseDuration();

    if (f1 < 0.8F)
    {
        float f2 = MathHelper.abs(MathHelper.cos(f / 4.0F * (float)Math.PI) * 0.1F);
        GlStateManager.translate(0.0F, f2, 0.0F);
    }

    float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
    int i = p_187454_2_ == EnumHandSide.RIGHT ? 1 : -1;
    GlStateManager.translate(f3 * 0.6F * (float)i, f3 * -0.5F, f3 * 0.0F);
    GlStateManager.rotate((float)i * f3 * 90.0F, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
    GlStateManager.rotate((float)i * f3 * 30.0F, 0.0F, 0.0F, 1.0F);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:19,代碼來源:ItemRenderer.java

示例5: onActiveItemUseTick

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@SubscribeEvent
public void onActiveItemUseTick(LivingEntityUseItemEvent.Tick event) {
    ItemStack stack = event.getItem();
    if (stack.getItem() == TrumpetSkeletonItems.TRUMPET) {
        if (event.getDuration() == stack.getMaxItemUseDuration() - 10) {
            EntityLivingBase user = event.getEntityLiving();
            World world = user.world;

            user.playSound(TrumpetSkeletonSoundEvents.ITEM_TRUMPET_USE, 1.0F, 0.9F + world.rand.nextFloat() * 0.2F);
            if (!world.isRemote) {
                List<EntityLivingBase> spookedEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, user.getEntityBoundingBox().grow(10.0D));
                for (EntityLivingBase spookedEntity : spookedEntities) {
                    if (spookedEntity == user) continue;
                    double deltaX = user.posX - spookedEntity.posX;
                    double deltaZ = user.posZ - spookedEntity.posZ;
                    double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
                    if (distance > 0.25D) {
                        spookedEntity.knockBack(user, 0.5F, deltaX / distance, deltaZ / distance);
                    }
                    spookedEntity.setRevengeTarget(user);
                }
                stack.damageItem(1, user);
            }
        } else if (event.getDuration() <= stack.getMaxItemUseDuration() - 15) {
            event.setCanceled(true);
        }
    }
}
 
開發者ID:JamiesWhiteShirt,項目名稱:trumpet-skeleton,代碼行數:29,代碼來源:TrumpetSkeleton.java

示例6: getIcon

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
   public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) 
{
	if(player.getItemInUse() == null) { return this.itemIcon; }
        
        int Pulling = stack.getMaxItemUseDuration() - useRemaining;	// Displaying the bow drawing animation based on the use state
       
        if (Pulling >= 18) { return this.pull_2; }
        else if (Pulling > 13) { return this.pull_1; }
        else if (Pulling > 0) { return this.pull_0; }              
        
        return itemIcon;
   }
 
開發者ID:Domochevsky,項目名稱:minecraft-quiverbow,代碼行數:14,代碼來源:EnderBow.java

示例7: getIcon

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) 	// On hand display
{
	if(player.getItemInUse() == null) { return this.itemIcon; }

	int Pulling = stack.getMaxItemUseDuration() - useRemaining;	// Displaying the bow drawing animation based on the use state

	if (Pulling >= 18) { return this.pull_2; }
	else if (Pulling > 13) { return this.pull_1; }
	else if (Pulling > 0) { return this.pull_0; }

	return this.itemIcon;
}
 
開發者ID:Domochevsky,項目名稱:minecraft-quiverbow,代碼行數:14,代碼來源:QuiverBow.java

示例8: getIcon

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
{
       if (usingItem != null && usingItem.getItem() == this)
       {
           int j = usingItem.getMaxItemUseDuration() - useRemaining;
           float force = j / getUseSpeed(player);

		if (force >= 1.25) // Fully drawn
           {
			return getItemIconForUseDuration(3);
		}
		else if (force > 0.75)
           {
			return getItemIconForUseDuration(2);
           }
		else if (force > 0.25) // Minimum required force to fire
           {
               return getItemIconForUseDuration(1);
           }
		else if (force > 0)
           {
               return getItemIconForUseDuration(0);
           }
       }
       return getIcon(stack, renderPass);
}
 
開發者ID:Wahazar,項目名稱:TFCPrimitiveTech,代碼行數:28,代碼來源:ItemSlingshot.java

示例9: processPlayerBlockPlacement

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
/**
 * Processes block placement and block activation (anvil, furnace, etc.)
 */
public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
    WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
    ItemStack itemstack = this.playerEntity.inventory.getCurrentItem();
    boolean flag = false;
    BlockPos blockpos = packetIn.getPosition();
    EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection());
    this.playerEntity.markPlayerActive();

    if (packetIn.getPlacedBlockDirection() == 255)
    {
        if (itemstack == null)
        {
            return;
        }

        this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack);
    }
    else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit())
    {
        if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
        {
            this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ());
        }

        flag = true;
    }
    else
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())});
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation));
        flag = true;
    }

    if (flag)
    {
        this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos));
        this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing)));
    }

    itemstack = this.playerEntity.inventory.getCurrentItem();

    if (itemstack != null && itemstack.stackSize == 0)
    {
        this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
        itemstack = null;
    }

    if (itemstack == null || itemstack.getMaxItemUseDuration() == 0)
    {
        this.playerEntity.isChangingQuantityOnly = true;
        this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
        Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
        this.playerEntity.openContainer.detectAndSendChanges();
        this.playerEntity.isChangingQuantityOnly = false;

        if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack()))
        {
            this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem()));
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:68,代碼來源:NetHandlerPlayServer.java

示例10: tryUseItem

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        return false;
    }
    else
    {
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ItemStack itemstack = stack.useItemRightClick(worldIn, player);

        if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
        {
            player.inventory.mainInventory[player.inventory.currentItem] = itemstack;

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
            }

            if (!player.isUsingItem())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:48,代碼來源:ItemInWorldManager.java

示例11: renderItem

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
	TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
	ResourceLocation resource = textureManager.getResourceLocation(stack.getItemSpriteNumber());

	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	ItemStack usingItem = player.getItemInUse();
	int useRemaining = player.getItemInUseCount();

	ItemBow bow = (ItemBow) stack.getItem();

	IIcon icon = bow.getIcon(stack, 0);
	if (usingItem != null && usingItem == stack) {
		int charge = stack.getMaxItemUseDuration() - useRemaining;
		if (charge >= 18)
			icon = bow.getItemIconForUseDuration(2);
		else if (charge > 13)
			icon = bow.getItemIconForUseDuration(1);
		else if (charge > 0)
			icon = bow.getItemIconForUseDuration(0);
	}
	if (icon == null)
		icon = ((TextureMap) textureManager.getTexture(resource)).getAtlasSprite("missingno");

	OpenGLHelper.pushMatrix();
	textureManager.bindTexture(resource);

	OpenGLHelper.colour(bow.getColorFromItemStack(stack, 0));

	OpenGLHelper.disableLighting();
	OpenGLHelper.enableAlpha();
	OpenGLHelper.enableBlend();
	OpenGlHelper.glBlendFunc(770, 771, 1, 0);

	renderItem.renderIcon(0, 0, icon, 16, 16);

	OpenGLHelper.enableLighting();
	OpenGLHelper.disableAlpha();
	OpenGLHelper.disableBlend();

	if (stack.hasEffect(0))
		renderItem.renderEffect(textureManager, 0, 0);

	OpenGLHelper.popMatrix();
}
 
開發者ID:jm-organization,項目名稱:connor41-etfuturum2,代碼行數:46,代碼來源:ItemBowRenderer.java

示例12: processRightClick

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand)
{
    if (this.gameType == GameType.SPECTATOR)
    {
        return EnumActionResult.PASS;
    }
    else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
    {
        return EnumActionResult.PASS;
    }
    else
    {
        int i = stack.func_190916_E();
        int j = stack.getMetadata();
        ActionResult<ItemStack> actionresult = stack.useItemRightClick(worldIn, player, hand);
        ItemStack itemstack = (ItemStack)actionresult.getResult();

        if (itemstack == stack && itemstack.func_190916_E() == i && itemstack.getMaxItemUseDuration() <= 0 && itemstack.getMetadata() == j)
        {
            return actionresult.getType();
        }
        else if (actionresult.getType() == EnumActionResult.FAIL && itemstack.getMaxItemUseDuration() > 0 && !player.isHandActive())
        {
            return actionresult.getType();
        }
        else
        {
            player.setHeldItem(hand, itemstack);

            if (this.isCreative())
            {
                itemstack.func_190920_e(i);

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.func_190926_b())
            {
                player.setHeldItem(hand, ItemStack.field_190927_a);
            }

            if (!player.isHandActive())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return actionresult.getType();
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:54,代碼來源:PlayerInteractionManager.java

示例13: processRightClick

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand)
{
    if (this.gameType == GameType.SPECTATOR)
    {
        return EnumActionResult.PASS;
    }
    else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
    {
        return EnumActionResult.PASS;
    }
    else
    {
        if (net.minecraftforge.common.ForgeHooks.onItemRightClick(player, hand, stack)) return net.minecraft.util.EnumActionResult.PASS;
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ActionResult<ItemStack> actionresult = stack.useItemRightClick(worldIn, player, hand);
        ItemStack itemstack = (ItemStack)actionresult.getResult();

        if (itemstack == stack && itemstack.stackSize == i && itemstack.getMaxItemUseDuration() <= 0 && itemstack.getMetadata() == j)
        {
            return actionresult.getType();
        }
        else
        {
            player.setHeldItem(hand, itemstack);

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.setHeldItem(hand, (ItemStack)null);
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, itemstack, hand);
            }

            if (!player.isHandActive())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return actionresult.getType();
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:52,代碼來源:PlayerInteractionManager.java


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