Jump to content

[1.8.9][Networking] Some questions about dedicated server and modded clients


Recommended Posts

Posted

Good evening,

 

I'd apologize in advance for the lack of visual code, my problem is purely based on concept understanding that I need to clarify in my mind.

It has been about one year that I have "forge modding times", all repressed by studies or a lack of understanding : I'd like to correct the latter.

 

Doing some research on google, I have found a good explanation of "how client and server sides" are separated in Minecraft thanks to The Grey Ghost. (This topic is dated on 2013 but it seems to be still valid)

 

From what I understood, a modder is able to create a mod with client side and server side for both dedications : when launched in singleplayer, the server side is still handled by the "client program" while in multiplayer, the server side is nicely handled by the "server program" but putting client code in it is kind of useless.

 


 

Let's say that a modder would like to open a forge modded server. Within, he would like to create a "quest system" where data are stored in a database. The modded clients can access to this server and use the quest system : the modded client asks for a quest (e.g pressing a button) and the servers responds using packets to the client.

 

In this hypothesis, the modded client just has to handle client input (button), packet requests (and responses obviously) and quest rendering (gui) while the modded server has to handle the research (specific quest in db), and packets req/res. In this case, all tasks are well distributed to their dedication.

 

The point that I don't understand very well is : how to achieve this, knowing client and server have to get the same mod so that the client can connect to the server.

 

I might be wrong for the last sentence, in which case I'd like some explanations on it, but I already encountered some errors where I couldn't connect to the server due to mods difference. For maintainability and common sense reasons, it would be obvious to not put all the database system in the modded client. Furthermore, I would like to clarify that modded clients cannot play in singleplayer (which is a little bit obvious, without database system it would be pointless).

 

I think I have a clue but I'm not sure : the solution would be to implement the packets differently in both client and server, so that client and server would be compatible and the quest system would be well done at packets implementation.

 

I would thank you in advance for any help or clarification on this, that would be valuable to me, to better understand this principle.  :)

Squirrel ! Squirrel ! Squirrel !

Posted

Im not sure if I get ur quesiton right.

Forge already ensures that clients can only join if they got the exact same version (of course u need to change the version of the mod when making a new release)

Posted

Im not sure if I get ur quesiton right.

Forge already ensures that clients can only join if they got the exact same version (of course u need to change the version of the mod when making a new release)

 

Hello @Failender,

 

Is this the only constraint to connect a modded client to a modded server ?

 

For TL;DR, I'd like to make a mod that handles client stuff for modded client, and a mod that handles server stuff (including quest system and database system) for the modded server : in itself, it is the same mod but separated in two versions: one for the client and one for the server. The thing that I would like to achieve is to separate the tasks so that the dedicated server hasn't the client code and the modded client haven't the server part.

 

The client shouldn't have the packet handling that the dedicated server do. The server aswell shouldn't have the client handling (like input or gui rendering) that is reserved for clients.

 

I don't know if I can make myself understood in fact.  ;D

 

EDIT : is there any documentation that explains the forge versioning/compatibility that you point out ?

Squirrel ! Squirrel ! Squirrel !

Posted

I am not sure what exacly you want to know because 1st you claim that you found good explanation for sides and then you seem to think that server and client mod is something different.

 

