diff --git a/src/main/java/harmonised/pmmo/features/mobscaling/MobAttributeHandler.java b/src/main/java/harmonised/pmmo/features/mobscaling/MobAttributeHandler.java index fe047e7c..23260522 100644 --- a/src/main/java/harmonised/pmmo/features/mobscaling/MobAttributeHandler.java +++ b/src/main/java/harmonised/pmmo/features/mobscaling/MobAttributeHandler.java @@ -32,10 +32,9 @@ @Mod.EventBusSubscriber(modid=Reference.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE) public class MobAttributeHandler { private static final UUID MODIFIER_ID = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcb"); - private static final UUID MODIFIER_ID2 = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcc"); - private static final UUID CUSTOM_MOD_ID_ADDITION = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcd"); - private static final UUID CUSTOM_MOD_ID_MULTIPLY_BASE = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fce"); - private static final UUID CUSTOM_MOD_ID_MULTIPLY_TOTAL = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcf"); + private static final UUID GLOBAL_DIMENSION_ADDITION_MODIFIER_ID = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcd"); + private static final UUID GLOBAL_DIMENSION_MULTIPLY_BASE_MODIFIER_ID = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fce"); + private static final UUID GLOBAL_DIMENSION_MULTIPLY_TOTAL_MODIFIER_ID = UUID.fromString("c95a6e8c-a1c3-4177-9118-1e2cf49b7fcf"); /**Used for balancing purposes to ensure configurations do not exceed known limits.*/ private static final Map CAPS = Map.of( new ResourceLocation("generic.max_health"), 1024f, @@ -61,9 +60,11 @@ public static void onBossAdd(EntityJoinLevelEvent event) { public static void onMobSpawn(FinalizeSpawn event) { if (!Config.MOB_SCALING_ENABLED.get()) return; - handle(event.getEntity(), event.getLevel().getLevel() - , new Vec3(event.getX(), event.getY(), event.getZ()) - , event.getLevel().getDifficulty().getId()); + if (event.getEntity().getType().is(Reference.MOB_TAG)) { + handle(event.getEntity(), event.getLevel().getLevel() + , new Vec3(event.getX(), event.getY(), event.getZ()) + , event.getLevel().getDifficulty().getId()); + } } private static void handle(LivingEntity entity, ServerLevel level, Vec3 spawnPos, int diffScale) { @@ -79,7 +80,7 @@ private static void handle(LivingEntity entity, ServerLevel level, Vec3 spawnPos var dimMods = dimData.mobModifiers().getOrDefault(RegistryUtil.getId(entity), new HashMap<>()); var bioMods = bioData.mobModifiers().getOrDefault(RegistryUtil.getId(entity), new HashMap<>()); - var dimModsCustom = dimData.globalMobModifiers(); + var dimensionalGlobalMobModifiers = dimData.globalMobModifiers(); var multipliers = Config.MOB_SCALING.get(); final float bossMultiplier = entity.getType().is(Tags.EntityTypes.BOSSES) ? Config.BOSS_SCALING_RATIO.get().floatValue() : 1f; @@ -88,7 +89,7 @@ private static void handle(LivingEntity entity, ServerLevel level, Vec3 spawnPos .map(ResourceLocation::new) .collect(Collectors.toSet()); - for (MobModifier att : dimModsCustom) { + for (MobModifier att : dimensionalGlobalMobModifiers) { var attributeLocation = new ResourceLocation(att.attribute()); var attribute = ForgeRegistries.ATTRIBUTES.getValue(attributeLocation); if (attribute == null) continue; @@ -104,10 +105,10 @@ private static void handle(LivingEntity entity, ServerLevel level, Vec3 spawnPos default -> AttributeModifier.Operation.ADDITION; }; UUID modifierID = switch (att.operation()) { - case "addition" -> CUSTOM_MOD_ID_ADDITION; - case "multiply_base" -> CUSTOM_MOD_ID_MULTIPLY_BASE; - case "multiply_total" -> CUSTOM_MOD_ID_MULTIPLY_TOTAL; - default -> CUSTOM_MOD_ID_ADDITION; + case "addition" -> GLOBAL_DIMENSION_ADDITION_MODIFIER_ID; + case "multiply_base" -> GLOBAL_DIMENSION_MULTIPLY_BASE_MODIFIER_ID; + case "multiply_total" -> GLOBAL_DIMENSION_MULTIPLY_TOTAL_MODIFIER_ID; + default -> GLOBAL_DIMENSION_ADDITION_MODIFIER_ID; }; attributeInstance.removeModifier(modifierID); attributeInstance.addPermanentModifier(new AttributeModifier(modifierID, "Boost to By Dimension Scaling", bonus, operation)); @@ -124,16 +125,7 @@ private static void handle(LivingEntity entity, ServerLevel level, Vec3 spawnPos double base = baseValue(entity, attributeID, attributeInstance); float cap = CAPS.getOrDefault(attributeID, Float.MAX_VALUE); float bonus = getBonus(nearbyPlayers, config, diffScale, base, cap); - float dimBonus = dimMods.getOrDefault(attributeID.toString(), 0d).floatValue(); - float bioBonus = bioMods.getOrDefault(attributeID.toString(), 0d).floatValue(); - boolean hasDimBonus = dimBonus >= 10000; - if (hasDimBonus) { - dimBonus /= 10000; - AttributeModifier modifier = new AttributeModifier(MODIFIER_ID2, "Boost to Mob Scaling", dimBonus, AttributeModifier.Operation.MULTIPLY_BASE); - attributeInstance.removeModifier(MODIFIER_ID2); - attributeInstance.addPermanentModifier(modifier); - } - bonus += !hasDimBonus ? dimMods.getOrDefault(attributeID.toString(), 0d).floatValue() : 0f; + bonus += dimMods.getOrDefault(attributeID.toString(), 0d).floatValue(); bonus += bioMods.getOrDefault(attributeID.toString(), 0d).floatValue(); bonus *= bossMultiplier; AttributeModifier modifier = new AttributeModifier(MODIFIER_ID, "Boost to Mob Scaling", bonus, AttributeModifier.Operation.ADDITION); @@ -189,15 +181,12 @@ private static float getBonus(List nearbyPlayers, Map co //get the average level for each skill and calculate its modifier from the configuration formula float outValue = 0f; for (Map.Entry configEntry : config.entrySet()) { - float currValue = 0f; int averageLevel = totalLevel.getOrDefault(configEntry.getKey(), 0)/nearbyPlayers.size(); if (averageLevel < Config.MOB_SCALING_BASE_LEVEL.get()) continue; - currValue += Config.MOB_USE_EXPONENTIAL_FORMULA.get() + outValue += Config.MOB_USE_EXPONENTIAL_FORMULA.get() ? Math.pow(Config.MOB_EXPONENTIAL_POWER_BASE.get(), (Config.MOB_EXPONENTIAL_LEVEL_MOD.get() * (averageLevel - Config.MOB_SCALING_BASE_LEVEL.get()))) : (averageLevel - Config.MOB_SCALING_BASE_LEVEL.get()) * Config.MOB_LINEAR_PER_LEVEL.get(); - currValue *= configEntry.getValue(); - currValue -= configEntry.getValue(); - outValue += currValue; + outValue *= configEntry.getValue(); } MsLoggy.DEBUG.log(LOG_CODE.FEATURE, "Modifier Value: "+outValue * scale); outValue *= scale;