It is currently Wed Sep 20, 2017 7:18 am

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: AutoHandRefill and stackable off-hand items
PostPosted: Sun Aug 20, 2017 12:58 am 

Joined: Fri Aug 24, 2012 9:05 pm
Posts: 2
Minecraft Name: Chaos_Dancer
AutoHandRefil has some strange issues when you have a stack of placeable items in your off-hand slot (I typically run arround w/ torches in my off-hand, but I tested and this also happens with cobble blocks).

If you left click on a placeable spot when you have a placable stack of items in your offhand, and have currently selected an empty spot on your action bar, the game will get confused, place an item from your off-hand, and move the offhand items to to the empty spot on your action bar.

Also, if you are placing items from your action bar, and have a stack of same items in your offhand, it will pull the items from there to your action bar.

This is more of a enhancement request than a bug, if you run out of a stackable item on your off-hand, it will not replace the stack from your inventory.

 Post subject: Re: AutoHandRefill and stackable off-hand items
PostPosted: Mon Aug 21, 2017 6:24 pm 
User avatar

Joined: Thu Jan 26, 2012 6:19 am
Posts: 464
Minecraft Name: Boomod
offhand usage as being able to place things is what tripped me up, I was unaware it was possible, so my system only checks and refills the empty main hand.

The process I use is lacking enough information for me to properly use - I can either listen to the player interacting with a block (which doesn't distinguish between a pending placement vs container opening vs a block actually being within reach) and try to note what they are holding and placing with and preventing it (the algorithm for this i can't even imagine) OR as I do now, listen for the block placement event.

Since I only want to take action when the player places the last of a stack, and replenish it, this means checking if their hand is empty when that last block was placed, but I lose the information about what was held (this is going to be a problem for the rare items I need to deal with). I am able to determine that if the block placed was dirt, then you had a dirt stack, if it was wheat crops, then you had seeds.

The problem comes in with the fact that I only do this extra work to back-figure the stack and check for more to refill from IF the player has an empty hand. And this is currently just main-hand assumed, only checking main hand, only doing the checks IF his main hand is empty.

I am unable to detect which hand was used to place the block, that information is not available in the event, and is something that has been requested of sponge folks for a while.

Being unable to detect, I would have to do this:
See if the main hand is empty, and if it is, then ... follow through as I do now?
If the main hand isn't empty, check if the offhand is, and replace that.

The problem is going to be that if you hold a stack of torches in your main hand, and keep your offhand empty, then, hey, your offhand is the one that just emptied out...and it will swap them. Then it will say 'main hand is empty now, it must have placed them' Otherwise, I Can do the expensive processes to reconstruct what item was being held on each placement, and compare if that is the same as an item being held, and if so, ignore it assuming it came from there.

But what do I do when both the main and off hand are empty as the result of one of those being used to place something? If you were placing torches with your offhand, and had an empty main hand, now you have two empty hands, and I can't tell which it came from, and have to flip a coin to guess wrongly most of the time for most people...

I have worked around such things in the past by doing something such as making a list of users and what hand they are using during the interact event, then retrieving that info and deleting it from the list immediately afterwards in the block place event, but the problem with that approach is there can be cases that result in instances where the info does not get removed from the list, and then those end up in memory leaks.

I will have to wait until the information is provided about what hand things came from, and what they were gets put into sponge, in order to solve this problem. For now, I can't come up with a decent work-around because in m y mind its this:

-- if hand isn't empty, then skip doing alllll this work to figure out what was placed and scan through the inventory looking for more
-- if hand is empty, figure out what was placed by back-calculating from the block what they held, then scan the inventory slots to find more, and refill the hand.

Is not something that will translate well, and require this algorithm:
-- if both main and offhand are not empty, then skip everything
-- determine what itemstack represents the thing being placed
-- if the main hand is holding that item, skip out
-- if the off hand is holding that item, skip out
-- if the main hand is empty and offhand is not empty, refill main hand
-- if the offhand is empty and main hand is not empty, refill offhand
-- if the main hand is empty and the offhand is also empty: ??

That puts a lot of work up-front. If I was only checking blocks it would be okay, but any crops and a few other things result in things that are not mini-versions of the physical block, and need to be worked out as seeds, etc, which puts a lot of checks and tests to be run every time.

Because imagine a person who never puts something in their offhand, it will always be empty, so everytime they place something, its going to be firing and checking over and over...

It is DOABLE that process outlined above, but, what do I do in the case of both empty hands? I'd have to assume the other.

I will give this some thought as to what I might be able to do temporarily, but I need the workaround I come up with to be thinking about the bigger performance picture in the end, and my rare-drops system is going to be already pushing things in many place, I need a workaround that wont result in memoryleaking as different plugins disrupt the event chain in different ways for different reasons.

The offhand placement really messed up a plugin like this, one based on simplicity of 'hand empty? yes, refill it then' simple check to bypass the costlier other work.

There might be some new events that I can look at, but I think they only pertain to stuff like edible items and bow-charging and throwing eggs..

 Post subject: Re: AutoHandRefill and stackable off-hand items
PostPosted: Sat Sep 16, 2017 6:41 am 
User avatar

Joined: Thu Jan 26, 2012 6:19 am
Posts: 464
Minecraft Name: Boomod
Sponge has pushed a massive, major core update to their system, and I'm in the process of upgrading everything I have to use the new core system, and report lots of bugs to them about it.

The system replaces a singular chain of information handed between events in order to provide the rich, robust power that sponge provides to work with things, because the singular chain ended up with a lot of ambiguous conditions that were not considered during the API blueprint design process, and could result in conditions where things fought and overwrote each other.
The new system uses two chains of information, and uses a much more rigid standardized system of providing and using that information, with each system just adding another layer onto a pile with no regard to order implying anything. What I have seen from this system sofar is that it is not difficult to merely swap my existing code to use the new stuff, however, the power of the new system is that it eliminates a huge pile of work-around systems put in use, to pass that info along. As such, I have been able to collapse lots of workaround code out of my plugins sofar, and this is no different.

Instead of having to try to infer what the player was holding when they placed the last of the item, and have nothing in their hand - which required approximiately 150 lines of code to list off all cases of ie seed placement, that beet plants mean beet seeds were used.. I can not collapse all of that code down to two lines, because now that information - which itemstack had been used in the event - is passed along in that second chain. The design of the second chain allows room for a sensible request for adding another category of data passed along, that being which hand was holding it, but that is currently not there. But a request will be made for that to be added, as this new system is more capable of reporting that information, while the existing system used to code the playersever at this time does not have it.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to: