diff --git a/CHANGELOG.md b/CHANGELOG.md index 44117fd..9709860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,2 @@ ## Change -- port to 1.20.6 \ No newline at end of file +- sync from `sakura-ryoko/minihud` \ No newline at end of file diff --git a/build.gradle b/build.gradle index ae0ec7a..aee8e14 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ dependencies { neoForge "net.neoforged:neoforge:${project.neoforge_version}" modImplementation "maven.modrinth:mafglib:${project.malilib_version}" - modImplementation "maven.modrinth:forged-networking-api:0.1.0+mc1.20.6" + modImplementation("maven.modrinth:neonetwork:${project.neonetwork_version}") implementation "com.google.code.findbugs:jsr305:3.0.2" } diff --git a/gradle.properties b/gradle.properties index 23ca407..9f3791f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ loom.platform=neoforge # Base properties minecraft_version=1.20.6 - neoforge_version=20.6.113-beta + neoforge_version=20.6.119 yarn_mappings=1.20.6+build.3 - yarn_patch=1.20.5+build.3 + yarn_patch=1.20.6+build.4 # Mod Properties - mod_version=0.1.2 + mod_version=0.1.3 maven_group=org.thinkingstudio.bocchud archives_base_name=BoccHUD mod_id=bocchud @@ -19,4 +19,5 @@ loom.platform=neoforge curseforge_id=916504 # Dependencies - malilib_version=0.1.8-mc1.20.6 + malilib_version=0.1.12-mc1.20.6 + neonetwork_version=0.1.5+mc1.20.6 diff --git a/src/main/java/fi/dy/masa/minihud/Reference.java b/src/main/java/fi/dy/masa/minihud/Reference.java index 7e44bc3..31bd193 100644 --- a/src/main/java/fi/dy/masa/minihud/Reference.java +++ b/src/main/java/fi/dy/masa/minihud/Reference.java @@ -1,7 +1,7 @@ package fi.dy.masa.minihud; -import fi.dy.masa.malilib.util.StringUtils; import net.minecraft.MinecraftVersion; +import fi.dy.masa.malilib.util.StringUtils; public class Reference { @@ -9,5 +9,6 @@ public class Reference public static final String MOD_NAME = "BoccHUD"; public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID); public static final String MC_VERSION = MinecraftVersion.CURRENT.getName(); - public static final String MOD_STRING = MOD_ID+"-"+MC_VERSION+"-"+MOD_VERSION; + public static final String MOD_TYPE = "neoforge"; + public static final String MOD_STRING = MOD_ID + "-" + MOD_TYPE + "-" + MC_VERSION + "-" + MOD_VERSION; } diff --git a/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresHandler.java b/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresHandler.java index 3c4ca7f..d6b758f 100644 --- a/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresHandler.java +++ b/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresHandler.java @@ -1,12 +1,16 @@ package fi.dy.masa.minihud.network; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import org.thinkingstudio.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; +import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.Identifier; -import fi.dy.masa.malilib.network.ClientPlayHandler; +import net.minecraft.util.Util; +import net.minecraft.util.math.random.Random; import fi.dy.masa.malilib.network.IPluginClientPlayHandler; +import fi.dy.masa.malilib.network.PacketSplitter; import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.minihud.MiniHUD; import fi.dy.masa.minihud.util.DataStorage; @@ -16,29 +20,23 @@ @OnlyIn(Dist.CLIENT) public abstract class ServuxStructuresHandler implements IPluginClientPlayHandler { - private final static ServuxStructuresHandler INSTANCE = new ServuxStructuresHandler<>() + private final static ServuxStructuresHandler INSTANCE = new ServuxStructuresHandler<>() { @Override - public void receive(ServuxStructuresPayload payload, ClientPlayNetworking.Context context) + public void receive(ServuxStructuresPacket.Payload payload, ClientPlayNetworking.Context context) { ServuxStructuresHandler.INSTANCE.receivePlayPayload(payload, context); } }; - public static ServuxStructuresHandler getInstance() { return INSTANCE; } + public static ServuxStructuresHandler getInstance() { return INSTANCE; } - public static final Identifier CHANNEL_ID = new Identifier("servux", "structures"); - public static final int PROTOCOL_VERSION = 2; - public static final int PACKET_S2C_METADATA = 1; - public static final int PACKET_S2C_STRUCTURE_DATA = 2; - public static final int PACKET_C2S_STRUCTURES_REGISTER = 3; - public static final int PACKET_C2S_STRUCTURES_UNREGISTER = 4; - public static final int PACKET_S2C_SPAWN_METADATA = 10; - public static final int PACKET_C2S_REQUEST_SPAWN_METADATA = 11; + public static final Identifier CHANNEL_ID = Identifier.of("servux", "structures"); private boolean servuxRegistered; private boolean payloadRegistered = false; private int failures = 0; private static final int MAX_FAILURES = 4; + private long readingSessionKey = -1; @Override public Identifier getPayloadChannel() { return CHANNEL_ID; } @@ -63,27 +61,57 @@ public void setPlayRegistered(Identifier channel) } } - @Override - public void decodeNbtCompound(Identifier channel, NbtCompound data) + public void decodeStructuresPacket(Identifier channel, ServuxStructuresPacket packet) { - switch (data.getInt("packetType")) + if (channel.equals(CHANNEL_ID) == false) { - case PACKET_S2C_METADATA -> + return; + } + switch (packet.getType()) + { + case PACKET_S2C_STRUCTURE_DATA -> { - if (DataStorage.getInstance().receiveServuxMetadata(data)) + if (this.readingSessionKey == -1) { - this.servuxRegistered = true; + this.readingSessionKey = Random.create(Util.getMeasuringTimeMs()).nextLong(); + } + + PacketByteBuf fullPacket = PacketSplitter.receive(this, this.readingSessionKey, packet.getBuffer()); + + if (fullPacket != null) + { + try + { + NbtCompound nbt = fullPacket.readNbt(); + this.readingSessionKey = -1; + + if (nbt != null) + { + NbtList structures = nbt.getList("Structures", Constants.NBT.TAG_COMPOUND); + //MiniHUD.printDebug("decodeStructuresPacket(): received Structures Data of size {} (in bytes) // structures [{}]", nbt.getSizeInBytes(), structures.size()); + + DataStorage.getInstance().addOrUpdateStructuresFromServer(structures, this.servuxRegistered); + } + else + { + MiniHUD.logger.warn("decodeStructuresPacket(): Structures Data: error reading fullBuffer NBT is NULL"); + } + } + catch (Exception e) + { + MiniHUD.logger.error("decodeStructuresPacket(): Structures Data: error reading fullBuffer [{}]", e.getLocalizedMessage()); + } } } - case PACKET_S2C_SPAWN_METADATA -> DataStorage.getInstance().receiveSpawnMetadata(data); - case PACKET_S2C_STRUCTURE_DATA -> + case PACKET_S2C_METADATA -> { - MiniHUD.printDebug("ServuxStructuresHandler#decodeNbtCompound(): received Structures Data payload of size {} (in bytes)", data.getSizeInBytes()); - - NbtList structures = data.getList("Structures", Constants.NBT.TAG_COMPOUND); - DataStorage.getInstance().addOrUpdateStructuresFromServer(structures, this.servuxRegistered); + if (DataStorage.getInstance().receiveServuxMetadata(packet.getCompound())) + { + this.servuxRegistered = true; + } } - default -> MiniHUD.logger.warn("ServuxStructuresHandler#decodeNbtCompound(): received unhandled packetType {} of size {} bytes.", data.getInt("packetType"), data.getSizeInBytes()); + case PACKET_S2C_SPAWN_METADATA -> DataStorage.getInstance().receiveSpawnMetadata(packet.getCompound()); + default -> MiniHUD.logger.warn("decodeStructuresPacket(): received unhandled packetType {} of size {} bytes.", packet.getPacketType(), packet.getTotalSize()); } } @@ -92,10 +120,9 @@ public void reset(Identifier channel) { if (channel.equals(CHANNEL_ID) && this.servuxRegistered) { - MiniHUD.printDebug("reset() called for {}", channel.toString()); - this.servuxRegistered = false; this.failures = 0; + this.readingSessionKey = -1; } } @@ -103,7 +130,6 @@ public void resetFailures(Identifier channel) { if (channel.equals(CHANNEL_ID) && this.failures > 0) { - MiniHUD.printDebug("resetFailures() called for {}", channel.toString()); this.failures = 0; } } @@ -113,18 +139,23 @@ public void receivePlayPayload(T payload, ClientPlayNetworking.Context ctx) { if (payload.getId().id().equals(CHANNEL_ID)) { - ((ClientPlayHandler) ClientPlayHandler.getInstance()).decodeNbtCompound(CHANNEL_ID, ((ServuxStructuresPayload) payload).data()); + ServuxStructuresHandler.INSTANCE.decodeStructuresPacket(CHANNEL_ID, ((ServuxStructuresPacket.Payload) payload).data()); } } @Override - public void encodeNbtCompound(NbtCompound data) + public void encodeWithSplitter(PacketByteBuf buffer, ClientPlayNetworkHandler handler) + { + // NO-OP + } + + public void encodeStructuresPacket(ServuxStructuresPacket packet) { - if (ServuxStructuresHandler.INSTANCE.sendPlayPayload(new ServuxStructuresPayload(data)) == false) + if (ServuxStructuresHandler.INSTANCE.sendPlayPayload(new ServuxStructuresPacket.Payload(packet)) == false) { if (this.failures > MAX_FAILURES) { - MiniHUD.logger.warn("encodeNbtCompound: encountered [{}] sendPayload failures, cancelling any Servux join attempt(s)", MAX_FAILURES); + MiniHUD.logger.warn("encodeStructuresPacket(): encountered [{}] sendPayload failures, cancelling any Servux join attempt(s)", MAX_FAILURES); this.servuxRegistered = false; ServuxStructuresHandler.INSTANCE.unregisterPlayReceiver(); DataStorage.getInstance().onPacketFailure(); diff --git a/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPacket.java b/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPacket.java new file mode 100644 index 0000000..1a5b5d5 --- /dev/null +++ b/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPacket.java @@ -0,0 +1,238 @@ +package fi.dy.masa.minihud.network; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import io.netty.buffer.Unpooled; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.packet.CustomPayload; +import fi.dy.masa.malilib.network.IClientPayloadData; +import fi.dy.masa.minihud.MiniHUD; + +public class ServuxStructuresPacket implements IClientPayloadData +{ + private Type packetType; + private NbtCompound nbt; + private PacketByteBuf buffer; + public static final int PROTOCOL_VERSION = 2; + + public ServuxStructuresPacket(Type type, @Nullable NbtCompound nbt) + { + this.packetType = type; + + if (nbt != null && nbt.isEmpty() == false) + { + this.nbt = new NbtCompound(); + this.nbt.copyFrom(nbt); + } + if (this.buffer != null) + { + this.buffer.clear(); + this.buffer = new PacketByteBuf(Unpooled.buffer()); + } + } + + public ServuxStructuresPacket(Type type, @Nonnull PacketByteBuf packet) + { + this.packetType = type; + this.nbt = new NbtCompound(); + this.buffer = packet; + } + + @Override + public int getVersion() + { + return PROTOCOL_VERSION; + } + + @Override + public int getPacketType() + { + return this.packetType.get(); + } + + @Override + public int getTotalSize() + { + int total = 2; + + if (this.nbt != null && this.nbt.isEmpty() == false) + { + total += this.nbt.getSizeInBytes(); + } + if (this.buffer != null) + { + total += this.buffer.readableBytes(); + } + + return total; + } + + public Type getType() + { + return this.packetType; + } + + public NbtCompound getCompound() + { + return this.nbt; + } + + public PacketByteBuf getBuffer() + { + return this.buffer; + } + + public boolean hasBuffer() { return this.buffer != null && this.buffer.isReadable(); } + + public boolean hasNbt() { return this.nbt != null && !this.nbt.isEmpty(); } + + @Override + public boolean isEmpty() + { + return !this.hasBuffer() && !this.hasNbt(); + } + + @Override + public void toPacket(PacketByteBuf output) + { + output.writeVarInt(this.getPacketType()); + + if (this.packetType.equals(Type.PACKET_S2C_STRUCTURE_DATA)) + { + // Write Packet Buffer + try + { + output.writeBytes(this.buffer.readBytes(this.buffer.readableBytes())); + } + catch (Exception e) + { + MiniHUD.logger.error("ServuxStructuresPacket#toPacket: error writing data to packet: [{}]", e.getLocalizedMessage()); + } + } + else + { + // Write NBT + try + { + output.writeNbt(this.nbt); + } + catch (Exception e) + { + MiniHUD.logger.error("ServuxStructuresPacket#toPacket: error writing NBT to packet: [{}]", e.getLocalizedMessage()); + } + } + } + + @Nullable + public static ServuxStructuresPacket fromPacket(PacketByteBuf input) + { + int i = input.readVarInt(); + Type type = getType(i); + + if (type == null) + { + // Invalid Type + MiniHUD.logger.warn("ServuxStructuresPacket#fromPacket: invalid packet type received"); + } + else if (type.equals(Type.PACKET_S2C_STRUCTURE_DATA)) + { + // Read Packet Buffer + try + { + return new ServuxStructuresPacket(type, new PacketByteBuf(input.readBytes(input.readableBytes()))); + } + catch (Exception e) + { + MiniHUD.logger.error("ServuxStructuresPacket#fromPacket: error reading Buffer from packet: [{}]", e.getLocalizedMessage()); + } + } + else + { + // Read Nbt + try + { + return new ServuxStructuresPacket(type, input.readNbt()); + } + catch (Exception e) + { + MiniHUD.logger.error("ServuxStructuresPacket#fromPacket: error reading NBT from packet: [{}]", e.getLocalizedMessage()); + } + } + + return null; + } + + @Override + public void clear() + { + if (this.nbt != null && this.nbt.isEmpty() == false) + { + this.nbt = new NbtCompound(); + } + if (this.buffer != null && this.buffer.readableBytes() > 0) + { + this.buffer.clear(); + this.buffer = new PacketByteBuf(Unpooled.buffer()); + } + + this.packetType = null; + } + + @Nullable + public static Type getType(int input) + { + for (Type type : Type.values()) + { + if (type.get() == input) + { + return type; + } + } + + return null; + } + + public enum Type + { + PACKET_S2C_METADATA(1), + PACKET_S2C_STRUCTURE_DATA(2), + PACKET_C2S_STRUCTURES_REGISTER(3), + PACKET_C2S_STRUCTURES_UNREGISTER(4), + PACKET_S2C_STRUCTURE_DATA_START(5), + PACKET_S2C_SPAWN_METADATA(10), + PACKET_C2S_REQUEST_SPAWN_METADATA(11); + + private final int type; + + Type(int type) + { + this.type = type; + } + + int get() { return this.type; } + } + + public record Payload(ServuxStructuresPacket data) implements CustomPayload + { + public static final Id ID = new Id<>(ServuxStructuresHandler.CHANNEL_ID); + public static final PacketCodec CODEC = CustomPayload.codecOf(Payload::write, Payload::new); + + public Payload(PacketByteBuf input) + { + this(fromPacket(input)); + } + + private void write(PacketByteBuf output) + { + data.toPacket(output); + } + + @Override + public Id getId() + { + return ID; + } + } +} diff --git a/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPayload.java b/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPayload.java deleted file mode 100644 index 9166f33..0000000 --- a/src/main/java/fi/dy/masa/minihud/network/ServuxStructuresPayload.java +++ /dev/null @@ -1,22 +0,0 @@ -package fi.dy.masa.minihud.network; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.packet.CustomPayload; - -/** - * ServuX Structures Data Provider; the actual Payload shared between MiniHUD and ServuX - */ -public record ServuxStructuresPayload(NbtCompound data) implements CustomPayload -{ - public static final Id TYPE = new Id<>(ServuxStructuresHandler.CHANNEL_ID); - public static final PacketCodec CODEC = CustomPayload.codecOf(ServuxStructuresPayload::write, ServuxStructuresPayload::new); - - public ServuxStructuresPayload(PacketByteBuf buf) { this(buf.readNbt()); } - - private void write(PacketByteBuf buf) { buf.writeNbt(data); } - - @Override - public Id getId() { return TYPE; } -} diff --git a/src/main/java/fi/dy/masa/minihud/util/DataStorage.java b/src/main/java/fi/dy/masa/minihud/util/DataStorage.java index 142087e..e0d5820 100644 --- a/src/main/java/fi/dy/masa/minihud/util/DataStorage.java +++ b/src/main/java/fi/dy/masa/minihud/util/DataStorage.java @@ -12,7 +12,6 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; - import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; @@ -38,7 +37,6 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.gen.structure.Structure; - import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.network.ClientPlayHandler; import fi.dy.masa.malilib.network.IPluginClientPlayHandler; @@ -49,7 +47,7 @@ import fi.dy.masa.minihud.config.RendererToggle; import fi.dy.masa.minihud.data.MobCapDataHandler; import fi.dy.masa.minihud.network.ServuxStructuresHandler; -import fi.dy.masa.minihud.network.ServuxStructuresPayload; +import fi.dy.masa.minihud.network.ServuxStructuresPacket; import fi.dy.masa.minihud.renderer.*; import fi.dy.masa.minihud.renderer.shapes.ShapeManager; import fi.dy.masa.minihud.renderer.worker.ChunkTask; @@ -62,7 +60,7 @@ public class DataStorage private static final DataStorage INSTANCE = new DataStorage(); private final MobCapDataHandler mobCapData = new MobCapDataHandler(); - private final static ServuxStructuresHandler HANDLER = ServuxStructuresHandler.getInstance(); + private final static ServuxStructuresHandler HANDLER = ServuxStructuresHandler.getInstance(); private boolean worldSeedValid = false; private boolean carpetServer = false; private boolean servuxServer = false; @@ -75,7 +73,8 @@ public class DataStorage private int structureDataTimeout = 30 * 20; private boolean serverTPSValid; private boolean hasSyncedTime; - private String serverVersion; + private String servuxVersion; + private int servuxTimeout; private boolean hasStructureDataFromServer; private boolean structureRendererNeedsUpdate; private boolean structuresNeedUpdating; @@ -96,7 +95,6 @@ public class DataStorage private final PriorityBlockingQueue taskQueue = Queues.newPriorityBlockingQueue(); private final Thread workerThread; private final ThreadWorker worker; - private int timeout; private DataStorage() { @@ -113,12 +111,12 @@ public static DataStorage getInstance() public void onGameInit() { ClientPlayHandler.getInstance().registerClientPlayHandler(HANDLER); - HANDLER.registerPlayPayload(ServuxStructuresPayload.TYPE, ServuxStructuresPayload.CODEC, IPluginClientPlayHandler.BOTH_CLIENT); + HANDLER.registerPlayPayload(ServuxStructuresPacket.Payload.ID, ServuxStructuresPacket.Payload.CODEC, IPluginClientPlayHandler.BOTH_CLIENT); } public Identifier getNetworkChannel() { return ServuxStructuresHandler.CHANNEL_ID; } - public IPluginClientPlayHandler getPacketHandler() { return HANDLER; } + public IPluginClientPlayHandler getPacketHandler() { return HANDLER; } public MobCapDataHandler getMobCapData() { @@ -145,6 +143,7 @@ public void reset(boolean isLogout) */ HANDLER.reset(this.getNetworkChannel()); HANDLER.resetFailures(this.getNetworkChannel()); + this.servuxServer = false; this.hasInValidServux = false; this.structureDataTimeout = 30 * 20; @@ -171,7 +170,7 @@ public void reset(boolean isLogout) this.lastStructureUpdatePos = null; this.structures.clear(); this.clearTasks(); - this.timeout = -1; + this.servuxTimeout = -1; ShapeManager.INSTANCE.clear(); OverlayRendererBeaconRange.INSTANCE.clear(); @@ -213,15 +212,15 @@ public void setIsServuxServer() } } - public void setServerVersion(String ver) + public void setServuxVersion(String ver) { if (ver != null && ver.isEmpty() == false) { - this.serverVersion = ver; + this.servuxVersion = ver; } else { - this.serverVersion = "unknown"; + this.servuxVersion = "unknown"; } } @@ -236,7 +235,7 @@ public void onWorldPre() { if (this.hasIntegratedServer == false) { - HANDLER.registerPlayReceiver(ServuxStructuresPayload.TYPE, HANDLER::receivePlayPayload); + HANDLER.registerPlayReceiver(ServuxStructuresPacket.Payload.ID, HANDLER::receivePlayPayload); } } @@ -266,7 +265,7 @@ public void onWorldJoin() /** * Store's the world registry manager for Dynamic Lookup for various data * Set this at WorldLoadPost - * @param manager + * @param manager () */ public void setWorldRegistryManager(DynamicRegistryManager manager) { @@ -297,10 +296,9 @@ public void requestSpawnMetadata() if (this.hasIntegratedServer == false && this.hasServuxServer()) { NbtCompound nbt = new NbtCompound(); - nbt.putInt("packetType", ServuxStructuresHandler.PACKET_C2S_REQUEST_SPAWN_METADATA); nbt.putString("version", Reference.MOD_STRING); - HANDLER.encodeNbtCompound(nbt); + HANDLER.encodeStructuresPacket(new ServuxStructuresPacket(ServuxStructuresPacket.Type.PACKET_C2S_REQUEST_SPAWN_METADATA, nbt)); } } @@ -858,20 +856,20 @@ public void registerStructureChannel() { if (HANDLER.isPlayRegistered(this.getNetworkChannel())) { - MiniHUD.printDebug("registerStructureChannel(): sending STRUCTURES_REGISTER to Servux"); + MiniHUD.printDebug("DataStorage#registerStructureChannel(): sending STRUCTURES_REGISTER to Servux"); NbtCompound nbt = new NbtCompound(); - nbt.putInt("packetType", ServuxStructuresHandler.PACKET_C2S_STRUCTURES_REGISTER); nbt.putString("version", Reference.MOD_STRING); - HANDLER.encodeNbtCompound(nbt); + HANDLER.encodeStructuresPacket(new ServuxStructuresPacket(ServuxStructuresPacket.Type.PACKET_C2S_STRUCTURES_REGISTER, nbt)); } } else { this.shouldRegisterStructureChannel = false; } - // QuickCarpet doesn't exist for 1.20.5 + // QuickCarpet doesn't exist for 1.20.5+, + // Will re-add if they update it } public boolean receiveServuxMetadata(NbtCompound data) @@ -879,14 +877,14 @@ public boolean receiveServuxMetadata(NbtCompound data) if (this.servuxServer == false && this.hasIntegratedServer == false && this.shouldRegisterStructureChannel) { - MiniHUD.printDebug("checkServuxMetadata: received METADATA from Servux"); + MiniHUD.printDebug("DataStorage#checkServuxMetadata(): received METADATA from Servux"); - if (data.getInt("version") != ServuxStructuresHandler.PROTOCOL_VERSION) + if (data.getInt("version") != ServuxStructuresPacket.PROTOCOL_VERSION) { MiniHUD.logger.warn("structureChannel: Mis-matched protocol version!"); } - this.timeout = data.getInt("timeout"); - this.setServerVersion(data.getString("servux")); + this.servuxTimeout = data.getInt("timeout"); + this.setServuxVersion(data.getString("servux")); this.setWorldSpawn(new BlockPos(data.getInt("spawnPosX"), data.getInt("spawnPosY"), data.getInt("spawnPosZ"))); this.setSpawnChunkRadius(data.getInt("spawnChunkRadius"), true); this.setIsServuxServer(); @@ -909,9 +907,9 @@ public void receiveSpawnMetadata(NbtCompound data) { if (this.hasIntegratedServer == false) { - MiniHUD.printDebug("receiveSpawnMetadata() from Servux"); + MiniHUD.printDebug("DataStorage#receiveSpawnMetadata(): from Servux"); - this.setServerVersion(data.getString("servux")); + this.setServuxVersion(data.getString("servux")); this.setWorldSpawn(new BlockPos(data.getInt("spawnPosX"), data.getInt("spawnPosY"), data.getInt("spawnPosZ"))); this.setSpawnChunkRadius(data.getInt("spawnChunkRadius"), true); @@ -929,11 +927,9 @@ public void unregisterStructureChannel() this.servuxServer = false; if (this.hasInValidServux == false) { - MiniHUD.printDebug("unregisterStructureChannel: for {}", this.serverVersion); - NbtCompound nbt = new NbtCompound(); - nbt.putInt("packetType", ServuxStructuresHandler.PACKET_C2S_STRUCTURES_UNREGISTER); + MiniHUD.printDebug("DataStorage#unregisterStructureChannel(): for {}", this.servuxVersion != null ? this.servuxVersion : ""); - HANDLER.encodeNbtCompound(nbt); + HANDLER.encodeStructuresPacket(new ServuxStructuresPacket(ServuxStructuresPacket.Type.PACKET_C2S_STRUCTURES_UNREGISTER, new NbtCompound())); HANDLER.reset(this.getNetworkChannel()); } } @@ -997,7 +993,7 @@ public void addOrUpdateStructuresFromServer(NbtList structures, boolean isServux if (structures.getHeldType() == Constants.NBT.TAG_COMPOUND) { - this.structureDataTimeout = this.timeout + 240; + this.structureDataTimeout = this.servuxTimeout + 300; long currentTime = this.mc.world.getTime(); final int count = structures.size(); @@ -1022,7 +1018,7 @@ public void addOrUpdateStructuresFromServer(NbtList structures, boolean isServux } } - MiniHUD.printDebug("DataStorage#addOrUpdateStructuresFromServer(): received {} structures // total size {} -> {}", count, oldCount, this.structures.size()); + MiniHUD.printDebug("addOrUpdateStructuresFromServer: received {} structures // total size {} -> {}", count, oldCount, this.structures.size()); this.structureRendererNeedsUpdate = true; this.hasStructureDataFromServer = true; @@ -1039,7 +1035,7 @@ private void removeExpiredStructures(long currentTime, int timeout) if (countBefore != countAfter) { - MiniHUD.printDebug("removeExpiredStructures from server: {} -> {} structures", countBefore, countAfter); + MiniHUD.printDebug("removeExpiredStructures: from server: {} -> {} structures", countBefore, countAfter); } } @@ -1091,7 +1087,7 @@ private void addStructureDataFromGenerator(ServerWorld world, BlockPos playerPos } } - MiniHUD.printDebug("Structure data updated from the integrated server: {} -> {} structures", lastCount, this.structures.size()); + MiniHUD.printDebug("addStructureDataFromGenerator: updated from the integrated server: {} -> {} structures", lastCount, this.structures.size()); this.structureRendererNeedsUpdate = true; } diff --git a/src/main/java/org/thinkingstudio/bocchud/BoccHUD.java b/src/main/java/org/thinkingstudio/bocchud/BoccHUD.java index fc32eec..b8fdf80 100644 --- a/src/main/java/org/thinkingstudio/bocchud/BoccHUD.java +++ b/src/main/java/org/thinkingstudio/bocchud/BoccHUD.java @@ -3,16 +3,18 @@ import fi.dy.masa.minihud.MiniHUD; import fi.dy.masa.minihud.Reference; import fi.dy.masa.minihud.gui.GuiConfigs; +import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.common.Mod; import net.neoforged.fml.loading.FMLLoader; -import org.thinkingstudio.mafglib.util.ForgePlatformUtils; +import org.thinkingstudio.mafglib.util.NeoUtils; -@Mod(Reference.MOD_ID) +@Mod(value = Reference.MOD_ID, dist = Dist.CLIENT) public class BoccHUD { public BoccHUD() { if (FMLLoader.getDist().isClient()) { MiniHUD.onInitialize(); - ForgePlatformUtils.getInstance().registerModConfigScreen(Reference.MOD_ID, (screen) -> { + + NeoUtils.getInstance().registerModConfigScreen(Reference.MOD_ID, (screen) -> { GuiConfigs gui = new GuiConfigs(); gui.setParent(screen); return gui; diff --git a/src/main/resources/assets/bocchud/lang/en_us.json b/src/main/resources/assets/bocchud/lang/en_us.json index 2595a1c..e220485 100644 --- a/src/main/resources/assets/bocchud/lang/en_us.json +++ b/src/main/resources/assets/bocchud/lang/en_us.json @@ -1,4 +1,6 @@ { + "fml.menu.mods.info.description.bocchud": "MiniHUD unofficial (Neo)Forge port. Configurable \"mini-F3\" info lines, and various overlay renderers.", + "malilib.gui.button.render_layers_gui.set_to_player": "Set Here", "minihud.gui.button.config_gui.colors": "Colors", @@ -16,7 +18,7 @@ "minihud.gui.button.shape_renderer_toggle": "Shape Renderer: %s", "minihud.gui.button.shape_renderer.toggle_combine_quads": "Combine Quads: %s", - "minihud.gui.button.hover.shape_renderer.spawn_sphere.toggle_use_quadrants": "§7Corner Quarants uses basically 4 separate spheres at the corners\n§7of the rectangle area defined by the center and the margin distance.\n§7The corner quadrants was the old behavior, and it gets derpy (especially on the\n§7cardinal sides) if the margin increases to more than a few blocks.\n§7The new default is not using the corner quadrants anymore,\n§7but instead to kind of \"slide the sphere around the margin perimeter\"\n§7to create the final shape.", + "minihud.gui.button.hover.shape_renderer.spawn_sphere.toggle_use_quadrants": "§7Corner Quadrants uses basically 4 separate spheres at the corners\n§7of the rectangle area defined by the center and the margin distance.\n§7The corner quadrants was the old behavior, and it gets derpy (especially on the\n§7cardinal sides) if the margin increases to more than a few blocks.\n§7The new default is not using the corner quadrants anymore,\n§7but instead to kind of \"slide the sphere around the margin perimeter\"\n§7to create the final shape.", "minihud.gui.label.center_colon": "Center:", "minihud.gui.label.color": "Color:", @@ -116,7 +118,7 @@ "minihud.hotkeys.category.renderer_toggle_hotkeys": "Renderer Toggle hotkeys", "minihud.hotkeys.category.structure_toggle_hotkeys": "Structure Toggle hotkeys", - "minihud.message.toggled_debug_mode.collisions": "Toggled Collison Boxes debug rendering to %s", + "minihud.message.toggled_debug_mode.collisions": "Toggled Collision Boxes debug rendering to %s", "minihud.message.toggled_debug_mode.height_map": "Toggled Height Map debug rendering to %s", "minihud.message.toggled_debug_mode.neighbor_updates": "Toggled Neighbor Update debug rendering to %s", "minihud.message.toggled_debug_mode.pathfinding": "Toggled Pathfinding debug rendering to %s", @@ -125,15 +127,20 @@ "minihud.message.toggled_using_center_position": "Toggled %s %s, using the center position %s", "minihud.message.toggled_using_position": "Toggled %s %s, using the position %s", - "minihud.message.toggled_using_world_spawn": "Toggled %s %s, using the world spawn %s", + "minihud.message.toggled_using_world_spawn": "Toggled %s %s, World spawn %s", + "minihud.message.toggled_using_player_spawn": "Toggled %s %s, Simulation distance %s", "minihud.message.error.invalid_dropped_chunks_hash_size": "Failed to parse the dropped chunks HashSet size from chat", "minihud.message.error.invalid_seed": "Failed to parse the world seed from chat", + "minihud.message.error.invalid_spawn_chunk_radius": "Failed to parse the spawn chunk radius from chat (0 < 32)", "minihud.message.error.shapes.select_shape_from_dropdown": "Select the Shape type to create from the dropdown widget", "minihud.message.distance_reference_point_set": "Set distance reference point to %s", "minihud.message.no_seed": "MiniHUD: World seed is not known", "minihud.message.seed_is": "The world seed in MiniHUD is currently set to '%s'", "minihud.message.seed_set": "MiniHUD: Set the world seed to '%s'", - "minihud.message.spawn_set": "MiniHUD: Set the world spawn to %s" + "minihud.message.spawn_set": "MiniHUD: Set the world spawn to %s", + "minihud.message.no_spawn_chunk_radius": "MiniHUD: Spawn Chunk Radius is not known (Default 2)", + "minihud.message.spawn_chunk_radius_is": "The spawn chunk radius in MiniHUD is currently set to '%s'", + "minihud.message.spawn_chunk_radius_set": "MiniHUD: Set the Spawn Chunk Radius to %s" } diff --git a/src/main/resources/assets/bocchud/lang/zh_cn.json b/src/main/resources/assets/bocchud/lang/zh_cn.json index fd046e7..a606c7c 100644 --- a/src/main/resources/assets/bocchud/lang/zh_cn.json +++ b/src/main/resources/assets/bocchud/lang/zh_cn.json @@ -1,4 +1,6 @@ { + "fml.menu.mods.info.description.bocchud": "MiniHUD 非官方 (Neo)Forge 移植。可配置 “迷你的F3” 信息线和各种叠加渲染器。", + "malilib.gui.button.render_layers_gui.set_to_player": "定位至玩家", "minihud.gui.button.config_gui.colors": "颜色", @@ -127,9 +129,11 @@ "minihud.message.toggled_using_center_position": "切换 %s %s, 使用中心位置 %s", "minihud.message.toggled_using_position": "切换 %s %s, 使用位置 %s", "minihud.message.toggled_using_world_spawn": "切换 %s %s, 使用世界出生点 %s", + "minihud.message.toggled_using_player_spawn": "切换 %s %s,模拟距离 %s", "minihud.message.error.invalid_dropped_chunks_hash_size": "从聊天框中解析掉落方块的数值大小失败", "minihud.message.error.invalid_seed": "从聊天框中解析世界种子失败", + "minihud.message.error.invalid_spawn_chunk_radius": "无法解析聊天中的生成区块半径(0 < 32)", "minihud.message.error.shapes.select_shape_from_dropdown": "从下拉栏中选择要创建的形状类型", "minihud.message.distance_reference_point_set": "设置距离参考点位 %s", @@ -137,6 +141,9 @@ "minihud.message.seed_is": " MiniHUD 设置的当前世界种子为 '%s'", "minihud.message.seed_set": "MiniHUD: 设置世界种子为 '%s'", "minihud.message.spawn_set": "MiniHUD: 设置世界出生点到 %s", + "minihud.message.no_spawn_chunk_radius": "MiniHUD: 生成区块半径未知(默认为 2)", + "minihud.message.spawn_chunk_radius_is": "MiniHUD 中的生成区块半径当前设置为'%s'", + "minihud.message.spawn_chunk_radius_set": "MiniHUD: 将生成区块半径设置为 %s", "beeTooltips":"bee | 蜜蜂工具提示", "Adds the number of contained bees to the tooltip of Bee Hive and Bee Nest items":"提示蜂箱和蜂巢物品中的蜜蜂数量",