FallenMoonNetwork / CanaryMod

Server administration mod and API for Minecraft beta multiplayer server
http://canarymod.net
GNU Lesser General Public License v3.0
20 stars 14 forks source link

Hook Suggestion: onAnvilUse #70

Closed BluXDragon closed 11 years ago

BluXDragon commented 11 years ago

We need to be able to hook into repairing, merging and renaming of items. The hook should be called when a change is done in the anvil, and NOT when the output item is taken out of the anvil. Doing it this way would add possibilities to manipulate costs, prevent certain name changes and change the output item.

I suggest HookParametersAnvilUse onAnvilUse(HookParamentersAnvilUse hp)

Inside the HookParametersAnvilUse should be; Player getPlayer(); Block getBlock(); //returns the block of the anvil being used Anvil getAnvil(); //returns the Anvil (ComplexBlock). Item getFirstInput(); //returns the Item on the left hand side of input. Null if none. Item getSecondInput(); //returns the Item on the right hand side of input. Null if none. Item getOutput(); //gets the Item which is the result. Null if none. int getLevels(); //gets the cost of the action. Zero if none, since ints hate null. Item setOutput(); //sets the output Item. int setLevels(); //sets the cost of the action.

To get name changes, we could simply hp.getFirstInput().getName and compare it to hp.getOutput().getName()

Not sure how to go about denying completely. Could just set the output item to null, or have a DENY_ACTION or whatever to do so.

However, that's just my suggestion, you can just make it a simple boolean if you like. I'd be happy with anything, but the above is optimal :3 I feel so demanding listing all those features, but yeah. D:

WWOL commented 11 years ago

Block getAnvil(); //returns the anvil being used

Could be Anvil getAnvil(); Maybe?

I feel so demanding listing all those features, but yeah. D:

Demanding is good, it gives details. :)

WWOL

Edit: I love the markdown stuff, it's fun. :P

BluXDragon commented 11 years ago

I was thinking about Anvil getAnvil(), but what point is there in having an Anvil class? They don't store any items when not being used, so... I guess the only value to think about is orientation, since damage is stored via block data. That's probably NBT, isn't it? That'd be the sole reason to have an Anvil class, and that just seems over the top to me.

And as long as it doesn't make me sound like a jackass, good :3

WWOL commented 11 years ago

I didn't know they didn't keep item's. I have never used one so I don't know much about them.

I suppose Block getAnvil() would be fine.

WWOL

gregcarlin commented 11 years ago

We already have an Anvil class, and it contains methods for getting and setting the output and getting and setting the item name. So you really just need the hook and getters and setters for the input and xp levels.

BluXDragon commented 11 years ago

So we do. I knew someone did something with Anvil but without the hook I struggle to see how this can be reasonably used.

gregcarlin commented 11 years ago

I could have this called whenever something in the name section of the anvil changes. Is that sufficient? It wouldn't be called when the item is removed.

BluXDragon commented 11 years ago

I quote my OP; "The hook should be called when a change is done in the anvil, and NOT when the output item is taken out of the anvil. "

That is perfect :P

Edit: Oh you mean just renaming the item? I would have uses for that, but that's not really "onAnvilUse" is it? That's just onRenameItem <.<

gregcarlin commented 11 years ago

What else changes inside an anvil? Just the slots, I guess. I'll see if I can get those involved too.

BluXDragon commented 11 years ago

This is why I wanted it as "HookParametersAnvilUse" - since it encompasses a bunch of different things. The three item slots, the cost in levels and the name slot. While unintentional, I totally wrote that in order of priority.

gregcarlin commented 11 years ago

Is it safe to not be called when there's nothing in the first slot, as you can't really do anything with the second slot alone anyway?

gregcarlin commented 11 years ago

Damn it I forgot to mention the issue again. This is pretty much good except for a few minor bugs: 8ecfb8887a8b1742e8299c523f5f5444731cb293