Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am creating a mod that has invincible tools which take experience from the player each time they are used.

Can someone please tell me how to make the tools take away the experience when used?

share|improve this question
4  
What have you tried? –  John McDonald Jun 26 '13 at 22:05
    
I have not actually tested anything yet, but I searched through all of minecraft's source code, but couldn't find anything on taking XP from the user –  Andrew Graber Jun 26 '13 at 22:11
1  
"I have not actually tested anything yet" - it's better to try first and then ask. Not only it follows the rules of this server, but it is much more rewarding to figure it out yourself ;) –  sm4 Jun 27 '13 at 3:43
    
It would be helpful to know whether you're writing a client- or server-side mod, and which framework(s) you're using such as Bukkit or Forge. –  Travis Christian Jun 28 '13 at 15:17

2 Answers 2

up vote 9 down vote accepted

You could look in the game code to find the code for enchanting. Since that takes away experience, it should tell you how, although it may be in levels. Also, you could look in the code for the anvil. In those, you should find variables for experience. You could probably subtract from those variables for every 2 or so blocks that you mine/dig/chop, like the vanilla tools do for their damage values. Also, i found a tutorial that could probably help you, in the Resources below.

I found this in the source code: entityplayermp.addExperienceLevel(). You could do entityplayermp.addExperienceLevel(-1) and could probably use entityplayermp.subtractExperienceLevel(1). I don't know if the second option would work.

Possible Solutions: What you can do, because in tools there is this:

onBlockDestroyed = "itemstack.damageItem(2)

you can do:

onBlockDestroyed = entityplayermp.addExperienceLevel(-1)

Another option is to write a new method. Instead of calling onPlayerDestroyBlock call onPlayerDestroyBlockWithXPick, which would include the code:

entityplayermp.addExperienceLevel(-1)

The disadvantage of this, though, is that you would have to replace all vanilla/modded blocks with your own version of them, to include the method.

Resources:

MCP (Mod Coder Pack) to decompile the code, if you haven't already.

The Forge Ore Dictionary: a dictionary of all common mods's items and vanilla items.

The Tutorial: A modding tutorial that i found, includes code for a pickaxe, among other things.

Disclaimer: This code may not work, even though i took it from credible sources, i may have made a mistake.

share|improve this answer

Two resources that will help you greatly:

You'll probably want to checkout MCP. I've used it a good amount and it's really nice. Spend a decent amount of time just reading the code before you start though. If you google MCP tutorials you'll get a lot of short easy tutorials to help you out.

Good luck!

share|improve this answer
    
Thanks, @Tips48, but I already have MCP and I had been looking through it for ages, trying to find the answer. –  Andrew Graber Jun 27 '13 at 3:09
    
To find the methods to add/remove exp, check in EntityHuman. To help you out, here's the CraftBukkit code for it. All though it's the server version and is different with its decompiled names, it should help you. github.com/Bukkit/CraftBukkit/blob/master/src/main/java/net/… –  Tips48 Jun 27 '13 at 3:34
    
I'm pretty sure I've got it figured out, but with one small problem... I have no idea how to implement this in my code. I Tried this: "onBlockDestroyed = entityplayermp.addExperienceLevel(-1);" but it says "Syntax error on token "onBlockDestroyed", VariableDeclaratorId expected after this token" –  Andrew Graber Jun 27 '13 at 3:55
    
yeah you need to find the method where the block is destroyed then take away the experience level. If you're attempting to do an operation like that, you might want to focus on learning basic java for a little longer –  Tips48 Jun 27 '13 at 4:14
1  
-1 This answer isn't much more than a suggestion of where to start to find the answer. Can you elaborate more on the actual steps that should be taken to complete the task? –  Byte56 Jun 28 '13 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.