mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Restore loading of feature datapacks in TestServer
This commit is contained in:
parent
ceb5661e2d
commit
f6c919d6a8
2 changed files with 34 additions and 3 deletions
|
@ -18,8 +18,11 @@ package net.fabricmc.fabric.impl.resource.loader;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -135,4 +138,33 @@ public final class ModResourcePackUtil {
|
|||
FeatureFlags.DEFAULT_ENABLED_FEATURES
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vanilla enables all available datapacks automatically in TestServer#create, but it does so in alphabetical order,
|
||||
* which means the Vanilla pack has higher precedence than modded, breaking our tests.
|
||||
* To fix this, we move all modded pack profiles to the end of the list.
|
||||
*/
|
||||
public static DataPackSettings createTestServerSettings(List<String> enabled, List<String> disabled) {
|
||||
// Collect modded profiles
|
||||
Set<String> moddedProfiles = new HashSet<>();
|
||||
ModResourcePackCreator modResourcePackCreator = new ModResourcePackCreator(ResourceType.SERVER_DATA);
|
||||
modResourcePackCreator.register(profile -> moddedProfiles.add(profile.getName()));
|
||||
|
||||
// Remove them from the enabled list
|
||||
List<String> moveToTheEnd = new ArrayList<>();
|
||||
|
||||
for (Iterator<String> it = enabled.iterator(); it.hasNext();) {
|
||||
String profile = it.next();
|
||||
|
||||
if (moddedProfiles.contains(profile)) {
|
||||
moveToTheEnd.add(profile);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Add back at the end
|
||||
enabled.addAll(moveToTheEnd);
|
||||
|
||||
return new DataPackSettings(enabled, disabled);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,13 +28,12 @@ import net.minecraft.test.TestServer;
|
|||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackUtil;
|
||||
|
||||
/**
|
||||
* Vanilla enables all available datapacks automatically in TestServer#create, but it does so in alphabetical order,
|
||||
* which means the Vanilla pack has higher precedence than modded, breaking our tests.
|
||||
* @see ModResourcePackUtil#createTestServerSettings
|
||||
*/
|
||||
@Mixin(TestServer.class)
|
||||
public class TestServerMixin {
|
||||
@Redirect(method = "create", at = @At(value = "NEW", target = "(Ljava/util/List;Ljava/util/List;)Lnet/minecraft/resource/DataPackSettings;"))
|
||||
private static DataPackSettings replaceDefaultDataPackSettings(List<String> enabled, List<String> disabled) {
|
||||
return ModResourcePackUtil.createDefaultDataConfiguration().dataPacks();
|
||||
return ModResourcePackUtil.createTestServerSettings(enabled, disabled);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue