diff --git a/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/EffekLightningBolt.java b/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/EffekLightningBolt.java new file mode 100644 index 0000000..851d9e5 --- /dev/null +++ b/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/EffekLightningBolt.java @@ -0,0 +1,5 @@ +package mod.chloeprime.aaaparticles.common.internal; + +public interface EffekLightningBolt { + boolean aaaParticles$getEffekTicket(); +} diff --git a/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/package-info.java b/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/package-info.java new file mode 100644 index 0000000..0e69d56 --- /dev/null +++ b/common/src/main/java/mod/chloeprime/aaaparticles/common/internal/package-info.java @@ -0,0 +1,4 @@ +@ApiStatus.Internal +package mod.chloeprime.aaaparticles.common.internal; + +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file diff --git a/common/src/main/java/mod/chloeprime/aaaparticles/mixin/MixinLightningBolt.java b/common/src/main/java/mod/chloeprime/aaaparticles/mixin/MixinLightningBolt.java index f6313b1..6a1d36b 100644 --- a/common/src/main/java/mod/chloeprime/aaaparticles/mixin/MixinLightningBolt.java +++ b/common/src/main/java/mod/chloeprime/aaaparticles/mixin/MixinLightningBolt.java @@ -1,28 +1,24 @@ package mod.chloeprime.aaaparticles.mixin; -import mod.chloeprime.aaaparticles.client.ModClientHooks; +import mod.chloeprime.aaaparticles.common.internal.EffekLightningBolt; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LightningBolt; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.Unique; @Mixin(LightningBolt.class) -public abstract class MixinLightningBolt extends Entity { - @Shadow private int life; +public abstract class MixinLightningBolt extends Entity implements EffekLightningBolt { + @Unique private boolean aaaParticles$effekTicket = true; - @Inject( - method = "tick", - at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;tick()V") - ) - private void playLightingEffek(CallbackInfo ci) { - if (life == 0 && level.isClientSide()) { - ModClientHooks.playLightningEffek((LightningBolt) (Object) this); + @Override + public boolean aaaParticles$getEffekTicket() { + if (aaaParticles$effekTicket) { + aaaParticles$effekTicket = false; + return true; } + return false; } public MixinLightningBolt(EntityType entityType, Level level) { diff --git a/common/src/main/java/mod/chloeprime/aaaparticles/mixin/client/MixinLightningBoltRenderer.java b/common/src/main/java/mod/chloeprime/aaaparticles/mixin/client/MixinLightningBoltRenderer.java index 136dc2e..0a2fbe5 100644 --- a/common/src/main/java/mod/chloeprime/aaaparticles/mixin/client/MixinLightningBoltRenderer.java +++ b/common/src/main/java/mod/chloeprime/aaaparticles/mixin/client/MixinLightningBoltRenderer.java @@ -1,6 +1,8 @@ package mod.chloeprime.aaaparticles.mixin.client; import com.mojang.blaze3d.vertex.PoseStack; +import mod.chloeprime.aaaparticles.client.ModClientHooks; +import mod.chloeprime.aaaparticles.common.internal.EffekLightningBolt; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.LightningBoltRenderer; import net.minecraft.world.entity.LightningBolt; @@ -15,7 +17,10 @@ public class MixinLightningBoltRenderer { method = "render(Lnet/minecraft/world/entity/LightningBolt;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At("HEAD"), cancellable = true ) - private void disableVanillaLightningModel(LightningBolt lightningBolt, float f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) { + private void disableVanillaLightningModelAndPlayEffek(LightningBolt bolt, float f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) { + if (((EffekLightningBolt) bolt).aaaParticles$getEffekTicket()) { + ModClientHooks.playLightningEffek(bolt); + } ci.cancel(); } }