#How do I listen for a dropped item moving? - Custom Hopper

1 messages · Page 1 of 1 (latest)

celest scroll
#

I have tried 3 different ways but for each I don't know where to go from here, and I can't come up with another way.

Why do I even want this? I am trying to create a custom (chunk)hopper system where instead of all hoppers constantly looking for items above them, the item itself checks if there is a (chunk)hopper underneath it (or in the same chunk) every time it's location changes. To reduce lag.

What I tried:

    1. I tried using an Event created by spigot, the problem is that EntityMoveEvent only works for LivingEntity, and I can't find another event.
    1. I tried using NMS mojang mappings, but because the packet is clientbound I can't overwrite the channelRead() method from ChannelDuplexHandler (because it simply doesn't trigger when an entity moves), and the write() method's Object isn't a packet, instead it prints PooledUnsafeHeapByteBuf() and I have no idea what that means or if and how I can get a packet out of that https://pastes.dev/FVFGqzDGxs
    1. I tried using ProtocolLib's PacketType.Play.Server.REL_ENTITY_MOVE but I have no idea how to decode the packet into an Item instance with the correct ItemStack, Chunk, Location etc. Because the wiki is simply not simple to understand. https://pastes.dev/nk08OW7Zm2
      It prints something like this when I drop an item and it moves due to gravity and velocity (The values vary) :
[16:19:13 INFO]: 47
[16:19:13 INFO]: 0
[16:19:13 INFO]: 0
[16:19:13 INFO]: 0
[16:19:13 INFO]: false
[16:19:13 INFO]: false
[16:19:13 INFO]: true
zenith crescent
#

They're all good approaches, however I believe the usual task is better than listening for all entity movement

#

Approaches 2 and 3 are flawed

#

If there are no players nearby to send packets to, there's no point in sending them in the first place

#

You can get all entities at a chunk by doing Chunk#getEntities

#

Just make that task run once a second and also listen to EntitySpawnEvent and your usual item drop events first

celest scroll
# zenith crescent Just make that task run once a second and also listen to EntitySpawnEvent and yo...

Oh yes this would totally work, but won't having an infinitely repeating task for every chunk with a chunkhopper cause lag on the server? I thought if I listen for dropped items moving it might be more laggy when a lot of items are in waterstreams or falling but at the end they will always stop.

Also if I were to use this approach I assume I should do something like this https://www.spigotmc.org/threads/guide-on-workload-distribution-or-how-to-handle-heavy-splittable-tasks.409003/

zenith crescent
#

Well, yes and no

#

It depends on your data structure

#

If you're only ticking hoppers in loaded chunks it's fine

#

Just make a data structure where you can get every hopper in a chunk, and once a second you go over every item and filter them to what goes where

#

Iterate items once

celest scroll
# zenith crescent If you're only ticking hoppers in loaded chunks it's fine

Alright so if I use the chunkload & chunkunload events to add and remove chunks with a chunkhopper in them to the runnable task I should be good? Also I don't think it's possible for items to drop or despawn in unloaded chunks so nothing should be lost I think.

Also I don't really know what you meant with your last 2 sentences and if you're talking about recoding normal hoppers or chunkhoppers, and if you're talking about the item pickup system or the transfer system, and how I should iterate the items once.

zenith crescent
#

Idea is

#

What if you have multiple chunk hoppers in the same chunk

#

Let's say you have 2 chunk hoppers and 300 items

#

You want to go over every item once

#

And for each item go over all the chunk hoppers to see where it lands

gray cosmos
#

or you can just not allow 2 in 1 chunk

celest scroll
#

Ah I see, so it doesn't get duplicated, I was writing about how I can keep the effect of the items getting picked up in order without creating a runnable for each item but I already found the answer #help-development message