diff --git a/src/main/java/com/goby56/wakes/duck/ProducesWake.java b/src/main/java/com/goby56/wakes/duck/ProducesWake.java index 5e7393b..4652c9e 100644 --- a/src/main/java/com/goby56/wakes/duck/ProducesWake.java +++ b/src/main/java/com/goby56/wakes/duck/ProducesWake.java @@ -1,7 +1,6 @@ package com.goby56.wakes.duck; import com.goby56.wakes.particle.custom.SplashPlaneParticle; -import net.minecraft.client.particle.Particle; import net.minecraft.util.math.Vec3d; public interface ProducesWake { @@ -14,4 +13,6 @@ public interface ProducesWake { double getVerticalVelocity(); void setSplashPlane(SplashPlaneParticle particle); + void setRecentlyTeleported(boolean b); + } diff --git a/src/main/java/com/goby56/wakes/mixin/TameableTeleportMixin.java b/src/main/java/com/goby56/wakes/mixin/TameableTeleportMixin.java new file mode 100644 index 0000000..43429aa --- /dev/null +++ b/src/main/java/com/goby56/wakes/mixin/TameableTeleportMixin.java @@ -0,0 +1,23 @@ +package com.goby56.wakes.mixin; + +import com.goby56.wakes.duck.ProducesWake; +import net.minecraft.entity.ai.goal.FollowOwnerGoal; +import net.minecraft.entity.passive.TameableEntity; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(FollowOwnerGoal.class) +public class TameableTeleportMixin { + @Shadow private TameableEntity tameable; + + @Inject(at = @At("TAIL"), method = "tryTeleportTo") + private void onTeleport(int x, int y, int z, CallbackInfoReturnable cir) { + if (cir.getReturnValue()) { + ((ProducesWake) tameable).setRecentlyTeleported(true); + } + } +} diff --git a/src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java b/src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java index c97e9e9..a6fcf24 100644 --- a/src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java +++ b/src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java @@ -7,14 +7,20 @@ import com.goby56.wakes.duck.ProducesWake; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.Entity; +import net.minecraft.network.packet.s2c.play.PositionFlag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; 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.injection.callback.CallbackInfoReturnable; + +import java.util.Set; @Mixin(Entity.class) public abstract class WakeSpawnerMixin implements ProducesWake { @@ -32,6 +38,7 @@ public abstract class WakeSpawnerMixin implements ProducesWake { @Unique private double verticalNumericalVelocity = 0; @Unique private Float producingWaterLevel = null; @Unique private SplashPlaneParticle splashPlane; + @Unique private boolean hasRecentlyTeleported = false; @Override public boolean onWaterSurface() { @@ -54,8 +61,7 @@ public double getVerticalVelocity() { @Override public Vec3d getPrevPos() { - if (this.prevPosOnSurface == null) return null; - return new Vec3d(this.prevPosOnSurface.x, this.prevPosOnSurface.y, this.prevPosOnSurface.z); + return this.prevPosOnSurface; } @Override @@ -73,7 +79,19 @@ public void setSplashPlane(SplashPlaneParticle particle) { this.splashPlane = particle; } - @Inject(at = @At("HEAD"), method = "tick") + @Override + public void setRecentlyTeleported(boolean b) { + this.hasRecentlyTeleported = b; + } + + // TODO FIX PLAYER TELEPORTATION CAUSING LONG WAKES +// @Inject(at = @At("TAIL"), method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDLjava/util/Set;FF)Z") +// private void onTeleport(ServerWorld world, double destX, double destY, double destZ, Set flags, float yaw, float pitch, CallbackInfoReturnable cir) { +// this.setRecentlyTeleported(true); +// System.out.printf("%s wants to teleport\n", this); +// } + + @Inject(at = @At("TAIL"), method = "tick") private void tick(CallbackInfo info) { this.onWaterSurface = this.isTouchingWater() && !this.isSubmergedInWater(); Entity thisEntity = ((Entity) (Object) this); @@ -86,7 +104,7 @@ private void tick(CallbackInfo info) { return; } - if (this.onWaterSurface) { + if (this.onWaterSurface && this.horizontalNumericalVelocity > 1e-3 && !this.hasRecentlyTeleported) { if (this.producingWaterLevel == null) this.producingWaterLevel = WakesUtils.getWaterLevel(this.world, thisEntity); @@ -99,6 +117,7 @@ private void tick(CallbackInfo info) { this.producingWaterLevel = null; this.prevPosOnSurface = null; } + this.setRecentlyTeleported(false); } @Inject(at = @At("TAIL"), method = "onSwimmingStart") diff --git a/src/main/java/com/goby56/wakes/utils/WakesUtils.java b/src/main/java/com/goby56/wakes/utils/WakesUtils.java index d615a36..61245b4 100644 --- a/src/main/java/com/goby56/wakes/utils/WakesUtils.java +++ b/src/main/java/com/goby56/wakes/utils/WakesUtils.java @@ -84,11 +84,6 @@ public static void placeWakeTrail(Entity entity) { } } - // TODO FIX ENTERING BOAT CREATES LONG WAKE -// if (velocity < WakesClient.CONFIG_INSTANCE.minimumProducerVelocity) { -// ((ProducesWake) entity).setPrevPos(null); -// } - Vec3d prevPos = producer.getPrevPos(); if (prevPos == null) { return; diff --git a/src/main/resources/wakes.mixins.json b/src/main/resources/wakes.mixins.json index af8ada7..9cb9487 100644 --- a/src/main/resources/wakes.mixins.json +++ b/src/main/resources/wakes.mixins.json @@ -1,11 +1,12 @@ { - "required": true, - "package": "com.goby56.wakes.mixin", - "compatibilityLevel": "JAVA_17", - "client": [ - "WakeSpawnerMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "com.goby56.wakes.mixin", + "compatibilityLevel": "JAVA_17", + "client": [ + "WakeSpawnerMixin", + "TameableTeleportMixin" + ], + "injectors": { + "defaultRequire": 1 + } } \ No newline at end of file