Jump to content

AutoRepairing Tools : 1 Durability every 15 seconds. How? Help :)


Recommended Posts

Posted

Hi guys. My mod is progressing and I am learning so much from the nice guys on these forums!

I have been working on implementing an auto repair system on my tools so when they reach a certain tier of tool material they start to repair their durability at a rate of 1 durability every 15 seconds. However it ended up preventing the tools from taking damage and then they stopped working, unable to break any blocks what so ever. This was put together by looking at some other peoples opensource code with repair class and methods but I scrapped it because it just wasn't working.

 

I tried setting up an onUpdate method that would check the tools NBT data looking for its tool tier level and whether it had been repaired recently. Then setting it up so that once it is at the max tier and that the int of when it had been repaired has reach a limit it sets currentMaxDurability = currentMaxDurability + 1. But that didn't work either.

 

I have searched the forums for something related but I am yet to find anything that is remotely helpful.

 

I was wondering if anyone has a simple solution or some sort of example? I looked at some Artifacts code and that didn't help either.

 

Any help would be appreciated :) !

Posted

It would be really helpful if you showed us whatever code you had tried, rather than just a description, but it sounds like "currentMaxDurability = currentMaxDurability + 1" has nothing to do with the ItemStack. You need to actually reduce the damage on the stack, because damage is added until it reaches max damage at which point it breaks.

 

Perhaps try something like this, but be sure to include your other checks as needed:

if (stack.getItemDamage() > 0) {
stack.setItemDamage(stack.getItemDamage() - 1);
}

Posted

I was about to say the same, when a warning came up saying someone else has posted something.... xD

If I helped then you help, hit that Thank You button or Applaud.

Posted

Yeah sorry. That isnt any where near how my code works I was just showing an example. A way that I think about it thats all.

 

 

I am just struggling with creating a loop which checks the items NBT data and does stuff from there.

 

Just gunna give this another go and report back. :3

 

 

 

Posted

Riiiight, This is what I am trying to use but the results are odd.

 

@Override
    public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
        int del = par1ItemStack.stackTagCompound.getInteger("repairDelay");
//if repairDelay Variable is greater than 0. Reduce its number by 1. Repeating
        if (del > 0) {
            --del;
// once the variable del is 0 then
        } else if (par1ItemStack.getItemDamage() > 0) {
// tool's damage is reduced by 1
// causing the tool to regenerate durability
            par1ItemStack.setItemDamage(par1ItemStack.getItemDamage() - 1);
            if (par5)
                del = 200;
            else
                del = 1200;
        }
        par1ItemStack.stackTagCompound.setInteger("repairDelay", del);
    }

 

 

When I use this, my tools end up not working at all. Its like the delay that is set up causes the tools to not work until the delay int becomes 0 then it works for 1 second, then the tool stops working again for a short period of time.

Posted

That's pretty bizarre, but if I recall correctly you are doing a lot of custom stuff with your tool class. You didn't happen to override the "public int getDamage(ItemStack stack)" method, did you? If so, that may be part of the issue.

 

On a side note, I would probably check if (stack.getItemDamage() > 0) as the very first step in the onUpdate method, with everything else inside of that, since you only care about damaged stacks trying to repair.

Posted

I could post all my code if you would prefer. But yes I change my max Damage based on NBT data points that build up as the tools are used.

 

