Jump to content

[1.19] Migrating a mod from 1.18


Quipex

Recommended Posts

Hello, first of all, I'm new to forge so if I'm missing some basic things, feel free to point me into it.

I'm trying to migrate a minecraft mod from 1.18 to 1.19. Its pretty much done, but there is one bug that I can't resolve.

On the original mod (1.18) there is packet handler that takes care of the main business logic: it scans cube of a configured radius, finds chests and fills them from player's inventory. Here's github link to the method that does the job.

On contrary, my migrated (1.19) method does the same. The main issue is that on the Line 184 after we map BlockPos to BlockEntity and filter by NotNull, we get  0 blocks (at 1.18 it determines everything fine):

var blockEntities = BlockPos.betweenClosedStream(minX, minY, minZ, maxX, maxY, maxZ)
                .map(world::getBlockEntity)
                .toList();
DropOff.LOGGER.debug("Found {} block entities", blockEntities.size());

var nonNulls = blockEntities.stream()
                .filter(Objects::nonNull).toList();
DropOff.LOGGER.debug("Found {} non-nulls", nonNulls.size());

This are the sources of Level#getBlockEntity(BlockPos):

   @Nullable
   public BlockEntity getBlockEntity(BlockPos p_46716_) {
      if (this.isOutsideBuildHeight(p_46716_)) {
         return null;
      } else {
         return !this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(p_46716_).getBlockEntity(p_46716_, LevelChunk.EntityCreationType.IMMEDIATE);
      }
   }

So I guess my issue lays in `Thread.currentThread() != this.thread`.

 

I reckon I did something wrong with the event listeners which led to this problem. Please help me troubleshoot the problem.

FYI: 1.19 repo, 1.18 repo

Edited by Quipex
Link to comment
Share on other sites

You probably want to look at "handling packets" here: https://forge.gemwire.uk/wiki/SimpleChannel

i.e. making sure you run on the correct thread so you are doing things in a thread safe way and not running concurrently with other stuff on the networking thread(s)

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

The 1.18.1 Level.getBlockEntity() also has that thread check, so I don't see how your code works there?

I suggest you add some logging or use a debugger to figure out what is really happening (on both versions).

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I've just been testing your 2 branches.

In 1.18.2 the thread is usually already the ServerThread so it works. But this isn't guaranteed, it could be a networking thread.

In 1.19.2 the thread is usually a networking thread so it fails.

 

When I wrap your handle() code inside a

ctx.get().enqueueWork(() -> {
// original code here
});

it is always on the server thread and so works.

 

So it looks like you didn't change your code properly, maybe you didn't save it?

NOTE: You will need to fix this for 1.18.2 as well. As I said above, this code could run on "any" thread unless you force it onto the ServerThread.

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

UPD: saw your comment above, let me check that

 

Ok, so I've debugged and now I can confirm that on the 1.18 Thread.currentThread() != this.thread produces false, when on 1.19 it gives true. Only things that come to my mind are: I made some event handlers static (to compare: 1.18 and 1.19)

Edited by Quipex
too late to respond
Link to comment
Share on other sites

12 minutes ago, warjort said:

NOTE: You will need to fix this for 1.18.2 as well. As I said above, this code could run on "any" thread unless you force it onto the ServerThread.

Weird thing: I've wrapped 1.18 code inside enqueueWork and now it also returns only nulls..

Link to comment
Share on other sites

You will need to debug that for yourself.

Maybe the chunk you are referencing isn't loaded or you have "broken" the BlockEntity in your test world during some previous testing?

I've just been testing with a chest and got it to work.

Try creating a new test world so you know you don't have corrupt data.

 

BTW: "Pinging" does nothing except adding noise the thread.

If it really did something I would I turn it off. 🙂 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

This is the change I made to get 1.19.2 to work:

diff --git a/src/main/java/tfar/quickstack/networking/C2SPacketRequestDropoff.java b/src/main/java/tfar/quickstack/networking/C2SPacketRequestDropoff.java
index 7a1d17a..ee58ebb 100644
--- a/src/main/java/tfar/quickstack/networking/C2SPacketRequestDropoff.java
+++ b/src/main/java/tfar/quickstack/networking/C2SPacketRequestDropoff.java
@@ -58,6 +58,7 @@ public class C2SPacketRequestDropoff {
     }

     public void handle(Supplier<NetworkEvent.Context> ctx) {
+ctx.get().enqueueWork(() -> {
         ServerPlayer player = ctx.get().getSender();
         Set<InventoryData> nearbyInventories = getNearbyInventories(player);

@@ -97,6 +98,7 @@ public class C2SPacketRequestDropoff {
                 new S2CReportPacket(itemsCounter, affectedContainers, nearbyInventories.size(),
                         rendererCubeTargets));
         ctx.get().setPacketHandled(true);
+});
     }

     public void dropOff(Player player, IItemHandler target, InventoryData data) {
@@ -172,6 +174,7 @@ public class C2SPacketRequestDropoff {
         Level world = player.level;
         DropOff.LOGGER.debug("World info: {}", world);
         DropOff.LOGGER.debug("Is client: {}", world.isClientSide());
+        DropOff.LOGGER.debug("" + Thread.currentThread());

         DropOff.LOGGER.debug("Scanning x({},{}) y({},{}), z({},{})", minX, maxX, minY, maxY, minZ, maxZ);
         var blockEntities = BlockPos.betweenClosedStream(minX, minY, minZ, maxX, maxY, maxZ)

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

5 minutes ago, warjort said:

Maybe the chunk you are referencing isn't loaded or you have "broken" the BlockEntity in your test world during some previous testing?

No, just tested on a brand new world, it must be something else.

6 minutes ago, warjort said:

I've just been testing with a chest and got it to work.

Just to make sure I got you right: it highlights the chests and prompts in console how many chests were checked in total (not 0)?

Link to comment
Share on other sites

Quote

[19:50:14] [Netty Local Client IO #0/INFO] [minecraft/ChatComponent]: [System] [CHAT] [DropOff]: 1 items moved to 1 containers of 1 checked in total.

And I got the highlighted chest.

I am just intuiting what it supposed to do. You haven't explained it.

 

But anyway, it's not really my task to debug your code. I only did the stuff above because what you were talking about didn't make sense and I wanted to know why.

 

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.