diff --git a/src/main/java/com/arazadaz/dd/Main.java b/src/main/java/com/arazadaz/dd/Main.java index 40840e5..dccf4cf 100644 --- a/src/main/java/com/arazadaz/dd/Main.java +++ b/src/main/java/com/arazadaz/dd/Main.java @@ -1,11 +1,16 @@ package com.arazadaz.dd; +import com.arazadaz.dd.api.origins.OriginID; +import com.arazadaz.dd.api.origins.OriginManager; import com.arazadaz.dd.config.Config; import com.arazadaz.dd.core.DDVault; import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.phys.Vec3; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; @@ -65,6 +70,16 @@ private void commonSetup(final FMLCommonSetupEvent event) @SubscribeEvent public void onServerStarting(ServerStartingEvent event) { + LevelData data = event.getServer().getLevel(Level.OVERWORLD).getLevel().getLevelData(); + + Vec3 spawnVec = new Vec3(data.getXSpawn(), data.getYSpawn(), data.getZSpawn()); + + if(Config.useSpawnOrigin) { + OriginID spawnOrigin = OriginManager.registerOrigin(spawnVec, "spawn"); + vault.userOrigins.add(spawnOrigin); + } + + } // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent diff --git a/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java b/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java index 0469711..0ed5312 100644 --- a/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java +++ b/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java @@ -47,7 +47,7 @@ public static double getWorldSpawnDifficultyHere(Vec3 pos, Level level, Difficul //Primary getter public static double getOriginDifficultyHere(Vec3 pos, Level level, DifficultyType type, RadiusMode rMode, String originTag, Optional entity){ //Calculates from nearest origin point of specific type - String levelID = level.toString(); //Will have to debug this to see what value is given. + String levelID = level.dimension().location().getPath(); Origin origin = OriginManager.getNearestOrigin(levelID, originTag, pos); diff --git a/src/main/java/com/arazadaz/dd/api/origins/Origin.java b/src/main/java/com/arazadaz/dd/api/origins/Origin.java index a7dd37c..b399e7a 100644 --- a/src/main/java/com/arazadaz/dd/api/origins/Origin.java +++ b/src/main/java/com/arazadaz/dd/api/origins/Origin.java @@ -24,23 +24,9 @@ public Origin(Vec3 pos, String[] formulas, String[] tags, double range, boolean //Add default type to origin or none if desired if(defaultTag == 1){ //Default tag - - newTags = new String[tags.length+1]; - for(int i = 1; i<=tags.length; i++){ - newTags[i] = tags[i]; - } - - newTags[0] = "default"; - + newTags = injectDefaultTag(tags, "default"); }else if(defaultTag == 2){ //Dynamic tag - - newTags = new String[tags.length+1]; - for(int i = 1; i<=tags.length; i++){ - newTags[i] = tags[i]; - } - - newTags[0] = "dynamic"; //Dynamic because these are generally going to be used for generated origin points after the world was loaded. - + newTags = injectDefaultTag(tags, "dynamic"); //Dynamic because these are generally going to be used for generated origin points after the world was loaded. }else{ //No default tag newTags = tags; //Keep original tags, exists to prevent conflicts and in case a mod dev wants to specifically design how their origin point interacts with the game. } @@ -53,6 +39,18 @@ public Origin(Vec3 pos, String[] formulas, String[] tags, double range, boolean } + private String[] injectDefaultTag(String[] originalTags, String tag){ + + String[] newTags = new String[originalTags.length+1]; + for(int i = 1; i<=originalTags.length; i++){ + newTags[i] = originalTags[i-1]; + } + + newTags[0] = tag; //On top since it'll be checked most probably + + return newTags; + } + //Bulk of logic goes here public double getDifficultyHere(Vec3 pos, DifficultyType type, RadiusMode rMode, DDContext context){ @@ -69,17 +67,17 @@ public double getDifficultyHere(Vec3 pos, DifficultyType type, RadiusMode rMode, case CIRCLE -> { difficulty = runModifiers(modifierIterator, context, 0); - return difficulty; + return getFinalDifficulty(difficulty); } case SQUARE -> { difficulty = runModifiers(modifierIterator, context, 1); - return difficulty; + return getFinalDifficulty(difficulty); } case CUSTOM -> { difficulty = runModifiers(modifierIterator, context, 2); - return difficulty; + return getFinalDifficulty(difficulty); } default -> {return 0;} //Should never occur @@ -87,6 +85,11 @@ public double getDifficultyHere(Vec3 pos, DifficultyType type, RadiusMode rMode, } + private double getFinalDifficulty(double finalDifficulty){ + finalDifficulty = noCalculationBound ? finalDifficulty : Math.min(1, finalDifficulty); + return finalDifficulty; + } + private double runModifiers(Iterator modifierIterator, DDContext context, int formula){ //Formula can be 0, 1, or 2 with those values representing circle, square, and custom respectively. double base = new FormulaInterpreter().run(Config.formulas[formula], this, pos); diff --git a/src/main/java/com/arazadaz/dd/api/origins/OriginManager.java b/src/main/java/com/arazadaz/dd/api/origins/OriginManager.java index 8c48bfc..d910ff4 100644 --- a/src/main/java/com/arazadaz/dd/api/origins/OriginManager.java +++ b/src/main/java/com/arazadaz/dd/api/origins/OriginManager.java @@ -11,11 +11,11 @@ public class OriginManager { - private static HashMap> originMap; //Mapping of origins to each world/all; + private static HashMap> originMap = new HashMap<>(); //Mapping of origins to each world/all; - public static OriginID registerOrigin(Vec3 pos, String[] tags){ //basic, less control + public static OriginID registerOrigin(Vec3 pos, String... tags){ //basic, less control double range = 0; //Will get global value from config after it's setup String[] formulas = null; //will get global formulas from config after it's setup diff --git a/src/main/java/com/arazadaz/dd/config/Config.java b/src/main/java/com/arazadaz/dd/config/Config.java index c133f03..13c7c8d 100644 --- a/src/main/java/com/arazadaz/dd/config/Config.java +++ b/src/main/java/com/arazadaz/dd/config/Config.java @@ -72,7 +72,7 @@ private static void mapOrigins(String originSpec){ case 1 -> {} //Do nothing case 3 -> { Vec3 srcPos = new Vec3(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])); - OriginID userOrigin = OriginManager.registerOrigin(srcPos, new String[]{"userOrigin"}); + OriginID userOrigin = OriginManager.registerOrigin(srcPos, "userOrigin"); Main.vault.userOrigins.add(userOrigin); }