Skip to content

Commit

Permalink
Initial flag system implementation
Browse files Browse the repository at this point in the history
Implement FeatureElement extensions
Implement saving/loading flag states to/from disk
Add coloring to flag list command
Remove ability to mark flags as enabled by default
Add basic java docs
Add parented element patches
Extend test to actually implement a GameTest

GameTest validates the following
- flag can be enabled and disabled
- all flagged elements match the expected enabled state

register flagged block & entity type
Add java doc to Flags
Update deprecated comments
Move flag manager events to NeoForgeEventHandler
Migrate SavedData over to LevelAttachment
Formatting
Fix junit tests hanging
Append enabled flags to crash reports
Reapply Item and MobEffect patches
Tear out old system
Initial implementation of overhauled system
Namespace the flags
Remove old unneeded json file
Fix data gen crashing
Fix junit tests hanging in CI
Update to use reference sets
Reapply MobEffect patches
Append modded feature flags to crash reports
Add RequiredFlagsCondition to allow marking data files as requiring a set of flags
  • Loading branch information
ApexModder committed Sep 5, 2024
1 parent 0303531 commit ffde592
Show file tree
Hide file tree
Showing 39 changed files with 1,037 additions and 48 deletions.
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)",
+ () -> 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

0 comments on commit ffde592

Please sign in to comment.