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 4 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
37 changes: 31 additions & 6 deletions patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
static Minecraft instance;
private static final Logger LOGGER = LogUtils.getLogger();
public static final boolean ON_OSX = Util.getPlatform() == Util.OS.OSX;
@@ -399,6 +_,7 @@
private final long clientStartTimeMs;
private long clientTickCount;
private String debugPath = "root";
+ private final net.neoforged.neoforge.flag.FlagManager moddedFlagManager = new net.neoforged.neoforge.flag.FlagManager(this::syncFlag);

public Minecraft(GameConfig p_91084_) {
super("Client");
@@ -435,7 +_,6 @@
}
}, Util.nonCriticalIoPool());
Expand Down Expand Up @@ -378,14 +386,31 @@
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 +_,16 @@
@Nullable
public static String getLauncherBrand() {
return System.getProperty("minecraft.launcher.brand");
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return moddedFlagManager;
+ }
+
+ private void syncFlag(net.neoforged.neoforge.flag.Flag flag, boolean enabled) {
+ if(singleplayerServer != null)
+ moddedFlagManager.saveToLevel(singleplayerServer.overworld());
}

public EntityModelSet getEntityModels() {
@OnlyIn(Dist.CLIENT)
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();
}
}
14 changes: 13 additions & 1 deletion patches/net/minecraft/client/server/IntegratedServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--- a/net/minecraft/client/server/IntegratedServer.java
+++ b/net/minecraft/client/server/IntegratedServer.java
@@ -73,10 +_,12 @@
@@ -73,10 +_,13 @@
this.setPvpAllowed(true);
this.setFlightAllowed(true);
this.initializeKeyPair();
+ net.neoforged.neoforge.server.ServerLifecycleHooks.handleServerAboutToStart(this);
this.loadLevel();
+ minecraft.getModdedFlagManager().loadFromLevel(overworld()); // Neo: Load flag data
GameProfile gameprofile = this.getSingleplayerProfile();
String s = this.getWorldData().getLevelName();
this.setMotd(gameprofile != null ? gameprofile.getName() + " - " + s : s);
Expand All @@ -21,3 +22,14 @@
this.executeBlocking(() -> {
for (ServerPlayer serverplayer : Lists.newArrayList(this.getPlayerList().getPlayers())) {
if (!serverplayer.getUUID().equals(this.uuid)) {
@@ -320,5 +_,10 @@
super.reportChunkSaveFailure(p_352264_, p_352355_, p_331440_);
this.warnOnLowDiskSpace();
this.minecraft.execute(() -> SystemToast.onChunkSaveFailure(this.minecraft, p_331440_));
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return minecraft.getModdedFlagManager();
}
}
19 changes: 19 additions & 0 deletions patches/net/minecraft/gametest/framework/GameTestServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
--- a/net/minecraft/gametest/framework/GameTestServer.java
+++ b/net/minecraft/gametest/framework/GameTestServer.java
@@ -70,6 +_,7 @@
private static final WorldOptions WORLD_OPTIONS = new WorldOptions(0L, false, false);
@Nullable
private MultipleTestTracker testTracker;
+ private final net.neoforged.neoforge.flag.FlagManager moddedFlagManager = new net.neoforged.neoforge.flag.FlagManager((flag, enabled) -> { /* NOOP: No syncing during game tests */ });

public static GameTestServer create(
Thread p_206607_, LevelStorageSource.LevelStorageAccess p_206608_, PackRepository p_206609_, Collection<TestFunction> p_206610_, BlockPos p_206611_
@@ -151,6 +_,7 @@
public boolean initServer() {
this.setPlayerList(new PlayerList(this, this.registries(), this.playerDataStorage, 1) {
Expand All @@ -16,3 +24,14 @@
return true;
}

@@ -301,5 +_,10 @@
@Override
public boolean isSingleplayerOwner(GameProfile p_177617_) {
return false;
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return moddedFlagManager;
}
}
21 changes: 21 additions & 0 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -167,7 +_,7 @@
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;

-public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource, AutoCloseable {
+public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource, AutoCloseable, net.neoforged.neoforge.common.extensions.IMinecraftServerExtension {
private static final Logger LOGGER = LogUtils.getLogger();
public static final String VANILLA_BRAND = "vanilla";
private static final float AVERAGE_TICK_TIME_SMOOTHING = 0.8F;
@@ -264,7 +_,7 @@

public static <S extends MinecraftServer> S spin(Function<Thread, S> p_129873_) {
Expand Down Expand Up @@ -205,6 +214,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 Flages (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 Down
26 changes: 24 additions & 2 deletions patches/net/minecraft/server/dedicated/DedicatedServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -80,6 +_,8 @@
@@ -80,6 +_,9 @@
@Nullable
private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker;
private final ServerLinks serverLinks;
+ @Nullable
+ private net.minecraft.client.server.LanServerPinger dediLanPinger;
+ private final net.neoforged.neoforge.flag.FlagManager moddedFlagManager = new net.neoforged.neoforge.flag.FlagManager(this::syncFlag);

public DedicatedServer(
Thread p_214789_,
Expand All @@ -17,13 +18,14 @@
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));

String s1;
@@ -185,11 +_,13 @@
@@ -185,11 +_,14 @@
long i = Util.getNanos();
SkullBlockEntity.setup(this.services, this);
GameProfileCache.setUsesAuthentication(this.usesAuthentication());
+ net.neoforged.neoforge.server.ServerLifecycleHooks.handleServerAboutToStart(this);
LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
this.loadLevel();
+ moddedFlagManager.loadFromLevel(overworld()); // Neo: Load flag data
long j = Util.getNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double)j / 1.0E9);
LOGGER.info("Done ({})! For help, type \"help\"", s);
Expand Down Expand Up @@ -68,3 +70,23 @@
Util.shutdownExecutors();
SkullBlockEntity.clear();
}
@@ -618,6 +_,19 @@
@Override
public ServerLinks serverLinks() {
return this.serverLinks;
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return moddedFlagManager;
+ }
+
+ private void syncFlag(net.neoforged.neoforge.flag.Flag flag, boolean enabled) {
+ moddedFlagManager.saveToLevel(overworld());
+
+ net.neoforged.neoforge.network.PacketDistributor.sendToAllPlayers(
+ new net.neoforged.neoforge.flag.ClientboundSyncFlag(flag, enabled)
+ );
}

private static ServerLinks createServerLinks(DedicatedServerSettings p_352317_) {
8 changes: 6 additions & 2 deletions patches/net/minecraft/server/level/ServerLevel.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
ServerLevel.this.dragonParts.put(enderdragonpart.getId(), enderdragonpart);
}
}
@@ -1733,24 +_,106 @@
@@ -1733,24 +_,110 @@
if (ServerLevel.this.isUpdatingNavigations) {
String s = "onTrackingStart called during navigation iteration";
Util.logAndPauseIfInIde(
Expand Down Expand Up @@ -243,7 +243,7 @@
public void onSectionChange(Entity p_215086_) {
p_215086_.updateDynamicGameEventListener(DynamicGameEventListener::move);
}
}
+ }
+
+ @Override
+ public java.util.Collection<net.neoforged.neoforge.entity.PartEntity<?>> getPartEntities() {
Expand Down Expand Up @@ -323,4 +323,8 @@
+ }
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return server.getModdedFlagManager();
}
}
11 changes: 11 additions & 0 deletions patches/net/minecraft/server/level/WorldGenRegion.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@
int i = SectionPos.blockToSectionCoord(p_9580_.getBlockX());
int j = SectionPos.blockToSectionCoord(p_9580_.getBlockZ());
this.getChunk(i, j).addEntity(p_9580_);
@@ -469,5 +_,10 @@
@Override
public long nextSubTickCount() {
return this.subTickCount.getAndIncrement();
+ }
+
+ @Override
+ public net.neoforged.neoforge.flag.FlagManager getModdedFlagManager() {
+ return level.getModdedFlagManager();
}
}
31 changes: 30 additions & 1 deletion patches/net/minecraft/world/effect/MobEffect.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
public static final Codec<Holder<MobEffect>> CODEC = BuiltInRegistries.MOB_EFFECT.holderByNameCodec();
public static final StreamCodec<RegistryFriendlyByteBuf, Holder<MobEffect>> STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT);
private static final int AMBIENT_ALPHA = Mth.floor(38.25F);
@@ -48,6 +_,7 @@
private int blendDurationTicks;
private Optional<SoundEvent> soundOnAdded = Optional.empty();
private FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
+ private java.util.Set<net.neoforged.neoforge.flag.Flag> requiredFlags = new java.util.HashSet<>();

protected MobEffect(MobEffectCategory p_19451_, int p_19452_) {
this.category = p_19451_;
@@ -130,6 +_,18 @@
return this;
}
Expand All @@ -28,11 +36,32 @@
public MobEffect setBlendDuration(int p_316265_) {
this.blendDurationTicks = p_316265_;
return this;
@@ -181,8 +_,24 @@
@@ -171,6 +_,10 @@
return this;
}

+ /**
+ * @deprecated Prefer {@linkplain #requiredFlags(net.neoforged.neoforge.flag.Flag...)}
+ */
+ @Deprecated
public MobEffect requiredFeatures(FeatureFlag... p_338702_) {
this.requiredFeatures = FeatureFlags.REGISTRY.subset(p_338702_);
return this;
@@ -181,8 +_,34 @@
return this.requiredFeatures;
}

- static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) {
+ public MobEffect requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
+ return this;
+ }
+
+ @Override
+ public java.util.Set<net.neoforged.neoforge.flag.Flag> requiredFlags() {
+ return requiredFlags;
+ }
+
+ /**
+ * Neo: Allowing mods to define client behavior for their MobEffects
+ * @deprecated Use {@link net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent} instead
Expand Down
Loading