Skip to content

Commit

Permalink
Update Config
Browse files Browse the repository at this point in the history
  • Loading branch information
UnRealDinnerbone committed Sep 18, 2023
1 parent 9985c23 commit 3a1e47c
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 80 deletions.
42 changes: 31 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17)
multiLoader.root() {
minecraftVersion.set(project.property("minecraft_version"))
modID.set(project.property("mod_id"))
singleOutputJar.set(true)
splitSources.set(true)
dataGen {
useFabric.set(project(":common").file("src/generated/resources"))
Expand Down Expand Up @@ -54,7 +53,11 @@ subprojects {
}
maven {
name = "nanite"
url = uri("https://maven.nanite.dev/releases")
url = uri("https://maven.nanite.dev/snapshots")
}
maven {
name = "UnRealDinnerbone"
url = "https://maven.unreal.codes/releases"
}
}

Expand All @@ -81,27 +84,44 @@ subprojects {

}

tasks.register("singleJar", SingleOutputJar.class) {
getArchiveIdentifier().set("${project.property("mod_name")}ML")
getOutput().set(project.file("build/libs/${project.property("mod_name")}-${project.version}.jar"))
}


publishMods {
file = tasks.singleJar.output
dryRun = providers.environmentVariable("CURSE_TOKEN").getOrNull() == null
changelog = file("./CHANGELOG.md").text
version = "${mod_version}"
type = STABLE

curseforge {
projectId = project.property("curse_id")
accessToken = providers.environmentVariable("CURSE_TOKEN")
def fabricOptions = publishOptions {
file = project.provider { project(":fabric").tasks.remapJar }.flatMap { it.archiveFile }
displayName = "${project.name} Fabric ${mod_version}+mc${minecraft_version}"
modLoaders.add("fabric")
}

def forgeOptions = publishOptions {
file = project.provider { project(":forge").tasks.jar }.flatMap { it.archiveFile }
displayName = "${project.name} Forge ${mod_version}+mc${minecraft_version}"
modLoaders.add("forge")
}

def curseForgeOptions = curseforgeOptions {
accessToken = providers.environmentVariable("CURSE_TOKEN")
projectId = project.property("curse_id")
minecraftVersions.add("${minecraft_version}")
requires {
slug = "trenzalore"
}
}

curseforge("curseforgeFabric") {
from(curseForgeOptions, fabricOptions)
requires {
slug = "fabric-api"
}
}

curseforge("curseforgeForge") {
from(curseForgeOptions, forgeOptions)
}

}

2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ multiLoader.common()
publishing.publications.mavenJava.from components.java

dependencies {
implementation("com.unrealdinnerbone:trenzalore-common:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}")
implementation("com.unrealdinnerbone:trenzalore-common:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}-SNAPSHOT")
}
29 changes: 4 additions & 25 deletions common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
package com.unrealdinnerbone.jamd;

import com.google.common.base.Suppliers;
import com.unrealdinnerbone.config.ConfigManager;
import com.unrealdinnerbone.trenzalore.api.config.ConfigManger;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class JAMD {
public static final String MOD_ID = "jamd";

private static final List<String> DEFAULT_BLACKLIST = List.of(
"minecraft:ore_gold_deltas",
"minecraft:ore_infested",
"minecraft:ore_magma",
"minecraft:ore_gravel",
"minecraft:ore_soul_sand",
"minecraft:ore_gold_extra",
"minecraft:ore_quartz_nether",
"minecraft:ore_gold_nether",
"minecraft:ore_quartz_deltas",
"minecraft:ore_gravel_nether",
"minecraft:ore_dirt",
"minecraft:ore_blackstone",
"minecraft:ore_andesite_upper",
"minecraft:ore_clay"

);
public static final Supplier<JamdConfig> CONFIG = Suppliers.memoize(() -> ConfigManger.getOrCreateConfig(JAMD.MOD_ID, JamdConfig.class, () -> new JamdConfig(true, DEFAULT_BLACKLIST)));

public static final String MOD_ID = "jamd";
private static final ConfigManager CONFIG_MANAGER = ConfigManger.createConfigManager(MOD_ID);
public static final JamdConfig CONFIG = CONFIG_MANAGER.loadConfig("general", JamdConfig::new);

public static void init() {

Expand Down
37 changes: 35 additions & 2 deletions common/src/main/java/com/unrealdinnerbone/jamd/JamdConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
package com.unrealdinnerbone.jamd;

import java.util.List;
import com.unrealdinnerbone.config.ConfigCreator;
import com.unrealdinnerbone.config.config.BooleanConfig;
import com.unrealdinnerbone.config.config.ListConfig;

public record JamdConfig(boolean dynamicOreAddition, List<String> blackListedOres) {
public class JamdConfig {

private final BooleanConfig dynamicOreAdditionConfig;
private final ListConfig<String> blackListedOresConfig;
public JamdConfig(ConfigCreator configCreator) {
dynamicOreAdditionConfig = configCreator.createBoolean("dynamicOreAddition", true);
blackListedOresConfig = configCreator.createList("blackListedOres", new String[]{
"minecraft:ore_gold_deltas",
"minecraft:ore_infested",
"minecraft:ore_magma",
"minecraft:ore_gravel",
"minecraft:ore_soul_sand",
"minecraft:ore_gold_extra",
"minecraft:ore_quartz_nether",
"minecraft:ore_gold_nether",
"minecraft:ore_quartz_deltas",
"minecraft:ore_gravel_nether",
"minecraft:ore_dirt",
"minecraft:ore_blackstone",
"minecraft:ore_andesite_upper",
"minecraft:ore_clay",
"enlightened_end:.*"
}, String[].class);
}

public BooleanConfig getDynamicOreAdditionConfig() {
return dynamicOreAdditionConfig;
}

public ListConfig<String> getBlackListedOresConfig() {
return blackListedOresConfig;
}
}
8 changes: 6 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ multiLoader.fabric() {
publishing.publications.mavenJava.from components.java

dependencies {
modImplementation("com.unrealdinnerbone:trenzalore-fabric:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}")
}
modImplementation("com.unrealdinnerbone:trenzalore-fabric:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}-SNAPSHOT")
}

remapJar {
setArchivesBaseName("${project.property("mod_name")}-${project.name}".toLowerCase())
}
17 changes: 9 additions & 8 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ repositories {


dependencies {
implementation fg.deobf("com.unrealdinnerbone:trenzalore-forge:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}")
// implementation fg.deobf("curse.maven:energized-power-782147:4693008")
// implementation fg.deobf("curse.maven:elementary-ores-332609:4622524")
// implementation fg.deobf("curse.maven:flib-661261:4661080")
// implementation fg.deobf("curse.maven:tool-kit-324888:4598902")
// implementation fg.deobf("curse.maven:architectury-api-419699:4663010")
// implementation fg.deobf("curse.maven:powah-rearchitected-633483:4638301")
// implementation fg.deobf("curse.maven:cloth-config-348521:4633444")
implementation (fg.deobf("com.unrealdinnerbone:trenzalore-forge:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}-SNAPSHOT")) {
transitive = true
}
minecraftLibrary ("com.unrealdinnerbone:UnRealConfig-gson:12.3.4")

}

jar {
setArchivesBaseName("${project.property("mod_name")}-${project.name}".toLowerCase())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unrealdinnerbone.jamd;

import com.unrealdinnerbone.trenzalore.api.config.ConfigManger;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import com.unrealdinnerbone.config.config.ListConfig;
import com.unrealdinnerbone.config.exception.ConfigException;
import com.unrealdinnerbone.jamd.JAMD;
import com.unrealdinnerbone.jamd.JAMDForge;
import com.unrealdinnerbone.jamd.JAMDForgeRegistry;
import com.unrealdinnerbone.jamd.JAMDRegistry;
import com.unrealdinnerbone.trenzalore.api.config.ConfigManger;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderSet;
Expand All @@ -27,64 +30,70 @@
import net.minecraftforge.server.ServerLifecycleHooks;
import org.slf4j.Logger;

import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Pattern;

public record JAMDBiomeModifier() implements BiomeModifier
public class JAMDBiomeModifier implements BiomeModifier
{

public static final JAMDBiomeModifier INSTANCE = new JAMDBiomeModifier();

private static final Logger LOGGER = LogUtils.getLogger();
private final List<Pattern> matches;
private final boolean dynamicOreAddition;
public JAMDBiomeModifier() {
try {
dynamicOreAddition = JAMD.CONFIG.getDynamicOreAdditionConfig().getExceptionally();
matches = Arrays.stream(JAMD.CONFIG.getBlackListedOresConfig().getExceptionally())
.filter(Objects::nonNull)
.map(Pattern::compile)
.toList();
} catch (ConfigException e) {
throw new RuntimeException("Failed to load config", e);
}
}

@Override
public void modify(Holder<Biome> biome, Phase phase, ModifiableBiomeInfo.BiomeInfo.Builder builder) {
if(JAMD.CONFIG.get().dynamicOreAddition()) {
if(dynamicOreAddition) {
if (phase == Phase.ADD) {
List<String> strings = JAMD.CONFIG.get().blackListedOres();
if(biome.is(JAMDRegistry.Keys.OVERWORLD.biome())) {
HolderLookup.RegistryLookup<PlacedFeature> placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow();
handle(strings, placedFeatureRegistryLookup, builder);
handle(placedFeatureRegistryLookup, builder);
}else if(biome.is(JAMDRegistry.Keys.NETHER.biome())) {
HolderLookup.RegistryLookup<PlacedFeature> placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow();
// List<String> strings = JAMD.CONFIG.get().blackListNether();
handle(strings, placedFeatureRegistryLookup, builder);
handle(placedFeatureRegistryLookup, builder);
}else if(biome.is(JAMDRegistry.Keys.END.biome())) {
HolderLookup.RegistryLookup<PlacedFeature> placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow();
// List<String> strings = JAMD.CONFIG.get().blackListEnd();
handle(strings, placedFeatureRegistryLookup, builder);
handle(placedFeatureRegistryLookup, builder);
}
}
}
}

private static void handle(List<String> strings, HolderLookup.RegistryLookup<PlacedFeature> placedFeatureRegistryLookup, ModifiableBiomeInfo.BiomeInfo.Builder builder) {
private void handle(HolderLookup.RegistryLookup<PlacedFeature> placedFeatureRegistryLookup, ModifiableBiomeInfo.BiomeInfo.Builder builder) {
placedFeatureRegistryLookup.listElements().forEach(placedFeature -> {
if(!placedFeature.key().location().getNamespace().equalsIgnoreCase("enlightened_end")) {
if(!contains(strings, placedFeature.key().location().toString())) {
PlacedFeature s = placedFeature.get();
boolean isOreFeature = s.feature().get().feature() instanceof OreFeature;
if (isOreFeature) {
List<Holder<PlacedFeature>> features = builder.getGenerationSettings().getFeatures(GenerationStep.Decoration.UNDERGROUND_ORES);
if (features.stream().noneMatch(holder -> holder.is(placedFeature.key()))) {
builder.getGenerationSettings().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, placedFeature);
}
if (!matches(placedFeature.key().location().toString())) {
PlacedFeature s = placedFeature.get();
boolean isOreFeature = s.feature().get().feature() instanceof OreFeature;
if (isOreFeature) {
LOGGER.debug("Adding: " + placedFeature.key().location());
List<Holder<PlacedFeature>> features = builder.getGenerationSettings().getFeatures(GenerationStep.Decoration.UNDERGROUND_ORES);
if (features.stream().noneMatch(holder -> holder.is(placedFeature.key()))) {
builder.getGenerationSettings().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, placedFeature);
}
}
}else {
LOGGER.debug("Blacklisted: " + placedFeature.key().location());
}
});
}

private static boolean contains(List<String> values, String value) {
if(value.endsWith("*")) {
String substring = value.substring(0, value.length() - 1);
return values.stream().anyMatch(s -> s.toLowerCase().startsWith(substring.toLowerCase()));
}else {
return values.stream().anyMatch(s -> s.equalsIgnoreCase(value));
}

}
private boolean matches(String value) {
return matches.stream().anyMatch(pattern -> pattern.matcher(value).matches());

public static void main(String[] args) {
System.out.println(contains(List.of("enlightened_end:adamantite_node"), "enlightened_end:*"));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project
mod_version=3.2.2
mod_version=3.3.0
maven_group=com.unrealdinnerbone
curse_id=422981
mod_name=JAMD
Expand All @@ -18,7 +18,7 @@ fabric_version=0.83.1+1.20.1
fabric_loader_version=0.14.21

# Other
trenzalore_version=3.2.0
trenzalore_version=3.3.9

# Gradle
org.gradle.jvmargs=-Xmx3G
Expand Down

0 comments on commit 3a1e47c

Please sign in to comment.