
Feature Suggestion: Magnet holds items in a buffer.
K4N0 opened this issue ยท 14 comments
In an attempt to fix lag from so many items flying around players causing the server to time out.
Maybe if possible have the magnet hold all the items in some sort of buffer if the player can't pick them up. The player won't have access to the items until he clears inventory space or turns the magnet off.
Other players won't have access or be able to pick up the items even though they are next to the player with the magnet and a full inventory. Items won't be flying around the player. Items would be attached to the magnet in it's buffer. Hope that makes sense. I really like the magnet. i really don't want to ban it from the server. When the magnet is turned off the items would come out of the buffer and drop onto the floor. I understand the endless carrying capacity, but maybe it can hold Xamount of items and won't pick up any more. Then you can work on upgrades that hold more items in the buffer.
At the moment it is being used to carry endless very laggy large amounts of entities, so this maybe a good solution.
Players will always take advantage or cause trouble for servers if they can. There is no way to watch everyone at all times 24/7 to see who is causing this. There are plugins like Clearlag that remove all dropped entities after a warning every X amount of minutes, but you can't run that commant all the time and the server gets lagged out so fast after using the magnet.
If it is possible to fix it as you suggest, I'm all for it. It sounds good and that might fix the Xp dupe.
I think this is an X-Y problem. The real problem is that people are abusing the magnet to "carry" large amounts of items. PR #2920 will prevent that better than making the magnet an infinite pouch---which would just encourage people to do it more often.
Ultimately, a server owner has to take action against people lagging out the system with an abusive amount of item entities. I guess there are plugins that'll delete item entities if there are too many?
Not Enough Items mod seems to have magnet mode. When used in survival it will only pick up items that can fit in your inventory and the rest will just stay put. This seems to work very well and has a MIT license. https://github.com/Chicken-Bones/NotEnoughItems/blob/master/LICENSE.txt
I did some testing and nei magnet mode works great in survival. When i remove something from my inventory to create an open space it begins to pick up items to fill that slot. I haven't been able to cause the xp dupe bug either. Maybe something like this can be used for the magnet.
i like the magnet and how it work now, but i have found that it don't attract xp orb made by openblock shower. i don't know if is the same with regular xp orbs.
Now there seems to be a misconception about lag.
Lag is caused when a computation is taking too long. That can be because some item/block/entity does stupid things, like counting the amounts of lava blocks in the nether. That kind happens all the time, because many mod authors are not professional game coders. However, that is not what happens here.
It can also happen if there just is too much stuff around. So in vanilla, if you drop 1,000,000 items on the ground, the game will lag to a standstill. Because it not only has to render them all, but because it has to move all those item entities, check their collisions with players and blocks, and so on. This is generally not a coding error, but just simple overload.
Now, what does the Ender IO magnet do?
(1) It asks Minecraft for all item entities within a configured radius around the player.
(2) It then changes the velocity and speed of those item entities to give the illusion that they are being pulled towards the player.
(3) For item entities that are near the player, it tells them to check their collision with the player. (That is needed after every entity movement.)
That's it. (2) consist of 9 additions and 5 multiplications per item. That is about a lightweight a computation as you can get. Now, you asked to add "compare every item to every item in the player's inventory"---that is a massive piece of computing. It consists of up to 40 checks, each one comparing an itemstack (which has an item, a stack size, a stack size maximum, and for many items NBT values). We are talking about something that can takes several tens of thousand times longer to compute.
The PR above changes step (1). It limits the size of the list that will be produced by vanilla Minecraft for the magnet. Minecraft will still loop over all items in range, but it won't put them into a list. That saves a bit of time, but more importantly, a good chunk of memory. It will also limit the number of times step (2) has to run, but that nearly doesn't matter at all. That it limits the number of times step (3) is run however, does. That step already is doing the inventory check to see if an item can be picked up. Quite a good saving there.
@Fabboz We have special code for xp orbs, so it should work. I don't know if openblocks is doing something funny.
NEI magnet mode in SMP just applies some simple acceleration to items near players every tick. It also keeps track of the items 'picked up' by each player, It notifies the client of the items that are picked up and dropped (via their entityID) so the client can perform the same calculations.
I"m not a mod dev, but i know what works and what causes massive server lag / dupes xp.
Server lag:
Server lag from the magnet causes tps to drop to a standstill. ram and cpu usage is not affected.
That seems odd. Any other player attempting to join the server gets timed out. If you do make it in the game there is massive block lag and if you try to place your inventory into a chest it keeps coming back into your inventory. This does not seem to be a client fps issue. I have a decent computer and this issue has been reported from many people not just me.
I am only trying to help since there seems to be a magnet mode from nei that seems to work pretty well. Maybe such a method can be used to quickly fix the problem. It seems this issue has been around for quite some time. I'm just wondering if maybe someone is having a hard time fixing it or just has more important things to fix?
Just have a look at
and
https://github.com/Chicken-Bones/NotEnoughItems/blob/1.7/src/codechicken/nei/ClientHandler.java#L44
Which one does way more processing than the other one?
It may just be the Atomic Disassembler from mekanism. I was able to get Hard Mode Tweaks mod dev to add in a max mining speed for stone. It has destroyed the AD and made it not lag when i use the magnet. It may have just been too much at once. As far as the xp dupe, that is still a problem.
Sorry to bring this up again, but yesterday i added some arguments into my mcmyadmin config for java. Before i did this i had not noticed that my tps had been dropping to around 15 - 18. This is when i was experiencing the issue of block lag and once i stopped using the magnet i was not getting so much lag. Upon much further testing, plugin removal and mod removal / configuration i have got my tps stable to 19.98 - 20. I get 20 tps even with 5 players in 1 spot running around destroying blocks with magnets active. Its all the players i could get online at the time. I am not experiencing any block lag or xp dupes at all no matter how hard i tried to cause lag. I will post the java arguments when i get home and maybe you can help me know what it did so that others may benefit from this. I noticed a increase in cpu activity. I have 2 quad core cpu, 3.0 and 16gb of ram.
I was attempting to allow java - server to use all the cores of the cpu to increase the performance.
I'll get back to this issue once i get a few more hours of playtime.
Note after all of this, i installed optifine and my fps is maxed out at what i set it to 60fps. before it was around 35-60, but now it's steady at 60fps. I just hope i don't come accross any issues with it.
It seems to work very well on lower end computers. Mine is a medium computer thou.