@Override
    public IIcon getIconIndex(ItemStack thisItem) {
        NBTTagCompound evopoints = thisItem.getTagCompound();
        if (evopoints == null) {
            evopoints = new NBTTagCompound();
        }
        if (!evopoints.hasKey("evolutionPoints")) {
            evopoints.setInteger("evolutionPoints", 0);
        }
        thisItem.setTagCompound(evopoints);
        //NBTTagCompound repairDelay = thisItem.getTagCompound();
      //  if (repairDelay == null) {
      //      repairDelay = new NBTTagCompound();
      //  }
      //  if (!repairDelay.hasKey("repairDelay")) {
     //       repairDelay.setInteger("repairDelay", 1133);
      //  }
        thisItem.setTagCompound(evopoints);
        if (evopoints.getInteger("evolutionPoints") >= tier2Level && (evopoints.getInteger("evolutionPoints") < tier3Level)) {
            this.efficiencyOnProperMaterial = toolEffTier2;
            this.setMaxDamage(toolMaxDurTier2);
            return itemIconFleshBound;
        } else if (evopoints.getInteger("evolutionPoints") >= tier3Level && (evopoints.getInteger("evolutionPoints") < tier4Level)) {
            this.efficiencyOnProperMaterial = toolEffTier3;
            this.setMaxDamage(toolMaxDurTier3);
            return itemIconHideCoated;
        } else if (evopoints.getInteger("evolutionPoints") >= tier4Level) {
            this.efficiencyOnProperMaterial = toolEffTier4;
            this.setMaxDamage(toolMaxDurTier4);
            return itemIconScaleArmored;
        } else {
            this.efficiencyOnProperMaterial = toolEfficiency;
            this.setMaxDamage(toolMaxDurability);
            return itemIconFusedBone;
        }
    }

 

Thats the part where I adjust the maximum damage / durability of the tools depending on when a number limit is reached. :/

 

 

Posted

Where can I set the NBT data changes then? Because I can't work out a good spot to have the durability and efficiency change then. :/

 

@Override
    public IIcon getIcon(ItemStack thisItem, int pass) {
        NBTTagCompound evopoints = thisItem.getTagCompound();
        if (evopoints == null) {
            evopoints = new NBTTagCompound();
        }
        if (!evopoints.hasKey("evolutionPoints")) {
            evopoints.setInteger("evolutionPoints", 0);
        }
        thisItem.setTagCompound(evopoints);
        if (evopoints.getInteger("evolutionPoints") >= tier2Level && (evopoints.getInteger("evolutionPoints") < tier3Level)) {
            return itemIconFleshBound;
        } else if (evopoints.getInteger("evolutionPoints") >= tier3Level && (evopoints.getInteger("evolutionPoints") < tier4Level)) {
            return itemIconHideCoated;
        } else if (evopoints.getInteger("evolutionPoints") >= tier4Level) {
            return itemIconScaleArmored;
        } else {
            this.efficiencyOnProperMaterial = toolEfficiency;
            return itemIconFusedBone;
        }
    }

    @Override
    public IIcon getIconIndex(ItemStack thisItem) {
        NBTTagCompound evopoints = thisItem.getTagCompound();
        if (evopoints == null) {
            evopoints = new NBTTagCompound();
        }
        if (!evopoints.hasKey("evolutionPoints")) {
            evopoints.setInteger("evolutionPoints", 0);
        }
        thisItem.setTagCompound(evopoints);
        thisItem.setTagCompound(evopoints);
        if (evopoints.getInteger("evolutionPoints") >= tier2Level && (evopoints.getInteger("evolutionPoints") < tier3Level)) {
            this.efficiencyOnProperMaterial = toolEffTier2;
            this.setMaxDamage(toolMaxDurTier2);
            return itemIconFleshBound;
        } else if (evopoints.getInteger("evolutionPoints") >= tier3Level && (evopoints.getInteger("evolutionPoints") < tier4Level)) {
            this.efficiencyOnProperMaterial = toolEffTier3;
            this.setMaxDamage(toolMaxDurTier3);
            return itemIconHideCoated;
        } else if (evopoints.getInteger("evolutionPoints") >= tier4Level) {
            this.efficiencyOnProperMaterial = toolEffTier4;
            this.setMaxDamage(toolMaxDurTier4);
            return itemIconScaleArmored;
        } else {
            this.efficiencyOnProperMaterial = toolEfficiency;
            this.setMaxDamage(toolMaxDurability);
            return itemIconFusedBone;
        }

 

So is all of that read only / client side? :/

 

If so I need a good suggestion as to where I can place my updates of this.setMaxDamage and this.efficiencyOnProperMaterial because I am a bit stuck hehe. Atm it all works fine, no issues, Untill it comes to the repairing stuff. :/

Posted

Right. Im gunna post my code up for the 1 tool. The Pickaxe.

 

REDACTED!

 

 

REDACTED!

 

That is just 1 one too. Beware! My code will burn your eyes and cause you to become enraged.

 

 

 

I tried this code out atm and the onUpdate causes my tool to not work at all. Untill the delay caused by the onUpdate is finished. :/ But the tools doo repair now. They just dont work :P

Posted

@Override
    public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
        int del = 5000;
        while (del > 0) { --del;}

        if (par1ItemStack.getItemDamage() > 0 && del == 0)
        {
            System.out.println("Repairing");
            par1ItemStack.setItemDamage(par1ItemStack.getItemDamage() - 1);
           del = 5000;
        }

 

Like this I can mine but the tool repairs instantly. Arghhgh :P

Posted

BOLLOCKS!

 


---- Minecraft Crash Report ----
// Daisy, daisy...

Time: 28/03/14 21:07
Description: Ticking player

java.lang.NullPointerException: Ticking player
at com.aappleyard.evolvinggearmod.tools.FusedBonePickaxe.onUpdate(FusedBonePickaxe.java:171)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:468)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:643)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1856)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:360)
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:363)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:334)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:218)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at com.aappleyard.evolvinggearmod.tools.FusedBonePickaxe.onUpdate(FusedBonePickaxe.java:171)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:468)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:643)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1856)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:360)

