Jump to content

Recommended Posts

Posted (edited)

I have the EntityPlayerMP object and new nbt for the player how do I force update this player object I got with some capabilities I got from another nbttagcompound? I want all forge capabilities to update since player.readFromNBT() doesn't do it for me.

Edited by jredfox
Posted (edited)
9 hours ago, diesieben07 said:

Oh god, not this again...

 

  • You most likely do not want NBT.
  • Yes, readFromNBT reads the capability data.

I want to swap players capabilities all of them between two players if you use a certain item. ForgeCaps where the capabilities are always stored doesn't seem to update the capabilities readFromNBT(). I tested it with a couple mods they don't seem to sync of course they had guis. Maybe it's because it was a slightly older version but, I think the same issue persists is there a way to get around it like manually firing Entity Construction event?

Note everything is done via the server side

Edited by jredfox
Posted (edited)
2 hours ago, diesieben07 said:

No, there is no API to make mods re-sync their data to the client.

not asking for one what makes it update to begin with it has to know or they wouldn't appear on startup and the capabilities also wouldn't be registered.

It also is resisted on the server could I simply unregister and re-register all of them or better yet make the player a whole new entity player object?

Edited by jredfox
Posted (edited)
2 hours ago, diesieben07 said:

Mods probably send their data during PlayerLoggedInEvent and similar.

ok so would firing that event cause issues if somehow the capabilities get registered twice?

 

I will try and mess with this a bit more what happens when the player is cloned does that update everything where is the code starting when the player is being cloned?

Edited by jredfox
Posted
46 minutes ago, diesieben07 said:

It will not cause capabilities to register twice (registration happens during AttachCapabilityEvent). However it will make all handlers fire, you will get all actions from mod that happen during player login. This is most likely not what you want.

 

I have no idea what you are trying to say. Updates happen when the mods see the need for it. There is no common entry point to "update everything". No, you cannot bend over backwards and make it magically appear. What you want is not possible.

well I needed it happen at x point there should be a method in forge like entities have readNBT() that's stupid if they never synced changes and never made a reset method or update all

Posted (edited)

Misread the question

17 minutes ago, diesieben07 said:

I... what?

^^^ He makes a good point why would forge ever make something for you that you should make yourself by overriding about 3 methods?

 

You can have your tile entities extend a Base class that automagically handles this for you...

If this is what you would like, try looking at

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/machine/TileBase.java#

and

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/packet/PacketSyncTileEntity.java#

It automagically writes all your capabilities to NBT & syncs it every half second. 
I had quite a few problems with it (Not syncing even when explicitly told to, writing every face to NBT, syncing way too often). I've solved them so you might want to check out my implementation of it (my version can also write stuff other than caps to NBT)

 

My version of the Base tile class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityBase.java

My Sync Packet class and my networking class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketSyncTileEntity.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketHandler.java

2 classes that use it in my mod (Turbine is very simple, but only writes capabilities while Wire also writes "lastRecieved")

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityTurbine.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityWire.java

 

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
On 4/29/2018 at 4:34 AM, diesieben07 said:

Oh god, not this again...

 

  • You most likely do not want NBT.
  • Yes, readFromNBT reads the capability data.

ok then maybe the client isn't receiving the data. Does readEntityFromNBT() send a packet to the client maybe I need to create a packet to send to the client to update NBT? is there already a packet that does this?

 

I hope it's not the fact that the data doesn't change on the gui but, is changed on the capabilities so I can actually wip up a fix for mods with capabilities and guis

Edited by jredfox
Posted (edited)
On 4/30/2018 at 4:37 AM, Cadiboo said:

Misread the question

^^^ He makes a good point why would forge ever make something for you that you should make yourself by overriding about 3 methods?

 

You can have your tile entities extend a Base class that automagically handles this for you...

If this is what you would like, try looking at

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/machine/TileBase.java#

and

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/packet/PacketSyncTileEntity.java#

