mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 11:57:01 -05:00
Hooks for setting radius for explosion
This commit is contained in:
@@ -45,12 +45,18 @@ public final class ExplosionHooks {
|
||||
return IMPL.getRadius(explosion);
|
||||
}
|
||||
|
||||
public static void setRadius(Explosion explosion, float radius) {
|
||||
IMPL.setRadius(explosion, radius);
|
||||
}
|
||||
|
||||
public interface Impl {
|
||||
Vec3 getPosition(Explosion explosion);
|
||||
|
||||
Entity getSource(Explosion explosion);
|
||||
|
||||
float getRadius(Explosion explosion);
|
||||
|
||||
void setRadius(Explosion explosion, float radius);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -37,11 +37,18 @@ public class ExplosionHooksImpl implements ExplosionHooks.Impl {
|
||||
return ((ExplosionExtensions) explosion).architectury_getRadius();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRadius(Explosion explosion, float radius) {
|
||||
((ExplosionExtensions) explosion).architectury_setRadius(radius);
|
||||
}
|
||||
|
||||
public interface ExplosionExtensions {
|
||||
Vec3 architectury_getPosition();
|
||||
|
||||
Entity architectury_getSource();
|
||||
|
||||
float architectury_getRadius();
|
||||
|
||||
void architectury_setRadius(float v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -43,7 +40,7 @@ public class MixinExplosion implements ExplosionHooksImpl.ExplosionExtensions {
|
||||
@Shadow @Final private double y;
|
||||
@Shadow @Final private double z;
|
||||
@Shadow @Final @Nullable private Entity source;
|
||||
@Shadow @Final private float radius;
|
||||
@Shadow @Final @Mutable private float radius;
|
||||
@Unique Vec3 position;
|
||||
|
||||
@Inject(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;<init>(DDD)V", ordinal = 0),
|
||||
@@ -69,4 +66,9 @@ public class MixinExplosion implements ExplosionHooksImpl.ExplosionExtensions {
|
||||
public float architectury_getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void architectury_setRadius(float v) {
|
||||
radius = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,13 @@ public class ExplosionHooksImpl implements ExplosionHooks.Impl {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRadius(Explosion explosion, float v) {
|
||||
try {
|
||||
ObfuscationReflectionHelper.findField(Explosion.class, "field_77280_f").set(explosion, v);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user