Skip to content

Commit

Permalink
fix: issue with mob buffing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Sep 18, 2023
1 parent 13c238f commit 81e2da6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [2.0.7]

### Fixed

- Fixed an issue causing entities health to be buffed on each world load instead of just once. This has been fixed by moving to a attribute modifier instead of a flat health increase. The `uuid` for this attribute modifier is `a07a9434-d6c2-44f1-b5eb-394da41c9f9f`.

## [2.0.6]

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package dev.ftb.packcompanion.features.buffs;

import com.google.common.base.Suppliers;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.EntityEvent;
import dev.ftb.packcompanion.config.PCServerConfig;
import dev.ftb.packcompanion.features.ServerFeature;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.monster.Enemy;

import java.util.UUID;
import java.util.function.Supplier;

public class MobEntityBuff extends ServerFeature {
private static final UUID MODIFIER_UUID = UUID.fromString("a07a9434-d6c2-44f1-b5eb-394da41c9f9f");

private static Supplier<AttributeModifier> MODIFIER = Suppliers.memoize(() -> {
var multiplierValue = PCServerConfig.MODIFY_MOB_BASE_HEALTH.get();
return new AttributeModifier(MODIFIER_UUID, "ftbpc:mob_entity_health_buff", multiplierValue, AttributeModifier.Operation.MULTIPLY_BASE);
});

@Override
public void initialize() {
// On entity load
EntityEvent.ADD.register((entity, world) -> {
if (entity instanceof Enemy && entity instanceof Mob mob) {
AttributeInstance attribute = mob.getAttribute(Attributes.MAX_HEALTH);
if (attribute != null) {
attribute.setBaseValue(attribute.getBaseValue() * PCServerConfig.MODIFY_MOB_BASE_HEALTH.get());
mob.setHealth((float) attribute.getBaseValue());
if (attribute != null && attribute.getModifier(MODIFIER_UUID) == null) {
attribute.addPermanentModifier(MODIFIER.get());
((Mob) entity).setHealth(((Mob) entity).getMaxHealth());
}
}

Expand Down
11 changes: 11 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ configurations {
developmentFabric.extendsFrom common
}

repositories {
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
}

dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
Expand All @@ -32,6 +41,8 @@ dependencies {

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }

modRuntimeOnly "curse.maven:jade-324717:4328558"
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.19.2
enabled_platforms=fabric,forge

archives_base_name=ftb-pack-companion
mod_version=2.0.6
mod_version=2.0.7
maven_group=dev.ftb.mods

architectury_version=6.3.49
Expand Down

0 comments on commit 81e2da6

Please sign in to comment.