Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,5 +16,5 @@ mod_scm_url=scm:git:[email protected]: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
5 changes: 3 additions & 2 deletions src/main/java/adubbz/lockdown/Lockdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}
}
152 changes: 55 additions & 97 deletions src/main/java/adubbz/lockdown/mixin/client/MixinCreateWorldScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Difficulty> difficultyButton;
@Shadow
private CycleButton<Boolean> 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)
Expand All @@ -113,63 +87,47 @@ 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)
{
Lockdown.LOGGER.error("The template world does not exist at " + templateDirectory, e);
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);

}
28 changes: 13 additions & 15 deletions src/main/java/adubbz/lockdown/mixin/client/MixinTitleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}