Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.2] Modded feature flag #1435

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ffde592
Initial flag system implementation
ApexModder Sep 5, 2024
cf87e5e
Add basic javadocs
ApexModder Sep 5, 2024
9304502
Use Set.copyOf over Collections.unmodifiableSet
ApexModder Sep 5, 2024
10315b0
Add default body to extension methods
ApexModder Sep 5, 2024
4699578
Ensure using ReferenceSets everywhere when storing flags
ApexModder Sep 6, 2024
754d925
Fix typo in MinecraftServer
ApexModder Sep 6, 2024
6617bbc
Refactor extension method directly into `Minecraft`
ApexModder Sep 6, 2024
aa7a5de
Make ATTACHMENT_TYPES field private
ApexModder Sep 6, 2024
b0cb6db
PR review requests
ApexModder Sep 6, 2024
4f2db37
Add back missing `@deprecated` annotation
ApexModder Sep 6, 2024
8cbd09c
Add todo marker about conditions not working during initial server sp…
ApexModder Sep 6, 2024
fa89010
Major system refactoring
ApexModder Sep 6, 2024
026548d
Add javadoc to ICondition method
ApexModder Sep 6, 2024
21eff50
Add back missing api methods
ApexModder Sep 6, 2024
5890da1
Fix crash during data gen
ApexModder Sep 6, 2024
ed34f45
Mark levels as experimental when flags are enabled
ApexModder Sep 6, 2024
87fc66a
Add hover tooltip to command output
ApexModder Sep 6, 2024
ccb4aea
Localize command output
ApexModder Sep 6, 2024
68fb38c
Address few of Monicas requests
ApexModder Sep 7, 2024
39fd670
Ensure we are using ReferenceSets everywhere
ApexModder Sep 7, 2024
327ae5d
Add back vanilla constructor
ApexModder Sep 7, 2024
c17e1dd
Return empty flag manager rather than throwing
ApexModder Sep 7, 2024
0d32b26
More set type validation
ApexModder Sep 7, 2024
e847550
Split out experiments checks into local vars
ApexModder Sep 7, 2024
206f8f0
Update javadoc
ApexModder Sep 7, 2024
9b12643
Overhaul command to match monicas requests
ApexModder Sep 7, 2024
de4e095
Update to store empty sets until some flag is provided
ApexModder Sep 7, 2024
b05e171
Fix potentially copying empty set
ApexModder Sep 7, 2024
1e4128c
Add back missing admin permission to command
ApexModder Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
static Minecraft instance;
private static final Logger LOGGER = LogUtils.getLogger();
public static final boolean ON_OSX = Util.getPlatform() == Util.OS.OSX;
@@ -399,6 +_,9 @@
private final long clientStartTimeMs;
private long clientTickCount;
private String debugPath = "root";
+ @org.jetbrains.annotations.Nullable
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public net.neoforged.neoforge.flag.FlagManager clientModdedFlagManager;

public Minecraft(GameConfig p_91084_) {
super("Client");
@@ -435,7 +_,6 @@
}
}, Util.nonCriticalIoPool());
Expand Down Expand Up @@ -336,10 +346,11 @@
this.level = p_91157_;
this.updateLevelInEngines(p_91157_);
if (!this.isLocalServer) {
@@ -2093,6 +_,7 @@
@@ -2093,6 +_,8 @@
IntegratedServer integratedserver = this.singleplayerServer;
this.singleplayerServer = null;
this.gameRenderer.resetData();
+ this.clientModdedFlagManager = null;
+ net.neoforged.neoforge.client.ClientHooks.firePlayerLogout(this.gameMode, this.player);
this.gameMode = null;
this.narrator.clear();
Expand Down Expand Up @@ -378,14 +389,29 @@
if (itemstack == null) {
return;
}
@@ -2794,6 +_,10 @@

public void updateMaxMipLevel(int p_91313_) {
@@ -2796,6 +_,10 @@
this.modelManager.updateMaxMipLevel(p_91313_);
+ }
+
}
+ public ItemColors getItemColors() {
+ return this.itemColors;
+ }
+
public EntityModelSet getEntityModels() {
return this.entityModels;
}
@@ -2868,6 +_,14 @@
@Nullable
public static String getLauncherBrand() {
return System.getProperty("minecraft.launcher.brand");
+ }
+
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ if(clientModdedFlagManager != null)
+ return clientModdedFlagManager;
+ if(singleplayerServer != null)
+ return singleplayerServer.getModdedFlagManager();
+ return net.neoforged.neoforge.flag.FlagManager.EMPTY;
}