Well, since about 1.2 (around, I don't remember) modding has been redesigned to be compiled as one universal mod for both client and server.

Before going further:

Client = client.jar

Dedic = dedicated.jar

client-side = logical server side

server-side = logical server side

 

When:

1. Dedic is running - it runs server-side.

2. Client it running - it runs client-side and:

2.1. Nothing else on MP (server-side is handled by Dedic).

2.2. server-side on SP (integrated server-side)

2.3. When in LAN - one client will run integrated server, other clients will connect to LAN server like to Dedic.

 

Having Mod written as an universal jar - it doesn't matter where you run it. Data should be always handled on server-side, thus if you have any database it will always be loaded on server-side, which is Dedic OR integrated server.

Packets are still being "sent", even when you are on SP connected to your integrated server.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Im not sure if I get ur quesiton right.

Forge already ensures that clients can only join if they got the exact same version (of course u need to change the version of the mod when making a new release)

I'd like to make a mod that handles client stuff for modded client, and a mod that handles server stuff (including quest system and database system) for the modded server : in itself, it is the same mod but separated in two versions: one for the client and one for the server. The thing that I would like to achieve is to separate the tasks so that the dedicated server hasn't the client code and the modded client haven't the server part.

 

The client shouldn't have the packet handling that the dedicated server do. The server aswell shouldn't have the client handling (like input or gui rendering) that is reserved for clients.

 

Hell, well you gave your explanation, my prev post is quite irrelevand aside from fact that modding has been made SIDE-UNIVERSAL.

 

Do tell - do you want to achieve what you want to achieve because:

1. Privatization of code (e.g coding for private server).

2. Lowering size of files for players to download.

3. Don't know why and you think that it will be better, when in reality - it really won't.

4. When you say "database" you actually mean embedded DB engine that you think is useless for clients, thus you go back to point 2. with addition of "useless code".

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

You might have a "mod" that has such distinct client and server tasks that you'd provide separate jar files for each (but have them depend on each other). You could build separate client and server versions of the "same" mod, or you might be able to use version and dependency annotations (or parameters to the MOD annotation).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Im not sure if I get ur quesiton right.

Forge already ensures that clients can only join if they got the exact same version (of course u need to change the version of the mod when making a new release)

I'd like to make a mod that handles client stuff for modded client, and a mod that handles server stuff (including quest system and database system) for the modded server : in itself, it is the same mod but separated in two versions: one for the client and one for the server. The thing that I would like to achieve is to separate the tasks so that the dedicated server hasn't the client code and the modded client haven't the server part.

 

The client shouldn't have the packet handling that the dedicated server do. The server aswell shouldn't have the client handling (like input or gui rendering) that is reserved for clients.

 

Hell, well you gave your explanation, my prev post is quite irrelevand aside from fact that modding has been made SIDE-UNIVERSAL.

 

Do tell - do you want to achieve what you want to achieve because:

1. Privatization of code (e.g coding for private server).

2. Lowering size of files for players to download.

3. Don't know why and you think that it will be better, when in reality - it really won't.

4. When you say "database" you actually mean embedded DB engine that you think is useless for clients, thus you go back to point 2. with addition of "useless code".

 

Good morning,

 

The first thing you point out is exactly what I would like to accomplish : privatize the code so that the client can't be aware of the embedded DB engine. (and yes, by database I meant embedded DB engine) This is really easy for a player to be aware of the code by opening the jar file and exploring some classes. That is why I absolutely wanted to separate client and server tasks into two different jars.

 

Unless you know a cleaner way to achieve this, do you think it is still possible to do this ?

 

EDIT:

 

You might have a "mod" that has such distinct client and server tasks that you'd provide separate jar files for each (but have them depend on each other). You could build separate client and server versions of the "same" mod, or you might be able to use version and dependency annotations (or parameters to the MOD annotation).

 

That is, you understand where I was getting ! :D

Squirrel ! Squirrel ! Squirrel !

Posted

Lets be honest this will be a lot more work, but it is totally doable.

 

I dont know how to use that annotation stuff so maybe jerry can explain more there.

 

What you could do would be create to different workspaces (server / client) and work independant. On the client side do only client stuff (rendering /networking / blocks / items)

and on the server side do all the server stuff (most of the event handling/ networking / blocks / items)

It is just REALLY important that when you register your items / blocks / whatever via GameRegistry.register...() that you use the same names ( if im not mistaken)

Posted

You are making your life harder but whatever.

 

I can only suggest this approach:

Setup normal dev environment.

Create 2 mods - server and client one.

Proxify EVERYTHING - Client mod will fire everything it has in ClientProxy, Server will setup everything (databases, engines) in ServerProxy.

Write 2 different mods. that will somehow correspond to each other.

 

Why 2 mods, one workspace - well, easier to maintain - you can launch Dedic and Client at once and connect to test it.

 

Now where are main problems:

- You still need a lot of common code, since most stuff needs to be handled on both sides (e.g you send quest data, you recreate object on client, thus you need all quest classes).

- Client will NOT work on SP - since you don't have server's code (integrated), you need to take care of your shit when playing on SP (when using some client-event, you need to make if(sp) and then proceed with acting).

- Packets are "the shit" - your problem is with implementations that Forge alredy provides. SimpleNetworkWrapper and actually whole system requires you to have IMessage and MessageHandler. What you want to do is to make:

Dedic only have IMessage and Client only have MessageHandler or other way around.

Problem is actually that when you receive message, it will be recreated and passed to MessageHandler (that's why packts need empty constructor).

How to pass this? Well, you can't (if you want to use forge). You will need sided implementation of packets.

Next: SimpleNetworkWrapper allows you to register packets in PACKET<->HANDLER manner. You want to have INCOMING<->OUTGOING.

To resolve this you need to either write your own implementations (of networking) or "inject" your packets without pairing (meaning you register PACKET but not HANDLER).

You can do this like this:

SimpleIndexedCodec codec = ReflectionHelper.getPrivateValue(SimpleNetworkWrapper.class, this.getInstance(), "packetCodec"); // instance is ofc of your SNW
codec.addDiscriminator(packetId, message);

This way you can have OUTGOING packet with some ID. Now on receiving side you need to have both HANDLER and PACKET to receive (you also need to have same ID as incoming packet). That you register like any other packet.

 

Seriously, don't do that, just proxify your code and make one mod.

 

Oh and mark EVERYTHING (that is not common code) in your code with SideOnly:

http://www.minecraftforge.net/forum/index.php/topic,22764.0.html

 

EDIT

Additional shit: if you started modding/this is your first. DON'T do that. Without proper understanding of MC, you will most likely have a lot of problems.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Thank you Ernio for your answer !

 

Yup, the client has not to work in singleplayer on purpose, it is for a private server. I will do some extensive researches about Minecraft/Forge networking. :)

 

Why do I want to do this way ? This is a goal I set myself and that I would like to accomplish.

 

Thank you guys for your answers, I will keep you informed and surely will need your help later. :D

Squirrel ! Squirrel ! Squirrel !

Posted

If I ever need to do something like this, I will go with 2 mods:

 

modA: a server-side only mod to deal with the database engine and all the bits and pieces you want to keep off the client

 

modB: the actual mod you want to make

 

The logical server-side of modB will delegate all database-related jobs to modA, if modA is actually present

 

Z

 

 

 

 

Posted

And finally, the client mod depends on the presence of the server mod and/or the server mod requires a client to log in with the client mod.

 

BTW, You might not be able to stop code exposure. A player could still download the client mod for examination... unless you keep it all to yourself (only your servers and private correspondents would have it). Then you're doing something like public/private keys in encryption. Release one version of a mod publicly for players, and hold a private version of the same mod for yourself and your server(s).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

If he goes with the 2-mods structure I suggested he can keep all the private logic in the server-only mod and just release the public mod without need (and headaches) of having multiple versions of it

 

Z

Posted

And finally, the client mod depends on the presence of the server mod and/or the server mod requires a client to log in with the client mod.

 

BTW, You might not be able to stop code exposure. A player could still download the client mod for examination... unless you keep it all to yourself (only your servers and private correspondents would have it). Then you're doing something like public/private keys in encryption. Release one version of a mod publicly for players, and hold a private version of the same mod for yourself and your server(s).

 

If he goes with the 2-mods structure I suggested he can keep all the private logic in the server-only mod and just release the public mod without need (and headaches) of having multiple versions of it

 

Z

 

Hey guys,

 

Exactly, I don't really mind if clients want to take a look at the client mod code. I just don't want to expose the server part publicly. :)

 

