1
1
package noobanidus .mods .lootr .event ;
2
2
3
+ <<<<<<< HEAD
4
+ =======
5
+ import net .minecraft .server .level .ServerLevel ;
6
+ import net .minecraft .world .entity .Entity ;
7
+ >>>>>>> 28f bef8 (Test for off -thread cart creation .)
3
8
import net .minecraft .world .entity .EntityType ;
4
9
import net .minecraft .world .entity .vehicle .MinecartChest ;
5
10
import net .neoforged .bus .api .SubscribeEvent ;
@@ -19,10 +24,17 @@ public static void onEntityJoin(EntityJoinLevelEvent event) {
19
24
}
20
25
if (event .getEntity ().getType () == EntityType .CHEST_MINECART && event .getEntity () instanceof MinecartChest chest ) {
21
26
if (!chest .level ().isClientSide && chest .lootTable != null && ConfigManager .CONVERT_MINESHAFTS .get () && !ConfigManager .getLootBlacklist ().contains (chest .lootTable )) {
22
- LootrChestMinecartEntity lootr = new LootrChestMinecartEntity (chest .level (), chest .getX (), chest .getY (), chest .getZ ());
23
- lootr .setLootTable (chest .lootTable , chest .lootTableSeed );
24
- event .setCanceled (true );
25
- event .getLevel ().addFreshEntity (lootr );
27
+ if (chest .level () instanceof ServerLevel level ) {
28
+ LootrChestMinecartEntity lootr = new LootrChestMinecartEntity (chest .level , chest .getX (), chest .getY (), chest .getZ ());
29
+ lootr .setLootTable (chest .lootTable , chest .lootTableSeed );
30
+ event .setCanceled (true );
31
+ if (!level .getServer ().isSameThread ()) {
32
+ LootrAPI .LOG .error ("Minecart with Loot table created off main thread. Falling back on EntityTicker." );
33
+ EntityTicker .addEntity (lootr );
34
+ } else {
35
+ level .addFreshEntity (lootr );
36
+ }
37
+ }
26
38
}
27
39
}
28
40
}
0 commit comments