From 659bc97f79228199fe861520572e535e253d2de9 Mon Sep 17 00:00:00 2001 From: baguchan Date: Thu, 6 Jun 2024 00:30:16 +0900 Subject: [PATCH] swiming fix --- gradle.properties | 2 +- .../better_with_aquatic/mixin/EntityItemMixin.java | 10 ++++++++++ .../better_with_aquatic/mixin/EntityMixin.java | 11 +++++++++++ .../mixin/client/PlayerInputMixin.java | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5e56fb2..375d055 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,6 @@ halplibe_version=4.0.6 dragonfly_version=1.5.0-7.2-pre1 terrain_api_version=1.4.4-7.2-pre1 # Mod -mod_version=4.0.0 +mod_version=4.0.1 mod_group=baguchan mod_name=better_with_aquatic diff --git a/src/main/java/baguchan/better_with_aquatic/mixin/EntityItemMixin.java b/src/main/java/baguchan/better_with_aquatic/mixin/EntityItemMixin.java index 540304d..0ed1f27 100644 --- a/src/main/java/baguchan/better_with_aquatic/mixin/EntityItemMixin.java +++ b/src/main/java/baguchan/better_with_aquatic/mixin/EntityItemMixin.java @@ -1,11 +1,14 @@ package baguchan.better_with_aquatic.mixin; +import net.minecraft.core.block.material.Material; import net.minecraft.core.entity.Entity; import net.minecraft.core.entity.EntityItem; import net.minecraft.core.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(value = EntityItem.class, remap = false) public abstract class EntityItemMixin extends Entity { @@ -14,6 +17,13 @@ public EntityItemMixin(World world) { super(world); } + @Inject(method = "checkAndHandleWater", at = @At("HEAD"), cancellable = true) + public void checkAndHandleWater(boolean addVelocity, CallbackInfoReturnable cir) { + Entity entity = (Entity) (Object) this; + + cir.setReturnValue(this.world.handleMaterialAcceleration(this.bb, Material.water, entity, addVelocity)); + } + @Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/core/entity/EntityItem;yd:D", ordinal = 7)) public double tick(EntityItem instance) { if (this.wasInWater) { diff --git a/src/main/java/baguchan/better_with_aquatic/mixin/EntityMixin.java b/src/main/java/baguchan/better_with_aquatic/mixin/EntityMixin.java index 793cd31..eab303b 100644 --- a/src/main/java/baguchan/better_with_aquatic/mixin/EntityMixin.java +++ b/src/main/java/baguchan/better_with_aquatic/mixin/EntityMixin.java @@ -1,11 +1,15 @@ package baguchan.better_with_aquatic.mixin; +import net.minecraft.core.block.material.Material; import net.minecraft.core.entity.Entity; import net.minecraft.core.util.phys.AABB; import net.minecraft.core.world.World; 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(value = Entity.class, remap = false) public class EntityMixin { @@ -14,4 +18,11 @@ public class EntityMixin { @Shadow @Final public AABB bb; + + @Inject(method = "checkAndHandleWater", at = @At("HEAD"), cancellable = true) + public void checkAndHandleWater(boolean addVelocity, CallbackInfoReturnable cir) { + Entity entity = (Entity) (Object) this; + + cir.setReturnValue(this.world.handleMaterialAcceleration(this.bb, Material.water, entity, addVelocity)); + } } diff --git a/src/main/java/baguchan/better_with_aquatic/mixin/client/PlayerInputMixin.java b/src/main/java/baguchan/better_with_aquatic/mixin/client/PlayerInputMixin.java index 7582401..be4e012 100644 --- a/src/main/java/baguchan/better_with_aquatic/mixin/client/PlayerInputMixin.java +++ b/src/main/java/baguchan/better_with_aquatic/mixin/client/PlayerInputMixin.java @@ -34,7 +34,7 @@ public void tick(EntityPlayer entityplayer, CallbackInfo ci) { --this.sprintTimer; } if (entityplayer instanceof ISwiming) { - if (entityplayer.isUnderLiquid(Material.water) && !entityplayer.isSneaking()) { + if (BetterWithAquatic.isEnableSwim() && entityplayer.isUnderLiquid(Material.water) && !entityplayer.isSneaking()) { if (this.pressedForward) { if (this.sprintTimer == 0) { this.sprintTimer = 7;