It automagically writes all your capabilities to NBT & syncs it every half second. 
I had quite a few problems with it (Not syncing even when explicitly told to, writing every face to NBT, syncing way too often). I've solved them so you might want to check out my implementation of it (my version can also write stuff other than caps to NBT)

 

My version of the Base tile class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityBase.java

My Sync Packet class and my networking class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketSyncTileEntity.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketHandler.java

2 classes that use it in my mod (Turbine is very simple, but only writes capabilities while Wire also writes "lastRecieved")

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityTurbine.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityWire.java

 

I don't want it syncing every second just when I want it updating and preferable the client isn't required server side mod only. What about a packet to readFromNBT() to the client and will that update the forge capabilities? So like a readFromNBT() packet to the client for capabilities only?

if you read it's not my object necessary it could be a player or another entity

stop with the crossing lines plz

Edited by jredfox
Posted (edited)
46 minutes ago, diesieben07 said:

None of this is the case. Reading from NBT does not send a packet.

And such a packet does not exist. Reading from NBT on the client is not what you want. What you want is not possible.

well what I seen is there are two sides server and client both have nbt so if server has values updated and client does not then it should update capabilities on client side since they occur on both sides?

then what am I looking to do you said so yourself it should update capabilities data calling readFromNBT()

then why does the player inventory update when I say readFromNBT() on server and not capabilities that has to be client synced for the inventories what about capabilities. If it honestly isn't possible then this is a forge bug and should be reported since readFromNBT() should update data

Edited by jredfox
Posted (edited)
39 minutes ago, diesieben07 said:

This is not how NBT works.

NBT is a data serialization format. It is used for saving to disk. The client does not "have NBT" (neither does the server, but it at least uses it).

 

It reads the server-side capability, yes.

 

The player inventory is constantly monitored by the game on the server side since it may change from certain events (e.g. you pick up an item) and synced if necessary. Not all capabilities do this, in fact most probably don't. This is fine, since there is no mechanism to "just update data of an entity". If you want to so, the best way is to kill the entity and spawn a new one.

 

readFromNBT is for when the entity is loaded from disk. You should not be calling it in the first place. This is not a bug. You are using things in ways they are not designed to be used.

"I used this screwdriver to polish my car, but it really didn't polish it. This screwdriver must be broken!"

readFromNBT() does occur on client look at the code there is no file argument. readFromNBT() is simply to update variables there is no file argument. There are also client only variables written to nbt does it get saved ever I don't know. Look at player.writeToNBT() in console on client and server side there are a couple tags on client that are not on server.

Silkspawners main mechanic is to break block save it to stack (writeToNBT) and placeBlock(readFromNBT) both of which are never saved to the disk during that process until the itemstack or tile entity decides to save the data. The client even had to readFromNBT of the tile entity otherwise for a couple ticks it would display pig. Those methods are for saving .comparing, and manipulating data which means it's not always stored to the disk but, yes eventually that's it's main function is serialization with the exception of commands and mods that decide to do stuff to manipulate and update variables

you are talking about serialization methods yes those occur only from the disk and do call readFromNBT() after they get the nbt

Edited by jredfox
Posted (edited)

"If you want to so, the best way is to kill the entity and spawn a new one."

Ok how do I do this make the player = new player and then tell client it's a new player then use it to update from the nbt I gathered from a file I serialized to nbt?

I heard something about player cloning how do I do this on command while still serializing from nbt?

Edited by jredfox
Posted (edited)
11 minutes ago, diesieben07 said:

Where? If you are so sure about it, post exact locations where the client calls it.

 

Wat? How is that relevant?

 

This is complete bs. The client never saves an entity to NBT. Please clarify which client only variables you are talking about.

 

TileEntities are something else. They use (in vanilla, mods do not necessarily use this) NBT for syncing the data to the client. This is a completely separate process and does not use the same methods as saving to disk.

 

Regarding players you'd probably have to do some form of the respawning process. But this might make data disappear, since some mods will reset counters, stats, etc. on death/respawn.

 

Ultimately again: What you want is not possible, since there are no APIs for it. There is no concept of "apply new data to this entity" in Minecraft.

