Skip to content

Commit

Permalink
PMMO better scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandaismyname1 committed Jul 10, 2024
1 parent 3922343 commit 540d390
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 39 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.daemon=false
#Build Props
minecraft_version = 1.20.1
minecraft_version_range = [1.20,1.20.2)
forge_version = 47.1.0
forge_version = 47.2.20
forge_version_range = [46.0.1,)
loader_version_range = [46,)
mod_id = pmmo
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/harmonised/pmmo/api/APIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class APIUtils {
//===============CORE HOOKS======================================
/**get the player's current level in the skill provided
*
* @param skill skill name. Skills are case-sensitive and usually all lowercase
* @param skill skill attribute. Skills are case-sensitive and usually all lowercase
* @param player the player whose skills are being obtained.
* @return the current skill level of the player
*/
Expand All @@ -67,7 +67,7 @@ public static int getLevel(String skill, Player player) {

/**Sets the player's current level in the skill provided
*
* @param skill skill's name. skills are case-sensitive and usually all lowercase
* @param skill skill's attribute. skills are case-sensitive and usually all lowercase
* @param player the player whose skills are being set
* @param level the new level being applied to the skill
*/
Expand All @@ -81,7 +81,7 @@ public static void setLevel(String skill, Player player, int level) {
* providing a negative value in @{link levelChange} will reduce the player's
* level.
*
* @param skill skill name. Skills are case-sensitive and usually lowercase.
* @param skill skill attribute. Skills are case-sensitive and usually lowercase.
* @param player the player whose level is being changed
* @param levelChange the number of levels being changed by. negative values will reduce the player level.
* @return true if the level was in fact changed.
Expand All @@ -94,7 +94,7 @@ public static boolean addLevel(String skill, Player player, int levelChange) {

/**Gets the raw xp value associated with the specified skill and player.
*
* @param skill skill name. Skills are case-sensitive and usually lowercase.
* @param skill skill attribute. Skills are case-sensitive and usually lowercase.
* @param player the player whose experience is being sought.
* @return the raw experience earned in the specified skill.
*/
Expand All @@ -106,7 +106,7 @@ public static long getXp(String skill, Player player) {

/**Sets the raw XP value for the player in the skill specified.
*
* @param skill skill name. Skills are case-sensitive and usually lowercase.
* @param skill skill attribute. Skills are case-sensitive and usually lowercase.
* @param player the player whose skill is being set.
* @param xpRaw the new experience amount to be set for this skill
*/
Expand All @@ -119,7 +119,7 @@ public static void setXp(String skill, Player player, long xpRaw) {
/**Changes the player's current experience in the specified skill by the amount.
* Negative values will reduce current experience.
*
* @param skill skill name. Skills are case-sensitive and usually lowercase. if a
* @param skill skill attribute. Skills are case-sensitive and usually lowercase. if a
* skill group is passed into this method, it will be parsed according
* to its component skills and the xp distributed accordingly.
* @param player the player whose experience is being changed.
Expand Down Expand Up @@ -613,7 +613,7 @@ public static void registerEntityPredicate(ResourceLocation res, ReqType reqType
}

/**registers a Function to be used in providing the requirements for specific item
* skill requirements. The map consists of skill name and skill value pairs.
* skill requirements. The map consists of skill attribute and skill value pairs.
* The ResourceLocation and ReqType parameters are conditions for when this check
* should be applied and are used by PMMO to know which functions apply in which
* contexts.
Expand All @@ -627,7 +627,7 @@ public static void registerItemRequirementTooltipData(ResourceLocation res, ReqT
}

/**registers a Function to be used in providing the requirements for specific block
* skill requirements. The map consists of skill name and skill value pairs.
* skill requirements. The map consists of skill attribute and skill value pairs.
* The ResourceLocation and ReqType parameters are conditions for when this check
* should be applied and are used by PMMO to know which functions apply in which
* contexts.
Expand All @@ -641,7 +641,7 @@ public static void registerBlockRequirementTooltipData(ResourceLocation res, Req
}

/**registers a Function to be used in providing the requirements for specific entity
* skill requirements. The map consists of skill name and skill value pairs.
* skill requirements. The map consists of skill attribute and skill value pairs.
* The ResourceLocation and ReqType parameters are conditions for when this check
* should be applied and are used by PMMO to know which functions apply in which
* contexts.
Expand All @@ -655,7 +655,7 @@ public static void registerEntityRequirementTooltipData(ResourceLocation res, Re
}

/**registers a Function to be used in providing the experience gains for specific item
* and event. The map consists of skill name and experience value pairs.
* and event. The map consists of skill attribute and experience value pairs.
* The ResourceLocation and EventType parameters are conditions for when the function
* should be applied.
*
Expand All @@ -668,7 +668,7 @@ public static void registerItemXpGainTooltipData(ResourceLocation res, EventType
}

/**registers a Function to be used in providing the experience gains for specific block
* and event. The map consists of skill name and experience value pairs.
* and event. The map consists of skill attribute and experience value pairs.
* The ResourceLocation and EventType parameters are conditions for when the function
* should be applied.
*
Expand All @@ -681,7 +681,7 @@ public static void registerBlockXpGainTooltipData(ResourceLocation res, EventTyp
}

/**registers a Function to be used in providing the experience gains for specific entity
* and event. The map consists of skill name and experience value pairs.
* and event. The map consists of skill attribute and experience value pairs.
* The ResourceLocation and EventType parameters are conditions for when the function
* should be applied.
*
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/harmonised/pmmo/config/codecs/AttributeModifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package harmonised.pmmo.config.codecs;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

public record AttributeModifier(
String attribute,
double amount,
String operation
){

public static final Codec<AttributeModifier> CODEC = RecordCodecBuilder.create( instance ->
instance.group(
Codec.STRING.fieldOf( "attribute" ).forGetter( AttributeModifier::attribute),
Codec.DOUBLE.fieldOf( "amount" ).forGetter( AttributeModifier::amount ),
Codec.STRING.fieldOf( "operation" ).forGetter( AttributeModifier::operation )
).apply( instance, AttributeModifier::new )
);
}
18 changes: 14 additions & 4 deletions src/main/java/harmonised/pmmo/config/codecs/LocationData.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public record LocationData(
Map<ResourceLocation, Integer> negative,
List<ResourceLocation> veinBlacklist,
Map<String, Integer> travelReq,
List<AttributeModifier> dimensionalMobModifiers,
Map<ResourceLocation, Map<String, Double>> mobModifiers) implements DataSource<LocationData>{

public LocationData() {this(
false, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(),
new ArrayList<>(), new HashMap<>(), new HashMap<>());}
new ArrayList<>(), new HashMap<>(), new ArrayList<>(), new HashMap<>());}

@Override
public Map<String, Double> getBonuses(ModifierDataType type, CompoundTag nbt) {
Expand Down Expand Up @@ -81,8 +82,9 @@ public void setPositiveEffects(Map<ResourceLocation, Integer> pos) {
Codec.unboundedMap(ResourceLocation.CODEC, Codec.INT).optionalFieldOf("negative_effect").forGetter(ld -> Optional.of(ld.negative())),
Codec.list(ResourceLocation.CODEC).optionalFieldOf("vein_blacklist").forGetter(ld -> Optional.of(ld.veinBlacklist())),
Codec.unboundedMap(Codec.STRING, Codec.INT).optionalFieldOf("travel_req").forGetter(ld -> Optional.of(ld.travelReq())),
Codec.list(AttributeModifier.CODEC).optionalFieldOf("dimensional_mob_modifiers").forGetter(ld -> Optional.of(ld.dimensionalMobModifiers())),
Codec.unboundedMap(ResourceLocation.CODEC, CodecTypes.DOUBLE_CODEC).optionalFieldOf("mob_modifier").forGetter(ld -> Optional.of(ld.mobModifiers()))
).apply(instance, (override, tags, bonus, pos, neg, vein, req, mobs) ->
).apply(instance, (override, tags, bonus, pos, neg, vein, req, dimMobScaling, mobs) ->
new LocationData(
override.orElse(false),
new HashSet<>(tags.orElse(List.of())),
Expand All @@ -91,6 +93,7 @@ public void setPositiveEffects(Map<ResourceLocation, Integer> pos) {
DataSource.clearEmptyValues(neg.orElse(new HashMap<>())),
new ArrayList<>(vein.orElse(new ArrayList<>())),
DataSource.clearEmptyValues(req.orElse(new HashMap<>())),
new ArrayList<>(dimMobScaling.orElse(new ArrayList<>())),
DataSource.clearEmptyValues(mobs.orElse(new HashMap<>())))
));

Expand All @@ -102,6 +105,7 @@ public LocationData combine(LocationData two) {
Map<ResourceLocation, Integer> negative = new HashMap<>();
List<ResourceLocation> veinBlacklist = new ArrayList<>();
Map<String, Integer> travelReq = new HashMap<>();
List<AttributeModifier> dimensionalMobModifiers = new ArrayList<>();
Map<ResourceLocation, Map<String, Double>> mobModifiers = new HashMap<>();

BiConsumer<LocationData, LocationData> bothOrNeither = (o, t) -> {
Expand All @@ -128,7 +132,12 @@ public LocationData combine(LocationData two) {
veinBlacklist.add(rl);
});
travelReq.putAll(o.travelReq());
t.travelReq().forEach((key, value) -> travelReq.merge(key, value, (o1, n1) -> o1 > n1 ? o1 : n1));
t.travelReq().forEach((key, value) -> travelReq.merge(key, value, (o1, n1) -> o1 > n1 ? o1 : n1));
dimensionalMobModifiers.addAll(o.dimensionalMobModifiers());
t.dimensionalMobModifiers().forEach((am) -> {
if (!dimensionalMobModifiers.contains(am))
dimensionalMobModifiers.add(am);
});
mobModifiers.putAll(o.mobModifiers());
t.mobModifiers().forEach((key, value) -> {
mobModifiers.merge(key, value, (oldV, newV) -> {
Expand All @@ -146,12 +155,13 @@ public LocationData combine(LocationData two) {
negative.putAll(o.negative().isEmpty() ? t.negative() : o.negative());
veinBlacklist.addAll(o.veinBlacklist().isEmpty() ? t.veinBlacklist(): o.veinBlacklist());
travelReq.putAll(o.travelReq().isEmpty() ? t.travelReq() : o.travelReq());
dimensionalMobModifiers.addAll(o.dimensionalMobModifiers().isEmpty() ? t.dimensionalMobModifiers() : o.dimensionalMobModifiers());
mobModifiers.putAll(o.mobModifiers().isEmpty() ? t.mobModifiers() : o.mobModifiers());
},
bothOrNeither,
bothOrNeither);

return new LocationData(this.override() || two.override(), tagValues, bonusMap, positive, negative, veinBlacklist, travelReq, mobModifiers);
return new LocationData(this.override() || two.override(), tagValues, bonusMap, positive, negative, veinBlacklist, travelReq, dimensionalMobModifiers, mobModifiers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static <T> T register(
* Define a config value for a complex object.
* @param <T> The type of the thing in the config we are making a listener for
* @param builder Builder to build configs with
* @param name The name of the field in your config that will hold objects of this type
* @param name The attribute of the field in your config that will hold objects of this type
* @param codec A Codec for de/serializing your object type.
* @param defaultObject The default instance of your config field. The given codec must be able to serialize this;
* if it cannot, an exception will be intentionally thrown the first time the config attempts to load.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ public class MergeableCodecDataManager<T extends DataSource<T>, V> extends Simpl
private Map<ResourceLocation, T> overrideSettings = new HashMap<>();

/**
* Initialize a data manager with the given folder name, codec, and merger
* @param folderName The name of the folder to load data from,
* Initialize a data manager with the given folder attribute, codec, and merger
* @param folderName The attribute of the folder to load data from,
* e.g. "cheeses" would load data from "data/modid/cheeses" for all modids.
* Can include subfolders, e.g. "cheeses/sharp"
* @param logger A logger that will log parsing errors if they occur
* @param codec A codec that will be used to parse jsons. See drullkus's codec primer for help on creating these:
* https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910
* @param merger A merging function that uses a list of java-objects-that-were-parsed-from-json to create a final object.
* The list contains all successfully-parsed objects with the same ID from all mods and datapacks.
* (for a json located at "data/modid/folderName/name.json", the object's ID is "modid:name")
* As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:name id,
* (for a json located at "data/modid/folderName/attribute.json", the object's ID is "modid:attribute")
* As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:attribute id,
* and then all tag jsons defined with the same ID are merged additively into a single set of items, etc
*/
public MergeableCodecDataManager(final String folderName, final Logger logger, Codec<T> codec, final Function<List<T>, T> merger
Expand All @@ -122,17 +122,17 @@ public MergeableCodecDataManager(final String folderName, final Logger logger, C


/**
* Initialize a data manager with the given folder name, codec, and merger, as well as a user-defined GSON instance.
* @param folderName The name of the folder to load data from,
* Initialize a data manager with the given folder attribute, codec, and merger, as well as a user-defined GSON instance.
* @param folderName The attribute of the folder to load data from,
* e.g. "cheeses" would load data from "data/modid/cheeses" for all modids.
* Can include subfolders, e.g. "cheeses/sharp"
* @param logger A logger that will log parsing errors if they occur
* @param codec A codec that will be used to parse jsons. See drullkus's codec primer for help on creating these:
* https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910
* @param merger A merging function that uses a list of java-objects-that-were-parsed-from-json to create a final object.
* The list contains all successfully-parsed objects with the same ID from all mods and datapacks.
* (for a json located at "data/modid/folderName/name.json", the object's ID is "modid:name")
* As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:name id,
* (for a json located at "data/modid/folderName/attribute.json", the object's ID is "modid:attribute")
* As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:attribute id,
* and then all tag jsons defined with the same ID are merged additively into a single set of items, etc
* @param gson A GSON instance, allowing for user-defined deserializers. General not needed as the gson is only used to convert
* raw json to a JsonElement, which the Codec then parses into a proper java object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static <T> T register(
/**
* Define a config value for a complex object.
* @param <T> The type of the thing in the config we are making a listener for
* @param name The name of the field in your config that will hold objects of this type
* @param name The attribute of the field in your config that will hold objects of this type
* @param codec A Codec for de/serializing your object type.
* @param defaultObject The default instance of your config field. The given codec must be able to serialize this;
* if it cannot, an exception will be intentionally thrown the first time the config attempts to load.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private enum Category {
new HashMap<>(),
applyDefaults ? existing.veinBlacklist() : new ArrayList<>(),
applyDefaults ? existing.travelReq() : new HashMap<>(),
applyDefaults ? existing.dimensionalMobModifiers() : new ArrayList<>(),
applyDefaults ? existing.mobModifiers() : new HashMap<>());
JsonObject raw = LocationData.CODEC.encodeStart(JsonOps.INSTANCE, data).result().get().getAsJsonObject();
raw.remove("positive_effect");
Expand All @@ -231,6 +232,7 @@ private enum Category {
applyDefaults ? existing.negative() : new HashMap<>(),
applyDefaults ? existing.veinBlacklist() : new ArrayList<>(),
applyDefaults ? existing.travelReq() : new HashMap<>(),
applyDefaults ? existing.dimensionalMobModifiers() : new ArrayList<>(),
applyDefaults ? existing.mobModifiers() : new HashMap<>());
JsonObject raw = LocationData.CODEC.encodeStart(JsonOps.INSTANCE, data).result().get().getAsJsonObject();
return gson.toJson(raw);}),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/harmonised/pmmo/core/CoreUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static Map<String, Double> processSkillGroupBonus(Map<String, Double> map

/**Obtain the integer value for the skill color supplied.
*
* @param skill the skill name whose color is being obtained
* @param skill the skill attribute whose color is being obtained
* @return the integer skill value
*/
public static int getSkillColor(String skill) {
Expand Down
Loading

0 comments on commit 540d390

Please sign in to comment.