-
Notifications
You must be signed in to change notification settings - Fork 19
SyncData Type Support
Mikerooni edited this page Dec 30, 2023
·
1 revision
Here we list all the classes with built-in support and how to add support to a class.
-
Primitive
:int
,boolean
,Integer
,String
, ... Enum
NBT
FriendlyBuf
UUID
ResourceLocation
Component
Recipe
ItemStack
-
FluidStack
(ldlib) BlockPos
Size
Position
IGuiTexture
-
Array
: T[] value.... (if T is support) -
Collection
: Set, List.... (if T is support) -
ITagSerializable
: if class inherits fromITagSerializable
it can also be synced/persisted but it should be afinal
field. -
IManaged
: if class inherits fromIManaged
it can also be synced/persisted but it should be afinal
field. Besides, syndata annotations in Imanaged can also be handled.
The easiest way add support for a new class is to create an Accessor
.
public class GTRecipeAccessor extends CustomObjectAccessor<GTRecipe> {
public GTRecipeAccessor() {
super(GTRecipe.class, true); // field class, whether this accessor is available for its children class
}
@Override
public ITypedPayload<?> serialize(AccessorOp accessorOp, GTRecipe gtRecipe) {
FriendlyByteBuf serializedHolder = new FriendlyByteBuf(Unpooled.buffer());
serializedHolder.writeUtf(gtRecipe.id.toString());
GTRecipeSerializer.SERIALIZER.toNetwork(serializedHolder, gtRecipe);
return FriendlyBufPayload.of(serializedHolder);
}
@Override
public GTRecipe deserialize(AccessorOp accessorOp, ITypedPayload<?> payload) {
if (payload instanceof FriendlyBufPayload buffer) {
var id = new ResourceLocation(buffer.getPayload().readUtf());
return GTRecipeSerializer.SERIALIZER.fromNetwork(id, buffer.getPayload());
}
return null;
}
}
register accessors
TypedPayloadRegistries.register(Class<T> clazz, Supplier<T> factory, IAccessor accessor, int priority)
-
clazz
: payload class, Generally speaking, it is the same as the payload used in the accessor. The payload here is persisted only. You can use different payloads in the accessor and check for the correct type. -
factory
: payload instance -
accessor
: accessor -
priority
: priority (if this field can be handled by multi accessors)
Forge:
@LDLibPlugin
public class LDLibPlugin implements ILDLibPlugin {
@Override
public void onLoad() {
// in ldlib plugin
register(FriendlyBufPayload.class, FriendlyBufPayload::new, new GTRecipeAccessor(), 1000);
}
}
Fabric: add an entrypoints:
"entrypoints": {
"ldlib_pugin": [
"com.gregtechceu.gtceu.integration.ldlib.fabric.LDLibPlugin"
],
}
public class LDLibPlugin implements ILDLibPlugin {
@Override
public void onLoad() {
// in ldlib plugin
register(FriendlyBufPayload.class, FriendlyBufPayload::new, new GTRecipeAccessor(), 1000);
}
}
1. Home
Compass
SyncData
UI Editor Basic Tutorial
- Tutorial 1: Start
- Tutorial 2: Basic Interaction
- Tutorial 3: Resources