Necesse

Necesse

Not enough ratings
CustomDataLib
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
42.107 KB
23 Aug, 2023 @ 7:12am
24 Mar @ 9:05am
17 Change Notes ( view )

Subscribe to download
CustomDataLib

Description
THIS LIBRARY MOD HAS REPLACED CustomPlayerLib AND YOU SHOULD NOT USE THAT LIBRARY AS IT IS OUTDATED AND BROKEN.


Base implementation for custom player data.
This is a library and doesn't add any functionality itself.

Docs available here[jubiman.github.io].

Credits
Huge credit to darkluke1111 on discord for pointing out previous issues with the library and helping me fix them. As well as brainstorming with me on how to make the library better. And generally reviewing my code and suggesting some improvements.
Credit for the CustomMob idea goes to real_thunderbear on discord as they needed it. I just added it to the library for ease of use for anyone in the future.

For Developers
Example mod using this library:
To be added

Make sure to modify your build.gradle file:
  • Add to dependencies:
    compileOnly "com.jubiman:customdatalib:1.+"
  • Add top level:
    project.ext.modDependencies = ["com.jubiman.customdatalib"]
  • If gradle can't resolve the package, add to the repositories (it should find it as it is in the Maven Central repository):

Using the library
First off I recommend reading the documentation here[jubiman.github.io]

Custom Player Data
This is mostly the same as the original CustomPlayerLib.
First you want to create a CustomPlayer class, which has a constructor with a long as argument.
All code fragments can be found in the example[github.com]
public class MyPlayer extends CustomPlayer { public MyPlayer(long auth) { super(auth); } }
Source[github.com]

Then create a CustomPlayersHandler class, which does the logic for all players in the game.
public class MyPlayersHandler extends CustomPlayersHandler<MyPlayer> { // It's recommended to store the name in a static constant, so you can easily access it public static final String name = "myplayers"; public MyPlayersHandler() { super(MyPlayer.class, name); } // These methods are not necessary, but they are recommended. /** * This replaces CustomPlayerRegistry.get(MyPlayers.name).get(auth) * with MyPlayers.getPlayer(auth). * It's just less code to write :) */ public static MyPlayersHandler getInstance() { return (MyPlayersHandler) CustomPlayerRegistry.INSTANCE.get(name); } /** * A null safe way to get a player from the map, adds player if they don't exist yet * @param auth the authentication of the player's ServerClient * @return the MyPlayer object belonging to the player */ public static MyPlayer getPlayer(long auth) { return getInstance().get(auth); } }
Source[github.com]

Then at last we need to register the classes by adding the following line to your mod's (annotated with @ModEntry) init() function:

New modular system
Instead of extending a different base class like CustomPlayerTickable, you can implement one or many of the different interfaces. Currently supported are: ClientTickable, Syncable, Savable and HUDDrawable.
All CustomData classes are tickable from the server-side, but by defining it as ClientTickable it will also be ticked on the client-side.
Please note that ClientTickable and Syncable require extra steps in order to properly function

ClientTickable
Currently only CustomPlayers are supported, as I do not see the need for client-side mob ticking.
This interface should mainly be used to cache values on the client-side which could be used by the HUDDrawable interface. Most of the times you can ignore this interface.
Please keep in mind that currently, only CustomPlayers are supported.

Syncable
The Syncable interface requires you to create a new packet: PacketMyPlayerSync (or whaterver your custom player naming is).
A new instance of this packet will be created in the getSyncPacket() class you implement from the Syncable interface.
The isContinuousSync() function should usually return false, as this will only sync once when the player connects. If this is set to true, the sync packet will be sent every second.
An example of the custom packet:
public class PacketSyncPlayer extends Packet {
1 Comments
Save 29 Dec, 2024 @ 12:54pm 
Outdated