For the moment (just for infos), I'm adding a connection pool for the server part but I'm having problems adding the lib to the jar using Forge Gradle. In fact, I don't really know how to create my own gradle tasks so that I can generate client build and server build at the same time (or separately), using Forge Gradle.

Squirrel ! Squirrel ! Squirrel !

Posted

Wow, you might finally have created a use-case for @SideOnly server files and a serverProxy to ref them. If you set them up right, you should be able to build your project twice, first with all pieces in place for yourself, and then with the server-only pieces deleted from your src tree to produce a version for public release. To that end, you might want to organize your files to place all server-only classes into a separate package for quick removal or replacement. Make sure to keep a master elsewhere.

 

I do a similar thing with resources in my alt paintings mod, deleting the rather large graphics files before building a lightweight version of the mod for dedicated servers.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Wow, you might finally have created a use-case for @SideOnly server files and a serverProxy to ref them. If you set them up right, you should be able to build your project twice, first with all pieces in place for yourself, and then with the server-only pieces deleted from your src tree to produce a version for public release. To that end, you might want to organize your files to place all server-only classes into a separate package for quick removal or replacement. Make sure to keep a master elsewhere.

 

I do a similar thing with resources in my alt paintings mod, deleting the rather large graphics files before building a lightweight version of the mod for dedicated servers.

 

Hello jeffry,

 

Thank you for you tip, I'll try to organize my code there are two separated packages, client and server. :)

However, I don't really understand well what are you meaning by "use-case for @SideOnly server files and a serverProxy to ref them" ?

Squirrel ! Squirrel ! Squirrel !

Posted

