Jump to content

[1.13.2] Weird Mod Crashing Phenomenon [STILL NOT SOLVED!!]


Recommended Posts

Posted (edited)

Ok so basically I opened my mod yesterday and (it was working fine the previous day) and my game crashes.

https://pastebin.com/raw/GEbhDj46 <--Crash file

 

From this I can see that 

"net.minecraft.util.ResourceLocationException: Non [a-z0-9_.-] character in namespace of location: .DS_Store:sounds.json" is the problem.

I've searched around my mods folder and even Reinstalled the mdk and imported my src folder over and it still crashes. So from this I know it is my mod and not forge.

 

[22:01:10.925] [Client thread/DEBUG] [ne.mi.fm.pa.ResourcePackLoader/CORE]: Generating PackInfo named mod:yrim for mod file /Users/nathandesouza/Desktop/mood/RandomItems 1.13.219/forge-1.13.2-25.0.219-mdk/bin/main
[22:01:10.930] [Client thread/DEBUG] [ne.mi.fm.pa.ResourcePackLoader/CORE]: Generating PackInfo named mod:forge for mod file /Users/nathandesouza/.gradle/caches/forge_gradle/minecraft_user_repo/net/minecraftforge/forge/1.13.2-25.0.219_mapped_snapshot_20180921-1.13/forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar
[22:01:10.934] [Client thread/INFO] [minecraft/SimpleReloadableResourceManager]: Reloading ResourceManager: forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar, main, Default
[22:01:11.085] [Client thread/WARN] [minecraft/Locale]: Skipped language file: .DS_Store:lang/en_us.json (net.minecraft.util.ResourceLocationException: Non [a-z0-9_.-] character in namespace of location: .DS_Store:lang/en_us.json)
[22:01:12.347] [Client thread/INFO] [STDOUT/]: [net.minecraft.init.Bootstrap:printToSYSOUT:467]: ---- Minecraft Crash Report ----
// There are four lights!

 

^ This is my console just before the crash report starts.

Any help is appreciated i've been trying for over 4 hours now.

 

UPDATE:

 

OK something weird is going on. My mod doesnt crash if I remove the 'assets' folder (src/main/resources/assets/). So i took everything out of my assets folder to try and narrow the cause down AND IT CRASHES. An empty assets folder crashes my game? My game runs fine if I DELETE the assets folder. But as soon as i put it back in it crashes again with the same error? The assets folder is EMPTY, I REPEAT THE ASSETS FOLDER IS EMPTY!!

 

Any suggestions are welcome!

Thanks! :D

Edited by Ywes
Posted
Quote

I  would try to remove the en_us.json

 

Like i said before, I have removed everything in my assets folder (including the language file).

Posted
3 minutes ago, Ywes said:

 

Like i said before, I have removed everything in my assets folder (including the language file).

sorry didn't read it quite fully
 

did you try to create the assets folder new and not just undo the deleted folder ... i could imagine that you have a hidden file in your previous assets folder

Posted (edited)

Indeed I have deleted and created a new folder. And still nothing.

 

Edit:

Might add that i have hidden folders turned on

Edited by Ywes
Posted

Not that im aware. Like i said I did a fresh install of the lastest mdk.

 

Also would you know where the sound.json file would be kept in the mdk folder?

Posted

But why is it doing it now? It has never happened before and ive been modding since 1.7.10 on this macOSX. Have you ever encountered a problem like this? I know you're like an expert at modding.

Posted
7 hours ago, Ywes said:

But why is it doing it now?

.DS_Store files are files that store the hierarchy of a directory as well as the information of the files in it; this provides constant time complexity when searching the hard disk for certain file via spotlight.

However, they can be very annoying to deal with sometimes.

To remove it, simply cd into the directory and rm -rf .DS_Store.

 

The log you posted only shows the warning, which should not cause a crash.

Please post the crash log so we could figure out what really is crashing.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
49 minutes ago, DavidM said:

To remove it, simply cd into the directory and rm -rf .DS_Store.

 

Ok so i tried this and too be completely honest i dont know if it worked. See the thing is apple hides .DS_STORE files in the newest update, even if you have hidden files on.

 

51 minutes ago, DavidM said:

The log you posted only shows the warning, which should not cause a crash.

Please post the crash log so we could figure out what really is crashing.

 

I already posted my crash report in my main post but here is my latest anyway.

Spoiler

---- Minecraft Crash Report ----
// Everything's going to plan. No, really, that was supposed to happen.

Time: 31/05/19 8:55 AM
Description: Initializing game

net.minecraft.util.ResourceLocationException: Non [a-z0-9_.-] character in namespace of location: .DS_Store:sounds.json
	at net.minecraft.util.ResourceLocation.<init>(SourceFile:35) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.util.ResourceLocation.<init>(SourceFile:47) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.audio.SoundHandler.onResourceManagerReload(SoundHandler.java:70) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.resources.SimpleReloadableResourceManager.addReloadListener(SimpleReloadableResourceManager.java:114) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.init(Minecraft.java:423) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:345) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:accesstransformer:B,pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(SourceFile:144) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {pl:object_holder_definalize:A,pl:runtime_enum_extender:A,pl:capability_inject_definalize:A,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:19) [modlauncher-2.1.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:32) [modlauncher-2.1.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50) [modlauncher-2.1.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:59) [modlauncher-2.1.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:44) [modlauncher-2.1.1.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:98) [forge-1.13.2-25.0.219_mapped_snapshot_20180921-1.13.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.util.ResourceLocation.<init>(SourceFile:35)
	at net.minecraft.util.ResourceLocation.<init>(SourceFile:47)
	at net.minecraft.client.audio.SoundHandler.onResourceManagerReload(SoundHandler.java:70)
	at net.minecraft.resources.SimpleReloadableResourceManager.addReloadListener(SimpleReloadableResourceManager.java:114)
	at net.minecraft.client.Minecraft.init(Minecraft.java:423)

-- Initialization --
Details:
Stacktrace:
	at net.minecraft.client.Minecraft.run(Minecraft.java:345)
	at net.minecraft.client.main.Main.main(SourceFile:144)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:19)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:32)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:59)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:44)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:98)

