Skip to content

Commit a00c376

Browse files
committed
Test for off-thread cart creation.
1 parent 86d245a commit a00c376

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/java/noobanidus/mods/lootr/event/HandleCart.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package noobanidus.mods.lootr.event;
22

3+
<<<<<<< HEAD
4+
=======
5+
import net.minecraft.server.level.ServerLevel;
6+
import net.minecraft.world.entity.Entity;
7+
>>>>>>> 28fbef8 (Test for off-thread cart creation.)
38
import net.minecraft.world.entity.EntityType;
49
import net.minecraft.world.entity.vehicle.MinecartChest;
510
import net.neoforged.bus.api.SubscribeEvent;
@@ -19,10 +24,17 @@ public static void onEntityJoin(EntityJoinLevelEvent event) {
1924
}
2025
if (event.getEntity().getType() == EntityType.CHEST_MINECART && event.getEntity() instanceof MinecartChest chest) {
2126
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+
}
2638
}
2739
}
2840
}

0 commit comments

Comments
 (0)