-- Player being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 265
Entity Name: Aappleyard
Entity's Exact location: 200.70, 70.00, 142.88
Entity's Block location: World: (200,70,142), Chunk: (at 8,4,14 in 12,8; contains blocks 192,0,128 to 207,255,143), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Entity's Momentum: 0.00, -0.08, 0.00
Stacktrace:
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:363)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:334)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:218)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@57ad78bb
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows 8 (amd64) version 6.2
Java Version: 1.7.0_51, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 909130352 bytes (867 MB) / 1038024704 bytes (989 MB) up to 3113877504 bytes (2969 MB)
JVM Flags: 3 total; -Xincgc -Xmx3G -Xms1024M
AABB Pool Size: 2942 (164752 bytes; 0 MB) allocated, 2798 (156688 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.01-pre FML v7.2.129.1047 Minecraft Forge 10.12.0.1047 4 mods loaded, 4 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.129.1047} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1047.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.0.1047} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1047.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
evolvinggearmod{1.0} [evolvinggearmod] (Evolving Gear Mod Wth IntelliJ) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 1366 (76496 bytes; 0 MB) allocated, 1351 (75656 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Aappleyard'/265, l='New World', x=200.70, y=70.00, z=142.88]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

Can't work out what its trying to tell me.

Posted


@Override
    public void onUpdate(ItemStack stack, World world, Entity par3Entity, int par4, boolean par5) {
        NBTTagCompound  evopoints = stack.getTagCompound();
        int ToolTier = evopoints.getInteger("ToolTier"); <---- LINE 171
        int currentDamage = stack.getItemDamage();

        if (currentDamage >=50 )
        {

            if (damage <= 349) {
                damage++;
            }

            System.out.println(damage);
            if (damage == 350) {
                if (ToolTier == 0) {
                    stack.damageItem(-1, (EntityPlayer) par3Entity);
                    damage = 0;
                } else if (ToolTier == 1) {
                    stack.damageItem(-2, (EntityPlayer) par3Entity);
                    damage = 0;

                } else if (ToolTier == 2) {
                    stack.damageItem(-3, (EntityPlayer) par3Entity);
                    damage = 0;

                } else if (ToolTier == 3) {
                    stack.damageItem(-4, (EntityPlayer) par3Entity);
                    damage = 0;

                } else {

                    System.out.println("damage is now 1000");
                }
            }
        }
        else {System.out.println("No Damage yet"); }
    }
}

 

This works making the tools repair but now when I try and craft them in a crafting bench and pick up the item it causes this crash, then it crashes every time I log in again.

Posted

I got it now! Thanks!

 

 

Hey would it be safe moving my state checks to the onUpdate? Because I have things that check its tier and depending on the tier it gives the tool a certain durability level or efficiency stat?

Posted

I just wanted to know if moving most of my tool checks to an onUpdate method is safe to do so? It will still only apply stat changed to that specific stack if the item is the correct item etc etc. I just wanted to know thats all.

