MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.6k stars 433 forks source link

Drones with chunkloader upgrade stop operating after going through a portal #3210

Open Kristopher38 opened 4 years ago

Kristopher38 commented 4 years ago

Versions: Minecraft: 1.12.2 Forge: 14.23.5.2768 OpenComputers: 1.7.5.192 Pure forge install without any third-party launchers, with only OpenComputers installed

Description: Drones with chunkloader upgrade stop operating after going to a dimension where portal exit isn't in a loaded chunk. That applies to going from the overworld to the nether/the end and vice versa. The drone resumes operation after the chunk that the drone ended up in gets loaded, e.g. a player loads it. If the chunk that the drone teleports to after going through a portal is loaded before the drone goes through, the drone runs as intended without a halt. This happens on singleplayer as well as on multiplayer server. I've tested it a bit and according to the logs (from locally hosted multiplayer server), the drone actually loads the dimension that it gets teleported into after going through a portal and even generates chunks around itself if it's a fresh area and fresh portal that wasn't used before. The issue is, after that the dimension gets immediately unloaded. I believe this could be the same issue as described in this issue, only that it's not an incompatibility with another mod, but rather an issue within OpenComputers itself.

Logs generated when going through a fresh portal:

[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 71] in dimension -1 (the_nether) while populating chunk [70, 72], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 74] in dimension -1 (the_nether) while populating chunk [70, 75], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 73] in dimension -1 (the_nether) while populating chunk [69, 74], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 72] in dimension -1 (the_nether) while populating chunk [69, 74], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [68, 72] in dimension -1 (the_nether) while populating chunk [69, 72], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 75] in dimension -1 (the_nether) while populating chunk [70, 76], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 76] in dimension -1 (the_nether) while populating chunk [70, 77], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:36] [Server thread/WARN] [FML]: OpenComputers loaded a new chunk [69, 81] in dimension -1 (the_nether) while populating chunk [70, 82], causing cascading worldgen lag.
[23:26:36] [Server thread/WARN] [FML]: Please report this to the mod's issue tracker. This log can be disabled in the Forge config.
[23:26:37] [Server thread/INFO] [FML]: Unloading dimension -1

Logs generated when going through an already-generated portal (on the exit end, notice the timestamps):

[23:28:31] [Server thread/INFO] [FML]: Loading dimension -1 (world) (net.minecraft.server.dedicated.DedicatedServer@2b70f90a)
[23:28:32] [Server thread/INFO] [FML]: Unloading dimension -1

How to reproduce:

  1. Teleport yourself away from the spawn chunks (10000 blocks should be more than enough) - that's for later, when testing going from the nether to the overworld, this step list is for testing overworld->nether
  2. Make a drone with chunkloader upgrade and EEPROM with a simple program to fly in a straight direction, e.g.
    
    local drone = component.proxy(component.list("drone")())
    local chunkloader = component.proxy(component.list("chunkloader")())

chunkloader.setActive(true) -- make sure the chunkloader upgrade is running drone.setStatusText(tostring(chunkloader.isActive())) -- verify it by setting status text drone.move(40, 0, 0) -- move 40 units east while true do drone.swing(0) -- do some action to yield end


2. Construct a nether portal so that when entering you're moving in the drone's moving direction (in the above program - east)
3. Go through the portal and if it's facing south/north in the nether, remake it so that it faces east/west
4. (Still in the nether) Clear the space (if it's obstructed) in front of the portal, that is - in the drone's moving direction (east) to visually determine later if it moved before the player entered
5. Go through the portal back to the overworld, place a drone in front of the portal (facing east, so that it's gonna enter the portal), and turn it on
6. Wait a few seconds and go through the portal - the drone is going to restart its operation and be near the player, still moving, instead of being stationary further away after already finishing moving while player was waiting for a while in the overworld (note that you might be facing a different direction when you exit the portal in the nether). Additionally, the drone going from the nether to the overworld can be similarly tested as well, yielding the same results.
hohserg1 commented 4 years ago

Do you tested this with one player on server? It bug may bound with dimension update mechanics: entities are not updated if dimension not contains players. For check it try follow:

  1. Execute steps 1-5
  2. Teleport youself away from first overworld place, build and enter to second nether portal
  3. Wait in the nether
  4. Return to first overworld place
  5. Execute step 6
Kristopher38 commented 4 years ago

I've tested this with your instructions on singleplayer as well as on multiplayer server, and also the other way around (from the nether to the overworld) and the drone still only starts moving when I enter the chunk in which it stopped execution.

Also note that, with my test setup, if I enter the portal before the drone does (with long runway for the drone, so the dimension for me finishes loading before the drone enters the portal), the drone runs continuously, i.e. I can see it seamlessly going out of the portal and flying straight. That means the chunk the drone is in before it enters the portal isn't unloaded when the only player exits the dimension, so it continues to fly straight into the portal.

There is also a way to provide stronger evidence to support this, e.g. setting up a stationary drone/robot with chunkloader upgrade near the exit of the portal, so the chunk with the portal in dimension where the drone exits it is always loaded, and then starting the drone from the other dimension to enter the portal (basically the setup in the first post, only that additionally in step 4. you place the drone/robot with chunkloader upgrade running in the same chunk that the exit portal is in). Drone entity still gets processed after exiting the portal on the other end, i.e. it has already finished moving when the player enters the dimension, even though there were no players in that dimension, but the chunk with the portal exit was loaded, which allowed it to move beyond that chunk.

My point is, it's not an issue with entity processing in dimensions without players. I believe it's a problem with with chunk loading when switching dimensions, but maybe someone else could provide more insight on this.

TheCodex6824 commented 2 years ago

I looked into this a bit, and I made a fix here. In short, the problem was that entities changing dimensions actually get "cloned" into a new entity instead of just moving the old one, which made the chunkloader not even realize it was supposed to be on. I fixed it by tracking when a drone was changing dimensions, and if it had an active chunkloader, record its address so I can enable the chunkloader on the newly cloned drone.

I could PR that, but EntityTravelToDimensionEvent is only on 1.12, so 1.7.10 would still have the bug. I didn't see anything in 1.7 that serves the same purpose as that event, so I'm not sure what to do about that.

asiekierka commented 2 years ago

I don't like that the chunkloader upgrade code doesn't store whether or not it's supposed to be enabled. This would make resolving the issue much simpler - instead of relying on ChunkloaderUpgradeHandler.restoredTickets and Forge's own chunkloader ticket tracking system in onConnect, we could simply check the chunkloader upgrade's own flag for whether or not it is meant to be enabled.

In this case, I would also extend the chunkloader upgrade's API with isEnabled and setEnabled (the latter aliased to setActive); this way, isActive would tell us if a chunkloader is actually active, while isEnabled would merely inform us of the user's current intent.