Changed the way level fix and dialog supress works
This commit is contained in:
parent
e27b6eb469
commit
277fd0c8fd
1 changed files with 50 additions and 20 deletions
|
@ -4,9 +4,12 @@ import org.betterx.worlds.together.WorldsTogether;
|
||||||
import org.betterx.worlds.together.world.event.WorldBootstrap;
|
import org.betterx.worlds.together.world.event.WorldBootstrap;
|
||||||
|
|
||||||
import com.mojang.serialization.Dynamic;
|
import com.mojang.serialization.Dynamic;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.screens.GenericDirtMessageScreen;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
|
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.level.LevelSettings;
|
import net.minecraft.world.level.LevelSettings;
|
||||||
import net.minecraft.world.level.levelgen.WorldDimensions;
|
import net.minecraft.world.level.levelgen.WorldDimensions;
|
||||||
import net.minecraft.world.level.levelgen.WorldOptions;
|
import net.minecraft.world.level.levelgen.WorldOptions;
|
||||||
|
@ -17,10 +20,11 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Mixin(WorldOpenFlows.class)
|
@Mixin(WorldOpenFlows.class)
|
||||||
public abstract class WorldOpenFlowsMixin {
|
public abstract class WorldOpenFlowsMixin {
|
||||||
|
@ -39,36 +43,62 @@ public abstract class WorldOpenFlowsMixin {
|
||||||
Runnable runnable
|
Runnable runnable
|
||||||
);
|
);
|
||||||
|
|
||||||
@Inject(
|
@Shadow
|
||||||
method = "checkForBackupAndLoad(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Ljava/lang/Runnable;)V",
|
@Final
|
||||||
cancellable = true,
|
private Minecraft minecraft;
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldOpenFlows;loadLevel(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lcom/mojang/serialization/Dynamic;ZZLjava/lang/Runnable;)V")
|
|
||||||
)
|
|
||||||
private void wt_callFixerOnLoad(
|
|
||||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
|
||||||
Runnable runnable,
|
|
||||||
CallbackInfo ci
|
|
||||||
) throws IOException {
|
|
||||||
final String levelID = levelStorageAccess.getLevelId();
|
|
||||||
final var dynamic = levelStorageAccess.getDataTag();
|
|
||||||
WorldBootstrap.InGUI.setupLoadedWorld(levelID, this.levelSource);
|
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Nullable
|
||||||
|
protected abstract LevelStorageSource.LevelStorageAccess createWorldAccess(String string);
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
protected abstract void checkForBackupAndLoad(
|
||||||
|
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||||
|
Runnable runnable
|
||||||
|
);
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "checkForBackupAndLoad(Ljava/lang/String;Ljava/lang/Runnable;)V",
|
||||||
|
cancellable = true,
|
||||||
|
at = @At("HEAD")
|
||||||
|
)
|
||||||
|
private void wt_callFixerOnLoad(String levelID, Runnable screenRunner, CallbackInfo ci) {
|
||||||
|
this.minecraft.forceSetScreen(new GenericDirtMessageScreen(Component.translatable("selectWorld.data_read")));
|
||||||
|
|
||||||
|
|
||||||
|
WorldBootstrap.InGUI.setupLoadedWorld(levelID, this.levelSource);
|
||||||
if (WorldBootstrap.InGUI.applyWorldPatches(levelSource, levelID, (appliedFixes) -> {
|
if (WorldBootstrap.InGUI.applyWorldPatches(levelSource, levelID, (appliedFixes) -> {
|
||||||
WorldBootstrap.finishedWorldLoad();
|
WorldBootstrap.finishedWorldLoad();
|
||||||
this.loadLevel(levelStorageAccess, dynamic, false, false, runnable);
|
|
||||||
|
LevelStorageSource.LevelStorageAccess levelStorageAccess = this.createWorldAccess(levelID);
|
||||||
|
if (levelStorageAccess == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.checkForBackupAndLoad(levelStorageAccess, screenRunner);
|
||||||
})) {
|
})) {
|
||||||
//cancel call when fix-screen is presented
|
//cancel call when fix-screen is presented
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
} else {
|
} else {
|
||||||
WorldBootstrap.finishedWorldLoad();
|
WorldBootstrap.finishedWorldLoad();
|
||||||
if (WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG) {
|
|
||||||
this.loadLevel(levelStorageAccess, dynamic, false, false, runnable);
|
|
||||||
//cancel call as we manually start the level load here
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ModifyArg(
|
||||||
|
method = "checkForBackupAndLoad(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Ljava/lang/Runnable;)V",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/client/gui/screens/worldselection/WorldOpenFlows;loadLevel(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lcom/mojang/serialization/Dynamic;ZZLjava/lang/Runnable;)V"
|
||||||
|
),
|
||||||
|
index = 3
|
||||||
|
)
|
||||||
|
public boolean wt_noWarningScreen(boolean bl) {
|
||||||
|
if (WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return bl;
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(method = "createFreshLevel", at = @At("HEAD"))
|
@Inject(method = "createFreshLevel", at = @At("HEAD"))
|
||||||
public void wt_createFreshLevel(
|
public void wt_createFreshLevel(
|
||||||
String string,
|
String string,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue