1.19.2 Freezes when used with Repurposed Structures
tatoyoda600 opened this issue ยท 1 comments
Was using this mod in a modpack alongside the Repurposed Structures mod in a modpack and the game froze indefinitely upon loading a chunk with one of its structures in it, the Underground Bastion. I narrowed the modpack down to just 4 mods and filed an issue with the Repurposed Structures mod (TelepathicGrunt/RepurposedStructures#340), but the creator informed me that it's an issue with a section of this mod's code:
This issue appears to happen because they include mobs in their structures, and has caused this same issue before alongside the Structure Gel API (https://gitlab.com/modding-legacy/structure-gel-api/-/issues/36).
Was able to narrow it down to the following mod combination:
- forge-1.19.2-43.4.0-installer.jar
- blueprint-1.19.2-6.2.0.jar
- environmental-1.19.2-3.1.1.jar
- repurposed_structures_forge-6.3.28+1.19.2.jar
- tectonic-forge-1.19-2.3.5a.jar
- (No additional datapacks, resource packs, or anything)
Steps I used to consistently repeat the issue:
- Seed:
-7123539784518700980
- Locate Underground Bastion:
/locate structure #repurposed_structures:explorer_maps/bastion_underground
- TP to Underground Bastion:
/tp @s 2384 ~ -3888
No crash report because it never reaches the crash.
Game log looks fine, it freezes without ever logging anything useful, so the last thing in all my logs is always the result of the /locate
command, followed by the logs for force quitting Minecraft when I decide to use Task Manager on it:
[net.minecraft.server.MinecraftServer/]: tatoyoda600 joined the game
[net.minecraft.advancements.AdvancementList/]: Loaded 19 advancements
[net.minecraft.client.gui.components.ChatComponent/]: [System] [CHAT] The nearest #repurposed_structures:explorer_maps/bastion_underground (repurposed_structures:bastion_underground) is at [2384, ~, -3888] (3696 blocks away)
[net.minecraft.client.Minecraft/]: Stopping!
The launcher just tells me that the game was closed forcefully:
Process crashed with exit code 1
Don't know anything about Minecraft modding, so I don't know the repercussions of the following code, if any, but I was able to get the game to stop freezing by editing MobMixin.java to have the code below.
The code below is based heavily on the code Structure Gel API began using after the issue cropped up there.
- Getting the
ServerLevelAccessor
: https://gitlab.com/modding-legacy/dungeons-plus/-/blob/1.19.x/src/main/java/com/legacy/dungeons_plus/events/DPCommonEvents.java#L82 - Using it to get the
StructureManager
: https://gitlab.com/modding-legacy/structure-gel-api/-/blob/1.19.2/src/main/java/com/legacy/structure_gel/api/structure/StructureAccessHelper.java#L102
New imports added:
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.ServerLevelAccessor;
Modification of the populateDefaultEquipmentSlots
function:
@Inject(method = "populateDefaultEquipmentSlots", at = @At("TAIL"))
private void populateDefaultEquipmentSlots(RandomSource random, DifficultyInstance difficulty, CallbackInfo info) {
int difficultyChance = difficulty.getDifficulty().getId() + 1;
if (this.getLevel() instanceof ServerLevelAccessor levelAccessor) {
if (levelAccessor.hasChunkAt(this.blockPosition())) {
StructureManager structureManager = levelAccessor instanceof ServerLevel sl ? sl.structureManager() : levelAccessor instanceof WorldGenRegion wg ? levelAccessor.getLevel().structureManager().forWorldGenRegion(wg) : null;
Optional<Named<Structure>> structures = levelAccessor.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).getTag(EnvironmentalStructureTags.HAS_HEALER_POUCH);
if (structureManager != null && structures.isPresent()) {
boolean valid = false;
for (Holder<Structure> structure : structures.get()) {
if (structure != null && structureManager.getStructureAt(this.blockPosition(), structure.value()).isValid()) {
valid = true;
break;
}
}
if (valid && random.nextDouble() < difficultyChance * 0.01F) {
this.setItemSlot(EquipmentSlot.CHEST, new ItemStack(EnvironmentalItems.HEALER_POUCH.get()));
this.armorDropChances[EquipmentSlot.CHEST.getIndex()] = 1.0F;
}
}
}
}
}