diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHost.java b/src/main/java/io/github/gaming32/worldhost/WorldHost.java index e620b53..4f65f1b 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHost.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHost.java @@ -117,6 +117,7 @@ //$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; //#endif //$$ import java.util.function.BiFunction; +//#if MC < 1.20.5 //#if NEOFORGE //$$ import net.neoforged.neoforge.client.ConfigScreenHandler; //#elseif MC >= 1.19.2 @@ -126,6 +127,7 @@ //#else //$$ import net.minecraftforge.fmlclient.ConfigGuiHandler; //#endif +//#endif //#if NEOFORGE //$$ import net.neoforged.neoforge.resource.ResourcePackLoader; //#elseif MC > 1.17.1 @@ -229,52 +231,16 @@ public void onInitializeClient() { //#endif private static void init() { - wordsForCid = - //#if FABRIC - FabricLoader.getInstance() - .getModContainer(MOD_ID) - .flatMap(c -> c.findPath("assets/world-host/16k.txt")) - .map(path -> { - try { - return Files.lines(path, StandardCharsets.US_ASCII); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - }) - //#else - //$$ ResourcePackLoader - //$$ .getPackFor(MOD_ID) - //#if MC >= 1.20.4 - //$$ .map(c -> c.openPrimary("worldhost")) - //#endif - //$$ .map(c -> { - //#if MC <= 1.19.2 - //$$ try { - //#endif - //$$ return ((PackResources)c).getResource(PackType.CLIENT_RESOURCES, new ResourceLocation("world-host", "16k.txt")); - //#if MC <= 1.19.2 - //$$ } catch (IOException e) { - //$$ throw new UncheckedIOException(e); - //$$ } - //#endif - //$$ }) - //#if MC > 1.19.2 - //$$ .map(i -> { - //$$ try { - //$$ return i.get(); - //$$ } catch (IOException e) { - //$$ throw new UncheckedIOException(e); - //$$ } - //$$ }) - //#endif - //$$ .map(is -> new InputStreamReader(is, StandardCharsets.US_ASCII)) - //$$ .map(BufferedReader::new) - //$$ .map(BufferedReader::lines) - //#endif - .orElseThrow(() -> new IllegalStateException("Unable to find 16k.txt")) - .filter(s -> !s.startsWith("//")) - .toList(); - + try (BufferedReader reader = new BufferedReader( + new InputStreamReader( + WorldHost.class.getResourceAsStream("/assets/world-host/16k.txt"), + StandardCharsets.US_ASCII + ) + )) { + wordsForCid = reader.lines().filter(s -> !s.startsWith("//")).toList(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } if (wordsForCid.size() != (1 << 14)) { throw new RuntimeException("Expected WORDS_FOR_CID to have " + (1 << 14) + " elements, but it has " + wordsForCid.size() + " elements."); } @@ -574,20 +540,36 @@ public static FriendlyByteBuf createByteBuf() { @SuppressWarnings("RedundantThrows") public static ServerStatus parseServerStatus(FriendlyByteBuf buf) throws IOException { - return new ClientboundStatusResponsePacket(buf) - //#if MC >= 1.19.4 - .status(); - //#else - //$$ .getStatus(); - //#endif + //#if MC >= 1.20.5 + return ClientboundStatusResponsePacket.STREAM_CODEC.decode(buf).status(); + //#elseif MC >= 1.19.4 + //$$ return new ClientboundStatusResponsePacket(buf).status(); + //#else + //$$ return new ClientboundStatusResponsePacket(buf).getStatus(); + //#endif + } + + public static FriendlyByteBuf writeServerStatus(ServerStatus metadata) { + if (metadata == null) { + metadata = WorldHost.createEmptyServerStatus(); + } + final FriendlyByteBuf buf = WorldHost.createByteBuf(); + //#if MC < 1.20.5 + //$$ new ClientboundStatusResponsePacket(metadata).write(buf); + //#else + ClientboundStatusResponsePacket.STREAM_CODEC.encode(buf, new ClientboundStatusResponsePacket(metadata)); + //#endif + return buf; } public static ServerStatus createEmptyServerStatus() { //#if MC >= 1.19.4 return new ServerStatus( Components.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), false - //#if FORGELIKE + //#if FORGELIKE && MC < 1.20.5 //$$ , Optional.empty() + //#elseif NEOFORGE + //$$ , false //#endif ); //#else @@ -696,6 +678,9 @@ public static void connect(Screen parentScreen, long cid, String host, int port) //#endif ), false //#endif + //#if MC >= 1.20.5 + , null + //#endif ); } @@ -863,7 +848,7 @@ public static CompletableFuture> checkForUpdates() { }); } - //#if FORGELIKE + //#if FORGELIKE && MC < 1.20.5 //$$ @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) //$$ public static class ClientModEvents { //$$ @SubscribeEvent diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java index cfea256..681ff2a 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java @@ -61,9 +61,11 @@ protected void init() { if (list == null) { list = new FriendsList(); - if (minecraft != null && minecraft.level != null) { - list.setRenderBackground(false); - } + //#if MC < 1.20.5 + //$$ if (minecraft != null && minecraft.level != null) { + //$$ list.setRenderBackground(false); + //$$ } + //#endif } setListSize(list, 32, WorldHost.BEDROCK_SUPPORT ? 80 : 64); addWidget(list); @@ -199,8 +201,10 @@ protected void renderDecorations(@NotNull GuiGraphics graphics, int mouseX, int //$$ final int y0 = this.y0; //$$ final int y1 = this.y1; //#endif - graphics.blit(BACKGROUND_LOCATION, x0, 0, 0f, 0f, width, y0, 32, 32); - graphics.blit(BACKGROUND_LOCATION, x0, y1, 0f, y1, width, height - y1, 32, 32); + //#if MC < 1.20.5 + //$$ graphics.blit(BACKGROUND_LOCATION, x0, 0, 0f, 0f, width, y0, 32, 32); + //$$ graphics.blit(BACKGROUND_LOCATION, x0, y1, 0f, y1, width, height - y1, 32, 32); + //#endif graphics.setColor(1f, 1f, 1f, 1f); graphics.fillGradient(RenderType.guiOverlay(), x0, y0, x1, y0 + 4, 0xff000000, 0, 0); graphics.fillGradient(RenderType.guiOverlay(), x0, y1 - 4, x1, y1, 0, 0xff000000, 0); diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java index 0e9eaff..77c5107 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java @@ -115,8 +115,13 @@ private void serverIsClosed(boolean waitForServer, CallbackInfo ci) { private void shareWorldOnLoad(UUID uuid, CallbackInfo ci) { if (!WorldHost.shareWorldOnLoad) return; WorldHost.shareWorldOnLoad = false; + //#if MC < 1.20.5 + //$$ final boolean allowCommands = worldData.getAllowCommands(); + //#else + final boolean allowCommands = worldData.isAllowCommands(); + //#endif final Component message; - if (publishServer(worldData.getGameType(), worldData.getAllowCommands(), HttpUtil.getAvailablePort())) { + if (publishServer(worldData.getGameType(), allowCommands, HttpUtil.getAvailablePort())) { message = wh$getOpenedMessage(); } else { message = Components.translatable("world-host.share_world.failed").withStyle(ChatFormatting.RED); diff --git a/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostC2SMessage.java b/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostC2SMessage.java index c70f95c..46a6e66 100644 --- a/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostC2SMessage.java +++ b/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostC2SMessage.java @@ -2,7 +2,6 @@ import io.github.gaming32.worldhost.WorldHost; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; import net.minecraft.network.protocol.status.ServerStatus; import java.io.DataOutputStream; @@ -88,9 +87,7 @@ record QueryResponse(long connectionId, ServerStatus metadata) implements WorldH public void encode(DataOutputStream dos) throws IOException { dos.writeByte(7); dos.writeLong(connectionId); - final FriendlyByteBuf buf = WorldHost.createByteBuf(); - new ClientboundStatusResponsePacket(metadata != null ? metadata : WorldHost.createEmptyServerStatus()) - .write(buf); + final FriendlyByteBuf buf = WorldHost.writeServerStatus(metadata); dos.writeInt(buf.readableBytes()); buf.readBytes(dos, buf.readableBytes()); } @@ -126,9 +123,7 @@ record NewQueryResponse(long connectionId, ServerStatus metadata) implements Wor public void encode(DataOutputStream dos) throws IOException { dos.writeByte(11); dos.writeLong(connectionId); - final FriendlyByteBuf buf = WorldHost.createByteBuf(); - new ClientboundStatusResponsePacket(metadata != null ? metadata : WorldHost.createEmptyServerStatus()) - .write(buf); + final FriendlyByteBuf buf = WorldHost.writeServerStatus(metadata); buf.readBytes(dos, buf.readableBytes()); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 07fd63a..836c1b3 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -43,9 +43,9 @@ modId = "minecraft" ##if MC == 1.20.1 #?? versionRange = "[1.20,1.20.2)" ##elseif MC == 1.20.4 -versionRange = "[1.20.3,1.20.5)" +#?? versionRange = "[1.20.3,1.20.5)" ##else -#?? versionRange = "$mc_version" +versionRange = "$mc_version" ##endif ##if MC < 1.20.4 #?? mandatory = true diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 401189f..796a4e5 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -26,7 +26,7 @@ side = "BOTH" [[dependencies.world_host]] modId = "minecraft" ##if MC == 1.20.6 -#?? versionRange = "[1.20.5,1.20.7)" +versionRange = "[1.20.5,1.20.7)" ##else #?? versionRange = "$mc_version" ##endif diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5f04028..0ad2861 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,9 +33,9 @@ //#elseif MC == 1.20.1 //?? "minecraft": ">=1.20- <1.20.2", //#elseif MC == 1.20.4 - "minecraft": ">=1.20.3- <1.20.5", + //?? "minecraft": ">=1.20.3- <1.20.5", //#elseif MC == 1.20.6 - //?? "minecraft": ">=1.20.5- <1.20.7", + "minecraft": ">=1.20.5- <1.20.7", //#else //?? "minecraft": "$mc_version", //#endif diff --git a/versions/mainProject b/versions/mainProject index 66d55ba..304eaac 100644 --- a/versions/mainProject +++ b/versions/mainProject @@ -1 +1 @@ -1.20.4-fabric \ No newline at end of file +1.20.6-fabric \ No newline at end of file