Jump to content

Recommended Posts

Posted

Ok so i essentially deleted and re-downloaded EVERYTHING event deleted the .gradle/caches/minecraft folder so it would re download all the minecraft files and Updated to forge 1070. Unfortunately it didnt fix anything although now when i load the game i get the following error for  all my blocks and items... 

 

[10:33:47] [server thread/WARN] [FML]: ****************************************

[10:33:47] [server thread/WARN] [FML]: * Illegal extra prefix tolkienaddon for name tolkienaddon:testBlock, invalid registry invocation/invalid name?

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:733)

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:211)

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:167)

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:156)

[10:33:47] [server thread/WARN] [FML]: *  at tolkienaddon.blocks.ModBlocks.register(ModBlocks.java:27)

[10:33:47] [server thread/WARN] [FML]: *  at tolkienaddon.blocks.TestBlock.<init>(TestBlock.java:23)...

[10:33:47] [server thread/WARN] [FML]: ****************************************

[10:33:47] [server thread/WARN] [FML]: ****************************************

[10:33:47] [server thread/WARN] [FML]: * Illegal extra prefix tolkienaddon for name tolkienaddon:sunFocus, invalid registry invocation/invalid name?

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:733)

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:139)

[10:33:47] [server thread/WARN] [FML]: *  at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:127)

[10:33:47] [server thread/WARN] [FML]: *  at tolkienaddon.items.ModItems.register(ModItems.java:86)

[10:33:47] [server thread/WARN] [FML]: *  at tolkienaddon.items.SunFocus.<init>(SunFocus.java:10)

[10:33:47] [server thread/WARN] [FML]: *  at tolkienaddon.items.ModItems.init(ModItems.java:61)...

[10:33:47] [server thread/WARN] [FML]: ****************************************

 

But everything still works so i have no idea what thats all about or how to fix it...

 

I think for now i will just wait to see if you have the same problem.

 

Edit: The error seems to be forge related i downgraded back to 1061 and it fixed it. I think it may be a bug because i cant see anything about it in the change log unless im looking in the wrong place? (changelog on the forge downloads page)

I am the author of Draconic Evolution

Posted

I worked on it a bit last night.  I had to catch up with where you're at, so worked on implementing the client to server stuff.  i got that working pretty handily.  I didn't quite get to the multiplayer testing because I the other computers on my network were all in use, but I think I can try again tonight (although it is my anniversary so will be going out for dinner and ???).  Sorry for the delay.

 

I promise to keep looking at this though as my time permits.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

No problem.

You dont need multiple computers to test multiplayer!!! simply start both the client and the server i your eclipse workspace (at the same time) and connect to the server using ":25565" (the server port)

 

Im not sure if you were actually planning to run 1 instance in server mode or two clients (with one open to lan) but just in case you dont know how to run your project in multiplayer mode you need to do the following.

 

1. create a new run configuration called "server" (or whatever you want)

2. set the main class to cpw.mods.fml.relauncher.ServerLaunchWrapper

3. leave Program arguments blank and in VM arguments add -Xincgc -Xmx1024M -Xms1024M

 

and thats it hit run and and the server should start and you should get the server gui instead of the regular minecraft window.

 

Edit: Just tested lan multiplayer works just fine probably because the server also has a client so its essentially the same as singleplayer just with an extra client.

I am the author of Draconic Evolution

Posted

No problem.

You dont need multiple computers to test multiplayer!!! simply start both the client and the server i your eclipse workspace (at the same time) and connect to the server using ":25565" (the server port)

 

Im not sure if you were actually planning to run 1 instance in server mode or two clients (with one open to lan) but just in case you dont know how to run your project in multiplayer mode you need to do the following.

 

1. create a new run configuration called "server" (or whatever you want)

2. set the main class to cpw.mods.fml.relauncher.ServerLaunchWrapper

3. leave Program arguments blank and in VM arguments add -Xincgc -Xmx1024M -Xms1024M

 

and thats it hit run and and the server should start and you should get the server gui instead of the regular minecraft window.

 