public EntityModelSet getEntityModels() {
@OnlyIn(Dist.CLIENT)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
WorldLoader.InitConfig worldloader$initconfig = createDefaultLoadConfig(packrepository, WorldDataConfiguration.DEFAULT);
CompletableFuture<WorldCreationContext> completablefuture = WorldLoader.load(
worldloader$initconfig,
@@ -219,7 +_,9 @@
WorldDimensions.Complete worlddimensions$complete = worldcreationcontext.selectedDimensions().bake(worldcreationcontext.datapackDimensions());
LayeredRegistryAccess<RegistryLayer> layeredregistryaccess = worldcreationcontext.worldgenRegistries()
.replaceFrom(RegistryLayer.DIMENSIONS, worlddimensions$complete.dimensionsRegistryAccess());
- Lifecycle lifecycle = FeatureFlags.isExperimental(worldcreationcontext.dataConfiguration().enabledFeatures())
+ // Neo: vanilla experimental flag present or modded flag present
+ var isExperimental = FeatureFlags.isExperimental(worldcreationcontext.dataConfiguration().enabledFeatures()) || !worldcreationcontext.dataConfiguration().enabledModdedFeatures().isEmpty();
+ Lifecycle lifecycle = isExperimental
? Lifecycle.experimental()
: Lifecycle.stable();
Lifecycle lifecycle1 = layeredregistryaccess.compositeAccess().allRegistriesLifecycle();
@@ -243,6 +_,10 @@
WorldCreationContext worldcreationcontext = this.uiState.getSettings();
LevelSettings levelsettings = this.createLevelSettings(flag);
Expand All @@ -19,12 +30,30 @@
this.minecraft
.createWorldOpenFlows()
.createLevelFromExistingSettings(optional.get(), worldcreationcontext.dataPackResources(), p_249152_, worlddata);
@@ -358,13 +_,15 @@
List<String> list = ImmutableList.copyOf(p_270299_.getSelectedIds());
List<String> list1 = p_270299_.getAvailableIds().stream().filter(p_232927_ -> !list.contains(p_232927_)).collect(ImmutableList.toImmutableList());
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(
- new DataPackConfig(list, list1), this.uiState.getSettings().dataConfiguration().enabledFeatures()
+ new DataPackConfig(list, list1), this.uiState.getSettings().dataConfiguration().enabledFeatures(), this.uiState.getSettings().dataConfiguration().enabledModdedFeatures()
);
if (this.uiState.tryUpdateDataConfiguration(worlddataconfiguration)) {
this.minecraft.setScreen(this);
} else {
FeatureFlagSet featureflagset = p_270299_.getRequestedFeatureFlags();
- if (FeatureFlags.isExperimental(featureflagset) && p_270896_) {
+ // Neo: vanilla experimental flag present or modded flag present
+ var isExperimental = FeatureFlags.isExperimental(featureflagset) || !worlddataconfiguration.enabledModdedFeatures().isEmpty();
+ if (isExperimental && p_270896_) {
this.minecraft.setScreen(new ConfirmExperimentalFeaturesScreen(p_270299_.getSelectedPacks(), p_269635_ -> {
if (p_269635_) {
this.applyNewPackConfig(p_270299_, worlddataconfiguration, p_270760_);
@@ -428,7 +_,7 @@
if (p_269627_) {
p_270552_.accept(this.uiState.getSettings().dataConfiguration());
} else {
- p_270552_.accept(WorldDataConfiguration.DEFAULT);
+ p_270552_.accept(new WorldDataConfiguration(new DataPackConfig(ImmutableList.of("vanilla"), ImmutableList.of()), FeatureFlags.VANILLA_SET)); // FORGE: Revert to *actual* vanilla data
+ p_270552_.accept(new WorldDataConfiguration(new DataPackConfig(ImmutableList.of("vanilla"), ImmutableList.of()), FeatureFlags.VANILLA_SET, it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet())); // FORGE: Revert to *actual* vanilla data
}
},
Component.translatable("dataPack.validation.failed"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
this.difficulty = p_104852_;
}

@@ -1069,14 +_,75 @@
@@ -1069,14 +_,80 @@
if (p_171712_ instanceof AbstractClientPlayer) {
ClientLevel.this.players.add((AbstractClientPlayer)p_171712_);
}
Expand Down Expand Up @@ -183,5 +183,10 @@
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public void setDayTimePerTick(float dayTimePerTick) {
+ this.dayTimePerTick = dayTimePerTick;
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return minecraft.getModdedFlagManager();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--- a/net/minecraft/gametest/framework/GameTestServer.java
+++ b/net/minecraft/gametest/framework/GameTestServer.java
@@ -79,7 +_,7 @@
} else {
p_206609_.reload();
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(
- new DataPackConfig(new ArrayList<>(p_206609_.getAvailableIds()), List.of()), FeatureFlags.REGISTRY.allFlags()
+ new DataPackConfig(new ArrayList<>(p_206609_.getAvailableIds()), List.of()), FeatureFlags.REGISTRY.allFlags(), net.neoforged.neoforge.flag.Flag.getFlags()
);
LevelSettings levelsettings = new LevelSettings(
"Test Level", GameType.CREATIVE, false, Difficulty.NORMAL, true, TEST_GAME_RULES, worlddataconfiguration
@@ -151,6 +_,7 @@
public boolean initServer() {
this.setPlayerList(new PlayerList(this, this.registries(), this.playerDataStorage, 1) {
Expand Down
9 changes: 9 additions & 0 deletions patches/net/minecraft/server/Main.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@
}
};
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
@@ -302,7 +_,7 @@
worlddataconfiguration = worlddataconfiguration1;
} else {
flag = true;
- worlddataconfiguration = new WorldDataConfiguration(p_248563_.initialDataPackConfiguration, FeatureFlags.DEFAULT_FLAGS);
+ worlddataconfiguration = new WorldDataConfiguration(p_248563_.initialDataPackConfiguration, FeatureFlags.DEFAULT_FLAGS, it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet());
}

WorldLoader.PackConfig worldloader$packconfig = new WorldLoader.PackConfig(p_251069_, worlddataconfiguration, p_249093_, flag);
97 changes: 87 additions & 10 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -264,7 +_,7 @@
@@ -261,10 +_,11 @@
private final PotionBrewing potionBrewing;
private volatile boolean isSaving;
private static final AtomicReference<RuntimeException> fatalException = new AtomicReference<>();
+ private final net.neoforged.neoforge.flag.FlagManager moddedFlagManager;

public static <S extends MinecraftServer> S spin(Function<Thread, S> p_129873_) {
AtomicReference<S> atomicreference = new AtomicReference<>();
Expand All @@ -9,6 +13,14 @@
thread.setUncaughtExceptionHandler((p_177909_, p_177910_) -> LOGGER.error("Uncaught exception in server thread", p_177910_));
if (Runtime.getRuntime().availableProcessors() > 4) {
thread.setPriority(8);
@@ -316,6 +_,7 @@
this.serverThread = p_236723_;
this.executor = Util.backgroundExecutor();
this.potionBrewing = PotionBrewing.bootstrap(this.worldData.enabledFeatures());
+ this.moddedFlagManager = new net.neoforged.neoforge.flag.ServerFlagManager(this, this.worldData.getDataConfiguration().enabledModdedFeatures());
}
}

@@ -372,6 +_,7 @@
this.readScoreboard(dimensiondatastorage);
this.commandStorage = new CommandStorage(dimensiondatastorage);
Expand Down Expand Up @@ -205,6 +217,18 @@
}

public SystemReport fillSystemReport(SystemReport p_177936_) {
@@ -1135,6 +_,11 @@
"Enabled Feature Flags",
() -> FeatureFlags.REGISTRY.toNames(this.worldData.enabledFeatures()).stream().map(ResourceLocation::toString).collect(Collectors.joining(", "))
);
+ // Neo: Append modded feature flags to crash reports
+ p_177936_.setDetail(
+ "Enabled Mod Features",
+ () -> moddedFlagManager.enabledFlags().map(net.neoforged.neoforge.flag.Flag::toStringShort).collect(Collectors.joining(", "))
+ );
p_177936_.setDetail("World Generation", () -> this.worldData.worldGenSettingsLifecycle().toString());
p_177936_.setDetail("World Seed", () -> String.valueOf(this.worldData.worldGenOptions().seed()));
if (this.serverId != null) {
@@ -1441,7 +_,7 @@

public CompletableFuture<Void> reloadResources(Collection<String> p_129862_) {
Expand All @@ -214,6 +238,23 @@
this
)
.thenCompose(
@@ -1451,6 +_,7 @@
closeableresourcemanager,
this.registries,
this.worldData.enabledFeatures(),
+ this.moddedFlagManager,
this.isDedicatedServer() ? Commands.CommandSelection.DEDICATED : Commands.CommandSelection.INTEGRATED,
this.getFunctionCompilationLevel(),
this.executor,
@@ -1470,7 +_,7 @@
this.resources = p_335203_;
this.packRepository.setSelected(p_129862_);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(
- getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()
+ getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures(), this.worldData.getDataConfiguration().enabledModdedFeatures()
);
this.worldData.setDataConfiguration(worlddataconfiguration);
this.resources.managers.updateRegistryTags();
@@ -1478,6 +_,7 @@
this.getPlayerList().reloadResources();
this.functionManager.replaceLibrary(this.resources.managers.getFunctionLibrary());
Expand All @@ -230,19 +271,44 @@
+ datapackconfig.addModPacks(net.neoforged.neoforge.common.CommonHooks.getModDataPacks());
if (p_341620_) {
- return configureRepositoryWithSelection(p_248681_, List.of("vanilla"), featureflagset, false);
+ return configureRepositoryWithSelection(p_248681_, net.neoforged.neoforge.common.CommonHooks.getModDataPacksWithVanilla(), featureflagset, false);
+ return configureRepositoryWithSelection(p_248681_, net.neoforged.neoforge.common.CommonHooks.getModDataPacksWithVanilla(), featureflagset, p_341632_.enabledModdedFeatures(), false);
} else {
Set<String> set = Sets.newLinkedHashSet();

@@ -1542,6 +_,8 @@
@@ -1542,18 +_,30 @@
set.add("vanilla");
}

- return configureRepositoryWithSelection(p_248681_, set, featureflagset, true);
+ net.neoforged.neoforge.resource.ResourcePackLoader.reorderNewlyDiscoveredPacks(set, datapackconfig.getEnabled(), p_248681_);
+
return configureRepositoryWithSelection(p_248681_, set, featureflagset, true);
+ return configureRepositoryWithSelection(p_248681_, set, featureflagset, p_341632_.enabledModdedFeatures(), true);
}
}

private static WorldDataConfiguration configureRepositoryWithSelection(
- PackRepository p_341680_, Collection<String> p_341677_, FeatureFlagSet p_341602_, boolean p_341662_
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
+ PackRepository p_341680_, Collection<String> p_341677_, FeatureFlagSet p_341602_, it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> enabledModdedFeatures, boolean p_341662_
) {
p_341680_.setSelected(p_341677_);
enableForcedFeaturePacks(p_341680_, p_341602_);
DataPackConfig datapackconfig = getSelectedPacks(p_341680_, p_341662_);
FeatureFlagSet featureflagset = p_341680_.getRequestedFeatureFlags().join(p_341602_);
- return new WorldDataConfiguration(datapackconfig, featureflagset);
+ return new WorldDataConfiguration(datapackconfig, featureflagset, enabledModdedFeatures);
+ }
+
+ /**
+ * @deprecated Prefer {@link #configureRepositoryWithSelection(PackRepository, Collection, FeatureFlagSet, it.unimi.dsi.fastutil.objects.ReferenceSet, boolean)}
+ */
+ @Deprecated
+ private static WorldDataConfiguration configureRepositoryWithSelection(
+ PackRepository p_341680_, Collection<String> p_341677_, FeatureFlagSet p_341602_, boolean p_341662_
+ ) {
+ return configureRepositoryWithSelection(p_341680_, p_341677_, p_341602_, it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet(), p_341662_);
}

private static void enableForcedFeaturePacks(PackRepository p_341674_, FeatureFlagSet p_341598_) {
@@ -1712,6 +_,31 @@

public abstract boolean isSingleplayerOwner(GameProfile p_129840_);
Expand Down Expand Up @@ -275,14 +341,25 @@
public void dumpServerProperties(Path p_177911_) throws IOException {
}

@@ -1873,6 +_,10 @@

public WorldData getWorldData() {
@@ -1875,6 +_,10 @@
return this.worldData;
+ }
+
}
+ public MinecraftServer.ReloadableResources getServerResources() {
+ return resources;
+ }
+
public RegistryAccess.Frozen registryAccess() {
return this.registries.compositeAccess();
}
@@ -1999,6 +_,10 @@

public RegistryAccess.Frozen registryAccess() {
public ServerLinks serverLinks() {
return ServerLinks.EMPTY;
+ }
+
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return moddedFlagManager;
}

public static record ReloadableResources(CloseableResourceManager resourceManager, ReloadableServerResources managers) implements AutoCloseable {
Loading