Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Fix issues with ProjectileHitActionPowerFactories.
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Dec 11, 2023
1 parent ed58a0c commit 011c5d9
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Modify Scale is broken, I know about it. I got frustrated trying to fix it, so I released this version early so TooManyOrigins players don't have to wait.

## Power Types
- Added `stop_after` field to `action_on_projectile_hit` power type.
- Added `stop_after` field to the `action_on_projectile_hit` power type.
- `action_when_projectile_hit` now functions when a non living entity is the owner of the projectile.

## Entity Condition Types
- Added `space` field to `velocity` entity condition type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
public interface ActionWhenProjectileHitPowerFactory<P> extends ProjectileHitActionPowerFactory<P> {

default void execute(P power, LivingEntity entity, Projectile projectile) {
if (!(projectile.getOwner() instanceof LivingEntity living)) return;
this.execute(power, entity, living, entity, projectile, 1);
this.execute(power, entity, projectile.getOwner(), entity, projectile, getDataFromPower(power).getInt("stop_after"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static SerializableData getSerializableData() {
.add("stop_after", SerializableDataTypes.INT, 1);
}

default void execute(P power, LivingEntity powerHolder, LivingEntity attacker, Entity target, Projectile projectile, int amountHit) {
default void execute(P power, LivingEntity powerHolder, Entity attacker, Entity target, Projectile projectile, int amountHit) {
SerializableData.Instance data = getDataFromPower(power);
if (canUse(power, powerHolder) && Services.CONDITION.checkBiEntity(data, "bientity_condition", projectile, target) && Services.CONDITION.checkBiEntity(data, "owner_bientity_condition", attacker, target)) {
Services.ACTION.executeBiEntity(data, "bientity_action", projectile, target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public abstract class ProjectileEntityMixin implements ProjectileEntityAccess {
Services.POWER.getPowers(living, ApugliPowers.ACTION_WHEN_PROJECTILE_HIT.get()).forEach(power -> ApugliPowers.ACTION_WHEN_PROJECTILE_HIT.get().execute(power, living, (Projectile)(Object)this));
if (hitResult instanceof EntityHitResult entityHitResult && this.getOwner() instanceof LivingEntity living)
Services.POWER.getPowers(living, ApugliPowers.ACTION_ON_PROJECTILE_HIT.get()).forEach(power -> {
ApugliPowers.ACTION_ON_PROJECTILE_HIT.get().execute(power, living, entityHitResult.getEntity(), (Projectile)(Object)this, this.apugli$entitiesHit.getOrDefault(Services.POWER.getPowerId(power), 0));
this.apugli$entitiesHit.compute(Services.POWER.getPowerId(power), (resourceLocation, integer) -> integer != null ? integer + 1 : 1);
ApugliPowers.ACTION_ON_PROJECTILE_HIT.get().execute(power, living, entityHitResult.getEntity(), (Projectile)(Object)this, this.apugli$entitiesHit.getOrDefault(Services.POWER.getPowerId(power), 0));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ public static void onProjectileImpact(ProjectileImpactEvent event) {
Services.POWER.getPowers(living, ApugliPowers.ACTION_WHEN_PROJECTILE_HIT.get()).forEach(power -> ApugliPowers.ACTION_WHEN_PROJECTILE_HIT.get().execute(power, living, event.getProjectile()));
if ((event.getProjectile().getOwner() instanceof LivingEntity living))
Services.POWER.getPowers(living, ApugliPowers.ACTION_ON_PROJECTILE_HIT.get()).forEach(power -> {
event.getProjectile().getCapability(EntitiesHitCapability.INSTANCE).ifPresent(cap -> cap.addHitEntity(Services.POWER.getPowerId(power)));
ApugliPowers.ACTION_ON_PROJECTILE_HIT.get().execute(power, living, ((EntityHitResult)event.getRayTraceResult()).getEntity(), event.getProjectile(), event.getProjectile().getCapability(EntitiesHitCapability.INSTANCE).map(cap -> cap.getPowerValue(Services.POWER.getPowerId(power))).orElse(0));
event.getProjectile().getCapability(EntitiesHitCapability.INSTANCE).ifPresent(cap -> cap.addToPowersThatHaveLanded(Services.POWER.getPowerId(power)));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int getPowerValue(ResourceLocation value) {


@Override
public void addToPowersThatHaveLanded(ResourceLocation value) {
public void addHitEntity(ResourceLocation value) {
this.apugli$entitiesHit.compute(value, (resourceLocation, integer) -> integer != null ? integer + 1 : 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface IEntitiesHitCapability extends ProjectileEntityAccess {

int getPowerValue(ResourceLocation value);

void addToPowersThatHaveLanded(ResourceLocation value);
void addHitEntity(ResourceLocation value);

}

0 comments on commit 011c5d9

Please sign in to comment.