Thanks, yeah I normally test multiplayer with separate computers.  I can try it both ways, and yes I do have a Server run configuration set up in Eclipse.  I'm slightly leery that running on the same computer could cause some issues with networking though especially when debugging custom packets.  I have multiple gaming computers in the house so will try it that way too.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Okay, I haven't got to the multiplayer yet because I noticed a weird thing with the client to server packets.  While it seems pretty clear in my code that it is only sending one packet from client to server, the onServerPacket event seems to fire twice -- the first time with the expected packet (i.e payload is as expected) and second time with an apparently 0 payload (at least that is what the first int read gives.

 

I'm pretty certain that the event is only happening on the server side because I assume the event is only there, then I check the side in the event handler method and check the side again later in the process packet method.

 

So there is some sort of spurious packet event.  I can ignore it, but would like to understand it.  Reading through the FMLNetworkEvent class there is some mention of a "reply" packet, but I'm not sure if that is related (especially since I think it would go the other way).

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I noticed the same thing. I think the server packet handler is being registered on both the server and the client so when sending a packet from the client it is received both on the server and the client that sent it. But i may be wrong.

I am the author of Draconic Evolution

Posted

I noticed the same thing. I think the server packet handler is being registered on both the server and the client so when sending a packet from the client it is received both on the server and the client that sent it. But i may be wrong.

 

That was my first thought but I don't think that is the case because the side field in both events indicated server side.

 

You know, maybe you should go back and use a different packet handling scheme.  My initial success with the server to client packets was so easy that I thought the rest would be straight forward.  But looks like some debug is needed.  I'm gong to work on it but probably not as fast as you need. 

 

I won't take it personally if you abandon my approach.  The frustrating thing is it seems so close to working...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
The frustrating thing is it seems so close to working...

Tell me about it thats why I have been messing with it for so long it is just so close to working

I will finish the project i am working on then i will look into the other options but i will be keeping an eye on this and may switch back if you get it working because this is just so simple to use.

 

BTW i assume from your posts that it dosnt but you haven't actually confirmed weather or not it works for you in multiplayer.

I am the author of Draconic Evolution

Posted

If you wanna try a different approach on packet handling, look at this code:

https://github.com/SanAndreasP/SAPManagerPack/tree/master/java/de/sanandrew/core/manpack/mod/packet

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/de/sanandrew/core/manpack/mod/ModCntManPack.java

 

And simultaneously this tutorial I've based it off (I recode some stuff, since it was a bit messy IMO)

http://www.minecraftforge.net/wiki/Netty_Packet_Handling

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

If you wanna try a different approach on packet handling, look at this code:

https://github.com/SanAndreasP/SAPManagerPack/tree/master/java/de/sanandrew/core/manpack/mod/packet

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/de/sanandrew/core/manpack/mod/ModCntManPack.java

 

And simultaneously this tutorial I've based it off (I recode some stuff, since it was a bit messy IMO)

http://www.minecraftforge.net/wiki/Netty_Packet_Handling

 

I like this one.  It also seems pretty straight forward and actually takes a similar approach to what I was trying to do.

 

Since you're a much more expert coder than I, I assume that this already works in multiplayer as well?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

If you wanna try a different approach on packet handling, look at this code:

https://github.com/SanAndreasP/SAPManagerPack/tree/master/java/de/sanandrew/core/manpack/mod/packet

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/de/sanandrew/core/manpack/mod/ModCntManPack.java

 

And simultaneously this tutorial I've based it off (I recode some stuff, since it was a bit messy IMO)

http://www.minecraftforge.net/wiki/Netty_Packet_Handling

 

I was going to check out your earlier suggestion is this the same?

Anyway i wont be starting on that until i finish what i am current project which is mostly just cleaning up my mod... may take a while lol. 

I am the author of Draconic Evolution

Posted

@SanAndreasP

Im trying to figure out how to use your system but im a bit lost can you please show me an example of how to send and receive a packet?

Also i noticed you have a method in your proxy called "registerPackets" im not exactly sure how that works ether. I apologize for being such a noob :)

 

Edit: also you have

channelHandler = new ChannelHandler(ModCntManPack.MOD_ID, ModCntManPack.MOD_CHANNEL);

in a modConstruction(FMLConstructionEvent event) method i assume this is something to do with your mod being a core mod in my case would i just add 

new ChannelHandler(MOD_ID, MOD_CHANNEL); to  public static ChannelHandler channelHandler;?

 

Edit2: I think im starting to figure it out but one thing i dont understand is "sendToAll(IPacket message)"

 

Edit3: I think I have it figured out.

 

Edit4: IT WORKS!!! although i discovered something interesting. The onBlockActivated method is only called client side when playing multiplayer

 

Edit5: onBlockActivated dosnt run server side if the block is within the protected spawn area and the player activating it is not op!

 

Edit6: that's a lot of edits... well at least i didn't hex post.

I am the author of Draconic Evolution

Posted

If you wanna try a different approach on packet handling, look at this code:

https://github.com/SanAndreasP/SAPManagerPack/tree/master/java/de/sanandrew/core/manpack/mod/packet

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/de/sanandrew/core/manpack/mod/ModCntManPack.java

 

