From 043676557684ba7fa46dedde2733d19701094a6e Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Tue, 18 Mar 2025 02:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0FastProjectile=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/FastProjectile.java | 4 ++++ .../entity/projectile/ProjectileEntity.java | 2 +- ...ClientboundSetEntityMotionPacketMixin.java | 20 ++++++++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/entity/projectile/FastProjectile.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/FastProjectile.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/FastProjectile.java new file mode 100644 index 000000000..bdeb1a6d8 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/FastProjectile.java @@ -0,0 +1,4 @@ +package com.atsuishio.superbwarfare.entity.projectile; + +public interface FastProjectile { +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index b0e463acc..20797c7b5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -66,7 +66,7 @@ import java.util.function.Function; import java.util.function.Predicate; @SuppressWarnings({"unused", "UnusedReturnValue", "SuspiciousNameCombination"}) -public class ProjectileEntity extends Projectile implements IEntityAdditionalSpawnData, GeoEntity { +public class ProjectileEntity extends Projectile implements IEntityAdditionalSpawnData, GeoEntity, FastProjectile { public static final EntityDataAccessor COLOR_R = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor COLOR_G = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/ClientboundSetEntityMotionPacketMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/ClientboundSetEntityMotionPacketMixin.java index 903ba9a5e..8a39b9784 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/ClientboundSetEntityMotionPacketMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/ClientboundSetEntityMotionPacketMixin.java @@ -1,7 +1,11 @@ package com.atsuishio.superbwarfare.mixins; +import com.atsuishio.superbwarfare.entity.projectile.FastProjectile; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; +import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -40,12 +44,18 @@ public class ClientboundSetEntityMotionPacketMixin { @Shadow private int za; - @Inject(method = "Lnet/minecraft/network/protocol/game/ClientboundSetEntityMotionPacket;" + - "(ILnet/minecraft/world/phys/Vec3;)V", at = @At(value = "RETURN")) + // TODO 实现仅对 FastProjectile 对象的动量修改 + @Inject(method = "(ILnet/minecraft/world/phys/Vec3;)V", at = @At(value = "RETURN")) public void init(int entityId, Vec3 motion, CallbackInfo ci) { - this.xa = (int) (motion.x * 8000.0D); - this.ya = (int) (motion.y * 8000.0D); - this.za = (int) (motion.z * 8000.0D); + ClientLevel level = Minecraft.getInstance().level; + if (level != null) { + Entity entity = level.getEntity(entityId); + if (entity instanceof FastProjectile) { + this.xa = (int) (motion.x * 8000.0D); + this.ya = (int) (motion.y * 8000.0D); + this.za = (int) (motion.z * 8000.0D); + } + } } @Redirect(method = "(Lnet/minecraft/network/FriendlyByteBuf;)V",