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 18 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.NULL;
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
}

public EntityModelSet getEntityModels() {
@OnlyIn(Dist.CLIENT)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
WorldLoader.InitConfig worldloader$initconfig = createDefaultLoadConfig(packrepository, WorldDataConfiguration.DEFAULT);
CompletableFuture<WorldCreationContext> completablefuture = WorldLoader.load(
worldloader$initconfig,
@@ -219,7 +_,7 @@
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())
+ Lifecycle lifecycle = FeatureFlags.isExperimental(worldcreationcontext.dataConfiguration().enabledFeatures()) || !worldcreationcontext.dataConfiguration().enabledModdedFeatures().isEmpty()
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
? 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 +28,28 @@
this.minecraft
.createWorldOpenFlows()
.createLevelFromExistingSettings(optional.get(), worldcreationcontext.dataPackResources(), p_249152_, worlddata);
@@ -358,13 +_,13 @@
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_) {
+ if ((FeatureFlags.isExperimental(featureflagset) || !worlddataconfiguration.enabledModdedFeatures().isEmpty()) && 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, java.util.Collections.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, java.util.Collections.emptySet());
}

WorldLoader.PackConfig worldloader$packconfig = new WorldLoader.PackConfig(p_251069_, worlddataconfiguration, p_249093_, flag);
89 changes: 79 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 Feature Flags (Modded)",
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
+ () -> getModdedFlagManager().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,25 @@
this
)
.thenCompose(
@@ -1454,7 +_,8 @@
this.isDedicatedServer() ? Commands.CommandSelection.DEDICATED : Commands.CommandSelection.INTEGRATED,
this.getFunctionCompilationLevel(),
this.executor,
- this
+ this,
+ this.worldData.getDataConfiguration().enabledModdedFeatures()
)
.whenComplete((p_212907_, p_212908_) -> {
if (p_212908_ != null) {
@@ -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 +273,34 @@
+ 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, false, p_341632_.enabledModdedFeatures());
} else {
Set<String> set = Sets.newLinkedHashSet();

@@ -1542,6 +_,8 @@
@@ -1542,18 +_,20 @@
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, true, p_341632_.enabledModdedFeatures());
}
}

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_, boolean p_341662_, Set<net.neoforged.neoforge.flag.Flag> enabledModdedFeatures
) {
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);
}

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 +333,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 {
46 changes: 42 additions & 4 deletions patches/net/minecraft/server/ReloadableServerResources.java.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
--- a/net/minecraft/server/ReloadableServerResources.java
+++ b/net/minecraft/server/ReloadableServerResources.java
@@ -40,7 +_,7 @@
private final ServerAdvancementManager advancements;
private final ServerFunctionLibrary functionLibrary;

- private ReloadableServerResources(RegistryAccess.Frozen p_206857_, FeatureFlagSet p_250695_, Commands.CommandSelection p_206858_, int p_206859_) {
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
+ private ReloadableServerResources(RegistryAccess.Frozen p_206857_, FeatureFlagSet p_250695_, Commands.CommandSelection p_206858_, int p_206859_, java.util.Set<net.neoforged.neoforge.flag.Flag> enabledModdedFlags) {
this.fullRegistryHolder = new ReloadableServerRegistries.Holder(p_206857_);
this.registryLookup = new ReloadableServerResources.ConfigurableRegistryLookup(p_206857_);
this.registryLookup.missingTagAccessPolicy(ReloadableServerResources.MissingTagAccessPolicy.CREATE_NEW);
@@ -49,6 +_,8 @@
this.commands = new Commands(p_206858_, CommandBuildContext.simple(this.registryLookup, p_250695_));
this.advancements = new ServerAdvancementManager(this.registryLookup);
this.functionLibrary = new ServerFunctionLibrary(p_206859_, this.commands.getDispatcher());
+ // Neo: Create context object
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.tagManager);
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.tagManager, enabledModdedFlags);
}

public ServerFunctionLibrary getFunctionLibrary() {
Expand Down Expand Up @@ -34,9 +43,20 @@
public static CompletableFuture<ReloadableServerResources> loadResources(
ResourceManager p_248588_,
LayeredRegistryAccess<RegistryLayer> p_335667_,
@@ -90,14 +_,27 @@
@@ -82,31 +_,62 @@
Commands.CommandSelection p_249301_,
int p_251126_,
Executor p_249136_,
- Executor p_249601_
+ Executor p_249601_,
+ java.util.Set<net.neoforged.neoforge.flag.Flag> enabledModdedFlags
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
) {
return ReloadableServerRegistries.reload(p_335667_, p_248588_, p_249136_)
.thenCompose(
p_335211_ -> {
ReloadableServerResources reloadableserverresources = new ReloadableServerResources(
p_335211_.compositeAccess(), p_250212_, p_249301_, p_251126_
- p_335211_.compositeAccess(), p_250212_, p_249301_, p_251126_
+ p_335211_.compositeAccess(), p_250212_, p_249301_, p_251126_, enabledModdedFlags
);
+ List<PreparableReloadListener> listeners = new java.util.ArrayList<>(reloadableserverresources.listeners());
+ listeners.addAll(net.neoforged.neoforge.event.EventHooks.onResourceReload(reloadableserverresources, p_335211_.compositeAccess()));
Expand All @@ -63,7 +83,25 @@
.thenApply(p_214306_ -> reloadableserverresources);
}
);
@@ -107,6 +_,7 @@
}

+ /**
+ * @deprecated Prefer to use {@link #loadResources(ResourceManager, LayeredRegistryAccess, FeatureFlagSet, Commands.CommandSelection, int, Executor, Executor, java.util.Set)}.
+ */
+ @Deprecated
+ public static CompletableFuture<ReloadableServerResources> loadResources(
+ ResourceManager p_248588_,
+ LayeredRegistryAccess<RegistryLayer> p_335667_,
+ FeatureFlagSet p_250212_,
+ Commands.CommandSelection p_249301_,
+ int p_251126_,
+ Executor p_249136_,
+ Executor p_249601_
+ ) {
+ return loadResources(p_248588_, p_335667_, p_250212_, p_249301_, p_251126_, p_249136_, p_249601_, java.util.Collections.emptySet());
+ }
+
public void updateRegistryTags() {
this.tagManager.getResult().forEach(p_335204_ -> updateRegistryTags(this.fullRegistryHolder.get(), (TagManager.LoadResult<?>)p_335204_));
AbstractFurnaceBlockEntity.invalidateCache();
Blocks.rebuildCache();
Expand Down
10 changes: 10 additions & 0 deletions patches/net/minecraft/server/WorldLoader.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@
);
RegistryAccess.Frozen registryaccess$frozen = layeredregistryaccess1.getAccessForLoading(RegistryLayer.DIMENSIONS);
RegistryAccess.Frozen registryaccess$frozen1 = RegistryDataLoader.load(
@@ -53,7 +_,8 @@
p_214363_.commandSelection(),
p_214363_.functionCompilationLevel(),
p_214366_,
- p_214367_
+ p_214367_,
+ worlddataconfiguration.enabledModdedFeatures()
)
.whenComplete((p_214370_, p_214371_) -> {
if (p_214371_ != null) {
Loading