Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

150 bunny water desync issue #180

Draft
wants to merge 26 commits into
base: 1.12.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7c9d90e
partial fix; dismount command when going underwater
demonlexe Aug 22, 2024
84f3b82
nit; only allow bunny to start riding player from server side, do not…
demonlexe Aug 23, 2024
6e8f010
nit; only allow any pets to start riding player from server side, do …
demonlexe Aug 23, 2024
7dcaff0
Revert "nit; only allow any pets to start riding player from server s…
demonlexe Aug 23, 2024
6539bf5
Reapply "nit; only allow any pets to start riding player from server …
demonlexe Aug 23, 2024
59223d4
try to allow re-mounting if entity is the same as before
demonlexe Aug 23, 2024
48e926c
Merge remote-tracking branch 'origin/1.12.2' into 150-bunny-water-des…
demonlexe Aug 23, 2024
3aa4f8d
Revert "Reapply "nit; only allow any pets to start riding player from…
demonlexe Aug 25, 2024
5beb6b6
add rats dependency for testing
demonlexe Aug 25, 2024
b2c19c2
revert unneeded changes
demonlexe Aug 25, 2024
30a8d1d
add rats dependency, llibrary
demonlexe Aug 25, 2024
abf5619
fix rats version, add forced mounting
demonlexe Aug 25, 2024
b5b715b
WIP; start copying Rats workflow for mounting/dismounting
demonlexe Aug 25, 2024
a2e22db
add the rats riding logic
demonlexe Aug 25, 2024
265a256
cleanup MOCEntity_Riding_Player logic
demonlexe Aug 25, 2024
0c5b267
nitfixes, add messenging
demonlexe Aug 25, 2024
38af288
use two different messaging channels, client/server
demonlexe Aug 25, 2024
0ec37b0
move client handling code to packet task
demonlexe Aug 25, 2024
e14fa98
nit; entityId => passengerId
demonlexe Aug 25, 2024
2c40070
nitfix; remove from server side
demonlexe Aug 25, 2024
d237658
force the dismount from client and server side
demonlexe Aug 25, 2024
9750aad
try to remove separate client message
demonlexe Aug 25, 2024
00c6d75
try passing player to handler fm
demonlexe Aug 25, 2024
1631709
Revert "try passing player to handler fm"
demonlexe Aug 25, 2024
87444e0
Revert "try to remove separate client message"
demonlexe Aug 25, 2024
7e07d99
use sendToAll for more stability
demonlexe Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ 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: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"
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/drzhark/mocreatures/MoCTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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 net.minecraft.block.Block;
import net.minecraft.block.BlockJukebox;
Expand Down Expand Up @@ -65,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;
Expand Down Expand Up @@ -1213,12 +1216,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) {
Expand All @@ -1227,12 +1225,11 @@ 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();
int passengerId = passenger.getEntityId();
MoCMessageHandler.INSTANCE.sendToAll(new MoCMessageDismountRidingEntityClient(passengerId));
MoCMessageHandler.INSTANCE.sendToServer(new MoCMessageDismountRidingEntityServer(passengerId));
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +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);
if (ret) {
NBTTagCompound tag = player.getEntityData();
tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID());
return true;
}
return false;
return super.startRiding(player, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,8 @@ 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());
return true;
} else {
TextComponentTranslation msg = new TextComponentTranslation("msg.mocreatures.petnotreadytorideplayer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +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);
if (ret) {
NBTTagCompound tag = player.getEntityData();
tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID());
return true;
}
return false;
return super.startRiding(player, true);
}

@Override
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +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);
if (ret) {
NBTTagCompound tag = player.getEntityData();
tag.setUniqueId("MOCEntity_Riding_Player", this.getUniqueID());
return true;
}
return false;
return super.startRiding(player, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ public boolean isMovementCeased() {
@Override
public void onStopRidingPlayer() {
// Stopped riding player, reset state to Idle.
super.onStopRidingPlayer();
changeKittyState(7);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = getYOffset();
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);
Expand Down Expand Up @@ -279,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();
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/drzhark/mocreatures/event/MoCEventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,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
Expand Down Expand Up @@ -155,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);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MoCMessageDismountRidingEntityClient, IMessage> {

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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 MoCMessageDismountRidingEntityServer implements IMessage, IMessageHandler<MoCMessageDismountRidingEntityServer, IMessage> {

public int passengerId;
public MoCMessageDismountRidingEntityServer() {
}

public MoCMessageDismountRidingEntityServer(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(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);
}
return null;
}

@Override
public String toString() {
return String.format("MoCMessageDismountRidingEntityServer - passengerId:%s", this.passengerId);
}

}