diff --git a/src/main/java/plus/dragons/visuality/config/EntityArmorParticleConfig.java b/src/main/java/plus/dragons/visuality/config/EntityArmorParticleConfig.java index c29970a..32bc2c2 100644 --- a/src/main/java/plus/dragons/visuality/config/EntityArmorParticleConfig.java +++ b/src/main/java/plus/dragons/visuality/config/EntityArmorParticleConfig.java @@ -23,8 +23,6 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; -import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.event.tick.EntityTickEvent; import org.jetbrains.annotations.Nullable; import plus.dragons.visuality.Visuality; import plus.dragons.visuality.data.ParticleWithVelocity; @@ -49,15 +47,14 @@ public EntityArmorParticleConfig() { particles.put(armor, entry.particle); } } - NeoForge.EVENT_BUS.addListener(this::spawnParticles); } - public void spawnParticles(EntityTickEvent.Post event) { + public void spawnParticles(LivingEntity entity) { if (!enabled) return; - if(!(event.getEntity() instanceof LivingEntity entity)) return; + Level level = entity.level(); - if(!level.isClientSide || !entity.isAlive()) + if(!entity.isAlive()) return; RandomSource random = entity.getRandom(); diff --git a/src/main/java/plus/dragons/visuality/config/EntityHitParticleConfig.java b/src/main/java/plus/dragons/visuality/config/EntityHitParticleConfig.java index f8d8425..757303b 100644 --- a/src/main/java/plus/dragons/visuality/config/EntityHitParticleConfig.java +++ b/src/main/java/plus/dragons/visuality/config/EntityHitParticleConfig.java @@ -20,9 +20,6 @@ import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.ThrownTrident; -import net.neoforged.bus.api.EventPriority; -import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.event.entity.living.LivingDamageEvent; import org.jetbrains.annotations.Nullable; import plus.dragons.visuality.Visuality; import plus.dragons.visuality.data.ParticleWithVelocity; @@ -48,23 +45,17 @@ public EntityHitParticleConfig() { particles.put(type, entry.particle); } } - NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, true, this::spawnParticles); } - public void spawnParticles(LivingDamageEvent.Post event) { + public void spawnParticles(LivingEntity entity,DamageSource damageSource, double amount) { + // Unfortunately LivingDamageEvent only calls in server side. So we use Mixin if (!this.enabled) return; - - DamageSource damageSource = event.getSource(); - LivingEntity entity = event.getEntity(); - if (!entity.level().isClientSide) - return; EntityType type = entity.getType(); if (!particles.containsKey(type)) return; - - double amount = 0; + Entity sourceEntity = damageSource.getDirectEntity(); if (sourceEntity == null) diff --git a/src/main/java/plus/dragons/visuality/mixin/LivingEntityMixin.java b/src/main/java/plus/dragons/visuality/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..8539833 --- /dev/null +++ b/src/main/java/plus/dragons/visuality/mixin/LivingEntityMixin.java @@ -0,0 +1,21 @@ +package plus.dragons.visuality.mixin; + +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import plus.dragons.visuality.config.Config; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin { + @Inject(method = "hurt", at = @At("HEAD")) + private void handleParticle(DamageSource source, float amount, CallbackInfoReturnable cir) { + var living = (LivingEntity) (Object) this; + if(living.level().isClientSide){ + Config.ENTITY_HIT_PARTICLES.spawnParticles(living,source,amount); + Config.ENTITY_ARMOR_PARTICLES.spawnParticles(living); + } + } +} diff --git a/src/main/resources/visuality.mixins.json b/src/main/resources/visuality.mixins.json index 8c4b697..4072f83 100644 --- a/src/main/resources/visuality.mixins.json +++ b/src/main/resources/visuality.mixins.json @@ -11,5 +11,8 @@ ], "injectors": { "defaultRequire": 1 - } + }, + "mixins": [ + "LivingEntityMixin" + ] }