Skip to content

Commit

Permalink
bette swim behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
baguchi committed Nov 15, 2023
1 parent 59805f4 commit 2a8f27c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ public void moveEntityWithHeading(float moveStrafing, float moveForward, Callbac
|| this.world.getBlockMaterial((int) (this.x), (int) (this.y + 1.0 - 0.1), (int) (this.z)) == Material.water) {
this.yd += (d3 - yd) * d4;
}
this.moveRelative(moveStrafing, moveForward, 0.025F);
this.xd += (this.getLookAngle().xCoord - xd) * 0.025F;
this.zd += (this.getLookAngle().zCoord - zd) * 0.025F;
}
}


@Inject(method = "onLivingUpdate", at = @At("HEAD"))
public void onLivingUpdate(CallbackInfo ci) {
if (this.world.getBlockId((int) (this.x), (int) this.y + 1, (int) (this.z)) != 0 && this.world.getBlockMaterial((int) (this.x), (int) this.y + 1, (int) (this.z)) != Material.water && (!this.isInWater())) {
if (!(this.world.getBlockId((int) (this.x), (int) this.y + 1, (int) (this.z)) != 0 && this.world.getBlockMaterial((int) (this.x), (int) this.y + 1, (int) (this.z)) != Material.water) && this.isVisuallyCrawling()) {
this.setSwimming(false);
}

if (this.isSwimming() && this.isInWater() && this.moveForward == 0 && this.moveStrafing == 0) {
this.setSwimming(false);
}
this.updateSwimAmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Mixin(value = NetHandler.class, remap = false)
public class NetHandlerMixin implements ISwimPacket {

public void handleMobEnchant(SwimPacket packet) {
public void handleSwim(SwimPacket packet) {
this.handleInvalidPacket(packet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NetServerHandlerMixin implements ISwimPacket {
private EntityPlayerMP playerEntity;

@Override
public void handleMobEnchant(SwimPacket packet) {
public void handleSwim(SwimPacket packet) {
if (playerEntity instanceof ISwiming) {
((ISwiming) playerEntity).setSwimming(packet.swim);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public class KeyboardInputMixin {

@Inject(method = "tick", at = @At(value = "TAIL"))
public void tick(EntityPlayer entityplayer, CallbackInfo ci) {
if (entityplayer.isInWater()) {

if (entityplayer instanceof ISwiming) {
if (entityplayer.isInWater()) {
if (keys[0]) {
this.sprintTime = 0;
if (this.sprintTime < 9) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package baguchan.better_with_aquatic.packet;

public interface ISwimPacket {
void handleMobEnchant(SwimPacket packet);
void handleSwim(SwimPacket packet);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void writePacketData(DataOutputStream dataOutputStream) throws IOExceptio

@Override
public void processPacket(NetHandler netHandler) {
((ISwimPacket) netHandler).handleMobEnchant(this);
((ISwimPacket) netHandler).handleSwim(this);
}

@Override
Expand Down

0 comments on commit 2a8f27c

Please sign in to comment.