diff --git a/build.gradle b/build.gradle index 6de8d97df..e162e12b1 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/src/main/java/drzhark/mocreatures/MoCTools.java b/src/main/java/drzhark/mocreatures/MoCTools.java index 4483adfcd..d306bc8f1 100644 --- a/src/main/java/drzhark/mocreatures/MoCTools.java +++ b/src/main/java/drzhark/mocreatures/MoCTools.java @@ -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; @@ -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; @@ -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) { @@ -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(); } diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java index 503c4f48f..30d7fef1b 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAmbient.java @@ -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 diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java index 8ca91bd5a..1e3107311 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAnimal.java @@ -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"); diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java index 012c45023..9b1457093 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityAquatic.java @@ -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 diff --git a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java index 06bd58289..2dce74b0e 100644 --- a/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java +++ b/src/main/java/drzhark/mocreatures/entity/MoCEntityMob.java @@ -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 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/entity/passive/MoCEntityBunny.java b/src/main/java/drzhark/mocreatures/entity/passive/MoCEntityBunny.java index 202ef06f0..ac29d8496 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 = 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); @@ -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(); 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) { diff --git a/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java b/src/main/java/drzhark/mocreatures/network/MoCMessageHandler.java index db9af6a6a..8a3da9b1f 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; @@ -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 @@ -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); + } + } } } } 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 new file mode 100644 index 000000000..892ef3395 --- /dev/null +++ b/src/main/java/drzhark/mocreatures/network/message/MoCMessageDismountRidingEntityServer.java @@ -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 { + + 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); + } + +}