Wow, you might finally have created a use-case for @SideOnly server files and a serverProxy to ref them. If you set them up right, you should be able to build your project twice, first with all pieces in place for yourself, and then with the server-only pieces deleted from your src tree to produce a version for public release. To that end, you might want to organize your files to place all server-only classes into a separate package for quick removal or replacement. Make sure to keep a master elsewhere.

 

@SideOnly=Server will not keep the annotated code out of the compiled jar, so it will not work for the public version of the mod and it's not needed for the private version

 

@Major Squirrel: I don't know how much code you will actually have in common between the "public" and "private" version of the mod but, again, I'll suggest to go with 2 distinct and separate mods (and 2 separate projects) to keep things clean and separate and to define an API to let the 2 mods interact with each other (if you end up with more than a couple of interfaces see the @API annotation)

 

Z

 

 

Posted

@SideOnly=Server will prove that a section of code can be left out of the public version (before it's actually removed from the src tree).

 

"Use case" is geek speak for "an example that shows how this feature could be useful". Use cases often drive product design, but they also help students to cement lessons about the features of complex tools (such as Minecraft + Forge).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Wow, you might finally have created a use-case for @SideOnly server files and a serverProxy to ref them. If you set them up right, you should be able to build your project twice, first with all pieces in place for yourself, and then with the server-only pieces deleted from your src tree to produce a version for public release. To that end, you might want to organize your files to place all server-only classes into a separate package for quick removal or replacement. Make sure to keep a master elsewhere.

 

@SideOnly=Server will not keep the annotated code out of the compiled jar, so it will not work for the public version of the mod and it's not needed for the private version

 

@Major Squirrel: I don't know how much code you will actually have in common between the "public" and "private" version of the mod but, again, I'll suggest to go with 2 distinct and separate mods (and 2 separate projects) to keep things clean and separate and to define an API to let the 2 mods interact with each other (if you end up with more than a couple of interfaces see the @API annotation)

 

Z

 

@SideOnly=Server will prove that a section of code can be left out of the public version (before it's actually removed from the src tree).

 

"Use case" is geek speak for "an example that shows how this feature could be useful". Use cases often drive product design, but they also help students to cement lessons about the features of complex tools (such as Minecraft + Forge).

 

Hey guys,

 

Thank you for you replies. It helps me to understand better the way Minecraft Forge works. :) I think I'll go for 2 separated projects for now because of the lack of knowledge. But if I had to create two separated jars from the same project, how could I accomplish this ? I thought about two maven tasks but I suppose this isn't the best way to do this here...

Squirrel ! Squirrel ! Squirrel !

Posted
if I had to create two separated jars from the same project, how could I accomplish this?

 

I make mine the old-fashioned way: I build a jar, move it to another folder, then delete bulky resources, then build the "lightweight" jar, then rename it and move it too. I get 2 versions in 2 minutes without needing to learn advanced gradle/maven mechanics. It works for my simple situation. My project switching (from one mod to another) is similarly primitive.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Hey guys,

 

Good news, it works ! I decided to create two projects separately using the same "mod" infos : version, modid, etc... For now, I have a client project and a server one. I have the same packet class in both projects, but each project has its own implementation of the packet. Registering the same packet to the same discriminator, it works like a charm !

 

However, I still have some questions about client/server side exercices : how can I check if my packets are leaking ? Furthermore, I decided to give a try sending player nickname through packets, here is the code :

 

    @Override
    public void             handleServerSide(MessageQuest message, EntityPlayer player) {
        ChatComponentText   text;

        text = new ChatComponentText("Currently, your singleplayer nickname is : " + message.playerName);
        player.addChatMessage(text);
        text = new ChatComponentText("However, here is your multiplayer nickname : " + player.getName());
        player.addChatMessage(text);
    }

 

Here, I am sending the player nickname through the packet. The message.playername is obtained by Minecraft.getMinecraft().thePlayer which is an EntityPlayerSP. The player.getName() is obtained through context.getServerHandler().playerEntity which is an EntityPlayerMP. Informations such as player nickname are "obtainable" by both client and server mechanics. Actually, I'm wondering how could I know when to get informations from server side or client side : I assume that the right method is to always get infos from server side, but I'd like your point of view about that :)

Squirrel ! Squirrel ! Squirrel !

Posted

The thing is if you think about it you ALWAYS know at which side you are at the moment.

If you are sending a packet always make sure that you define where your packet is going (client->server / server->client) that way you always know how to access the information when handling the packet.

e.g. a packet to sync tileentity data is supposed to go from server to client, so you know you can always access Minecraft.getMinecraft if needed etc

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

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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