Skip to content

Commit

Permalink
Bump MaLiLib / Litematica
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Feb 3, 2025
1 parent b64d520 commit 2296a6a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 36 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ mod_name = Syncmatica
mod_file_name = syncmatica-fabric

# Mod Version
mod_version = 0.3.13-sakura.3
mod_version = 0.3.13-sakura.4

# Dependencies (malilib, litematica)
#malilib_fileid=4946328
#litematica_fileid=4946471
malilib_version = 1.21.4-0.23.2-sakura.2
litematica_version = 1.21.4-0.21.2-sakura.1
malilib_version = 1.21.4-0.23.2-sakura.3
litematica_version = 1.21.4-0.21.2-sakura.2

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21.4
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/ch/endte/syncmatica/Feature.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.endte.syncmatica;

public enum Feature {
public enum Feature
{
CORE, // every feature that's part of 0.1.0 - it doesn't make sense to divide those further since compatibility with 0.0 of future versions
// cannot be maintained and the version is very alpha.
FEATURE, // the possibility of reporting on ones own features during version exchange
Expand All @@ -11,9 +12,12 @@ public enum Feature {
CORE_EX, // extended basic features - such as who owns a placement and subregion sharing
VERSION; // extended version metadata

public static Feature fromString(final String s) {
for (final Feature f : Feature.values()) {
if (f.toString().equals(s)) {
public static Feature fromString(final String s)
{
for (final Feature f : Feature.values())
{
if (f.toString().equals(s))
{
return f;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@Mixin(ClientCommonNetworkHandler.class)
public class MixinClientCommonNetworkHandler
{
// This exists because of the Communications Manager / Exchange Target system,
// and FAPI networking is too slow to register the receivers
@Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"), cancellable = true)
private void syncmatica$handlePacket(CustomPayloadS2CPacket packet, CallbackInfo ci)
{
Expand All @@ -34,7 +36,6 @@ public class MixinClientCommonNetworkHandler
// Cancel unnecessary processing if a PacketType we own is caught
if (ci.isCancellable())
ci.cancel();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public abstract class MixinClientPlayNetworkHandler implements IClientPlay
@Unique
private ClientCommunicationManager comManager = null;

// This exists because of the Communications Manager / Exchange Target system,
// and FAPI networking is too slow to register the receivers
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void syncmatica$handlePacket(CustomPayload packet, CallbackInfo ci)
{
Expand All @@ -42,7 +44,6 @@ public abstract class MixinClientPlayNetworkHandler implements IClientPlay
// Cancel unnecessary processing if a PacketType we own is caught
if (ci.isCancellable())
ci.cancel();

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@Mixin(ServerCommonNetworkHandler.class)
public class MixinServerCommonNetworkHandler
{
// This exists because of the Communications Manager / Exchange Target system,
// and FAPI networking is too slow to register the receivers
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void syncmatica$handlePacket(CustomPayloadC2SPacket packet, CallbackInfo ci)
{
Expand All @@ -30,7 +32,6 @@ public class MixinServerCommonNetworkHandler
// Cancel unnecessary processing if a PacketType we own is caught
if (ci.isCancellable())
ci.cancel();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public abstract class MixinServerPlayNetworkHandler implements IServerPlay
syncmatica$operateComms(sm -> sm.onPlayerLeave(syncmatica$getExchangeTarget()));
}

// This exists because of the Communications Manager / Exchange Target system,
// and FAPI networking is too slow to register the receivers
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void syncmatica$onCustomPayload(CustomPayloadC2SPacket packet, CallbackInfo ci)
{
Expand All @@ -59,7 +61,6 @@ public abstract class MixinServerPlayNetworkHandler implements IServerPlay
// Cancel unnecessary processing if a PacketType we own is caught
if (ci.isCancellable())
ci.cancel();

}
}

Expand Down
49 changes: 26 additions & 23 deletions src/main/java/ch/endte/syncmatica/network/PacketType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,90 @@

public enum PacketType
{
REGISTER_METADATA("syncmatica","register_metadata"),
REGISTER_METADATA("syncmatica", "register_metadata"),
// one packet will be responsible for sending the entire metadata of a syncmatic
// it marks the creation of a syncmatic - for now it also is responsible
// for changing the syncmatic server and client side

CANCEL_SHARE("syncmatica","cancel_share"),
CANCEL_SHARE("syncmatica", "cancel_share"),
// send to a client when a share failed,
// the client can cancel the upload or upon finishing send a removal packet

REQUEST_LITEMATIC("syncmatica","request_download"),
REQUEST_LITEMATIC("syncmatica", "request_download"),
// another group of packets will be responsible for downloading the entire
// litematic starting with a download request

SEND_LITEMATIC("syncmatica","send_litematic"),
SEND_LITEMATIC("syncmatica", "send_litematic"),
// a packet responsible for sending a bit of a litematic (16 kilobytes to be precise (half of what minecraft can send in one packet at most))

RECEIVED_LITEMATIC("syncmatica","received_litematic"),
RECEIVED_LITEMATIC("syncmatica", "received_litematic"),
// a packet responsible for triggering another send for a litematic
// by waiting until a response is sent I hope we can ensure
// that we do not overwhelm the clients' connection to the server

FINISHED_LITEMATIC("syncmatica","finished_litematic"),
FINISHED_LITEMATIC("syncmatica", "finished_litematic"),
// a packet responsible for marking the end of a litematic
// transmission

CANCEL_LITEMATIC("syncmatica","cancel_litematic"),
CANCEL_LITEMATIC("syncmatica", "cancel_litematic"),
// a packet responsible for cancelling an ongoing upload/download
// will be sent in several cases - upon errors mostly

REMOVE_SYNCMATIC("syncmatica","remove_syncmatic"),
REMOVE_SYNCMATIC("syncmatica", "remove_syncmatic"),
// a packet that will be sent to clients when a syncmatic got removed
// send to the server by a client if a specific client intends to remove a litematic from the server

REGISTER_VERSION("syncmatica","register_version"),
REGISTER_VERSION("syncmatica", "register_version"),
// this packet will be sent to the client when it joins the server
// upon receiving this packet the client will check the server version
// initializes syncmatica on the clients end
// if it can function with the version on the server then it will respond with a version of its own
// if the server can handle the client version the server will send

CONFIRM_USER("syncmatica","confirm_user"),
CONFIRM_USER("syncmatica", "confirm_user"),
// the confirm-user packet
// send after a successful version exchange
// fully starts up syncmatica on the clients end
// sends all server placements along to the client

FEATURE_REQUEST("syncmatica","feature_request"),
FEATURE_REQUEST("syncmatica", "feature_request"),
// requests the partner to send a list of its features
// does not require a fully finished handshake

FEATURE("syncmatica","feature"),
FEATURE("syncmatica", "feature"),
// sends feature set to the partner
// send during a version exchange to check if the 2 versions are compatible, and there is no
// default feature set available for the transmitted version
// afterwards the feature set is used to communicate to the partner

MODIFY("syncmatica","modify"),
MODIFY("syncmatica", "modify"),
// sends updated placement data to the client or vice versa

MODIFY_REQUEST("syncmatica","modify_request"),
MODIFY_REQUEST("syncmatica", "modify_request"),
// send from client to server to request the editing of placement values
// used to ensure that only one person can edit at a time thus preventing all kinds of stuff

MODIFY_REQUEST_DENY("syncmatica","modify_request_deny"),
MODIFY_REQUEST_ACCEPT("syncmatica","modify_request_accept"),
MODIFY_REQUEST_DENY("syncmatica", "modify_request_deny"),
MODIFY_REQUEST_ACCEPT("syncmatica", "modify_request_accept"),

MODIFY_FINISH("syncmatica","modify_finish"),
MODIFY_FINISH("syncmatica", "modify_finish"),
// send from client to server to mark that the editing of placement values has concluded
// sends along the final data of the placement

MESSAGE("syncmatica","mesage");
MESSAGE("syncmatica", "mesage");
// sends a message from client to server - allows for future compatibility
// can't fix the typo here lol

public final Identifier identifier;

PacketType(final String id, final String channel) { identifier = Identifier.of(id, channel); }
PacketType(final String id, final String channel) {identifier = Identifier.of(id, channel);}

public static boolean containsIdentifier(final Identifier id) {
for (final PacketType p : PacketType.values()) {
if (id.equals(p.identifier)) { // this took I kid you not 4-5 hours to find
public static boolean containsIdentifier(final Identifier id)
{
for (final PacketType p : PacketType.values())
{
if (id.equals(p.identifier))
{ // this took I kid you not 4-5 hours to find
return true;
}
}
Expand Down Expand Up @@ -115,5 +118,5 @@ public static PacketType getType(final Identifier id)
return null;
}

public Identifier getId() { return this.identifier; }
public Identifier getId() {return this.identifier;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.annotation.Nonnull;
import ch.endte.syncmatica.network.SyncmaticaPacket;
import ch.endte.syncmatica.network.actor.ActorClientPlayHandler;

import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -44,9 +45,12 @@ public static void receiveSyncPayload(@Nonnull SyncmaticaPacket data)
public static void receiveSyncPayload(SyncmaticaPacket.Payload payload, ClientPlayNetworking.Context context)
{
// Has threading issues ?
if (context.client().getNetworkHandler() != null) {
if (context.client().getNetworkHandler() != null)
{
decodeSyncData(payload.data(), context.client().getNetworkHandler());
} else {
}
else
{
decodeSyncData(payload.data(), MinecraftClient.getInstance().getNetworkHandler());
}
}
Expand All @@ -62,6 +66,7 @@ public static <T extends CustomPayload> void sendSyncPacket(@Nonnull T payload)
public static <T extends CustomPayload> void sendSyncPacket(@Nonnull T payload, @Nonnull ClientPlayNetworkHandler handler)
{
Packet<?> packet = new CustomPayloadC2SPacket(payload);

if (handler.accepts(packet))
{
handler.sendPacket(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class ServerPlayHandler
public static void decodeSyncData(@Nonnull SyncmaticaPacket data, @Nonnull ServerPlayNetworkHandler handler)
{
IServerPlay iDo = ((IServerPlay) handler);

iDo.syncmatica$operateComms(sm -> sm.onPacket(iDo.syncmatica$getExchangeTarget(), data.getType(), data.getPacket()));
}

Expand Down Expand Up @@ -52,6 +53,7 @@ public static <T extends CustomPayload> void sendSyncPacket(@Nonnull T payload,
public static <T extends CustomPayload> void sendSyncPacket(@Nonnull T payload, @Nonnull ServerPlayNetworkHandler handler)
{
Packet<?> packet = new CustomPayloadS2CPacket(payload);

if (handler.accepts(packet))
{
handler.sendPacket(packet);
Expand Down

0 comments on commit 2296a6a

Please sign in to comment.