Closed xc0ff33 closed 11 months ago
This is covered in the very first documentation chapter, please read it.
This is an issue tracker not a support forum so please keep development questions in discord.
This is an issue tracker, use the discord for support questions. Though for a quick answer your LightningEntity mixin can extend your Entity mixin, and you need to use an interface to expose the setter to your utility class. That's explained in page 1 of the GitHub wiki, which you should read if you haven't already. Also, @Unique
is not helpful on public members, instead prefix them with your modid to avoid conflicts.
Oops, bad timing :P
This is probably really obvious (I'm very new to mixins and modding with fabric in general) but I need to call a method that a mixin adds to a class from another class that isn't a mixin.
In more depth: I need to call a method called
setFX
which is added toEntity
by a mixinEntitySetFXMixin
from a classLightningFX
that isn't a mixin.This isn't it though. I have to do the same thing, but instead with a
boolean
field. The field is calledisFX
and is also added toEntity
byEntitySetFXMixin
. ThesetFX
method setsisFX
(both are inEntity
) to true. I need to get this field from a mixinLightningFXMixin
that targetsLightningEntity
. (LightningFXMixin
redirects thespawnFire()
method inLightningEntity
to only spawn fire ifisFX
is false of the lightning object)Entity
is the superclass ofLightningEntity
, so I should be able to callLightningEntity.setFX()
. Obviously, IntelliJ won't compile this, as no method exists. I tried using a hacky solution usinggetMethod()
andgetBoolean()
, but the game crashed when I tried to callsetFX
even if it existed at the time (.mixin.out
showed me so). Is there something I'm doing wrong?All mixins are loaded on both the client and the server.
Here is my code:
**LightningFXMixin.java** - This is what's getting `isFX` from `Entity`! ``` package modid.mixin.fx.lightning; import net.minecraft.entity.LightningEntity; 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.Redirect; @Mixin(LightningEntity.class) public abstract class LightningFXMixin { @Shadow protected abstract void spawnFire(int spreadAttempts); @Redirect(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LightningEntity;spawnFire(I)V")) private void injected(LightningEntity instance, int spreadAttempts) { if (!this.isFX) { this.spawnFire(spreadAttempts); } } } ``` **EntitySetFXMixin** - This is what's mixing in `isFX` and `setFX()` into `Entity`! ``` // all this compiles and gets mixed in package modid.mixin.fx; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @Mixin(Entity.class) public class EntitySetFXMixin { @Unique public boolean isFX = false; @Unique public void setFX() { isFX = true; } } ``` **LightningFX** - This is what creates the `LightningEntity` object and spawns it in, calling `setFX` on it! ``` package modid.fx; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnReason; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.entity.LightningEntity; public class LightningFX { public void create(ServerWorld world, BlockPos pos) { EntityTypeHere was my hacky solution: (this 90% wasn't the correct way to do it)
**Calling `setFX` in `LightningFX`** ``` package modid.fx; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnReason; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.entity.LightningEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.*; public class LightningKillFX { public void create(ServerWorld world, BlockPos pos) { EntityType