Jump to content

Recommended Posts

Posted

Okay, so, for whatever reason, the rotation on my block causes it to desync with the server when broken. I know it's the rotation, as I commented all of it out, ran it, and it was perfectly okay. Any ideas as to how to fix this? I've tried copying from the furnace class, extending the furnace class, following a tutorial on block rotations. All of it led to the same desyncing problem.

Code is right here:

 

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
1 minute ago, diesieben07 said:
  • Problematic code, issue 4, 5, 10, 14.
  • Do not use that "re-use the tile entity" hack that the vanilla furnace uses. Override TileEntity#shouldRefresh.
  • You are not retaining the BURNING property in metadata. You must serialize and deserialize all properties that are not stored elsewhere (and set via getActualState) in getMetaFromState resp. getStateFromMeta.

Except, in reference to 4 and 5, as well as 10, the tile entity isn't the issue. Nor is it the BURNING property. There exist 2 other tile entities, both of which work flawlessly, and act similarly, code-wise, to this one. It's the rotation that's screwing it up.

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
3 minutes ago, Daring Do said:

Except, in reference to 4 and 5, as well as 10, the tile entity isn't the issue. Nor is it the BURNING property. There exist 2 other tile entities, both of which work flawlessly, and act similarly, code-wise, to this one. It's the rotation that's screwing it up.

 

diesieben07 is being helpful by providing additional review to your code. Even though it may not be directly related to your reported problem, these are in fact problems. Note that sometimes when code is "unhealthy" it is not immediately clear there is a problem -- bugs can lurk without causing full crashes -- so you can't just say that it is fine because you think it is working elsewhere. For example, because you don't serialize the BURNING property your saves will be screwed up. diesieben07 took the time to write up that list of common problems for a reason -- many mods have had trouble due to them.

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

Posted (edited)
8 minutes ago, jabelar said:

 

diesieben07 is being helpful by providing additional review to your code. Even though it may not be directly related to your reported problem, these are in fact problems. Note that sometimes when code is "unhealthy" it is not immediately clear there is a problem -- bugs can lurk without causing full crashes -- so you can't just say that it is fine because you think it is working elsewhere. For example, because you don't serialize the BURNING property your saves will be screwed up. diesieben07 took the time to write up that list of common problems for a reason -- many mods have had trouble due to them.

Maybe so, but I came here looking for a solution to this problem specifically. If I find other problems later on, I'll come back here and debate on whether or not to rewrite 3 tile entities and blocks. I didn't finish the BURNING bit, as I haven't gotten the rotation issue functioning properly, which is my number one concern right now.

 

And while, yes, I do appreciate them trying to assist in a potential issue later down the line, I'd rather fix the one right in front of my face.

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
8 minutes ago, Daring Do said:

And while, yes, I do appreciate them trying to assist in a potential issue later down the line, I'd rather fix the one right in front of my face.

Did you even attempt to make the changes diesieben described, they could be somehow interfering with your blocks rotation.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
1 minute ago, Animefan8888 said:

Did you even attempt to make the changes diesieben described, they could be somehow interfering with your blocks rotation.

It would take me a few hours to make all of those changes to one of them, and test it to make sure it didn't break anything at all, especially in the case of one of them, which has been problematic from the beginning up until recently, but I'm fairly certain that they wouldn't affect the desynchronization between the server and the client when the block has the ability to rotate.

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)
12 minutes ago, Daring Do said:

It would take me a few hours to make all of those changes to one of them, and test it to make sure it didn't break anything at all, especially in the case of one of them, which has been problematic from the beginning up until recently, but I'm fairly certain that they wouldn't affect the desynchronization between the server and the client when the block has the ability to rotate.

Problem 4 takes like 30 seconds to do as well as problem 10(setUnlocalizedName(getRegistryName().toString)) and 14. 5 Might take upwards of 4 to 5 minutes. To apply to one Block/TileEntity. As long as you know what you are doing.While you say that your problem is with the rotation, I can't understand how simply having a rotation causes the server to desync from the client when the block is broken. So what you should do is step through your code in your IDE's debugger.

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
4 minutes ago, Animefan8888 said:

Problem 4 takes like 30 seconds to do as well as problem 10(setUnlocalizedName(getRegistryName().toString)) and 14. 5 Might take upwards of 4 to 5 minutes. To apply to one Block/TileEntity. As long as you know what you are doing.While you say that your problem is with the rotation, I can't understand how simply having a rotation causes the server to desync from the client when the block is broken. So what you should do is step through your code in your IDE's debugger.

See, the thing is... I don't know why either, hence why I'm here. I tried everything I know how to do, and it just does. And again, I said "few hours to make all of those changes to one of them, and test it to make sure it didn't break anything at all". There's more than just changing things, I want to make sure everything works under every condition in which it should work. I don't want to end up releasing a bug-riddled mod, after patching so many since the last release.

 

Unless there's irrefutable proof that those steps would fix this whole problem, I don't want to spend the time messing with it at the moment. That, or have proof that it's related to this problem.

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)

You don't need to test any of the fixes from problems 10 and 14. 4 takes literally 30 seconds to fix and test: all you're doing is overriding a different method and removing the implements/extends.  Fix 5 is the only one that takes more than token effort.

 

