Jump to content

Recommended Posts

Posted

So I am trying to code an item similar to Project E's Repair talsman that repairs items slowly. I didn't know where to start so I looked at some of project e's code for the item and began coding. I have everything done, but it doesn't seem to work like the repair talsman. I can either get it to repair items very very fast, when I want it to repair about a durability every few seconds, or i can get it to repair 1 durability upon loading the world, or not work at all if I mess around with the code. I would like to try and get it to repair 1 durability every few seoconds. So here is the code for the different classes, if you need anything else I can post it.

 Class for the actual repair item- http://pastebin.com/eyuKFkdi

Class for the timer for how often it repairs- http://pastebin.com/XVjVyw5r

Player Event class to attatch Capability- http://pastebin.com/M6zWgrdt

Player Tick class- http://pastebin.com/fJrPPzAq

Main class where everything is registered- http://pastebin.com/21sxr9v0

Posted

1) Why are you storing the capability on the player and not on the item stack?

2) Why are you creating a stack tag compound and then doing jack all with it?

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

I was trying to learn from Project E's code for coding the item. I can't answer those questions as i am trying to learn from they'yre code, just trying to figure out why the item wont repair durability every few seconds.

Posted

Use the debugger. Find out why it's happening every tick instead of every 20 by examining the values at runtime.

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

I agree with Draco. You need breaks in the tick, activate- and can- Repair methods to see the sequence of when they're being called. From what I saw, the code doesn't smell right. It looks as if activate is being called much more often than needed, and it looks as if shouldUpdate is being set false just as often. It also appears as if activateRepair and canRepair are being called in rapid succession without the tick having a chance to run. Things are just not in order (or else I'm not reading it right).

 

Ideally, you would activate such a timer when the talisman is placed into (player) inventory. It would then continue ticking until removed. Each time the tick count reached 20, it would repair all items (and reset the counter to zero). To do that, the itemStack would probably need to remember what inventory it is in. It would also need to store its tick count when unloaded from the world. I haven't used capabilities yet, so I am unsure how much of that is handled for you.

 

Optionally, you could have it also tick while in some other inventory (such as a chest, NPC mob or anvil) so it could repair items there as well.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.