Skip to content

Commit

Permalink
Invert PlayerSyncPredicate#isSyncOptional
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Apr 19, 2024
1 parent 51c9c60 commit c623b54
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public interface ComponentContainer extends NbtSerializable {
*
* @param component the component of which to look up the key
* @return the found key, or {@code null} if the component is not part of this container
* @since 5.3.0
* @since 6.0.0
*/
@Nullable
@ApiStatus.Experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ public void syncWith(ServerPlayerEntity player, ComponentProvider provider, Comp
if (predicate.shouldSyncWith(player)) {
RegistryByteBuf buf = new RegistryByteBuf(Unpooled.buffer(), player.getServerWorld().getRegistryManager());
writer.writeSyncPacket(buf, player);
CustomPayload payload = provider.toComponentPacket(this, !predicate.isSyncOptional(), buf);
CustomPayload payload = provider.toComponentPacket(this, predicate.isRequiredOnClient(), buf);

if (payload != null) {
if (ServerPlayNetworking.canSend(player, payload.getId())) {
ServerPlayNetworking.getSender(player).sendPacket(payload, PacketCallbacks.always(buf::release));
} else {
if (!predicate.isSyncOptional()) {
if (predicate.isRequiredOnClient()) {
player.networkHandler.disconnect(Text.literal("This server requires Cardinal Components API (unhandled packet: " + payload.getId().id() + ")" + ComponentsInternals.getClientOptionalModAdvice()));
}
buf.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public interface PlayerSyncPredicate {
boolean shouldSyncWith(ServerPlayerEntity player);

/**
* If this method returns {@code true} and a client cannot handle a sync packet, the sync will be skipped.
* Otherwise, a sync update will disconnect the client.
* If this method returns {@code true} and a client cannot handle a sync packet, they will be disconnected.
* Otherwise, the sync will be skipped.
*/
default boolean isSyncOptional() {
return false;
default boolean isRequiredOnClient() {
return true;
}

static PlayerSyncPredicate all() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ public static void logDeserializationWarnings(Collection<String> missedKeyIds) {
}

public static @NotNull String getClientOptionalModAdvice() {
return FabricLoader.getInstance().isDevelopmentEnvironment() ? "\n§eDEV ADVICE: If your mod is supposed to be client-optional, try overriding isSyncOptional() in your component." : "";
return FabricLoader.getInstance().isDevelopmentEnvironment() ? "\n§eDEV ADVICE: If your mod is supposed to be client-optional, try overriding isRequiredOnClient() in your component." : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public WorldVita(World world) {
}

@Override
public boolean isSyncOptional() {
return true;
public boolean isRequiredOnClient() {
return false;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Updated to 1.20.5
This update introduces multiple breaking changes - a migration guide is available on [the Ladysnake website](https://ladysnake.org/wiki/cardinal-components-api/upgrade-instructions/CCA-6-changes).

**Additions**
- Added `C2SSelfMessagingComponent`, a new experimental utility interface to simplify client-to-server messaging on player components
- Added `WorldComponentRegistry#registerFor` methods, allowing for dimension-specific world components
- Scoreboard and team components now support client ticking

Expand Down

0 comments on commit c623b54

Please sign in to comment.