-- System Details --
Details:
	Minecraft Version: 1.13.2
	Operating System: Mac OS X (x86_64) version 10.14.5
	Java Version: 1.8.0_211, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 236591344 bytes (225 MB) / 530579456 bytes (506 MB) up to 954728448 bytes (910 MB)
	JVM Flags: 1 total; -Xss1M
	FML: New FML!
	Loaded coremods (and transformers): Nothing
	Launched Version: MOD_DEV
	LWJGL: 3.1.6 build 14
	OpenGL: Intel HD Graphics 4000 OpenGL Engine GL version 2.1 INTEL-12.9.22, Intel Inc.
	GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because ARB_framebuffer_object is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'forge'
	Type: Client (map_client.txt)
	Resource Packs: 
	Current Language: English (US)
	Profiler Position: N/A (disabled)
	CPU: 4x Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz

 

 

Thank you!

Posted (edited)

Running ls -ld .* would show all hidden files in the current directory. You could use that to test for .DS_Store.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

Ok i deleted the .DS_STORE files but to no avail. But i discovered something very interesting. 

So basically I redid my entire assets folder except this time i made them in eclipse instead of creating folders and it worked (without any files).

But as soon as i moved my files (the .lang and json ect) it crashed again with the same error. 

So i redid the whole assets package again and i made the .jsons and .lang files inside eclipse itself and it worked, no more crashing. UNTIL i refreshed my wrokspace and now its crashing again.

Do you have any idea whats going on?

Posted
4 hours ago, Ywes said:

Ok i deleted the .DS_STORE files but to no avail. But i discovered something very interesting. 

So basically I redid my entire assets folder except this time i made them in eclipse instead of creating folders and it worked (without any files).

But as soon as i moved my files (the .lang and json ect) it crashed again with the same error. 

So i redid the whole assets package again and i made the .jsons and .lang files inside eclipse itself and it worked, no more crashing. UNTIL i refreshed my wrokspace and now its crashing again.

Do you have any idea whats going on?

Yes. .DS_Store updates every time a file/sub directory name changes, a file/sub directory is added/deleted, or a file is edited.

When you create a folder or file in eclipse, it seems that the action will not trigger a .DS_Store update.

Creating a folder via Finder will cause an update.

 

There is probably a way to disable the generation of DSstore via a command, but I don’t know it. Try google it up.

 

2 hours ago, diesieben07 said:

Jesus lord. It's as if they make their OS more unusable with every update.

Apple do patronize its user. To illustrate, you cannot create a new text file in Mac OS via right click because Apple thinks “adding the option to create an empty text file might confuse the user; they should use tools they are working with, like Pages or Keynote, to create new files”.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

  • 4 months later...
Posted
On 5/31/2019 at 3:19 AM, DavidM said:

Yes. .DS_Store updates every time a file/sub directory name changes, a file/sub directory is added/deleted, or a file is edited.

When you create a folder or file in eclipse, it seems that the action will not trigger a .DS_Store update.

Creating a folder via Finder will cause an update.

 

There is probably a way to disable the generation of DSstore via a command, but I don’t know it. Try google it up.

 

Apple do patronize its user. To illustrate, you cannot create a new text file in Mac OS via right click because Apple thinks “adding the option to create an empty text file might confuse the user; they should use tools they are working with, like Pages or Keynote, to create new files”.

I also have a problem with this, even though this may be a little back I wish I could get some assistance.

net.minecraft.util.ResourceLocationException: Non [a-z0-9_.-] character in namespace of location: .DS_Store:sounds.json

Posted
15 hours ago, diesieben07 said:

Go ask google on how to disable those hideous stupid files.

I did disable them from being created, yet I don't know how to remove it entirely.

[P.S] Does it have to do with anything alongside my code or just that one thing?

  • 2 months later...
Posted

I run this command before running the ./gradle build or if I have made name changes outside of the Eclipse environment.

 

find . -name '.DS_Store' -type f -delete

 

It clears out any pesky .DS_Store files out of my eclipse folder

 

 

Posted (edited)
On 1/5/2020 at 10:32 AM, kwpugh said:

find . -name '.DS_Store' -type f -delete

This is also the solution I found.

Please note this only occurs for Eclipse, IntelliJ has no such problem.

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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

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

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

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

  • 4 months later...
Posted

Here is my answer. I am also a mac user with the same issue. The problem is that OSX puts .DS_STORE in the run files, crashing the game.

1. Duplicate the mod folder. This will make code editors think you are on a different project.

2. Delete the "runs" folder. This will make IntelliJ (or any code editor, like eclipse) forget about the DS_STORE files.

Posted
On 1/4/2020 at 12:21 AM, Max801 said:

I have this same problem even when using 1.14.4. Has anyone found a solution?

Yes, Duplicate the MDK folder and delete the runs from the duplicate. The .DS_STORE file will be gone. Run the duplicate.

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.