From 59db14461b947845f84f14ce78f86300b1d734a5 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 27 Jan 2025 16:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E7=89=88=E7=88=86=E7=82=B8=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=87=BB=E9=80=80=E8=BD=BD=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/mixins/ExplosionMixin.java | 65 +++++++++++++++---- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/ExplosionMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/ExplosionMixin.java index ab22025e8..0ba8af383 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/ExplosionMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/ExplosionMixin.java @@ -1,24 +1,67 @@ package com.atsuishio.superbwarfare.mixins; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.player.Player; +import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; import net.minecraft.world.level.Explosion; -import org.objectweb.asm.Opcodes; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Final; 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.ModifyVariable; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.List; +import java.util.Set; @Mixin(Explosion.class) public class ExplosionMixin { - @ModifyVariable(method = "explode()V", at = @At(value = "STORE", opcode = Opcodes.DSTORE), ordinal = 14) - private double modifyD11(double d) { - Minecraft mc = Minecraft.getInstance(); - Player player = mc.player; - if (player == null) return d; + @Final + @Shadow + private double x; + @Final + @Shadow + private double y; - return d; + @Final + @Shadow + private double z; + + @Inject(method = "explode()V", + at = @At( + value = "INVOKE_ASSIGN", + target = "Ljava/util/List;get(I)Ljava/lang/Object;", + ordinal = 0), + locals = LocalCapture.CAPTURE_FAILHARD) + public void explode(CallbackInfo ci, Set set, int i, float f2, int k1, int l1, int i2, int i1, int j2, int j1, List list, Vec3 vec3, int k2) { + if (list.size() >= k2) { + var obj = list.get(k2); + if (obj instanceof VehicleEntity vehicle) { + if (!vehicle.ignoreExplosion()) { + double d12 = Math.sqrt(vehicle.distanceToSqr(vec3)) / (double) f2; + if (d12 <= 1.0D) { + double d5 = vehicle.getX() - this.x; + double d7 = vehicle.getEyeY() - this.y; + double d9 = vehicle.getZ() - this.z; + double d13 = Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9); + if (d13 != 0.0D) { + d5 /= d13; + d7 /= d13; + d9 /= d13; + double d14 = Explosion.getSeenPercent(vec3, vehicle); + double d10 = (1.0D - d12) * d14; + + d5 *= d10; + d7 *= d10; + d9 *= d10; + Vec3 vec31 = new Vec3(d5, d7, d9).multiply(-1, -1, -1); + vehicle.setDeltaMovement(vehicle.getDeltaMovement().add(vec31)); + } + } + } + } + } } - }