Skip to content

Commit 48bee14

Browse files
committed
Potentially fix #646: certain chests not converting.
The "aggressive mode" introduced in the previous release caused all chests that were spawned and registered as block entities and then *later* had a loot table set with `setLootTable were ignored.
1 parent 58f37d1 commit 48bee14

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/main/java/noobanidus/mods/lootr/block/entities/TileTicker.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class TileTicker {
3232
private final static Set<Entry> tileEntries = new ObjectLinkedOpenHashSet<>();
3333
private final static Set<Entry> pendingEntries = new ObjectLinkedOpenHashSet<>();
3434
private static boolean tickingList = false;
35+
private static boolean alertedLargeQuantity = false;
3536

3637
public static void addEntry(RandomizableContainerBlockEntity incoming ,Level level, BlockPos position) {
3738
if (ConfigManager.DISABLE.get()) {
@@ -71,16 +72,26 @@ public static void addEntry(RandomizableContainerBlockEntity incoming ,Level lev
7172
}
7273
}
7374

74-
if (incoming.lootTable == null || ConfigManager.isBlacklisted(incoming.lootTable)) {
75-
return;
75+
if (ConfigManager.AGGRESSIVE_MODE.get()) {
76+
if (incoming.lootTable == null || ConfigManager.isBlacklisted(incoming.lootTable)) {
77+
return;
78+
}
7679
}
7780

7881
Entry newEntry = new Entry(dimension, position, chunks, ServerLifecycleHooks.getCurrentServer().getTickCount());
7982
synchronized (listLock) {
8083
if (tickingList) {
8184
pendingEntries.add(newEntry);
85+
if (pendingEntries.size() > 100 && !alertedLargeQuantity && !ConfigManager.AGGRESSIVE_MODE.get()) {
86+
LootrAPI.LOG.error("There are over 100 entries in the pending conversion list without aggressive mode enabled. This may cause TPS issues. If TPS issues persist after first launch, consider enabling aggressive mode in the configuration.");
87+
alertedLargeQuantity = true;
88+
}
8289
} else {
8390
tileEntries.add(newEntry);
91+
if (tileEntries.size() > 100 && !alertedLargeQuantity && !ConfigManager.AGGRESSIVE_MODE.get()) {
92+
LootrAPI.LOG.error("There are over 100 entries in the conversion list without aggressive mode enabled. This may cause TPS issues. If TPS issues persist after first launch, consider enabling aggressive mode in the configuration.");
93+
alertedLargeQuantity = true;
94+
}
8495
}
8596
}
8697
}

src/main/java/noobanidus/mods/lootr/config/ConfigManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ConfigManager {
4949
public static final ForgeConfigSpec.BooleanValue CONVERT_ELYTRAS;
5050
public static final ForgeConfigSpec.BooleanValue CONVERT_WOODEN_CHESTS;
5151
public static final ForgeConfigSpec.BooleanValue CONVERT_TRAPPED_CHESTS;
52+
public static final ForgeConfigSpec.BooleanValue AGGRESSIVE_MODE;
5253
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> ADDITIONAL_CHESTS;
5354
public static final ForgeConfigSpec.ConfigValue<List<? extends String>> ADDITIONAL_TRAPPED_CHESTS;
5455
// Breaking
@@ -123,6 +124,7 @@ public class ConfigManager {
123124
List<? extends String> empty = Collections.emptyList();
124125
Predicate<Object> validator = o -> o instanceof String && ((String) o).contains(":");
125126
Predicate<Object> modidValidator = o -> o instanceof String && !((String) o).contains(":");
127+
AGGRESSIVE_MODE = COMMON_BUILDER.comment("if true, all block entities will be checked before being added to the ticker for an eligible loot table. enable this if a huge quantity of containers are clogging the conversion system; note that aggressive mode may prevent certain chests from properly converted even though eligible").define("aggressive_mode", false);
126128
REPORT_UNRESOLVED_TABLES = COMMON_BUILDER.comment("lootr will automatically log all unresolved tables (i.e., for containers that have a loot table associated with them but, for whatever reason, the lookup for this table returns empty). setting this option to true additionally informs players when they open containers.").define("report_unresolved_tables", false);
127129
ADDITIONAL_CHESTS = COMMON_BUILDER.comment("a list of additional chests that should be converted (in the format of [\"modid:name\", \"modid:other_name\"], must be a tile entity instance of RandomizableContainerBlockEntity)").defineList("additional_chests", empty, validator);
128130
ADDITIONAL_TRAPPED_CHESTS = COMMON_BUILDER.comment("a list of additional trapped chests that should be converted (in the format of [\"modid:name\", \"modid:other_name\"], must be a tile entity instance of RandomizableContainerBlockEntity)").defineList("additional_trapped_chests", empty, validator);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package noobanidus.mods.lootr.mixins;
2+
3+
import net.minecraft.resources.ResourceLocation;
4+
import net.minecraft.world.level.Level;
5+
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
6+
import noobanidus.mods.lootr.api.blockentity.ILootBlockEntity;
7+
import noobanidus.mods.lootr.block.entities.TileTicker;
8+
import noobanidus.mods.lootr.config.ConfigManager;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(RandomizableContainerBlockEntity.class)
15+
public class MixinRandomizableContainerBlockEntity {
16+
@Inject(method = "setLootTable(Lnet/minecraft/resources/ResourceLocation;J)V", at = @At("RETURN"))
17+
private void lootrOnSetLootTable(ResourceLocation p_59627_, long p_59628_, CallbackInfo ci) {
18+
if (ConfigManager.DISABLE.get() || !ConfigManager.AGGRESSIVE_MODE.get()) {
19+
return;
20+
}
21+
22+
RandomizableContainerBlockEntity incoming = (RandomizableContainerBlockEntity) (Object) this;
23+
24+
if (!incoming.hasLevel() || incoming instanceof ILootBlockEntity) {
25+
return;
26+
}
27+
28+
Level level = incoming.getLevel();
29+
30+
if (level == null) {
31+
return; // This should be false because `hasLevel`
32+
}
33+
34+
if (level.isClientSide()) {
35+
return;
36+
}
37+
// By default block entities outside of the world border are
38+
// not converted. When the world border changes, you will
39+
// need to restart the server.
40+
if (ConfigManager.CHECK_WORLD_BORDER.get() && !level.getWorldBorder()
41+
.isWithinBounds(incoming.getBlockPos())) {
42+
return;
43+
}
44+
45+
TileTicker.addEntry(incoming, level, incoming.getBlockPos());
46+
}
47+
}

src/main/resources/lootr.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"MixinLevelChunk",
1010
"MixinPoiType",
1111
"MixinPoiTypes",
12+
"MixinRandomizableContainerBlockEntity",
1213
"MixinStructureTemplate"
1314
],
1415
"client": [

0 commit comments

Comments
 (0)