SpongePowered / Sponge

The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
MIT License
390 stars 211 forks source link

[1.10.2] world.getEntitiesWithinAABB Always returning empty #832

Closed Thutmose closed 8 years ago

Thutmose commented 8 years ago

Whenever I call world.getEntitiesWithinAABB, I always get an empty list.

https://github.com/Thutmose/Pokecube/blob/1.10/Pokecube%20Core/src/main/java/pokecube/core/events/handlers/SpawnHandler.java#L605-L606

This is the prime location I am calling it, I use it to determine if there are too many mobs in the area before spawning more. This method is called whenever WorldTickEvent is fired, and only server side and if the phase is Phase.END.

When I add in a debug print, like this: if (world.getTotalWorldTime() % 20 == 0) System.out.println(num + " " + list.size() + " " + box); on line 612 of the above class, it prints this without spongeforge:

93 96 box[-359.4350225891916, 4.0, 72.5692321820978 -> -295.4350225891916, 142.0, 136.5692321820978]

and this with spongeforge: 0 0 box[-359.4350225891916, 4.0, 72.5692321820978 -> -295.4350225891916, 142.0, 136.5692321820978]

I only spawn entities if the first of those two numbers is less than a configurable spawn rate, normally set to 10, so when it always returns 0, my mobs never stop spawning.

This also persists if I have the global.conf as follows: http://pastebin.com/Rpn5TpMD

This was tested with spongeforge 1550 for minecraft 1.10.2, using Minecraft Forge 2007, and the following assortment of mods:

image

where the version of Pokecube Core there was modified to make those above prints.

This issue was mainly brought to my attention due to this: https://github.com/Thutmose/Pokecube/issues/107

Aaron1011 commented 8 years ago

@bloodmc: I think this issue is related to the collision patches.

Thutmose commented 8 years ago

It wasn't fixed by disabling collision patches though, that was tried before I posted the issue here.

Thutmose commented 8 years ago

I found why this happens, the issue is as follows:

https://github.com/SpongePowered/SpongeCommon/blob/bleeding/src/main/java/org/spongepowered/common/mixin/core/world/MixinChunk.java#L423

Here, the list of entities is cleared if the event is null or canceled. This causes a problem if the event is null for some reason.

https://github.com/SpongePowered/SpongeCommon/blob/bleeding/src/main/java/org/spongepowered/common/event/SpongeCommonEventFactory.java#L206

Here a null cause is assigned if not from active entity, tile entity or block snapshot. This then results in the event returning null, thereby clearing the list in MixinChunk. This is why my list is always empty, I am not calling it from either of those three, I am calling it from a class which listens for WorldTickEvent from forge.

gabizou commented 8 years ago

Fixed in the latest commit.