Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19.2 Freezes when used with Repurposed Structures #419

Open
tatoyoda600 opened this issue Jun 21, 2024 · 1 comment
Open

1.19.2 Freezes when used with Repurposed Structures #419

tatoyoda600 opened this issue Jun 21, 2024 · 1 comment

Comments

@tatoyoda600
Copy link

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:

if (structure != null && serverLevel.structureManager().getStructureAt(this.blockPosition(), structure.value()).isValid()) {

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:

Steps I used to consistently repeat the issue:

  1. Seed: -7123539784518700980
  2. Locate Underground Bastion: /locate structure #repurposed_structures:explorer_maps/bastion_underground
  3. 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
@tatoyoda600
Copy link
Author

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.

if (structure != null && serverLevel.structureManager().getStructureAt(this.blockPosition(), structure.value()).isValid()) {

The code below is based heavily on the code Structure Gel API began using after the issue cropped up there.

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;
			}
		}
	}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant