Jump to content

Recommended Posts

Posted

So I have an item that I want to make lost a durability every 5 seconds, so every 100 ticks. I've done some looking around about implementing a tick counter into NBT to help track this, but so far I have been unsuccessful in getting this to work(as entire functions that are present in the tutorial are not there any more). 

Posted

Override the

onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {}

 method of your Item. It's called every tick the Item is in the players inventory.

 

Posted

Define "doesn't work."

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
2 hours ago, TheSunCat said:

I tried that, and adding a counter, but it refuses to work.

I done that once before and it act perfect:

Spoiler

    @Override
    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
    {
        return false;
    }

    @Override
    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
        if(entityIn instanceof EntityLivingBase)
        {
            if(!stack.hasTagCompound())
            {
                stack.setTagCompound(new NBTTagCompound());
            }
            
            if (stack.getTagCompound().hasKey("TickCounter"))
            {
                int tickCounter = stack.getTagCompound().getInteger("TickCounter");
                if (tickCounter <= 0)
                {
                    stack.damageItem(1, ((EntityLivingBase) entityIn));
                    stack.getTagCompound().setInteger("TickCounter", 100);
                }
                else
                {
                    stack.getTagCompound().setInteger("TickCounter", --tickCounter);
                }
            }
            else
            {
                stack.getTagCompound().setInteger("TickCounter", 100);
            }
        }
    }

 

 

 

Edited by Lhykos
Posted

Whenever I load a world with the code above in my item class I crash with this error.

Spoiler

[09:40:09] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:210) ~[NetworkSystem.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:817) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
Caused by: java.lang.NullPointerException
    at com.Frost2779.AWillToLive.Items.ItemFullWill.onUpdate(ItemFullWill.java:43) ~[ItemFullWill.class:?]
    at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:503) ~[ItemStack.class:?]
    at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:390) ~[InventoryPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:563) ~[EntityPlayer.class:?]
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2292) ~[EntityLivingBase.class:?]
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:258) ~[EntityPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:367) ~[EntityPlayerMP.class:?]
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:176) ~[NetHandlerPlayServer.class:?]
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:218) ~[NetworkDispatcher$1.class:?]
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:308) ~[NetworkManager.class:?]
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:195) ~[NetworkSystem.class:?]
    ... 5 more

 

Posted

Crash is useless without your Item class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

My mistake

package com.Frost2779.AWillToLive.Items;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemFullWill extends Item {

    public ItemFullWill(){
        this.setMaxDamage(100);
        this.setMaxStackSize(1);

    }

    @Override
    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
        return false;
    }

    @Override
    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {

        if(entityIn instanceof EntityLivingBase)
        {
            if (stack.hasTagCompound() && stack.getTagCompound().hasKey("TickCounter"))
            {
                int tickCounter = stack.getTagCompound().getInteger("TickCounter");
                if (tickCounter <= 0)
                {
                    stack.damageItem(1, ((EntityLivingBase) entityIn));
                    stack.getTagCompound().setInteger("TickCounter", 100);
                }
                else
                {
                    stack.getTagCompound().setInteger("TickCounter", --tickCounter);
                }
            }
            else
            {
                stack.getTagCompound().setInteger("TickCounter", 100);
            }
        }
    }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.