And simultaneously this tutorial I've based it off (I recode some stuff, since it was a bit messy IMO)

http://www.minecraftforge.net/wiki/Netty_Packet_Handling

 

I like this one.  It also seems pretty straight forward and actually takes a similar approach to what I was trying to do.

 

Since you're a much more expert coder than I, I assume that this already works in multiplayer as well?

 

Yes, works flawless for me.

 

@SanAndreasP

Im trying to figure out how to use your system but im a bit lost can you please show me an example of how to send and receive a packet?

Also i noticed you have a method in your proxy called "registerPackets" im not exactly sure how that works ether. I apologize for being such a noob :)

 

Edit: also you have

channelHandler = new ChannelHandler(ModCntManPack.MOD_ID, ModCntManPack.MOD_CHANNEL);

in a modConstruction(FMLConstructionEvent event) method i assume this is something to do with your mod being a core mod in my case would i just add 

new ChannelHandler(MOD_ID, MOD_CHANNEL); to  public static ChannelHandler channelHandler;?

 

Edit2: I think im starting to figure it out but one thing i dont understand is "sendToAll(IPacket message)"

 

Edit3: I think I have it figured out.

 

Edit4: IT WORKS!!! although i discovered something interesting. The onBlockActivated method is only called client side when playing multiplayer

 

Edit5: onBlockActivated dosnt run server side if the block is within the protected spawn area and the player activating it is not op!

 

Edit6: that's a lot of edits... well at least i didn't hex post.

 

There's an example packet class in the link. To send / receive packets, use something like this:

            IPacket packet = new PacketChangeBCGUI(3, this.teBiomeChanger.xCoord, this.teBiomeChanger.yCoord, this.teBiomeChanger.zCoord);
            ESPModRegistry.channelHandler.sendToServer(packet);

First instantiate the new Packet class with the parameters you wanna send, then just send it with your channelHandler.

 

1. I had some problems when I initialized directly on declaration, so you might wanna use the preInit for that. You can also use the modConstruction event like I did, it's fired also for normal mods.

5. I think this is a problem with MC directly, idk.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I am sending packets like this.

Tolkienaddon.channelHandler.sendToServer(new ButtonPacket((button.id, true));

ant it seems to be working perfectly what difference would it make if i use

IPacket packet = new ButtonPacket((button.id, true);
ESPModRegistry.channelHandler.sendToServer(packet);

I am the author of Draconic Evolution

Posted

It looks like you're making progress with SanAndreas' method.

 

In terms of my method, I have set up multiplayer in the dev environment and it fails with what I think is same error you saw:

[13:59:45] [server thread/ERROR] [net.minecraft.server.MinecraftServer]: Encountered an unexpected exception
java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient
at wildanimals.entities.herdanimals.EntityHerdAnimal.sendSyncPacket(EntityHerdAnimal.java:474) ~[EntityHerdAnimal.class:?]
at wildanimals.entities.herdanimals.EntityHerdAnimal.setRearing(EntityHerdAnimal.java:417) ~[EntityHerdAnimal.class:?]
at wildanimals.entities.herdanimals.EntityHerdAnimal.attackEntityFrom(EntityHerdAnimal.java:292) ~[EntityHerdAnimal.class:?]
at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1401) ~[EntityPlayer.class:?]
at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:873) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51) ~[C02PacketUseEntity.class:?]
at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69) ~[C02PacketUseEntity.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:720) ~[MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:341) ~[DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:608) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) [MinecraftServer$2.class:?]
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[?:1.7.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[?:1.7.0_51]
... 14 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/multiplayer/WorldClient for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) ~[forgeSrc-1.7.2-10.12.1.1071.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:276) ~[launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:174) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[?:1.7.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[?:1.7.0_51]

 

The weird thing is that, as far as I can understand, it seems to be a problem with the vanilla class WorldClient.  I'm not sure that we could have really mucked that up.  Seems like some bug.  I'll start a separate topic on that issue itself -- how could it fail to find the vanilla class?

 

Otherwise, it is possible it is issue with running multiplayer in development environment on same computer.  I think I'll try to see if I can get it running with exported mods on separate computers.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I am sending packets like this.

Tolkienaddon.channelHandler.sendToServer(new ButtonPacket((button.id, true));

ant it seems to be working perfectly what difference would it make if i use

IPacket packet = new ButtonPacket((button.id, true);
ESPModRegistry.channelHandler.sendToServer(packet);

 

I just like to seperate stuff. It's just a difference in coding style, not a functional one.

 

BTW: the registerPackets method in my proxies are deprecated. I didn't come around to remove them, so you can ignore those.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.