You can do 4, 10, and 14 pretty much all in one go.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You know what? Fuck it. I've been here before, I've only ever gotten shit, and only once ever gotten assistance with the problem I've been having. I'm this close to just saying fuck it to the rotation, and changing the model all together so that rotation isn't an issue. Unlike this shitshow, MDC and MMD both at least try and help with the problems you're currently trying to solve, not point out other ones that you might have, that aren't causing any problems in the current.

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted

These are problems you are likely to come back with, and sometimes fixing issues you didn't know you had ends up fixing the issue you were focusing on.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Posted (edited)
9 minutes ago, diesieben07 said:

Did you even read my post to the end? My last point is the actual problem.

If you really do not care about fixing these common problems: Just fix this actual problem.

 

11 minutes ago, DaemonUmbra said:

These are problems you are likely to come back with, and sometimes fixing issues you didn't know you had ends up fixing the issue you were focusing on.

Thank you for the help. I'd like to apologise for my partner's behavior. Can you explain why you'd recommend the aforementioned changes?

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)
26 minutes ago, ModMCdl said:

Can you explain why you'd recommend the aforementioned changes?

Problem #4:

ITileEntityProvider is outdated, still using numeric metadata as a paramter, rather than a fully defined IBlockState

For BlockContainer, it will cause issues, as BlockContainer overrides several methods of the block class that it is very unlikely that you actually want to override, such as what model type your block uses. 90% of TileEntity blocks do not need a TESR, but BlockContainer sets the default model type to INVISIBLE in preparation for a TESR.

 

Problem #5:

IInventory is deprecated in favor of more flexible and inter-mod compatible Capabilities.

 

Problem #10:

Quote

TileEntity registration names and enum entries added using EnumHelper should contain your ModID to avoid collisions between mods.

 

Problem #14:

You cannot control the order of execution when dealing with static initializers. As a result you can have objects created before the other objects they depend on (e.g. a CreativeTab that gets created with a null item icon, or an item that gets a null creative tab).

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
18 minutes ago, ModMCdl said:

Thank you for the help. I'd like to apologise for my partner's behavior. Can you explain why you'd recommend the aforementioned changes?

I can answer this question in their steed if you don't mind.

  • 4 " These classes are legacy vanilla code. " Old unnecessary code. just override hasTileEntity(IBlockState) and createTileEntity(World, IBlockState).
  • 5 Intermod compatibility. IInventory is provided by Minecraft and Forge has provided a system that works much better. The old system has been shipped away since the capability system was first introduced.
  • 10 They can conflict with other mods, however a modid is unique to your mod(hopefully), thus removing the conflict. A good strategy would be to set unlocalized names to the registry name.
  • 14 Static initializers are immpossible to control. You do not know when they are initialized, so therefore forge cannot assign the modid for the registry correctly. There are also other reasons for using the event system, but there are too many and I don't want to type them out.
  • 1 hour ago, Daring Do said:

    Do not use that "re-use the tile entity" hack that the vanilla furnace uses. Override TileEntity#shouldRefresh.

    Less code and uses a method in the TileEntity instead of some method in the Block class.

  • 1 hour ago, Daring Do said:

    You are not retaining the BURNING property in metadata. You must serialize and deserialize all properties that are not stored elsewhere (and set via getActualState) in getMetaFromState resp. getStateFromMeta.

    Self explanatory, but it saves and loads the blocks metadata/blockstate correctly.

Now on to your problem with the de-syncing. If you remove onBlockAdded and onBlockPlacedBy it will fix your issue.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Okay.... so yes, I was wrong, but now clicking on the block causes you to hard crash. I got upset, and I apologize. I really shouldn't have. I just _really_ hate having to make changes like this to blocks with tile entities, as normally they just break entirely, which this moment kind of reinforced just then.

 

Other than the IItemHandler bit and the changing of the BURNING variable (which I wasn't done with, I was just trying to solve this problem first), I've done all that was in there. Reason for not doing the IItemHandler bit is because I don't understand jackshit when it comes to that. I work better with seeing examples, tearing them down, and analyzing them. It's entirely possible that's the reason it's crashing, but I have no idea how to fix it (and yes, I did read the information provided on it, it only left me more confused). I've gone ahead and updated the code, but I have to go for the night.

 

Again, I'm really sorry for lashing out like I had..

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted

Here's an example of an ItemStackHandler in use:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/ores/entities/TileEntitySifter.java

 

the outputslotwrapper is used for the GUI so that the player can't insert items into the output slot (but the machine can still do so when it generates its output). Predominantly you will want to look at getCapability.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
12 minutes ago, Daring Do said:

I've gone ahead and updated the code

Github hasn't changed except for setState and the implementations being changed.

shouldRefresh should compare the two IBlockStates parameters past in and return a value from that. aka if the blocks are not the same.

12 minutes ago, Daring Do said:

but now clicking on the block causes you to hard crash

Override hasTileEntity(IBlockState) instead of hasTileEntity()

12 minutes ago, Daring Do said:

but I have to go for the night.

Have a good night.

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • 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() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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