From eb2b9b5e1a53b82b4938bf2691a683b2ff17bd07 Mon Sep 17 00:00:00 2001 From: Arazadaz Date: Mon, 5 Feb 2024 16:54:51 -0600 Subject: [PATCH] Added a DDContext class for use with Difficulty Modifiers. For now, it only contains an optional entity class variable. Added Map for Difficulty Modifiers in DDVault --- src/main/java/com/arazadaz/dd/api/DDContext.java | 16 ++++++++++++++++ .../arazadaz/dd/api/DifficultyCalculator.java | 14 ++++++++------ .../java/com/arazadaz/dd/api/origins/Origin.java | 3 ++- src/main/java/com/arazadaz/dd/core/DDVault.java | 6 ++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/arazadaz/dd/api/DDContext.java diff --git a/src/main/java/com/arazadaz/dd/api/DDContext.java b/src/main/java/com/arazadaz/dd/api/DDContext.java new file mode 100644 index 0000000..2c6a9b3 --- /dev/null +++ b/src/main/java/com/arazadaz/dd/api/DDContext.java @@ -0,0 +1,16 @@ +package com.arazadaz.dd.api; + +import net.minecraft.world.entity.LivingEntity; + +import javax.annotation.Nullable; + +public class DDContext { + + + public LivingEntity entity; + + public DDContext(@Nullable LivingEntity entity){ + this.entity = entity; + } + +} diff --git a/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java b/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java index eae179e..0dc6260 100644 --- a/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java +++ b/src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java @@ -8,6 +8,8 @@ import com.arazadaz.dd.api.Modes.*; import net.minecraft.world.phys.Vec3; +import javax.swing.text.html.Option; +import java.util.Optional; import java.util.function.Predicate; public class DifficultyCalculator { @@ -18,7 +20,7 @@ public static double getDifficultyHere(LivingEntity entity, DifficultyType type, Vec3 pos = entity.position(); Level level = entity.level(); - return getDifficultyHere(pos, level, type, rMode); + return getOriginDifficultyHere(pos, level, type, rMode, "default", Optional.of(entity)); } @@ -27,13 +29,13 @@ public static double getDifficultyHere(Vec3 pos, Level level, DifficultyType typ //Needs to be able to gather origins from all worlds and world-specific origins - return getOriginDifficultyHere(pos, level, type, rMode, "default"); //default is applied to user-defined origins/spawn automatically. Mods defined origins can apply it too and should unless they have a reason to omit it. + return getOriginDifficultyHere(pos, level, type, rMode, "default", Optional.empty()); //default is applied to user-defined origins/spawn automatically. Mods defined origins can apply it too and should unless they have a reason to omit it. } public static double getWorldSpawnDifficultyHere(Vec3 pos, Level level, DifficultyType type, RadiusMode rMode){ //Calculates from spawn origin(returning 0 if disabled) - return getOriginDifficultyHere(pos, level, type, rMode, "spawn"); + return getOriginDifficultyHere(pos, level, type, rMode, "spawn", Optional.empty()); } @@ -42,20 +44,20 @@ 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){ //Calculates from nearest origin point of specific type + 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. Origin originPoint = OriginManager.getNearestOrigin(levelID, originTag, pos); - return originPoint.getDifficultyHere(pos, type, rMode); + return originPoint.getDifficultyHere(pos, type, rMode, new DDContext(entity.orElse(null))); } //Precise control of difficulty with modifiers - public static void addDifficultyModifier(Predicate predicateCondition, DifficultyType type, RadiusMode rMode, ModifierMode modMode){ //Will register to DDvault + public static void addDifficultyModifier(Predicate predicateCondition, DifficultyType type, RadiusMode rMode, ModifierMode modMode){ //Will register to DDvault switch(modMode){ 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 327a327..1aa85a3 100644 --- a/src/main/java/com/arazadaz/dd/api/origins/Origin.java +++ b/src/main/java/com/arazadaz/dd/api/origins/Origin.java @@ -1,5 +1,6 @@ package com.arazadaz.dd.api.origins; +import com.arazadaz.dd.api.DDContext; import com.arazadaz.dd.api.Modes.*; import net.minecraft.world.phys.Vec3; @@ -48,7 +49,7 @@ public Origin(Vec3 pos, String[] formulas, String[] tags, double range, boolean //Bulk of logic goes here - public double getDifficultyHere(Vec3 pos, DifficultyType type, RadiusMode rMode){ + public double getDifficultyHere(Vec3 pos, DifficultyType type, RadiusMode rMode, DDContext context){ switch(rMode){ diff --git a/src/main/java/com/arazadaz/dd/core/DDVault.java b/src/main/java/com/arazadaz/dd/core/DDVault.java index 4c36b57..caeddd4 100644 --- a/src/main/java/com/arazadaz/dd/core/DDVault.java +++ b/src/main/java/com/arazadaz/dd/core/DDVault.java @@ -1,8 +1,12 @@ package com.arazadaz.dd.core; +import com.arazadaz.dd.api.DDContext; +import com.arazadaz.dd.api.Modes.DifficultyType; import com.arazadaz.dd.api.origins.OriginID; import java.util.ArrayList; +import java.util.HashMap; +import java.util.function.Predicate; //Keeps track of internally defined origins such as user ones or the spawn origin. Mostly used for disabling them if the Origin Manager instructs it. //Keeps track of difficulty modifiers @@ -13,5 +17,7 @@ public class DDVault { public static ArrayList userOrigins = new ArrayList<>(); public static OriginID spawnOrigin; + public static HashMap> > difficultyModifiers; + }