Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
186 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ pipeline { | |
tools { | ||
jdk 'java17' | ||
} | ||
environment { | ||
environment { | ||
MODGRADLE_CI = 'true' | ||
} | ||
stages { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
buildscript { | ||
apply from: 'https://moddingx.github.io/ModUtils/v4/buildscript.gradle', to: buildscript | ||
apply from: 'https://moddingx.github.io/ModUtils/v5/buildscript.gradle', to: buildscript | ||
} | ||
|
||
apply from: 'https://moddingx.github.io/ModUtils/v4/mod.gradle' | ||
apply from: 'https://moddingx.github.io/ModUtils/v5/mod.gradle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,2 @@ | ||
org.gradle.jvmargs=-Xmx3G | ||
org.gradle.daemon=false | ||
|
||
# mod properties | ||
modid=defaultworldtype | ||
group=de.melanx | ||
base_version=3.2 | ||
|
||
# dependencies | ||
forge_version=1.19.3-44.0.0 | ||
#mappings=sugarcane_2022.03.13-1.18.2 | ||
|
||
# upload properties | ||
upload_versions=1.19.3 | ||
upload_release=beta | ||
modrinth_project=defaultworldtype | ||
curse_project=373014 | ||
|
||
# misc | ||
local_maven=/var/www/maven | ||
license_name=The Apache License, Version 2.0 | ||
license_url=https://www.apache.org/licenses/LICENSE-2.0.txt |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# mod properties | ||
modid=defaultworldtype | ||
group=de.melanx | ||
base_version=4.0 | ||
|
||
# dependencies | ||
forge_version=1.20.1-47.1.42 | ||
mappings=sugarcane_2023.07.23-1.20.1 | ||
|
||
# upload properties | ||
upload_versions=1.20.1 | ||
upload_release=beta | ||
modrinth_project=defaultworldtype | ||
curse_project=373014 | ||
|
||
# misc | ||
local_maven=/var/www/maven | ||
mixin=true | ||
license=The Apache License, Version 2.0 | ||
license_url=https://www.apache.org/licenses/LICENSE-2.0.txt | ||
changelog_repository=https://github.com/MelanX/DefaultWorldType/commit/%H |
56 changes: 56 additions & 0 deletions
56
src/main/java/de/melanx/defaultworldtype/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.melanx.defaultworldtype; | ||
|
||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.presets.WorldPreset; | ||
import net.minecraftforge.common.ForgeConfigSpec; | ||
import net.minecraftforge.fml.ModLoadingContext; | ||
import net.minecraftforge.fml.config.ModConfig; | ||
import net.minecraftforge.fml.loading.FMLPaths; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class ClientConfig { | ||
|
||
static { | ||
final Pair<ClientConfig, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); | ||
CLIENT_SPEC = specPair.getRight(); | ||
CLIENT = specPair.getLeft(); | ||
} | ||
|
||
public static final Path CONFIG_PATH = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath().toString(), DefaultWorldType.MODID); | ||
public static final ClientConfig CLIENT; | ||
public static final ForgeConfigSpec CLIENT_SPEC; | ||
|
||
public static ForgeConfigSpec.ConfigValue<String> worldTypeName; | ||
|
||
ClientConfig(ForgeConfigSpec.Builder builder) { | ||
builder.push("world-preset"); | ||
worldTypeName = builder | ||
.comment("Type in the name from the world type which should be selected by default.") | ||
.define("world-preset", "minecraft:normal", String.class::isInstance); | ||
builder.pop(); | ||
} | ||
|
||
public static void setup() { | ||
try { | ||
Files.createDirectory(CONFIG_PATH); | ||
} catch (FileAlreadyExistsException e) { | ||
DefaultWorldType.LOGGER.info("Config directory " + DefaultWorldType.MODID + " already exists. Skip creating."); | ||
} catch (IOException e) { | ||
DefaultWorldType.LOGGER.error("Failed to create " + DefaultWorldType.MODID + " config directory", e); | ||
} | ||
|
||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC, DefaultWorldType.MODID + "/client-config.toml"); | ||
} | ||
|
||
public static ResourceKey<WorldPreset> getKey() { | ||
return ResourceKey.create(Registries.WORLD_PRESET, new ResourceLocation(worldTypeName.get())); | ||
} | ||
} |
121 changes: 1 addition & 120 deletions
121
src/main/java/de/melanx/defaultworldtype/DefaultWorldType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,20 @@ | ||
package de.melanx.defaultworldtype; | ||
|
||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; | ||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.IdMap; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.presets.WorldPreset; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.client.event.ScreenEvent; | ||
import net.minecraftforge.common.ForgeConfigSpec; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.ModLoadingContext; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.config.ModConfig; | ||
import net.minecraftforge.fml.loading.FMLEnvironment; | ||
import net.minecraftforge.fml.loading.FMLPaths; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
|
||
@Mod(DefaultWorldType.MODID) | ||
public class DefaultWorldType { | ||
|
||
public static final String MODID = "defaultworldtype"; | ||
public static final ClientConfig CLIENT; | ||
public static final ForgeConfigSpec CLIENT_SPEC; | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
public static Path configPath; | ||
|
||
static { | ||
final Pair<ClientConfig, ForgeConfigSpec> specPair2 = new ForgeConfigSpec.Builder().configure(ClientConfig::new); | ||
CLIENT_SPEC = specPair2.getRight(); | ||
CLIENT = specPair2.getLeft(); | ||
} | ||
public static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
public DefaultWorldType() { | ||
if (FMLEnvironment.dist == Dist.CLIENT) { | ||
ClientConfig.setup(); | ||
MinecraftForge.EVENT_BUS.register(this); | ||
} | ||
} | ||
|
||
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) | ||
private static class GuiEventHandler { | ||
private static boolean doneLogging; | ||
private static boolean createdWorldTypeFile; | ||
|
||
@SubscribeEvent | ||
@OnlyIn(Dist.CLIENT) | ||
public static void onPreInitCreateWorld(ScreenEvent.Opening event) { | ||
Screen screenGui = event.getScreen(); | ||
String worldTypeName = ClientConfig.worldTypeName.get(); | ||
|
||
if (screenGui instanceof CreateWorldScreen createWorldScreen) { | ||
if (!createdWorldTypeFile) { | ||
createAvailablePresetsFile(createWorldScreen.worldGenSettingsComponent); | ||
createdWorldTypeFile = true; | ||
} | ||
|
||
Optional<Holder<WorldPreset>> preset = createWorldScreen.worldGenSettingsComponent.preset; | ||
if (preset.isPresent() && preset.get().is(new ResourceLocation(worldTypeName))) { | ||
if (!doneLogging) { | ||
LOGGER.info("Already correct preset selected: " + worldTypeName); | ||
} | ||
|
||
return; | ||
} | ||
|
||
Optional<Holder<WorldPreset>> customPreset = WorldGenSettingsComponent.findPreset(createWorldScreen.worldGenSettingsComponent.settings(), Optional.of(ResourceKey.create(Registries.WORLD_PRESET, new ResourceLocation(worldTypeName)))); | ||
if (customPreset.isPresent()) { | ||
createWorldScreen.worldGenSettingsComponent.preset = customPreset; | ||
createWorldScreen.worldGenSettingsComponent.updateSettings((registry, worldDimensions) -> customPreset.get().value().createWorldDimensions()); | ||
return; | ||
} | ||
|
||
if (!doneLogging) { | ||
LOGGER.error(String.format("World-type %s is an invalid world-type.", worldTypeName)); | ||
doneLogging = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void createAvailablePresetsFile(WorldGenSettingsComponent component) { | ||
File file = Paths.get(configPath.toString()).resolve("world-types.txt").toFile(); | ||
try (FileWriter writer = new FileWriter(file)) { | ||
IdMap<Holder<WorldPreset>> holders = component.registryHolder().registryOrThrow(Registries.WORLD_PRESET).asHolderIdMap(); | ||
writer.write(holders.size() + " possible world presets found: \n"); | ||
for (Holder<WorldPreset> holder : holders) { | ||
if (holder.unwrapKey().isPresent()) { | ||
writer.write(holder.unwrapKey().get().location().toString() + "\n"); | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static class ClientConfig { | ||
public static ForgeConfigSpec.ConfigValue<String> worldTypeName; | ||
public static ForgeConfigSpec.ConfigValue<String> flatMapSettings; | ||
|
||
ClientConfig(ForgeConfigSpec.Builder builder) { | ||
builder.push("world-preset"); | ||
worldTypeName = builder | ||
.comment("Type in the name from the world type which should be selected by default.") | ||
.define("world-preset", "minecraft:normal", String.class::isInstance); | ||
builder.pop(); | ||
} | ||
|
||
public static void setup() { | ||
configPath = Paths.get(FMLPaths.CONFIGDIR.get().toAbsolutePath().toString(), MODID); | ||
try { | ||
Files.createDirectory(configPath); | ||
} catch (FileAlreadyExistsException e) { | ||
LOGGER.info("Config directory " + MODID + " already exists. Skip creating."); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to create " + MODID + " config directory", e); | ||
} | ||
|
||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_SPEC, MODID + "/client-config.toml"); | ||
} | ||
} | ||
} |
Oops, something went wrong.