you said create a new one. How do I clone the player then with a different nbt then it's own and set it to be the new player for the client? Assuming I already set the uuid most and least from the current player?

Edited by jredfox
Posted
1 minute ago, diesieben07 said:

Look at the respawning process for how to clone the player. Then deserialize the new instance from your modified NBT before fully respawning it.

It might work. It might break completely.

 

Also, please stop referring to things "having NBT". It is wildly inaccurate and conveys a wrong understanding about how all of this works.

Well the re spawn process doesn't even give out a new player I am pretty sure but, I will check it out. 

What about when the client logs onto the server and the entity is created there can that be hacked into giving out a new player from the old one? Where is that code located at?

Posted (edited)
6 minutes ago, diesieben07 said:

Yes, it does. This is why PlayerEvent.Clone exists.

 

We already had this. It would trigger everything that happens on login, such as welcome messages, login stats, etc.

Well I could simply look at the logic and not fire the forge events so the messages don't appear and manually handle the capabilities

the player event clone exists but, I have no clue when it's fired? I believe I tried dying before and it didn't fire let me check

Edited by jredfox
Posted (edited)
9 minutes ago, diesieben07 said:

No, because the events are what tell the mods "hey, player logged in" and then the mods send their data. For the millionth time: There is no API to say to a capability "please sync yourself to the client". No, even if you bend over backwards. IT DOES NOT EXIST.

 

Then look at the god damn code. You have an IDE. USE IT.

must have been on the wrong bus in older versions last time I tried it. It does occur during respawn sometime. this might be enough data to do what I need. will write back if it's not

Ok it appears I have found more questions then answers:
the player clone event doesn't fire on player death
the player clone event only fires when the client hits the respawn button are you sure this is the code I should be looking at?

Edited by jredfox
Posted (edited)
2 hours ago, diesieben07 said:

Indeed, why would it?

 

Yes, like I said you need to adapt the code. Cut out the whole "okay client, please show respawn gui" - "okay server, respawn button was pressed" process and just do the respawn immediately.

It would help if I knew what class it's in

The client code just leads to a packet being sent it could be anywhere that the server does something with it:
 

    public void respawnPlayer()
    {
        this.connection.sendPacket(new CPacketClientStatus(CPacketClientStatus.State.PERFORM_RESPAWN));
    }

 

 

Edit: It appears I found it in the network connection from entity player mp. It has alot of code not going to want to use it all like reset positions and dimensions I handled that before I would call the manual respawn.

Edited by jredfox
Posted (edited)
4 hours ago, loordgek said:

@jredfox  what are you making for mod ??

two things a test item to swap playerdata between two players and a uuidfixer(if change is dedicated force update everything). Trying to get it working without player re logging.

right now just trying to get it working from a hard coded playerdata without player re logging 

Could be used as a magic spell for the test item if someone wanted to use it 

Edited by jredfox
Posted (edited)
20 hours ago, diesieben07 said:

Indeed, why would it?

 

Yes, like I said you need to adapt the code. Cut out the whole "okay client, please show respawn gui" - "okay server, respawn button was pressed" process and just do the respawn immediately.

Ok I have confirmed what you said there is no such update method without re logging. I physically made the player a new object and the capabilities still didn't update and sync with everything else.

I think there should be in the future an updateCapability() and updateAllCapabilities() method in forge based where you give it the nbt to re-serialize it. Since resource location is already required you should be able to send in the resource location and nbt to update the capability or give it everything and update all

Edited by jredfox
Posted (edited)
15 hours ago, diesieben07 said:

Indeed, why would it?

 

Yes, like I said you need to adapt the code. Cut out the whole "okay client, please show respawn gui" - "okay server, respawn button was pressed" process and just do the respawn immediately.

 

ok so I set the player connection location forceably disconnect the player and the position doesn't get saved. How many ticks before I can disconnect the player after the players location changes?

Note this is all done on server side and the set is a new set nothing added. Also note this is done on server side only and is integrated when testing.