Posted

Can someone confirm something for me?

 

 

here are two lines of code

 

 

this.setMaxDamage(toolMaxDurTier2);

 

This line is to set the tools durability to a variable assigned to toolMaxDurTier2;

 

stack.setMaxDamage(toolMaxDurTier2);

 

THis line does the same execept it sets that individual stacks durability to toolMaxDurTier2;

 

 

 

I know that stack.setMaxDamage doesn't work but is there a way to get the same results because at the moment my code is setting all my items to the same durability rather than it setting just the one item / stack to a different durability. ?

 

 

OR

 

Do I handle it a different way? Because of the way my tools work I cannot set up multiple tools. Each tool has several states, like leveling up tiers in minecraft. Think wood to stone to iron to diamond. Except this is all contained within 1 tool. As the tool is used to grows and changes into a better form, more powerful. I wanted to have it so the durability changes as the tool grows too however I noticed that this current setup causes all of the one type of tool to change durability :/ atleast I think it does.

 

 

Will do more testing but advice would be appreciated :D

Posted

Right I have a few ideas I want to pass across people and see what they think.

 

My issue is that I cannot have 1 tool have multiple durability levels which change at specific points related to NBT data on just that one item stack. If I change a tools max durability it changes the entire item class rather than just the stack.

 

My other issue is that I don't know how to have the item also have a different efficiency level which change at specific points related to NBT data without it also effecting the whole item class. etc etc

 

My idea for solutions.

 

 

1. I use NBT data to work out tools durability. If the NBT data holding durability info and NBT data holding current durability level are the same then the tool breaks. That's fine I can do that. My only issue is that the item won't have a durability bar that moves across as it takes damage. Is there any way of making a bar which fills out showing the items durability level related to the items NBT data not the vanilla minecraft durability data?

 

2. I forget the idea of having a tiered tool with multiple durability levels, efficiency levels and just have it all remain the same. The only change is its texture and other stats. (Rather not give in and do this easy option)

Posted


// when Block Destroyed
    @Override
    public boolean onBlockDestroyed(ItemStack stack, World world, Block blockID, int x, int y, int z, EntityLivingBase entity) {
        // If correct item
        if (stack.getItem() != null && stack.getItem() == EvolvingGearMod.FusedBonePickaxe) {
            // Create 2 NBT tags. Evolution Points and Evolution Meter Points
            System.out.println("Broke A Block with pickaxe");
            NBTTagCompound evopoints = stack.getTagCompound();
            if (evopoints == null) {
                evopoints = new NBTTagCompound();
            }
            if (!evopoints.hasKey("evolutionPoints")) {
                evopoints.setInteger("evolutionPoints", 0);
            }
            stack.setTagCompound(evopoints);


            NBTTagCompound toolDmg = stack.getTagCompound();
            if (toolDmg == null) {
                toolDmg = new NBTTagCompound();
            }
            if (!toolDmg.hasKey("ToolDmg")) {
                toolDmg.setInteger("ToolDmg", 0);
            }
            //stack.setTagCompound(toolDmg);


            NBTTagCompound toolMaxDura = stack.getTagCompound();
            if (toolMaxDura == null) {
                toolMaxDura = new NBTTagCompound();
            }
            if (!toolMaxDura.hasKey("ToolMaxDura")) {
                toolMaxDura.setInteger("ToolMaxDura", 0);
            }
            //stack.setTagCompound(toolMaxDura);
            // Increase evo points + 1
            evopoints.setInteger("evolutionPoints", evopoints.getInteger("evolutionPoints") + 1);
            //Damage Item NBT
            toolDmg.setInteger("ToolDmg", toolDmg.getInteger("ToolDmg") + 1);
            System.out.println(toolDmg.getInteger("ToolDmg") + " is the tools dmg. ");
            System.out.println(toolMaxDura.getInteger("ToolMaxDura") + " is the tools max durability.");
        }
        return blockDestroyed;
    }

 

 

That is getting called 2 times in a row causing me issues. No idea why either :/

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.

×
×
  • Create New...

Important Information

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