Skip to content

Commit

Permalink
Added a DDContext class for use with Difficulty Modifiers. For now, i…
Browse files Browse the repository at this point in the history
…t only contains an optional entity class variable. Added Map for Difficulty Modifiers in DDVault
  • Loading branch information
arazadaz committed Feb 5, 2024
1 parent b0963b7 commit 2822262
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/arazadaz/dd/api/DDContext.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
14 changes: 8 additions & 6 deletions src/main/java/com/arazadaz/dd/api/DifficultyCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));

}

Expand All @@ -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());

}

Expand All @@ -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<LivingEntity> 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<DDContext> predicateCondition, DifficultyType type, RadiusMode rMode, ModifierMode modMode){ //Will register to DDvault

switch(modMode){

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/arazadaz/dd/api/origins/Origin.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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){

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/arazadaz/dd/core/DDVault.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.arazadaz.dd.core;

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
Expand All @@ -13,5 +16,7 @@ public class DDVault {
public static ArrayList<OriginID> userOrigins = new ArrayList<>();
public static OriginID spawnOrigin;

public static HashMap<DifficultyType, ArrayList<Predicate> > difficultyModifiers;


}

0 comments on commit 2822262

Please sign in to comment.