diff --git a/gradle.properties b/gradle.properties index 1bf1e63..bfc77a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false # Project -mod_version=9.0.0 +mod_version=10.0.0 mod_id=lockdown mod_name=Lockdown mod_display_name=Lockdown @@ -16,5 +16,5 @@ mod_scm_url=scm:git:git@github.com:Glitchfiend/Lockdown.git mod_curseforge_id=244019 # Dependencies -minecraft_version=1.19 -forge_version=41.0.98 +minecraft_version=1.20.1 +forge_version=47.4.1 diff --git a/src/main/java/adubbz/lockdown/Lockdown.java b/src/main/java/adubbz/lockdown/Lockdown.java index d3e15fd..9760eed 100644 --- a/src/main/java/adubbz/lockdown/Lockdown.java +++ b/src/main/java/adubbz/lockdown/Lockdown.java @@ -7,6 +7,7 @@ import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,8 +17,8 @@ public class Lockdown public static final String MOD_ID = "lockdown"; public static final Logger LOGGER = LogManager.getLogger(MOD_ID); - public Lockdown() + public Lockdown(FMLJavaModLoadingContext context) { - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.SPEC, "lockdown.toml"); + context.registerConfig(ModConfig.Type.CLIENT, Config.SPEC, "lockdown.toml"); // new context, for 1.21.1+ versions } } diff --git a/src/main/java/adubbz/lockdown/mixin/client/MixinCreateWorldScreen.java b/src/main/java/adubbz/lockdown/mixin/client/MixinCreateWorldScreen.java index 2a582be..fc97bf5 100644 --- a/src/main/java/adubbz/lockdown/mixin/client/MixinCreateWorldScreen.java +++ b/src/main/java/adubbz/lockdown/mixin/client/MixinCreateWorldScreen.java @@ -6,26 +6,19 @@ import adubbz.lockdown.Config; import adubbz.lockdown.Lockdown; -import com.mojang.serialization.Lifecycle; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.gui.screens.GenericDirtMessageScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; -import net.minecraft.client.gui.screens.worldselection.WorldCreationContext; -import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; +import net.minecraft.client.gui.screens.worldselection.WorldCreationUiState; import net.minecraft.network.chat.Component; -import net.minecraft.world.Difficulty; import net.minecraft.world.level.LevelSettings; -import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.storage.LevelStorageSource; -import net.minecraft.world.level.storage.PrimaryLevelData; -import net.minecraft.world.level.storage.WorldData; import org.apache.commons.io.FileUtils; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -36,74 +29,55 @@ @Mixin(CreateWorldScreen.class) public abstract class MixinCreateWorldScreen extends Screen { - @Shadow - private String initName; - @Shadow - public boolean hardCore; - - @Shadow - private CycleButton modeButton; - @Shadow - private CycleButton difficultyButton; - @Shadow - private CycleButton commandsButton; - - @Shadow - private Button moreOptionsButton; - @Shadow - private Button gameRulesButton; - @Shadow - private Button dataPacksButton; - - @Shadow - private Component gameModeHelp1; - @Shadow - private Component gameModeHelp2; - @Shadow @Final - public WorldGenSettingsComponent worldGenSettingsComponent; + @Shadow + WorldCreationUiState uiState; protected MixinCreateWorldScreen(Component component) { super(component); } - @Inject(method="init", at=@At(value="RETURN")) - private void onInit(CallbackInfo ci) - { - if (Config.disableGameMode.get()) - { - this.modeButton.visible = false; - this.gameModeHelp1 = Component.translatable(""); - this.gameModeHelp2 = Component.translatable(""); - } - if (Config.disableCheats.get()) - { - this.commandsButton.visible = false; - } - - if (Config.disableGameRules.get()) - { - this.gameRulesButton.visible = false; - } - - if (Config.disableDifficulty.get()) - { - this.difficultyButton.visible = false; - } - - if (Config.disableDataPacks.get()) - { - this.dataPacksButton.visible = false; - } - - if (Config.disableMoreWorldOptions.get()) - { - this.moreOptionsButton.visible = false; - } - } +/// +/// These appear to be held in "tabs" within other classes, probably will require reflection or something simpler, I'm sure someone familiar will know. +/// +// @Inject(method="init", at=@At(value="RETURN")) +// private void onInit(CallbackInfo ci) +// { +// if (Config.disableGameMode.get()) +// { +// this.modeButton.visible = false; +// this.gameModeHelp1 = Component.translatable(""); +// this.gameModeHelp2 = Component.translatable(""); +// } +// +// if (Config.disableCheats.get()) +// { +// this.commandsButton.visible = false; +// } +// +// if (Config.disableGameRules.get()) +// { +// this.gameRulesButton.visible = false; +// } +// +// if (Config.disableDifficulty.get()) +// { +// this.difficultyButton.visible = false; +// } +// +// if (Config.disableDataPacks.get()) +// { +// this.dataPacksButton.visible = false; +// } +// +// if (Config.disableMoreWorldOptions.get()) +// { +// this.moreOptionsButton.visible = false; +// } +// } @Inject(method="onCreate", at=@At(value="HEAD"), cancellable = true) private void onCreate(CallbackInfo ci) @@ -113,13 +87,12 @@ private void onCreate(CallbackInfo ci) File gameDirectory = this.minecraft.gameDirectory.getAbsoluteFile(); File templateDirectory = new File(gameDirectory + File.separator + Config.templateDirectory.get()); - // Queue the load screen whilst we copy the template this.queueLoadScreen(); // Copy the world try { - FileUtils.copyDirectory(templateDirectory, new File(gameDirectory + File.separator + "saves" + File.separator + this.initName)); + FileUtils.copyDirectory(templateDirectory, new File(gameDirectory + File.separator + "saves" + File.separator + uiState.getName())); } catch (IOException e) { @@ -127,49 +100,34 @@ private void onCreate(CallbackInfo ci) return; } + + //settings try { - LevelStorageSource.LevelStorageAccess storageAccess = this.minecraft.getLevelSource().createAccess(this.initName); - - // Rename the level for our new name - storageAccess.renameLevel(this.initName); - - // Replace the world data if needed - if (!Config.useTemplateWorldSettings.get()) - { - Lockdown.LOGGER.info("Replacing world data..."); - - // Create the new world data - WorldCreationContext worldCreationContext = this.worldGenSettingsComponent.createFinalSettings(this.hardCore); - LevelSettings levelSettings = this.createLevelSettings(worldCreationContext.worldGenSettings().isDebug()); - WorldData newWorldData = new PrimaryLevelData(levelSettings, worldCreationContext.worldGenSettings(), worldCreationContext.worldSettingsStability()); - - // Save the new world data - storageAccess.saveDataTag(this.worldGenSettingsComponent.registryHolder(), newWorldData); - } + LevelStorageSource.LevelStorageAccess storageAccess = this.minecraft.getLevelSource().createAccess(uiState.getName()); + storageAccess.renameLevel(uiState.getName()); - // Close the storage access storageAccess.close(); } catch (IOException e) { - SystemToast.onWorldAccessFailure(this.minecraft, this.initName); - Lockdown.LOGGER.error("Failed to rename level {}", this.initName, e); + SystemToast.onWorldAccessFailure(this.minecraft, uiState.getName()); + Lockdown.LOGGER.error("Failed to rename level {}", uiState.getName(), e); } - // Load the level - this.minecraft.createWorldOpenFlows().loadLevel(this, this.initName); + this.minecraft.createWorldOpenFlows().loadLevel(this, uiState.getName()); - // Cancel to prevent normal world creation ci.cancel(); } } - @Shadow - abstract LevelSettings createLevelSettings(boolean isDebug); - + @Unique private void queueLoadScreen() { this.minecraft.forceSetScreen(new GenericDirtMessageScreen(Component.translatable("selectWorld.data_read"))); } + + @Shadow + protected abstract LevelSettings createLevelSettings(boolean isDebug); + } diff --git a/src/main/java/adubbz/lockdown/mixin/client/MixinTitleScreen.java b/src/main/java/adubbz/lockdown/mixin/client/MixinTitleScreen.java index a5bf09b..809485c 100644 --- a/src/main/java/adubbz/lockdown/mixin/client/MixinTitleScreen.java +++ b/src/main/java/adubbz/lockdown/mixin/client/MixinTitleScreen.java @@ -5,9 +5,7 @@ package adubbz.lockdown.mixin.client; import adubbz.lockdown.Config; -import adubbz.lockdown.Lockdown; import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Widget; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.network.chat.Component; @@ -39,24 +37,24 @@ private void onInit(CallbackInfo ci) if (Config.disableSingleplayer.get()) { singleplayerButton.visible = false; - multiplayerButton.y -= 24; - realmsButton.y -= 24; - modsButton.y -= 24; - languageButton.y -= 24; - optionsButton.y -= 24; - quitButton.y -= 24; - accessibilityButton.y -= 24; + multiplayerButton.setY(multiplayerButton.getY() - 24); + realmsButton.setY(realmsButton.getY() - 24); + modsButton.setY(modsButton.getY() - 24); + languageButton.setY(languageButton.getY() - 24); + optionsButton.setY(optionsButton.getY() - 24); + quitButton.setY(quitButton.getY() - 24); + accessibilityButton.setY(accessibilityButton.getY() - 24); } if (Config.disableMultiplayer.get()) { multiplayerButton.visible = false; - realmsButton.y -= 24; - modsButton.y -= 24; - languageButton.y -= 24; - optionsButton.y -= 24; - quitButton.y -= 24; - accessibilityButton.y -= 24; + realmsButton.setY(realmsButton.getY() - 24); + modsButton.setY(modsButton.getY() - 24); + languageButton.setY(languageButton.getY() - 24); + optionsButton.setY(optionsButton.getY() - 24); + quitButton.setY(quitButton.getY() - 24); + accessibilityButton.setY(accessibilityButton.getY() - 24); } } }