-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.20.6] Add KnownPacks for mods (#901)
- Loading branch information
1 parent
a28986f
commit c888a68
Showing
10 changed files
with
185 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
patches/net/minecraft/client/multiplayer/KnownPacksManager.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- a/net/minecraft/client/multiplayer/KnownPacksManager.java | ||
+++ b/net/minecraft/client/multiplayer/KnownPacksManager.java | ||
@@ -44,6 +_,12 @@ | ||
} | ||
} | ||
|
||
+ if (list.size() > 1024) { | ||
+ list = list.subList(0, 1024); | ||
+ list1 = list1.subList(0, 1024); | ||
+ com.mojang.logging.LogUtils.getLogger().warn("NeoForge: too many KnownPacks requested; only the first 1024 will be sent via KnownPack, the rest will be synced normally"); | ||
+ } | ||
+ | ||
this.repository.setSelected(list1); | ||
return list; | ||
} |
12 changes: 12 additions & 0 deletions
12
patches/net/minecraft/network/protocol/configuration/ServerboundSelectKnownPacks.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- a/net/minecraft/network/protocol/configuration/ServerboundSelectKnownPacks.java | ||
+++ b/net/minecraft/network/protocol/configuration/ServerboundSelectKnownPacks.java | ||
@@ -10,7 +_,8 @@ | ||
|
||
public record ServerboundSelectKnownPacks(List<KnownPack> knownPacks) implements Packet<ServerConfigurationPacketListener> { | ||
public static final StreamCodec<ByteBuf, ServerboundSelectKnownPacks> STREAM_CODEC = StreamCodec.composite( | ||
- KnownPack.STREAM_CODEC.apply(ByteBufCodecs.list(64)), ServerboundSelectKnownPacks::knownPacks, ServerboundSelectKnownPacks::new | ||
+ // Neo: increase cap on number of KnownPacks to sync back to the server. This is safe even on vanilla connections, as no more packs will be synced here than were received in the S2C packet | ||
+ KnownPack.STREAM_CODEC.apply(ByteBufCodecs.list(1024)), ServerboundSelectKnownPacks::knownPacks, ServerboundSelectKnownPacks::new | ||
); | ||
|
||
@Override |
18 changes: 18 additions & 0 deletions
18
patches/net/minecraft/server/network/config/SynchronizeRegistriesTask.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- a/net/minecraft/server/network/config/SynchronizeRegistriesTask.java | ||
+++ b/net/minecraft/server/network/config/SynchronizeRegistriesTask.java | ||
@@ -45,11 +_,10 @@ | ||
} | ||
|
||
public void handleResponse(List<KnownPack> p_326076_, Consumer<Packet<?>> p_326167_) { | ||
- if (p_326076_.equals(this.requestedPacks)) { | ||
- this.sendRegistries(p_326167_, Set.copyOf(this.requestedPacks)); | ||
- } else { | ||
- this.sendRegistries(p_326167_, Set.of()); | ||
- } | ||
+ // Neo: instead of using either all available KnownPacks or none, allow partial fallback to normal syncing | ||
+ Set<KnownPack> requested = new java.util.HashSet<>(this.requestedPacks); | ||
+ requested.retainAll(p_326076_); | ||
+ this.sendRegistries(p_326167_, requested); | ||
} | ||
|
||
@Override |
11 changes: 9 additions & 2 deletions
11
patches/net/minecraft/server/packs/repository/ServerPacksSource.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
--- a/net/minecraft/server/packs/repository/ServerPacksSource.java | ||
+++ b/net/minecraft/server/packs/repository/ServerPacksSource.java | ||
@@ -72,7 +_,9 @@ | ||
@@ -72,11 +_,15 @@ | ||
} | ||
|
||
public static PackRepository createPackRepository(Path p_251569_, DirectoryValidator p_295336_) { | ||
- return new PackRepository(new ServerPacksSource(p_295336_), new FolderRepositorySource(p_251569_, PackType.SERVER_DATA, PackSource.WORLD, p_295336_)); | ||
+ final PackRepository packRepository = new PackRepository(new ServerPacksSource(p_295336_), new FolderRepositorySource(p_251569_, PackType.SERVER_DATA, PackSource.WORLD, p_295336_)); | ||
+ net.neoforged.neoforge.resource.ResourcePackLoader.populatePackRepository(packRepository, PackType.SERVER_DATA); | ||
+ net.neoforged.neoforge.resource.ResourcePackLoader.populatePackRepository(packRepository, PackType.SERVER_DATA, false); | ||
+ return packRepository; | ||
} | ||
|
||
public static PackRepository createVanillaTrustedRepository() { | ||
- return new PackRepository(new ServerPacksSource(new DirectoryValidator(p_293813_ -> true))); | ||
+ final PackRepository packRepository = new PackRepository(new ServerPacksSource(new DirectoryValidator(p_293813_ -> true))); | ||
+ net.neoforged.neoforge.resource.ResourcePackLoader.populatePackRepository(packRepository, PackType.SERVER_DATA, true); | ||
+ return packRepository; | ||
} | ||
|
||
public static PackRepository createPackRepository(LevelStorageSource.LevelStorageAccess p_250213_) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
tests/src/main/java/net/neoforged/neoforge/debug/resources/BulkKnownPackTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.debug.resources; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import java.util.Optional; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.PackLocationInfo; | ||
import net.minecraft.server.packs.PackSelectionConfig; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.repository.BuiltInPackSource; | ||
import net.minecraft.server.packs.repository.KnownPack; | ||
import net.minecraft.server.packs.repository.Pack; | ||
import net.minecraft.server.packs.repository.PackSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.neoforge.event.AddPackFindersEvent; | ||
import net.neoforged.neoforge.oldtest.world.LoginPacketSplitTest; | ||
import net.neoforged.testframework.DynamicTest; | ||
import net.neoforged.testframework.Test; | ||
import net.neoforged.testframework.TestFramework; | ||
import net.neoforged.testframework.TestListener; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.annotation.WithListener; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ForEachTest(groups = BulkKnownPackTest.GROUP, side = Dist.CLIENT) | ||
public class BulkKnownPackTest { | ||
public static final String GROUP = "resources"; | ||
private static final String NAMESPACE = "bulk_known_pack_test"; | ||
|
||
@TestHolder(description = "Tests that KnownPacks are correctly synced even when more than the vanilla 64 are present", enabledByDefault = true) | ||
@WithListener(BulkKnownPackTest.Listener.class) | ||
static void bulkKnownPackTest(final DynamicTest test) { | ||
test.framework().modEventBus().addListener(AddPackFindersEvent.class, event -> { | ||
if (event.getPackType() == PackType.SERVER_DATA) { | ||
for (int i = 0; i < 128; i++) { | ||
var id = "bulk_known_pack_test/" + i; | ||
PackLocationInfo info = new PackLocationInfo(id, Component.literal(i + "th containing single entry"), PackSource.BUILT_IN, Optional.of(new KnownPack(NAMESPACE, id, "1.0.0"))); | ||
final LoginPacketSplitTest.InMemoryResourcePack pack = new LoginPacketSplitTest.InMemoryResourcePack(info); | ||
generateEntry(pack, i); | ||
event.addRepositorySource(packs -> packs.accept(Pack.readMetaAndCreate( | ||
pack.location(), | ||
BuiltInPackSource.fixedResources(pack), | ||
PackType.SERVER_DATA, | ||
new PackSelectionConfig(true, Pack.Position.TOP, false)))); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static class Listener implements TestListener { | ||
@Override | ||
public void onEnabled(TestFramework framework, Test test, @Nullable Entity changer) { | ||
if (changer == null) { | ||
return; | ||
} | ||
RegistryAccess access = changer.registryAccess(); | ||
access.registry(Registries.BIOME).ifPresentOrElse(biomes -> { | ||
for (int i = 0; i < 128; i++) { | ||
var id = new ResourceLocation(NAMESPACE, "entry_" + i); | ||
if (biomes.getHolder(id).isEmpty()) { | ||
framework.changeStatus(test, Test.Status.failed("Entry " + id + " that should be synced by KnownPack not found"), changer); | ||
return; | ||
} | ||
framework.changeStatus(test, Test.Status.passed(), changer); | ||
} | ||
}, () -> { | ||
framework.changeStatus(test, Test.Status.failed("Failed to get biome registry"), changer); | ||
}); | ||
} | ||
} | ||
|
||
private static void generateEntry(LoginPacketSplitTest.InMemoryResourcePack pack, int i) { | ||
JsonObject json = new JsonObject(); | ||
json.addProperty("temperature", 1.0); | ||
json.addProperty("downfall", 1.0); | ||
json.addProperty("has_precipitation", false); | ||
JsonObject effects = new JsonObject(); | ||
effects.addProperty("sky_color", 0.0); | ||
effects.addProperty("fog_color", 0.0); | ||
effects.addProperty("water_color", 0.0); | ||
effects.addProperty("water_fog_color", 0.0); | ||
json.add("effects", effects); | ||
json.add("spawners", new JsonObject()); | ||
json.add("spawn_costs", new JsonObject()); | ||
json.add("carvers", new JsonObject()); | ||
json.add("features", new JsonArray()); | ||
pack.putData(new ResourceLocation(NAMESPACE, "worldgen/biome/entry_" + i + ".json"), json); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters