Skip to content

Commit

Permalink
Removed junk code from MobAttributeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandaismyname1 committed Jul 17, 2024
1 parent 9f24f16 commit 6691a52
Showing 1 changed file with 17 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceLocation, Float> CAPS = Map.of(
new ResourceLocation("generic.max_health"), 1024f,
Expand All @@ -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) {
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -189,15 +181,12 @@ private static float getBonus(List<Player> nearbyPlayers, Map<String, Double> co
//get the average level for each skill and calculate its modifier from the configuration formula
float outValue = 0f;
for (Map.Entry<String, Double> 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;
Expand Down

0 comments on commit 6691a52

Please sign in to comment.