Skip to content

Commit

Permalink
fix: using functional interface magic to fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlige committed Nov 27, 2024
1 parent a1fd20b commit eeef142
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
22 changes: 18 additions & 4 deletions src/client/java/com/github/zhenlige/xennote/XennoteClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.zhenlige.xennote;

import com.github.zhenlige.xennote.payload.BlockTuningPayload;
import com.github.zhenlige.xennote.payload.ClientInitPayload;
import com.github.zhenlige.xennote.payload.UpdateTuningPayload;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
Expand All @@ -11,19 +13,31 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import org.apache.commons.lang3.math.Fraction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import static com.github.zhenlige.xennote.XennoteMath.pOf;
import static com.github.zhenlige.xennote.XennoteMath.qOf;

public class XennoteClient implements ClientModInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger(Xennote.MOD_ID + " client");
//private static final Logger LOGGER = LoggerFactory.getLogger(Xennote.MOD_ID + " client");
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
ClientPlayNetworking.registerGlobalReceiver(BlockTuningPayload.ID, XennoteClient::blockConfig);
WorldTunings.initializeClient();
WorldTunings.initializeClient(setCurrent -> {
ClientPlayNetworking.registerGlobalReceiver(UpdateTuningPayload.ID, (payload, context) -> {
if (payload.tuning().isEmpty()) {
WorldTunings.getCurrent().tunings.remove(payload.tuningId());
} else {
WorldTunings.getCurrent().tunings.put(payload.tuningId(), payload.tuning().get());
}
});
ClientPlayNetworking.registerGlobalReceiver(ClientInitPayload.ID, (payload, context) ->
setCurrent.apply(new WorldTunings(payload.tuningMap()))
);
return null;
});
}
private static void blockConfig(BlockTuningPayload payload, ClientPlayNetworking.Context context) {
MinecraftClient client = context.client();
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/github/zhenlige/xennote/WorldTunings.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.github.zhenlige.xennote;

import com.github.zhenlige.xennote.annotation.NeedWorldTunings;
import com.github.zhenlige.xennote.payload.ClientInitPayload;
import com.github.zhenlige.xennote.payload.UpdateTuningPayload;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
Expand All @@ -20,6 +17,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class WorldTunings extends PersistentState {
private static final Logger LOGGER = LoggerFactory.getLogger(WorldTunings.class);
Expand Down Expand Up @@ -113,19 +111,8 @@ public static WorldTunings getServerState(@NotNull MinecraftServer server) {
}

@Environment(EnvType.CLIENT)
public static void initializeClient() {
LOGGER.debug("start client initializing");
ClientPlayNetworking.registerGlobalReceiver(UpdateTuningPayload.ID, (payload, context) -> {
if (payload.tuning().isEmpty()) {
current.tunings.remove(payload.tuningId());
} else {
current.tunings.put(payload.tuningId(), payload.tuning().orElse(JI));
}
});
ClientPlayNetworking.registerGlobalReceiver(ClientInitPayload.ID, (payload, context) -> {
current = new WorldTunings(payload.tuningMap());
log();
});
public static void initializeClient(Function<Function<WorldTunings, WorldTunings>, Void> func) {
func.apply(newCurrent -> current = newCurrent);
}

@NeedWorldTunings
Expand Down

0 comments on commit eeef142

Please sign in to comment.