From 7c9d90e3f27d71752c2382ddb26d57780619e6b7 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Thu, 22 Aug 2024 17:21:14 -0500 Subject: [PATCH 01/25] partial fix; dismount command when going underwater --- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 202ef06f0..170d9deec 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -9,6 +9,7 @@ import drzhark.mocreatures.entity.tameable.MoCEntityTameableAnimal; import drzhark.mocreatures.init.MoCLootTables; import drzhark.mocreatures.init.MoCSoundEvents; +import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; @@ -202,8 +203,11 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } + if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) + { + MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); + } if (!this.world.isRemote) { - if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; this.jumpTimer = 15; From 84f3b82d3a0afaa0202d6e32988a35ab65c97393 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Thu, 22 Aug 2024 20:01:02 -0500 Subject: [PATCH 02/25] nit; only allow bunny to start riding player from server side, do not initiate at all from client --- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 170d9deec..3cd3a7f76 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -182,10 +182,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (this.getRidingEntity() == null) { + if (this.getRidingEntity() == null && !this.world.isRemote) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!getIsTamed() && !this.world.isRemote) { + if (!getIsTamed()) { MoCTools.tameWithName(player, this); } } From 6e8f010f2f1d7202f4c26ce926947df0a00c8980 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Thu, 22 Aug 2024 20:36:57 -0500 Subject: [PATCH 03/25] nit; only allow any pets to start riding player from server side, do not initiate at all from client --- .../mocreatures/entity/hunter/MoCEntityPetScorpion.java | 4 ++-- .../drzhark/mocreatures/entity/hunter/MoCEntitySnake.java | 2 +- .../drzhark/mocreatures/entity/neutral/MoCEntityKitty.java | 4 ++-- .../drzhark/mocreatures/entity/passive/MoCEntityBird.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 6 +----- .../drzhark/mocreatures/entity/passive/MoCEntityMouse.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityTurtle.java | 2 +- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java index a10409f71..a938aa8b3 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java @@ -486,10 +486,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } } - if (this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { + if (!this.world.isRemote && this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!this.world.isRemote && !getIsTamed()) { + if (!getIsTamed()) { MoCTools.tameWithName(player, this); } } diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java index ddcc5c561..c1d9a1a02 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java @@ -175,7 +175,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return false; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java index 8bdd4c751..7410a1a81 100644 --- a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java +++ b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java @@ -476,7 +476,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return MoCTools.tameWithName(player, this); } if (!stack.isEmpty() && getKittyState() > 2 && pickable() && stack.getItem() == Items.LEAD) { - if (this.startRidingPlayer(player)) { + if (!this.world.isRemote && this.startRidingPlayer(player)) { changeKittyState(14); } return true; @@ -490,7 +490,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } // Can be picked up, then pick it up if (getKittyState() > 2 && pickable()) { - if (this.startRidingPlayer(player)) { + if (!this.world.isRemote && this.startRidingPlayer(player)) { changeKittyState(15); } return true; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java index 168c82f11..f30264d5f 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java @@ -324,7 +324,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!getIsTamed()) { return false; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 3cd3a7f76..00b04d62f 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -182,7 +182,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (this.getRidingEntity() == null && !this.world.isRemote) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; if (!getIsTamed()) { @@ -203,10 +203,6 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } - if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) - { - MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); - } if (!this.world.isRemote) { if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java index 2174c5ec9..543f9ec33 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java @@ -155,7 +155,7 @@ public double getYOffset() { @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java index 6e245b222..5754e5fb8 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java @@ -147,7 +147,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { flipflop(false); return true; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } From 7dcaff012cad4b05ca29dd0492ef4264b2262f2e Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Thu, 22 Aug 2024 20:43:17 -0500 Subject: [PATCH 04/25] Revert "nit; only allow any pets to start riding player from server side, do not initiate at all from client" This reverts commit 6e8f010f2f1d7202f4c26ce926947df0a00c8980. --- .../mocreatures/entity/hunter/MoCEntityPetScorpion.java | 4 ++-- .../drzhark/mocreatures/entity/hunter/MoCEntitySnake.java | 2 +- .../drzhark/mocreatures/entity/neutral/MoCEntityKitty.java | 4 ++-- .../drzhark/mocreatures/entity/passive/MoCEntityBird.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 6 +++++- .../drzhark/mocreatures/entity/passive/MoCEntityMouse.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityTurtle.java | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java index a938aa8b3..a10409f71 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java @@ -486,10 +486,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } } - if (!this.world.isRemote && this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { + if (this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!getIsTamed()) { + if (!this.world.isRemote && !getIsTamed()) { MoCTools.tameWithName(player, this); } } diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java index c1d9a1a02..ddcc5c561 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java @@ -175,7 +175,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return false; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java index 7410a1a81..8bdd4c751 100644 --- a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java +++ b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java @@ -476,7 +476,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return MoCTools.tameWithName(player, this); } if (!stack.isEmpty() && getKittyState() > 2 && pickable() && stack.getItem() == Items.LEAD) { - if (!this.world.isRemote && this.startRidingPlayer(player)) { + if (this.startRidingPlayer(player)) { changeKittyState(14); } return true; @@ -490,7 +490,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } // Can be picked up, then pick it up if (getKittyState() > 2 && pickable()) { - if (!this.world.isRemote && this.startRidingPlayer(player)) { + if (this.startRidingPlayer(player)) { changeKittyState(15); } return true; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java index f30264d5f..168c82f11 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java @@ -324,7 +324,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!getIsTamed()) { return false; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 00b04d62f..3cd3a7f76 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -182,7 +182,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null && !this.world.isRemote) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; if (!getIsTamed()) { @@ -203,6 +203,10 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } + if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) + { + MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); + } if (!this.world.isRemote) { if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java index 543f9ec33..2174c5ec9 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java @@ -155,7 +155,7 @@ public double getYOffset() { @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java index 5754e5fb8..6e245b222 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java @@ -147,7 +147,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { flipflop(false); return true; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } From 6539bf56a9ec0f11cc30b53287502f3cec374354 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Fri, 23 Aug 2024 08:08:17 -0500 Subject: [PATCH 05/25] Reapply "nit; only allow any pets to start riding player from server side, do not initiate at all from client" This reverts commit 7dcaff012cad4b05ca29dd0492ef4264b2262f2e. --- .../mocreatures/entity/hunter/MoCEntityPetScorpion.java | 4 ++-- .../drzhark/mocreatures/entity/hunter/MoCEntitySnake.java | 2 +- .../drzhark/mocreatures/entity/neutral/MoCEntityKitty.java | 4 ++-- .../drzhark/mocreatures/entity/passive/MoCEntityBird.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 6 +----- .../drzhark/mocreatures/entity/passive/MoCEntityMouse.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityTurtle.java | 2 +- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java index a10409f71..a938aa8b3 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java @@ -486,10 +486,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } } - if (this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { + if (!this.world.isRemote && this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!this.world.isRemote && !getIsTamed()) { + if (!getIsTamed()) { MoCTools.tameWithName(player, this); } } diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java index ddcc5c561..c1d9a1a02 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java @@ -175,7 +175,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return false; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java index 8bdd4c751..7410a1a81 100644 --- a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java +++ b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java @@ -476,7 +476,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return MoCTools.tameWithName(player, this); } if (!stack.isEmpty() && getKittyState() > 2 && pickable() && stack.getItem() == Items.LEAD) { - if (this.startRidingPlayer(player)) { + if (!this.world.isRemote && this.startRidingPlayer(player)) { changeKittyState(14); } return true; @@ -490,7 +490,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } // Can be picked up, then pick it up if (getKittyState() > 2 && pickable()) { - if (this.startRidingPlayer(player)) { + if (!this.world.isRemote && this.startRidingPlayer(player)) { changeKittyState(15); } return true; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java index 168c82f11..f30264d5f 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java @@ -324,7 +324,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!getIsTamed()) { return false; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 3cd3a7f76..00b04d62f 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -182,7 +182,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (this.getRidingEntity() == null && !this.world.isRemote) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; if (!getIsTamed()) { @@ -203,10 +203,6 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } - if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) - { - MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); - } if (!this.world.isRemote) { if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java index 2174c5ec9..543f9ec33 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java @@ -155,7 +155,7 @@ public double getYOffset() { @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java index 6e245b222..5754e5fb8 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java @@ -147,7 +147,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { flipflop(false); return true; } - if (this.getRidingEntity() == null) { + if (!this.world.isRemote && this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } From 59223d41ac7c59887e5212285e858f339865ecd0 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Fri, 23 Aug 2024 08:21:24 -0500 Subject: [PATCH 06/25] try to allow re-mounting if entity is the same as before --- src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index 800f1e085..6c98b13cf 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -1054,7 +1054,8 @@ public boolean getIsGhost() { @Override public boolean startRidingPlayer(EntityPlayer player) { - if (MoCTools.getEntityRidingPlayer(player) != null) { + Entity entityOnPlayer = MoCTools.getEntityRidingPlayer(player); + if (entityOnPlayer != null && entityOnPlayer != this) { return false; // Something is already riding this player. } boolean ret = super.startRiding(player); From 3aa4f8d681a31669483c57e8bf15ead0cb7e48f8 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 19:05:51 -0500 Subject: [PATCH 07/25] Revert "Reapply "nit; only allow any pets to start riding player from server side, do not initiate at all from client"" This reverts commit 6539bf56a9ec0f11cc30b53287502f3cec374354. --- .../mocreatures/entity/hunter/MoCEntityPetScorpion.java | 4 ++-- .../drzhark/mocreatures/entity/hunter/MoCEntitySnake.java | 2 +- .../drzhark/mocreatures/entity/neutral/MoCEntityKitty.java | 4 ++-- .../drzhark/mocreatures/entity/passive/MoCEntityBird.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityBunny.java | 6 +++++- .../drzhark/mocreatures/entity/passive/MoCEntityMouse.java | 2 +- .../drzhark/mocreatures/entity/passive/MoCEntityTurtle.java | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java index a938aa8b3..a10409f71 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntityPetScorpion.java @@ -486,10 +486,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } } - if (!this.world.isRemote && this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { + if (this.getRidingEntity() == null && this.getAge() < 60 && !getIsAdult()) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!getIsTamed()) { + if (!this.world.isRemote && !getIsTamed()) { MoCTools.tameWithName(player, this); } } diff --git a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java index c1d9a1a02..ddcc5c561 100644 --- a/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java +++ b/src/main/java/drzhark/mocreatures/entity/hunter/MoCEntitySnake.java @@ -175,7 +175,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return false; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java index 79730017e..78cfbe8c5 100644 --- a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java +++ b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java @@ -476,7 +476,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { return MoCTools.tameWithName(player, this); } if (!stack.isEmpty() && getKittyState() > 2 && pickable() && stack.getItem() == Items.LEAD) { - if (!this.world.isRemote && this.startRidingPlayer(player)) { + if (this.startRidingPlayer(player)) { changeKittyState(14); } return true; @@ -490,7 +490,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { } // Can be picked up, then pick it up if (getKittyState() > 2 && pickable()) { - if (!this.world.isRemote && this.startRidingPlayer(player)) { + if (this.startRidingPlayer(player)) { changeKittyState(15); } return true; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java index f30264d5f..168c82f11 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBird.java @@ -324,7 +324,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!getIsTamed()) { return false; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 00b04d62f..3cd3a7f76 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -182,7 +182,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null && !this.world.isRemote) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; if (!getIsTamed()) { @@ -203,6 +203,10 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } + if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) + { + MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); + } if (!this.world.isRemote) { if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java index 543f9ec33..2174c5ec9 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityMouse.java @@ -155,7 +155,7 @@ public double getYOffset() { @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java index 5754e5fb8..6e245b222 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityTurtle.java @@ -147,7 +147,7 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { flipflop(false); return true; } - if (!this.world.isRemote && this.getRidingEntity() == null) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; } From 5beb6b6ccf0689bbabfe289863b2d613da34fbc0 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 19:06:03 -0500 Subject: [PATCH 08/25] add rats dependency for testing --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 6de8d97df..c798a047e 100644 --- a/build.gradle +++ b/build.gradle @@ -114,6 +114,7 @@ dependencies { implementation "curse.maven:just-enough-resources-jer-240630:4440936" implementation "curse.maven:morph-229080:2995522" implementation "curse.maven:pams-harvestcraft-221857:2904825" + implementation "curse.maven:rats-323596:3028671" runtimeOnly "com.cleanroommc:assetmover:2.5" runtimeOnly "curse.maven:baubles-227083:2518667" runtimeOnly "curse.maven:codechicken-lib-1-8-242818:2779848" From b2c19c25a7ea8d073aee58c8f507f057c0fd36ae Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 19:13:40 -0500 Subject: [PATCH 09/25] revert unneeded changes --- .../mocreatures/entity/passive/MoCEntityBunny.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 3cd3a7f76..202ef06f0 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -9,7 +9,6 @@ import drzhark.mocreatures.entity.tameable.MoCEntityTameableAnimal; import drzhark.mocreatures.init.MoCLootTables; import drzhark.mocreatures.init.MoCSoundEvents; -import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; @@ -182,10 +181,10 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) { MoCTools.playCustomSound(this, MoCSoundEvents.ENTITY_GENERIC_EAT); return true; } - if (this.getRidingEntity() == null && !this.world.isRemote) { + if (this.getRidingEntity() == null) { if (this.startRidingPlayer(player)) { this.rotationYaw = player.rotationYaw; - if (!getIsTamed()) { + if (!getIsTamed() && !this.world.isRemote) { MoCTools.tameWithName(player, this); } } @@ -203,11 +202,8 @@ public void onUpdate() { if (this.getRidingEntity() != null) { this.rotationYaw = this.getRidingEntity().rotationYaw; } - if (this.isInsideOfMaterial(Material.WATER) && this.isRiding() && this.getRidingEntity() != null && this.getRidingEntity().isInWater()) - { - MoCTools.dismountPassengerFromEntity(this, this.getRidingEntity(), true); - } if (!this.world.isRemote) { + if (--this.jumpTimer <= 0 && this.onGround && ((this.motionX > 0.05D) || (this.motionZ > 0.05D) || (this.motionX < -0.05D) || (this.motionZ < -0.05D))) { this.motionY = 0.3D; this.jumpTimer = 15; From 30a8d1d27327c87104b997ab260d8cb733b25186 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 19:22:11 -0500 Subject: [PATCH 10/25] add rats dependency, llibrary --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index c798a047e..cc46ca5d3 100644 --- a/build.gradle +++ b/build.gradle @@ -110,6 +110,7 @@ dependencies { implementation rfg.deobf("curse.maven:thermal-expansion-69163:2926431") implementation rfg.deobf("curse.maven:thermal-foundation-222880:2926428") implementation rfg.deobf("maven.modrinth:crossbow:1.1.0") + implementation "curse.maven:llibrary-243298:3116493" implementation "curse.maven:industrial-foregoing-266515:2745324" implementation "curse.maven:just-enough-resources-jer-240630:4440936" implementation "curse.maven:morph-229080:2995522" From abf561911354a6a39e0e015bc6f168ecab58ada6 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 19:42:54 -0500 Subject: [PATCH 11/25] fix rats version, add forced mounting --- build.gradle | 4 ++-- src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index cc46ca5d3..e162e12b1 100644 --- a/build.gradle +++ b/build.gradle @@ -110,12 +110,12 @@ dependencies { implementation rfg.deobf("curse.maven:thermal-expansion-69163:2926431") implementation rfg.deobf("curse.maven:thermal-foundation-222880:2926428") implementation rfg.deobf("maven.modrinth:crossbow:1.1.0") - implementation "curse.maven:llibrary-243298:3116493" + implementation "curse.maven:llibrary-243298:2505007" // dependency for Rats + implementation "curse.maven:rats-323596:3028671" // Rats implementation "curse.maven:industrial-foregoing-266515:2745324" implementation "curse.maven:just-enough-resources-jer-240630:4440936" implementation "curse.maven:morph-229080:2995522" implementation "curse.maven:pams-harvestcraft-221857:2904825" - implementation "curse.maven:rats-323596:3028671" runtimeOnly "com.cleanroommc:assetmover:2.5" runtimeOnly "curse.maven:baubles-227083:2518667" runtimeOnly "curse.maven:codechicken-lib-1-8-242818:2779848" diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index 2f42140b7..45410d7b9 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -1058,7 +1058,7 @@ public boolean startRidingPlayer(EntityPlayer player) { if (entityOnPlayer != null && entityOnPlayer != this) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player); + boolean ret = super.startRiding(player, true); if (ret) { NBTTagCompound tag = player.getEntityData(); tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); From b5b715bed0bd4211e1599f542c1a1ded70bd65e8 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 20:03:29 -0500 Subject: [PATCH 12/25] WIP; start copying Rats workflow for mounting/dismounting --- src/main/java/drzhark/mocreatures/MoCTools.java | 2 -- .../drzhark/mocreatures/entity/MoCEntityAmbient.java | 4 +++- .../drzhark/mocreatures/entity/MoCEntityAnimal.java | 2 ++ .../drzhark/mocreatures/entity/MoCEntityAquatic.java | 4 +++- .../java/drzhark/mocreatures/entity/MoCEntityMob.java | 4 +++- .../mocreatures/entity/neutral/MoCEntityKitty.java | 1 + .../java/drzhark/mocreatures/event/MoCEventHooks.java | 10 ---------- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 4483adfcd..a0195beb5 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1231,8 +1231,6 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, passenger.dismountRidingEntity(); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { - NBTTagCompound tag = entity.getEntityData(); - tag.setUniqueId("MOCEntity_Riding_Player", entity.getUniqueID()); // set to self, because cannot set to null. if (IMoCEntity.class.isAssignableFrom(passenger.getClass())) { ((IMoCEntity) passenger).onStopRidingPlayer(); } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java index 503c4f48f..1d1173e00 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java @@ -534,7 +534,7 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player); + boolean ret = super.startRiding(player, true); if (ret) { NBTTagCompound tag = player.getEntityData(); tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); @@ -545,6 +545,8 @@ public boolean startRidingPlayer(EntityPlayer player) { @Override public void onStopRidingPlayer() { + NBTTagCompound tag = this.getEntityData(); + tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index 45410d7b9..b54feb326 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -1072,6 +1072,8 @@ public boolean startRidingPlayer(EntityPlayer player) { @Override public void onStopRidingPlayer() { + NBTTagCompound tag = this.getEntityData(); + tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java index 012c45023..cb4bf3e84 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java @@ -1010,7 +1010,7 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player); + boolean ret = super.startRiding(player, true); if (ret) { NBTTagCompound tag = player.getEntityData(); tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); @@ -1021,6 +1021,8 @@ public boolean startRidingPlayer(EntityPlayer player) { @Override public void onStopRidingPlayer() { + NBTTagCompound tag = this.getEntityData(); + tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java index 06bd58289..58b9cf86f 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java @@ -510,7 +510,7 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player); + boolean ret = super.startRiding(player, true); if (ret) { NBTTagCompound tag = player.getEntityData(); tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); @@ -521,6 +521,8 @@ public boolean startRidingPlayer(EntityPlayer player) { @Override public void onStopRidingPlayer() { + NBTTagCompound tag = this.getEntityData(); + tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java index 78cfbe8c5..865285220 100644 --- a/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java +++ b/src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityKitty.java @@ -513,6 +513,7 @@ public boolean isMovementCeased() { @Override public void onStopRidingPlayer() { // Stopped riding player, reset state to Idle. + super.onStopRidingPlayer(); changeKittyState(7); } diff --git a/src/main/java/drzhark/mocreatures/event/MoCEventHooks.java b/src/main/java/drzhark/mocreatures/event/MoCEventHooks.java index e9d720b4f..d93530041 100644 --- a/src/main/java/drzhark/mocreatures/event/MoCEventHooks.java +++ b/src/main/java/drzhark/mocreatures/event/MoCEventHooks.java @@ -124,16 +124,6 @@ public void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) { IMoCTameable mocEntity = (IMoCTameable) player.getRidingEntity(); mocEntity.setRiderDisconnecting(true); } - - // Handles the ENTITY that is riding the PLAYER - Entity entityRidingPlayer = MoCTools.getEntityRidingPlayer(player); - if (entityRidingPlayer != null) { - // System.out.println("PLAYER LEFT THE GAME carrying entity: "+entityRidingPlayer); - if (IMoCEntity.class.isAssignableFrom(entityRidingPlayer.getClass())) { - IMoCEntity mocEntity = (IMoCEntity) entityRidingPlayer; - if (mocEntity.canRidePlayer()) MoCTools.dismountPassengerFromEntity(entityRidingPlayer, player, true); - } - } } private BlockPos getSafeSpawnPos(EntityLivingBase entity, BlockPos near) { From a2e22dbb975e320cb785b4eac4b7ad3d429fecef Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 20:13:52 -0500 Subject: [PATCH 13/25] add the rats riding logic --- .../entity/passive/MoCEntityBunny.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 202ef06f0..383bc2e1a 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -10,6 +10,7 @@ import drzhark.mocreatures.init.MoCLootTables; import drzhark.mocreatures.init.MoCSoundEvents; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAISwimming; @@ -167,6 +168,39 @@ protected ResourceLocation getLootTable() { return MoCLootTables.BUNNY; } + @Override + public void updateRidden() { + Entity entity = this.getRidingEntity(); + if (entity != null && (entity.isDead || entity instanceof EntityLivingBase && ((EntityLivingBase) entity).getHealth() <= 0.0F)) { + this.dismountRidingEntity(); + } else { + this.motionX = 0.0D; + this.motionY = 0.0D; + this.motionZ = 0.0D; + this.onUpdate(); + if (this.isRiding()) { + this.updateRiding(entity); + } + } + } + + public void updateRiding(Entity riding) { + if (riding != null && riding.isPassenger(this) && riding instanceof EntityPlayer) { + float radius = (((EntityPlayer) riding).isElytraFlying() ? 2 : 0); + float angle = (0.01745329251F * ((EntityPlayer) riding).renderYawOffset); + double extraX = radius * MathHelper.sin((float) (Math.PI + angle)); + double extraZ = radius * MathHelper.cos(angle); + double extraY = (riding.isSneaking() ? 1.1D : 1.4D); + this.rotationYaw = ((EntityPlayer) riding).rotationYawHead; + this.rotationYawHead = ((EntityPlayer) riding).rotationYawHead; + this.prevRotationYaw = ((EntityPlayer) riding).rotationYawHead; + this.setPosition(riding.posX + extraX, riding.posY + extraY, riding.posZ + extraZ); + if (((EntityPlayer) riding).isElytraFlying()) { + this.dismountRidingEntity(); + } + } + } + @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { final Boolean tameResult = this.processTameInteract(player, hand); From 265a256a9c7bf8d3fa8f86c04e96505941f2d578 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 20:23:00 -0500 Subject: [PATCH 14/25] cleanup MOCEntity_Riding_Player logic --- src/main/java/drzhark/mocreatures/MoCTools.java | 7 +------ .../drzhark/mocreatures/entity/MoCEntityAmbient.java | 10 +--------- .../drzhark/mocreatures/entity/MoCEntityAnimal.java | 4 ---- .../drzhark/mocreatures/entity/MoCEntityAquatic.java | 10 +--------- .../java/drzhark/mocreatures/entity/MoCEntityMob.java | 10 +--------- .../mocreatures/entity/passive/MoCEntityBunny.java | 4 ++-- 6 files changed, 6 insertions(+), 39 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index a0195beb5..597984034 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1213,12 +1213,7 @@ public static Entity findTheCorrectEntity(World world, UUID searchFor) { public static Entity getEntityRidingPlayer(EntityPlayer player) { // Get ID for entity that is currently riding player. - NBTTagCompound tag = player.getEntityData(); - UUID animalID = tag.getUniqueId("MOCEntity_Riding_Player"); - if (animalID == null || player.getUniqueID().equals(animalID)) { - return null; - } - return MoCTools.findTheCorrectEntity(player.getEntityWorld(), animalID); + return player.getPassengers().isEmpty() ? null : player.getPassengers().get(0); } public static void dismountPassengerFromEntity(Entity passenger, Entity entity, boolean force) { diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java index 1d1173e00..30d7fef1b 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java @@ -534,19 +534,11 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player, true); - if (ret) { - NBTTagCompound tag = player.getEntityData(); - tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); - return true; - } - return false; + return super.startRiding(player, true); } @Override public void onStopRidingPlayer() { - NBTTagCompound tag = this.getEntityData(); - tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index b54feb326..6935ce778 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -1060,8 +1060,6 @@ public boolean startRidingPlayer(EntityPlayer player) { } boolean ret = super.startRiding(player, true); if (ret) { - NBTTagCompound tag = player.getEntityData(); - tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); return true; } else { TextComponentTranslation msg = new TextComponentTranslation("msg.mocreatures.petnotreadytorideplayer"); @@ -1072,8 +1070,6 @@ public boolean startRidingPlayer(EntityPlayer player) { @Override public void onStopRidingPlayer() { - NBTTagCompound tag = this.getEntityData(); - tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java index cb4bf3e84..9b1457093 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java @@ -1010,19 +1010,11 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player, true); - if (ret) { - NBTTagCompound tag = player.getEntityData(); - tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); - return true; - } - return false; + return super.startRiding(player, true); } @Override public void onStopRidingPlayer() { - NBTTagCompound tag = this.getEntityData(); - tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java index 58b9cf86f..2dce74b0e 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java @@ -510,19 +510,11 @@ public boolean startRidingPlayer(EntityPlayer player) { if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } - boolean ret = super.startRiding(player, true); - if (ret) { - NBTTagCompound tag = player.getEntityData(); - tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID()); - return true; - } - return false; + return super.startRiding(player, true); } @Override public void onStopRidingPlayer() { - NBTTagCompound tag = this.getEntityData(); - tag.removeTag("MOCEntity_Riding_Player"); // Called when an Entity is dismounted from riding on the Player's head. } } diff --git a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 383bc2e1a..ac29d8496 100644 --- a/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java +++ b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java @@ -190,7 +190,7 @@ public void updateRiding(Entity riding) { float angle = (0.01745329251F * ((EntityPlayer) riding).renderYawOffset); double extraX = radius * MathHelper.sin((float) (Math.PI + angle)); double extraZ = radius * MathHelper.cos(angle); - double extraY = (riding.isSneaking() ? 1.1D : 1.4D); + double extraY = getYOffset(); this.rotationYaw = ((EntityPlayer) riding).rotationYawHead; this.rotationYawHead = ((EntityPlayer) riding).rotationYawHead; this.prevRotationYaw = ((EntityPlayer) riding).rotationYawHead; @@ -313,7 +313,7 @@ public boolean isNotScared() { @Override public double getYOffset() { if (this.getRidingEntity() instanceof EntityPlayer) { - return this.getRidingEntity().isSneaking() ? 0.25 : 0.5F; + return this.getRidingEntity().isSneaking() ? 1.5 : 1.8F; } return super.getYOffset(); From 0c5b267b6dc43875fd4c24189f9378fc99ea8ebc Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 20:34:57 -0500 Subject: [PATCH 15/25] nitfixes, add messenging --- .../java/drzhark/mocreatures/MoCTools.java | 4 +- .../mocreatures/entity/MoCEntityAnimal.java | 3 +- .../MoCMessageDismountRidingEntity.java | 48 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 597984034..b6a0be3e2 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -16,6 +16,7 @@ import drzhark.mocreatures.init.MoCItems; import drzhark.mocreatures.init.MoCSoundEvents; import drzhark.mocreatures.network.MoCMessageHandler; +import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntity; import drzhark.mocreatures.network.message.MoCMessageNameGUI; import net.minecraft.block.Block; import net.minecraft.block.BlockJukebox; @@ -1222,8 +1223,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); - passenger.setPositionAndUpdate(entity.posX, entity.posY + 1D, entity.posZ); - passenger.dismountRidingEntity(); + MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntity((entity).getEntityId())); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { if (IMoCEntity.class.isAssignableFrom(passenger.getClass())) { diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index 6935ce778..1e3107311 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -1054,8 +1054,7 @@ public boolean getIsGhost() { @Override public boolean startRidingPlayer(EntityPlayer player) { - Entity entityOnPlayer = MoCTools.getEntityRidingPlayer(player); - if (entityOnPlayer != null && entityOnPlayer != this) { + if (MoCTools.getEntityRidingPlayer(player) != null) { return false; // Something is already riding this player. } boolean ret = super.startRiding(player, true); diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java new file mode 100644 index 000000000..2867c4172 --- /dev/null +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java @@ -0,0 +1,48 @@ +package drzhark.mocreatures.network.message; + +import drzhark.mocreatures.entity.IMoCEntity; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class MoCMessageDismountRidingEntity implements IMessage, IMessageHandler { + + public int entityId; + public MoCMessageDismountRidingEntity() { + } + + public MoCMessageDismountRidingEntity(int entityId) { + this.entityId = entityId; + } + + @Override + public void toBytes(ByteBuf buffer) { + buffer.writeInt(this.entityId); + } + + @Override + public void fromBytes(ByteBuf buffer) { + this.entityId = buffer.readInt(); + } + + @Override + public IMessage onMessage(MoCMessageDismountRidingEntity message, MessageContext ctx) { + EntityPlayer player = ctx.getServerHandler().player; + + Entity entity = player.world.getEntityByID(this.entityId); + if (entity instanceof IMoCEntity) { + entity.dismountRidingEntity(); + entity.setPosition(player.posX, player.posY + 1D, player.posZ); + } + return null; + } + + @Override + public String toString() { + return String.format("MoCMessageDismountRidingEntity - entityId:%s", this.entityId); + } + +} From 38af2888d90b6cc179c8c50b82d7631727ed3e0c Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 21:14:41 -0500 Subject: [PATCH 16/25] use two different messaging channels, client/server --- .../java/drzhark/mocreatures/MoCTools.java | 8 +++- .../network/MoCMessageHandler.java | 2 + .../MoCMessageDismountRidingEntityClient.java | 48 +++++++++++++++++++ ...MoCMessageDismountRidingEntityServer.java} | 15 +++--- 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java rename src/main/java/drzhark/mocreatures/network/message/{MoCMessageDismountRidingEntity.java => MoCMessageDismountRidingEntityServer.java} (61%) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index b6a0be3e2..6c5f12698 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -16,7 +16,8 @@ import drzhark.mocreatures.init.MoCItems; import drzhark.mocreatures.init.MoCSoundEvents; import drzhark.mocreatures.network.MoCMessageHandler; -import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntity; +import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityClient; +import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityServer; import drzhark.mocreatures.network.message.MoCMessageNameGUI; import net.minecraft.block.Block; import net.minecraft.block.BlockJukebox; @@ -66,6 +67,7 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.relauncher.Side; @@ -1223,7 +1225,9 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); - MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntity((entity).getEntityId())); + int entityId = entity.getEntityId(); + MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(entityId),new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); + MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(entityId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { if (IMoCEntity.class.isAssignableFrom(passenger.getClass())) { diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index db9af6a6a..d452b77d6 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -41,6 +41,8 @@ public static void init() { INSTANCE.registerMessage(MoCMessageShuffle.class, MoCMessageShuffle.class, 11, Side.CLIENT); INSTANCE.registerMessage(MoCMessageTwoBytes.class, MoCMessageTwoBytes.class, 12, Side.CLIENT); INSTANCE.registerMessage(MoCMessageVanish.class, MoCMessageVanish.class, 13, Side.CLIENT); + INSTANCE.registerMessage(MoCMessageDismountRidingEntityServer.class, MoCMessageDismountRidingEntityServer.class, 14, Side.SERVER); + INSTANCE.registerMessage(MoCMessageDismountRidingEntityClient.class, MoCMessageDismountRidingEntityClient.class, 15, Side.CLIENT); } // Wrap client message handling due to 1.8 clients receiving packets on Netty thread diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java new file mode 100644 index 000000000..020d73d2a --- /dev/null +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java @@ -0,0 +1,48 @@ +package drzhark.mocreatures.network.message; + +import drzhark.mocreatures.entity.IMoCEntity; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class MoCMessageDismountRidingEntityClient implements IMessage, IMessageHandler { + + public int entityId; + public MoCMessageDismountRidingEntityClient() { + } + + public MoCMessageDismountRidingEntityClient(int entityId) { + this.entityId = entityId; + } + + @Override + public void toBytes(ByteBuf buffer) { + ByteBufUtils.writeVarInt(buffer, this.entityId, 5); + } + + @Override + public void fromBytes(ByteBuf buffer) { + this.entityId = ByteBufUtils.readVarInt(buffer, 5); + } + + @Override + public IMessage onMessage(MoCMessageDismountRidingEntityClient message, MessageContext ctx) { + EntityPlayer player = ctx.getServerHandler().player; + + Entity entity = player.world.getEntityByID(this.entityId); + if (entity instanceof IMoCEntity) { + entity.setPosition(player.posX, player.posY + 1D, player.posZ); + } + return null; + } + + @Override + public String toString() { + return String.format("MoCMessageDismountRidingEntityClient - entityId:%s", this.entityId); + } + +} diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java similarity index 61% rename from src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java rename to src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index 2867c4172..b346bba03 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntity.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -4,32 +4,33 @@ import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -public class MoCMessageDismountRidingEntity implements IMessage, IMessageHandler { +public class MoCMessageDismountRidingEntityServer implements IMessage, IMessageHandler { public int entityId; - public MoCMessageDismountRidingEntity() { + public MoCMessageDismountRidingEntityServer() { } - public MoCMessageDismountRidingEntity(int entityId) { + public MoCMessageDismountRidingEntityServer(int entityId) { this.entityId = entityId; } @Override public void toBytes(ByteBuf buffer) { - buffer.writeInt(this.entityId); + ByteBufUtils.writeVarInt(buffer, this.entityId, 5); } @Override public void fromBytes(ByteBuf buffer) { - this.entityId = buffer.readInt(); + this.entityId = ByteBufUtils.readVarInt(buffer, 5); } @Override - public IMessage onMessage(MoCMessageDismountRidingEntity message, MessageContext ctx) { + public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; Entity entity = player.world.getEntityByID(this.entityId); @@ -42,7 +43,7 @@ public IMessage onMessage(MoCMessageDismountRidingEntity message, MessageContext @Override public String toString() { - return String.format("MoCMessageDismountRidingEntity - entityId:%s", this.entityId); + return String.format("MoCMessageDismountRidingEntityServer - entityId:%s", this.entityId); } } From 0ec37b0d9320a5f4fe9154a03971845b14902627 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 21:23:00 -0500 Subject: [PATCH 17/25] move client handling code to packet task --- .../mocreatures/network/MoCMessageHandler.java | 10 ++++++++++ .../message/MoCMessageDismountRidingEntityClient.java | 11 ++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index d452b77d6..f2848a6f1 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -13,6 +13,7 @@ import drzhark.mocreatures.entity.passive.MoCEntityHorse; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; @@ -157,6 +158,15 @@ public void run() { MoCMessageNameGUI message = (MoCMessageNameGUI) this.message; Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.entityId); MoCProxyClient.mc.displayGuiScreen(new MoCGUIEntityNamer(((IMoCEntity) entity), ((IMoCEntity) entity).getPetName())); + } else if (this.message instanceof MoCMessageDismountRidingEntityClient) { + MoCMessageDismountRidingEntityClient message = (MoCMessageDismountRidingEntityClient) this.message; + Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.entityId); + if (entity instanceof IMoCEntity) { + EntityPlayer player = entity.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) entity.getRidingEntity() : null; + if (player != null) { + entity.setPosition(player.posX, player.posY + 1D, player.posZ); + } + } } } } diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java index 020d73d2a..9fddbfc91 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java @@ -1,9 +1,7 @@ package drzhark.mocreatures.network.message; -import drzhark.mocreatures.entity.IMoCEntity; +import drzhark.mocreatures.network.MoCMessageHandler; import io.netty.buffer.ByteBuf; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; @@ -31,12 +29,7 @@ public void fromBytes(ByteBuf buffer) { @Override public IMessage onMessage(MoCMessageDismountRidingEntityClient message, MessageContext ctx) { - EntityPlayer player = ctx.getServerHandler().player; - - Entity entity = player.world.getEntityByID(this.entityId); - if (entity instanceof IMoCEntity) { - entity.setPosition(player.posX, player.posY + 1D, player.posZ); - } + MoCMessageHandler.handleMessage(message, ctx); return null; } From e14fa985588bdef440bf89fa391a5e190531eac1 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 21:44:11 -0500 Subject: [PATCH 18/25] nit; entityId => passengerId --- src/main/java/drzhark/mocreatures/MoCTools.java | 6 +++--- .../mocreatures/network/MoCMessageHandler.java | 2 +- .../MoCMessageDismountRidingEntityClient.java | 14 ++++++++------ .../MoCMessageDismountRidingEntityServer.java | 14 +++++++------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 6c5f12698..668c56a3a 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1225,9 +1225,9 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); - int entityId = entity.getEntityId(); - MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(entityId),new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); - MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(entityId)); + int passengerId = passenger.getEntityId(); + MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId),new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); + MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { if (IMoCEntity.class.isAssignableFrom(passenger.getClass())) { diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index f2848a6f1..1b34b13f0 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -160,7 +160,7 @@ public void run() { MoCProxyClient.mc.displayGuiScreen(new MoCGUIEntityNamer(((IMoCEntity) entity), ((IMoCEntity) entity).getPetName())); } else if (this.message instanceof MoCMessageDismountRidingEntityClient) { MoCMessageDismountRidingEntityClient message = (MoCMessageDismountRidingEntityClient) this.message; - Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.entityId); + Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.passengerId); if (entity instanceof IMoCEntity) { EntityPlayer player = entity.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) entity.getRidingEntity() : null; if (player != null) { diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java index 9fddbfc91..16fe9b629 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java @@ -9,22 +9,24 @@ public class MoCMessageDismountRidingEntityClient implements IMessage, IMessageHandler { - public int entityId; + public int passengerId; + public MoCMessageDismountRidingEntityClient() { } - public MoCMessageDismountRidingEntityClient(int entityId) { - this.entityId = entityId; + public MoCMessageDismountRidingEntityClient(int passengerId) { + this.passengerId = passengerId; + } @Override public void toBytes(ByteBuf buffer) { - ByteBufUtils.writeVarInt(buffer, this.entityId, 5); + ByteBufUtils.writeVarInt(buffer, this.passengerId, 5); } @Override public void fromBytes(ByteBuf buffer) { - this.entityId = ByteBufUtils.readVarInt(buffer, 5); + this.passengerId = ByteBufUtils.readVarInt(buffer, 5); } @Override @@ -35,7 +37,7 @@ public IMessage onMessage(MoCMessageDismountRidingEntityClient message, MessageC @Override public String toString() { - return String.format("MoCMessageDismountRidingEntityClient - entityId:%s", this.entityId); + return String.format("MoCMessageDismountRidingEntityClient - passengerId:%s", this.passengerId); } } diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index b346bba03..fdfe2042f 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -11,29 +11,29 @@ public class MoCMessageDismountRidingEntityServer implements IMessage, IMessageHandler { - public int entityId; + public int passengerId; public MoCMessageDismountRidingEntityServer() { } - public MoCMessageDismountRidingEntityServer(int entityId) { - this.entityId = entityId; + public MoCMessageDismountRidingEntityServer(int passengerId) { + this.passengerId = passengerId; } @Override public void toBytes(ByteBuf buffer) { - ByteBufUtils.writeVarInt(buffer, this.entityId, 5); + ByteBufUtils.writeVarInt(buffer, this.passengerId, 5); } @Override public void fromBytes(ByteBuf buffer) { - this.entityId = ByteBufUtils.readVarInt(buffer, 5); + this.passengerId = ByteBufUtils.readVarInt(buffer, 5); } @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; - Entity entity = player.world.getEntityByID(this.entityId); + Entity entity = player.world.getEntityByID(this.passengerId); if (entity instanceof IMoCEntity) { entity.dismountRidingEntity(); entity.setPosition(player.posX, player.posY + 1D, player.posZ); @@ -43,7 +43,7 @@ public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageC @Override public String toString() { - return String.format("MoCMessageDismountRidingEntityServer - entityId:%s", this.entityId); + return String.format("MoCMessageDismountRidingEntityServer - passengerId:%s", this.passengerId); } } From 2c400705473b6530dd832fce8fcd8004e39a7fdf Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 22:02:04 -0500 Subject: [PATCH 19/25] nitfix; remove from server side --- src/main/java/drzhark/mocreatures/MoCTools.java | 2 +- .../message/MoCMessageDismountRidingEntityClient.java | 5 ++--- .../message/MoCMessageDismountRidingEntityServer.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 668c56a3a..a4e957d2e 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId),new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); + MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId), new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java index 16fe9b629..4e8511d11 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java @@ -16,17 +16,16 @@ public MoCMessageDismountRidingEntityClient() { public MoCMessageDismountRidingEntityClient(int passengerId) { this.passengerId = passengerId; - } @Override public void toBytes(ByteBuf buffer) { - ByteBufUtils.writeVarInt(buffer, this.passengerId, 5); + buffer.writeInt(this.passengerId); } @Override public void fromBytes(ByteBuf buffer) { - this.passengerId = ByteBufUtils.readVarInt(buffer, 5); + this.passengerId = buffer.readInt(); } @Override diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index fdfe2042f..d7b597c74 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -21,19 +21,19 @@ public MoCMessageDismountRidingEntityServer(int passengerId) { @Override public void toBytes(ByteBuf buffer) { - ByteBufUtils.writeVarInt(buffer, this.passengerId, 5); + buffer.writeInt(this.passengerId); } @Override public void fromBytes(ByteBuf buffer) { - this.passengerId = ByteBufUtils.readVarInt(buffer, 5); + this.passengerId = buffer.readInt(); } @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().player; - Entity entity = player.world.getEntityByID(this.passengerId); + Entity entity = player.world.getEntityByID(message.passengerId); if (entity instanceof IMoCEntity) { entity.dismountRidingEntity(); entity.setPosition(player.posX, player.posY + 1D, player.posZ); From d23765893c1a46a191dae925b996d91fc99c6e8c Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sat, 24 Aug 2024 22:32:40 -0500 Subject: [PATCH 20/25] force the dismount from client and server side --- .../drzhark/mocreatures/network/MoCMessageHandler.java | 9 +++++---- .../message/MoCMessageDismountRidingEntityServer.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index 1b34b13f0..8a3da9b1f 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -160,11 +160,12 @@ public void run() { MoCProxyClient.mc.displayGuiScreen(new MoCGUIEntityNamer(((IMoCEntity) entity), ((IMoCEntity) entity).getPetName())); } else if (this.message instanceof MoCMessageDismountRidingEntityClient) { MoCMessageDismountRidingEntityClient message = (MoCMessageDismountRidingEntityClient) this.message; - Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.passengerId); - if (entity instanceof IMoCEntity) { - EntityPlayer player = entity.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) entity.getRidingEntity() : null; + Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(message.passengerId); + if (passenger instanceof IMoCEntity) { + EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; if (player != null) { - entity.setPosition(player.posX, player.posY + 1D, player.posZ); + passenger.dismountRidingEntity(); + passenger.setPosition(player.posX, player.posY + 2D, player.posZ); } } } diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index d7b597c74..892ef3395 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -36,7 +36,7 @@ public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageC Entity entity = player.world.getEntityByID(message.passengerId); if (entity instanceof IMoCEntity) { entity.dismountRidingEntity(); - entity.setPosition(player.posX, player.posY + 1D, player.posZ); + entity.setPosition(player.posX, player.posY + 2D, player.posZ); } return null; } From 9750aad56219fee297feed338a986b0ad9845082 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sun, 25 Aug 2024 08:43:53 -0500 Subject: [PATCH 21/25] try to remove separate client message --- .../java/drzhark/mocreatures/MoCTools.java | 15 ++++++- .../network/MoCMessageHandler.java | 11 ----- .../MoCMessageDismountRidingEntityClient.java | 42 ------------------- .../MoCMessageDismountRidingEntityServer.java | 13 +----- 4 files changed, 15 insertions(+), 66 deletions(-) delete mode 100644 src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index a4e957d2e..bac20c7c9 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -16,9 +16,9 @@ import drzhark.mocreatures.init.MoCItems; import drzhark.mocreatures.init.MoCSoundEvents; import drzhark.mocreatures.network.MoCMessageHandler; -import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityClient; import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityServer; import drzhark.mocreatures.network.message.MoCMessageNameGUI; +import drzhark.mocreatures.proxy.MoCProxyClient; import net.minecraft.block.Block; import net.minecraft.block.BlockJukebox; import net.minecraft.block.BlockJukebox.TileEntityJukebox; @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId), new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); + handleDismountPassengerFromEntity(passengerId); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { @@ -1237,6 +1237,17 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } } + public static void handleDismountPassengerFromEntity(int passengerId) { + Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(passengerId); + if (passenger instanceof IMoCEntity) { + EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; + if (player != null) { + passenger.dismountRidingEntity(); + passenger.setPosition(player.posX, player.posY + 2D, player.posZ); + } + } + } + public static boolean isInsideOfMaterial(Material material, Entity entity) { double d = entity.posY + entity.getEyeHeight(); int i = MathHelper.floor(entity.posX); diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index 8a3da9b1f..0a8396d57 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -43,7 +43,6 @@ public static void init() { INSTANCE.registerMessage(MoCMessageTwoBytes.class, MoCMessageTwoBytes.class, 12, Side.CLIENT); INSTANCE.registerMessage(MoCMessageVanish.class, MoCMessageVanish.class, 13, Side.CLIENT); INSTANCE.registerMessage(MoCMessageDismountRidingEntityServer.class, MoCMessageDismountRidingEntityServer.class, 14, Side.SERVER); - INSTANCE.registerMessage(MoCMessageDismountRidingEntityClient.class, MoCMessageDismountRidingEntityClient.class, 15, Side.CLIENT); } // Wrap client message handling due to 1.8 clients receiving packets on Netty thread @@ -158,16 +157,6 @@ public void run() { MoCMessageNameGUI message = (MoCMessageNameGUI) this.message; Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.entityId); MoCProxyClient.mc.displayGuiScreen(new MoCGUIEntityNamer(((IMoCEntity) entity), ((IMoCEntity) entity).getPetName())); - } else if (this.message instanceof MoCMessageDismountRidingEntityClient) { - MoCMessageDismountRidingEntityClient message = (MoCMessageDismountRidingEntityClient) this.message; - Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(message.passengerId); - if (passenger instanceof IMoCEntity) { - EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; - if (player != null) { - passenger.dismountRidingEntity(); - passenger.setPosition(player.posX, player.posY + 2D, player.posZ); - } - } } } } diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java deleted file mode 100644 index 4e8511d11..000000000 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java +++ /dev/null @@ -1,42 +0,0 @@ -package drzhark.mocreatures.network.message; - -import drzhark.mocreatures.network.MoCMessageHandler; -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class MoCMessageDismountRidingEntityClient implements IMessage, IMessageHandler { - - public int passengerId; - - public MoCMessageDismountRidingEntityClient() { - } - - public MoCMessageDismountRidingEntityClient(int passengerId) { - this.passengerId = passengerId; - } - - @Override - public void toBytes(ByteBuf buffer) { - buffer.writeInt(this.passengerId); - } - - @Override - public void fromBytes(ByteBuf buffer) { - this.passengerId = buffer.readInt(); - } - - @Override - public IMessage onMessage(MoCMessageDismountRidingEntityClient message, MessageContext ctx) { - MoCMessageHandler.handleMessage(message, ctx); - return null; - } - - @Override - public String toString() { - return String.format("MoCMessageDismountRidingEntityClient - passengerId:%s", this.passengerId); - } - -} diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index 892ef3395..46ba0f22d 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -1,10 +1,7 @@ package drzhark.mocreatures.network.message; -import drzhark.mocreatures.entity.IMoCEntity; +import drzhark.mocreatures.MoCTools; import io.netty.buffer.ByteBuf; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -31,13 +28,7 @@ public void fromBytes(ByteBuf buffer) { @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { - EntityPlayer player = ctx.getServerHandler().player; - - Entity entity = player.world.getEntityByID(message.passengerId); - if (entity instanceof IMoCEntity) { - entity.dismountRidingEntity(); - entity.setPosition(player.posX, player.posY + 2D, player.posZ); - } + MoCTools.handleDismountPassengerFromEntity(message.passengerId); return null; } From 00c6d7525056ed257fa5c0aec260caf4511495be Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sun, 25 Aug 2024 09:09:12 -0500 Subject: [PATCH 22/25] try passing player to handler fm --- src/main/java/drzhark/mocreatures/MoCTools.java | 8 +++++--- .../message/MoCMessageDismountRidingEntityServer.java | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index bac20c7c9..7d9af0437 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - handleDismountPassengerFromEntity(passengerId); + handleDismountPassengerFromEntity(passengerId, entity instanceof EntityPlayer ? (EntityPlayer) entity : null); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { @@ -1237,10 +1237,12 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } } - public static void handleDismountPassengerFromEntity(int passengerId) { + public static void handleDismountPassengerFromEntity(int passengerId, EntityPlayer player) { Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(passengerId); if (passenger instanceof IMoCEntity) { - EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; + if (player == null) { + player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; + } if (player != null) { passenger.dismountRidingEntity(); passenger.setPosition(player.posX, player.posY + 2D, player.posZ); diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index 46ba0f22d..d397a0366 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -2,6 +2,7 @@ import drzhark.mocreatures.MoCTools; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -28,7 +29,9 @@ public void fromBytes(ByteBuf buffer) { @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { - MoCTools.handleDismountPassengerFromEntity(message.passengerId); + // get player from playerId + EntityPlayer player = ctx.getServerHandler().player; + MoCTools.handleDismountPassengerFromEntity(message.passengerId, player); return null; } From 16317095980b6fcf9df3888afe54a24dbfe495a4 Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sun, 25 Aug 2024 09:13:42 -0500 Subject: [PATCH 23/25] Revert "try passing player to handler fm" This reverts commit 00c6d7525056ed257fa5c0aec260caf4511495be. --- src/main/java/drzhark/mocreatures/MoCTools.java | 8 +++----- .../message/MoCMessageDismountRidingEntityServer.java | 5 +---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 7d9af0437..bac20c7c9 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - handleDismountPassengerFromEntity(passengerId, entity instanceof EntityPlayer ? (EntityPlayer) entity : null); + handleDismountPassengerFromEntity(passengerId); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { @@ -1237,12 +1237,10 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } } - public static void handleDismountPassengerFromEntity(int passengerId, EntityPlayer player) { + public static void handleDismountPassengerFromEntity(int passengerId) { Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(passengerId); if (passenger instanceof IMoCEntity) { - if (player == null) { - player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; - } + EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; if (player != null) { passenger.dismountRidingEntity(); passenger.setPosition(player.posX, player.posY + 2D, player.posZ); diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index d397a0366..46ba0f22d 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -2,7 +2,6 @@ import drzhark.mocreatures.MoCTools; import io.netty.buffer.ByteBuf; -import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -29,9 +28,7 @@ public void fromBytes(ByteBuf buffer) { @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { - // get player from playerId - EntityPlayer player = ctx.getServerHandler().player; - MoCTools.handleDismountPassengerFromEntity(message.passengerId, player); + MoCTools.handleDismountPassengerFromEntity(message.passengerId); return null; } From 87444e056028d7f151a2173a85446ec72d41747f Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sun, 25 Aug 2024 09:13:45 -0500 Subject: [PATCH 24/25] Revert "try to remove separate client message" This reverts commit 9750aad56219fee297feed338a986b0ad9845082. --- .../java/drzhark/mocreatures/MoCTools.java | 15 +------ .../network/MoCMessageHandler.java | 11 +++++ .../MoCMessageDismountRidingEntityClient.java | 42 +++++++++++++++++++ .../MoCMessageDismountRidingEntityServer.java | 13 +++++- 4 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index bac20c7c9..a4e957d2e 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -16,9 +16,9 @@ import drzhark.mocreatures.init.MoCItems; import drzhark.mocreatures.init.MoCSoundEvents; import drzhark.mocreatures.network.MoCMessageHandler; +import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityClient; import drzhark.mocreatures.network.message.MoCMessageDismountRidingEntityServer; import drzhark.mocreatures.network.message.MoCMessageNameGUI; -import drzhark.mocreatures.proxy.MoCProxyClient; import net.minecraft.block.Block; import net.minecraft.block.BlockJukebox; import net.minecraft.block.BlockJukebox.TileEntityJukebox; @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - handleDismountPassengerFromEntity(passengerId); + MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId), new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) { @@ -1237,17 +1237,6 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, } } - public static void handleDismountPassengerFromEntity(int passengerId) { - Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(passengerId); - if (passenger instanceof IMoCEntity) { - EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; - if (player != null) { - passenger.dismountRidingEntity(); - passenger.setPosition(player.posX, player.posY + 2D, player.posZ); - } - } - } - public static boolean isInsideOfMaterial(Material material, Entity entity) { double d = entity.posY + entity.getEyeHeight(); int i = MathHelper.floor(entity.posX); diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index 0a8396d57..8a3da9b1f 100644 --- a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java +++ b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java @@ -43,6 +43,7 @@ public static void init() { INSTANCE.registerMessage(MoCMessageTwoBytes.class, MoCMessageTwoBytes.class, 12, Side.CLIENT); INSTANCE.registerMessage(MoCMessageVanish.class, MoCMessageVanish.class, 13, Side.CLIENT); INSTANCE.registerMessage(MoCMessageDismountRidingEntityServer.class, MoCMessageDismountRidingEntityServer.class, 14, Side.SERVER); + INSTANCE.registerMessage(MoCMessageDismountRidingEntityClient.class, MoCMessageDismountRidingEntityClient.class, 15, Side.CLIENT); } // Wrap client message handling due to 1.8 clients receiving packets on Netty thread @@ -157,6 +158,16 @@ public void run() { MoCMessageNameGUI message = (MoCMessageNameGUI) this.message; Entity entity = MoCProxyClient.mc.player.world.getEntityByID(message.entityId); MoCProxyClient.mc.displayGuiScreen(new MoCGUIEntityNamer(((IMoCEntity) entity), ((IMoCEntity) entity).getPetName())); + } else if (this.message instanceof MoCMessageDismountRidingEntityClient) { + MoCMessageDismountRidingEntityClient message = (MoCMessageDismountRidingEntityClient) this.message; + Entity passenger = MoCProxyClient.mc.player.world.getEntityByID(message.passengerId); + if (passenger instanceof IMoCEntity) { + EntityPlayer player = passenger.getRidingEntity() instanceof EntityPlayer ? (EntityPlayer) passenger.getRidingEntity() : null; + if (player != null) { + passenger.dismountRidingEntity(); + passenger.setPosition(player.posX, player.posY + 2D, player.posZ); + } + } } } } diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java new file mode 100644 index 000000000..4e8511d11 --- /dev/null +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityClient.java @@ -0,0 +1,42 @@ +package drzhark.mocreatures.network.message; + +import drzhark.mocreatures.network.MoCMessageHandler; +import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class MoCMessageDismountRidingEntityClient implements IMessage, IMessageHandler { + + public int passengerId; + + public MoCMessageDismountRidingEntityClient() { + } + + public MoCMessageDismountRidingEntityClient(int passengerId) { + this.passengerId = passengerId; + } + + @Override + public void toBytes(ByteBuf buffer) { + buffer.writeInt(this.passengerId); + } + + @Override + public void fromBytes(ByteBuf buffer) { + this.passengerId = buffer.readInt(); + } + + @Override + public IMessage onMessage(MoCMessageDismountRidingEntityClient message, MessageContext ctx) { + MoCMessageHandler.handleMessage(message, ctx); + return null; + } + + @Override + public String toString() { + return String.format("MoCMessageDismountRidingEntityClient - passengerId:%s", this.passengerId); + } + +} diff --git a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java index 46ba0f22d..892ef3395 100644 --- a/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -1,7 +1,10 @@ package drzhark.mocreatures.network.message; -import drzhark.mocreatures.MoCTools; +import drzhark.mocreatures.entity.IMoCEntity; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -28,7 +31,13 @@ public void fromBytes(ByteBuf buffer) { @Override public IMessage onMessage(MoCMessageDismountRidingEntityServer message, MessageContext ctx) { - MoCTools.handleDismountPassengerFromEntity(message.passengerId); + EntityPlayer player = ctx.getServerHandler().player; + + Entity entity = player.world.getEntityByID(message.passengerId); + if (entity instanceof IMoCEntity) { + entity.dismountRidingEntity(); + entity.setPosition(player.posX, player.posY + 2D, player.posZ); + } return null; } From 7e07d991a78175b941dddeefe55ad6edf6d2e47f Mon Sep 17 00:00:00 2001 From: Alexis Kaufman Date: Sun, 25 Aug 2024 09:21:34 -0500 Subject: [PATCH 25/25] use sendToAll for more stability --- src/main/java/drzhark/mocreatures/MoCTools.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index a4e957d2e..d306bc8f1 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -1226,7 +1226,7 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity, if (force || entity.isSneaking() || passenger.isInWater()) { if (force) MoCreatures.LOGGER.info("Forcing dismount from " + entity + " for passenger " + passenger); int passengerId = passenger.getEntityId(); - MoCMessageHandler.INSTANCE.sendToAllAround(new MoCMessageDismountRidingEntityClient(passengerId), new NetworkRegistry.TargetPoint(entity.world.provider.getDimensionType().getId(), entity.posX, entity.posY, entity.posZ, 64)); + MoCMessageHandler.INSTANCE.sendToAll(new MoCMessageDismountRidingEntityClient(passengerId)); MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId)); MoCTools.playCustomSound(passenger, SoundEvents.ENTITY_CHICKEN_EGG); if (entity instanceof EntityPlayer) {