Skip to content

Commit

Permalink
Hit Particle Issue Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarbleGateKeeper committed Oct 21, 2024
1 parent b85239c commit af8f9cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/plus/dragons/visuality/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> cir) {
var living = (LivingEntity) (Object) this;
if(living.level().isClientSide){
Config.ENTITY_HIT_PARTICLES.spawnParticles(living,source,amount);
Config.ENTITY_ARMOR_PARTICLES.spawnParticles(living);
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/visuality.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"LivingEntityMixin"
]
}

0 comments on commit af8f9cc

Please sign in to comment.