p.connection.setPlayerLocation(x, y, z, e.rotationYaw, e.rotationPitch, set);
p.connection.disconnect(new TextComponentString("UUID Change Relog For Syninc Forge Capabilities"));



As for the spell thing I will just tell people it doesn't always sync with capabilities relog manually if you want it to update.

Edited by jredfox
Posted (edited)
17 minutes ago, diesieben07 said:

What... why are you disconnecting the player O.o

for my uuidfixer/checker if detected uuid is different readEntityFromNBT(proper) then teleport and discconect so forge capabilities are properly synced.

the uuid bug occurs when either the launcher sends the wrong information, mojang sends the wrong information, either one updated, or many other things I can't think of but, when that occurs playerdata wipes. My event is to prevent this regardless of launcher,mojang website response, or mc version. I have verified this 1.7.2-1.12.2 I cannot easily reproduce the bug but, I can simulate when the data is wrong does my patching work.

So the only thing that's not working is the coords even though I set them right before I disconnected the player it doesn't appear in the disk but, the dimension id and everything else did appear. I printed the pos of the player right before disconnection and it was the new pos I sent it but, not on the disk weird.

If I don't disconnect the player the coords will properly sync so how long before I should be able to disconnect the player without stuff not syning even though all those calls are on serve

Edited by jredfox
Posted (edited)
10 minutes ago, diesieben07 said:

What... WHATTTTT...

Do not tell me you are trying to change a player's UUID. This does not work.

 

Oh god, this again? We had this like a year ago it seems. You have failed to properly tell me how to reproduce this bug, if I remember correctly. You need to stop employing more and more hacks to work around the issues your own broken code causes.

no I check if the uuid has changed if it has I attempt to patch it. I am unable to reproduce this bug easily all I know is it does occur very rarely probably issues with website/launcher but, it does occur.

What am I talking about:
go into a world previously full inventory and say in a different dimension

eventually through time keep going back into the world and your uuid changes your player data is new and your progress all lost even though you are the same player, the level.dat backup failed for integrated server, and you have the same username. You can manually patch this by going to your old playerdata renaming the uuid most and least and rename the file to your new uuid but, my event is to automate this

Anyways how can I properly sync coords before disconnecting the player how many ticks do I have to wait one two? what's not syncing?

Should I be dependent upon vanilla saving it's stuff for the player or use an event handler to fix this issue by overriding everything when it occurs(not optimized)?


My mod doesn't change player's uuid at all. I am attempting to fix a vanilla issue that can be observed in both vanilla and forge without my mod installed or any other mods installed. It has nothing to do with me. uuidfixer is to simply fix the bug by patching data over when the player decieds to change it on it's own. Again it can be observed without any mods besides forge for sure

Edited by jredfox
Posted (edited)
4 minutes ago, diesieben07 said:

The thing is, nobody but you seems to have this bug.

 

And I still fail to understand why you want to disconnect the player.

zdoctor, choonster,micah_laster,all my freinds, hundreds of people on the mc forum know what I am talking about all they know is how to manually fix it when it occurs. They don't call it uuid bug but, they do know to mess with those tags like I said before and change the file name to the new file

Edited by jredfox
Posted (edited)
5 minutes ago, diesieben07 said:

The thing is, nobody but you seems to have this bug.

 

And I still fail to understand why you want to disconnect the player.

you said forge capabilities refuse to update without relog I am forcing user to relog because I agreed with you.

The issue is positions don't write to nbt if I disconnect the player on the same tick

Edited by jredfox
Posted (edited)
1 minute ago, diesieben07 said:

So you are telling me hundreds of people on some other forum have this bug. Yet none of them have ever arrived on this forum?

And you are telling me that none of these hundreds of people have ever decided to report a bug to Forge? Or to Mojang, if it is the launcher or "the website" as you say.

And you are telling me that none of these hundreds of people have ever found a way to reliably reproduce it?

 

I call bs.

https://www.minecraftforum.net/forums/support/java-edition-support/2225159-1-7-10-custom-modpack-player-data-randomly

2 seconds later

Edited by jredfox

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.