Skip to content

Commit

Permalink
Merge branch '1.21.x' into AttributeTemplatePublicity
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Nov 27, 2024
2 parents da40a62 + c0dbe21 commit 57fd4ba
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
+ this.pages.clear();
+ int tabIndex = 0;
+ List<CreativeModeTab> currentPage = new java.util.ArrayList<>();
+ for (CreativeModeTab sortedCreativeModeTab : net.neoforged.neoforge.common.CreativeModeTabRegistry.getSortedCreativeModeTabs()) {
+ for (CreativeModeTab sortedCreativeModeTab : net.neoforged.neoforge.common.CreativeModeTabRegistry.getSortedCreativeModeTabs().stream().filter(CreativeModeTab::hasAnyItems).toList()) {
+ currentPage.add(sortedCreativeModeTab);
+ tabIndex++;
+ if (tabIndex == 10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
this.functionLibrary = new ServerFunctionLibrary(p_206859_, this.commands.getDispatcher());
+ // Neo: Store registries and create context object
+ this.registryLookup = p_361583_;
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.postponedTags);
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.postponedTags, p_250695_);
}

public ServerFunctionLibrary getFunctionLibrary() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
p_78531_.get("Player").flatMap(CompoundTag.CODEC::parse).result().orElse(null),
p_78531_.get("WasModded").asBoolean(false),
new BlockPos(p_78531_.get("SpawnX").asInt(0), p_78531_.get("SpawnY").asInt(0), p_78531_.get("SpawnZ").asInt(0)),
@@ -192,7 +_,8 @@
.asStream()
.flatMap(p_338118_ -> p_338118_.asString().result().stream())
.collect(Collectors.toCollection(Sets::newLinkedHashSet)),
- p_78531_.get("removed_features").asStream().flatMap(p_338117_ -> p_338117_.asString().result().stream()).collect(Collectors.toSet()),
+ // Neo: Append removed modded feature flags
+ updateRemovedFeatureFlags(p_78531_.get("removed_features").asStream().flatMap(p_338117_ -> p_338117_.asString().result().stream()), p_78531_.get("enabled_features").asStream().flatMap(features -> features.asString().result().stream())).collect(Collectors.toSet()),
new TimerQueue<>(TimerCallbacks.SERVER_CALLBACKS, p_78531_.get("ScheduledEvents").asStream()),
(CompoundTag)p_78531_.get("CustomBossEvents").orElseEmptyMap().getValue(),
p_78531_.get("DragonFight").read(EndDragonFight.Data.CODEC).resultOrPartial(LOGGER::error).orElse(EndDragonFight.Data.DEFAULT),
@@ -200,7 +_,11 @@
p_251864_,
p_250651_,
Expand All @@ -42,7 +52,7 @@
}

private static ListTag stringCollectionToTag(Set<String> p_277880_) {
@@ -572,10 +_,44 @@
@@ -572,10 +_,58 @@
return this.settings.copy();
}

Expand Down Expand Up @@ -85,5 +95,19 @@
+ @Override
+ public void setDayTimePerTick(float dayTimePerTick) {
+ this.dayTimePerTick = dayTimePerTick;
+ }
+
+ private static java.util.stream.Stream<String> updateRemovedFeatureFlags(java.util.stream.Stream<String> removedFeatures, java.util.stream.Stream<String> enabledFeatures) {
+ var unknownFeatureFlags = new HashSet<net.minecraft.resources.ResourceLocation>();
+ // parses the incoming Stream<String> and spits out unknown flag names (ResourceLocation)
+ // we do not care about the returned FeatureFlagSet, only the flags which do not exist
+ net.minecraft.world.flag.FeatureFlags.REGISTRY.fromNames(enabledFeatures.map(net.minecraft.resources.ResourceLocation::parse).collect(Collectors.toSet()), unknownFeatureFlags::add);
+ // concat the received removed flags with our new additions
+ return java.util.stream.Stream.concat(removedFeatures, unknownFeatureFlags.stream()
+ // we only want modded flags, mojang has datafixers for vanilla flags
+ .filter(java.util.function.Predicate.not(name -> name.getNamespace().equals(net.minecraft.resources.ResourceLocation.DEFAULT_NAMESPACE)))
+ .map(net.minecraft.resources.ResourceLocation::toString))
+ // no duplicates should exist in this stream
+ .distinct();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public static class Server {
*/
public static class Common {
public final ModConfigSpec.EnumValue<TagConventionLogWarning.LogWarningMode> logUntranslatedItemTagWarnings;

public final ModConfigSpec.EnumValue<TagConventionLogWarning.LogWarningMode> logLegacyTagWarnings;

public final BooleanValue attributeAdvancedTooltipDebugInfo;

Common(ModConfigSpec.Builder builder) {
logUntranslatedItemTagWarnings = builder
.comment("A config option mainly for developers. Logs out modded item tags that do not have translations when running on integrated server. Format desired is tag.item.<namespace>.<path> for the translation key. Defaults to SILENCED.")
Expand All @@ -77,6 +80,11 @@ public static class Common {
.comment("A config option mainly for developers. Logs out modded tags that are using the 'forge' namespace when running on integrated server. Defaults to DEV_SHORT.")
.translation("neoforge.configgui.logLegacyTagWarnings")
.defineEnum("logLegacyTagWarnings", TagConventionLogWarning.LogWarningMode.DEV_SHORT);

attributeAdvancedTooltipDebugInfo = builder
.comment("Set this to true to enable showing debug information about attributes on an item when advanced tooltips is on.")
.translation("neoforge.configgui.attributeAdvancedTooltipDebugInfo")
.define("attributeAdvancedTooltipDebugInfo", true);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import net.neoforged.neoforge.common.advancements.critereon.SnowBootsEntityPredicate;
import net.neoforged.neoforge.common.conditions.AndCondition;
import net.neoforged.neoforge.common.conditions.FalseCondition;
import net.neoforged.neoforge.common.conditions.FlagCondition;
import net.neoforged.neoforge.common.conditions.ICondition;
import net.neoforged.neoforge.common.conditions.ItemExistsCondition;
import net.neoforged.neoforge.common.conditions.ModLoadedCondition;
Expand Down Expand Up @@ -385,6 +386,7 @@ public class NeoForgeMod {
public static final DeferredHolder<MapCodec<? extends ICondition>, MapCodec<OrCondition>> OR_CONDITION = CONDITION_CODECS.register("or", () -> OrCondition.CODEC);
public static final DeferredHolder<MapCodec<? extends ICondition>, MapCodec<TagEmptyCondition>> TAG_EMPTY_CONDITION = CONDITION_CODECS.register("tag_empty", () -> TagEmptyCondition.CODEC);
public static final DeferredHolder<MapCodec<? extends ICondition>, MapCodec<TrueCondition>> TRUE_CONDITION = CONDITION_CODECS.register("true", () -> TrueCondition.CODEC);
public static final DeferredHolder<MapCodec<? extends ICondition>, MapCodec<FlagCondition>> FEATURE_FLAG_CONDITION = CONDITION_CODECS.register("feature_flags", () -> FlagCondition.CODEC);

private static final DeferredRegister<MapCodec<? extends EntitySubPredicate>> ENTITY_PREDICATE_CODECS = DeferredRegister.create(Registries.ENTITY_SUB_PREDICATE_TYPE, NeoForgeVersion.MOD_ID);
public static final DeferredHolder<MapCodec<? extends EntitySubPredicate>, MapCodec<PiglinNeutralArmorEntityPredicate>> PIGLIN_NEUTRAL_ARMOR_PREDICATE = ENTITY_PREDICATE_CODECS.register("piglin_neutral_armor", () -> PiglinNeutralArmorEntityPredicate.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import org.jetbrains.annotations.ApiStatus;

public class ConditionContext implements ICondition.IContext {
private final Map<ResourceKey<? extends Registry<?>>, HolderLookup.RegistryLookup<?>> pendingTags;
private final FeatureFlagSet enabledFeatures;

public ConditionContext(List<Registry.PendingTags<?>> pendingTags) {
public ConditionContext(List<Registry.PendingTags<?>> pendingTags, FeatureFlagSet enabledFeatures) {
this.pendingTags = new IdentityHashMap<>();
this.enabledFeatures = enabledFeatures;

for (var tags : pendingTags) {
this.pendingTags.put(tags.key(), tags.lookup());
}
}

// Use FeatureFlagSet sensitive constructor
@ApiStatus.ScheduledForRemoval(inVersion = "1.21.4")
@Deprecated(forRemoval = true, since = "1.21.3")
public ConditionContext(List<Registry.PendingTags<?>> pendingTags) {
this(pendingTags, FeatureFlags.VANILLA_SET);
}

public void clear() {
this.pendingTags.clear();
}
Expand All @@ -33,4 +46,9 @@ public <T> boolean isTagLoaded(TagKey<T> key) {
var lookup = pendingTags.get(key.registry());
return lookup != null && lookup.get((TagKey) key).isPresent();
}

@Override
public FeatureFlagSet enabledFeatures() {
return enabledFeatures;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.common.conditions;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.flag.FeatureFlag;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;

/**
* Condition checking for the enabled state of a given {@link FeatureFlagSet}.
* <p>
* {@code requiredFeatures} - {@link FeatureFlagSet} containing all {@link FeatureFlag feature flags} to be validated.
* {@code expectedResult} - Validates that all given {@link FeatureFlag feature flags} are enabled when {@code true} or disabled when {@code false}.
*
* @apiNote Mainly to be used when flagged content is not contained within the same feature pack which also enables said {@link FeatureFlag feature flags}.
*/
public final class FlagCondition implements ICondition {
public static final MapCodec<FlagCondition> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
FeatureFlags.CODEC.fieldOf("flags").forGetter(condition -> condition.requiredFeatures),
Codec.BOOL.lenientOptionalFieldOf("expected_result", true).forGetter(condition -> condition.expectedResult)).apply(instance, FlagCondition::new));

private final FeatureFlagSet requiredFeatures;
private final boolean expectedResult;

private FlagCondition(FeatureFlagSet requiredFeatures, boolean expectedResult) {
this.requiredFeatures = requiredFeatures;
this.expectedResult = expectedResult;
}

@Override
public boolean test(IContext context) {
var flagsEnabled = requiredFeatures.isSubsetOf(context.enabledFeatures());
// true if: 'expectedResult' is true nd all given flags are enabled
// false if: `enabledEnabled' is false and all given flags are disabled
return flagsEnabled == expectedResult;
}

@Override
public MapCodec<? extends ICondition> codec() {
return CODEC;
}

public static ICondition isEnabled(FeatureFlagSet requiredFeatures) {
return new FlagCondition(requiredFeatures, true);
}

public static ICondition isEnabled(FeatureFlag requiredFlag) {
return isEnabled(FeatureFlagSet.of(requiredFlag));
}

public static ICondition isEnabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return isEnabled(FeatureFlagSet.of(requiredFlag, requiredFlags));
}

public static ICondition isDisabled(FeatureFlagSet requiredFeatures) {
return new FlagCondition(requiredFeatures, false);
}

public static ICondition isDisabled(FeatureFlag requiredFlag) {
return isDisabled(FeatureFlagSet.of(requiredFlag));
}

public static ICondition isDisabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return isDisabled(FeatureFlagSet.of(requiredFlag, requiredFlags));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import net.minecraft.resources.RegistryOps;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Unit;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

public interface ICondition {
Codec<ICondition> CODEC = NeoForgeRegistries.CONDITION_SERIALIZERS.byNameCodec()
Expand Down Expand Up @@ -91,5 +94,15 @@ public <T> boolean isTagLoaded(TagKey<T> key) {
* Returns {@code true} if the requested tag is available.
*/
<T> boolean isTagLoaded(TagKey<T> key);

default FeatureFlagSet enabledFeatures() {
// returning the vanilla set causes reports false positives for flags outside of vanilla
// return FeatureFlags.VANILLA_SET;

// lookup the active enabledFeatures from the current server
// if no server exists, delegating back to 'VANILLA_SET' should be fine (should rarely ever happen)
var server = ServerLifecycleHooks.getCurrentServer();
return server == null ? FeatureFlags.VANILLA_SET : server.getWorldData().enabledFeatures();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.util.List;
import net.minecraft.tags.TagKey;
import net.minecraft.world.flag.FeatureFlag;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;

public interface IConditionBuilder {
Expand Down Expand Up @@ -41,4 +43,28 @@ default ICondition modLoaded(String modid) {
default ICondition tagEmpty(TagKey<Item> tag) {
return new TagEmptyCondition(tag.location());
}

default ICondition isFeatureEnabled(FeatureFlagSet requiredFeatures) {
return FlagCondition.isEnabled(requiredFeatures);
}

default ICondition isFeatureEnabled(FeatureFlag requiredFlag) {
return FlagCondition.isEnabled(requiredFlag);
}

default ICondition isFeatureEnabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return FlagCondition.isEnabled(requiredFlag, requiredFlags);
}

default ICondition isFeatureDisabled(FeatureFlagSet requiredFeatures) {
return FlagCondition.isDisabled(requiredFeatures);
}

default ICondition isFeatureDisabled(FeatureFlag requiredFlag) {
return FlagCondition.isDisabled(requiredFlag);
}

default ICondition isFeatureDisabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return FlagCondition.isDisabled(requiredFlag, requiredFlags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.TooltipFlag;
import net.neoforged.neoforge.common.NeoForgeConfig;
import net.neoforged.neoforge.common.NeoForgeMod;
import net.neoforged.neoforge.common.util.AttributeUtil;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,7 +84,7 @@ default MutableComponent toComponent(AttributeModifier modif, TooltipFlag flag)
default Component getDebugInfo(AttributeModifier modif, TooltipFlag flag) {
Component debugInfo = CommonComponents.EMPTY;

if (flag.isAdvanced()) {
if (flag.isAdvanced() && NeoForgeConfig.COMMON.attributeAdvancedTooltipDebugInfo.get()) {
// Advanced Tooltips show the underlying operation and the "true" value. We offset MULTIPLY_TOTAL by 1 due to how the operation is calculated.
double advValue = (modif.operation() == Operation.ADD_MULTIPLIED_TOTAL ? 1 : 0) + modif.amount();
String valueStr = FORMAT.format(advValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ public static void sendToAllPlayers(CustomPacketPayload payload, CustomPacketPay
* Send the given payload(s) to all players tracking the given entity
*/
public static void sendToPlayersTrackingEntity(Entity entity, CustomPacketPayload payload, CustomPacketPayload... payloads) {
if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcast(entity, makeClientboundPacket(payload, payloads));
} else {
if (entity.level().isClientSide()) {
throw new IllegalStateException("Cannot send clientbound payloads on the client");
} else if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcast(entity, makeClientboundPacket(payload, payloads));
}
// Silently ignore custom Level implementations which may not return ServerChunkCache.
}

/**
* Send the given payload(s) to all players tracking the given entity and the entity itself if it is a player
*/
public static void sendToPlayersTrackingEntityAndSelf(Entity entity, CustomPacketPayload payload, CustomPacketPayload... payloads) {
if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcastAndSend(entity, makeClientboundPacket(payload, payloads));
} else {
if (entity.level().isClientSide()) {
throw new IllegalStateException("Cannot send clientbound payloads on the client");
} else if (entity.level().getChunkSource() instanceof ServerChunkCache chunkCache) {
chunkCache.broadcastAndSend(entity, makeClientboundPacket(payload, payloads));
}
// Silently ignore custom Level implementations which may not return ServerChunkCache.
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/neoforge/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
"neoforge.configuration.section.neoforge.server.toml.title": "Server settings",
"neoforge.configgui.advertiseDedicatedServerToLan": "Advertise Dedicated Server To LAN",
"neoforge.configgui.advertiseDedicatedServerToLan.tooltip": "Set this to true to enable advertising the dedicated server to local LAN clients so that it shows up in the Multiplayer screen automatically.",
"neoforge.configgui.attributeAdvancedTooltipDebugInfo": "Additional Attribute Advanced Tooltips",
"neoforge.configgui.attributeAdvancedTooltipDebugInfo.tooltip": "Set this to true to enable additional information about attributes on an item when advanced tooltips is on.",
"neoforge.configgui.forgeLightPipelineEnabled": "NeoForge Light Pipeline",
"neoforge.configgui.forgeLightPipelineEnabled.tooltip": "Enable the NeoForge block rendering pipeline - fixes the lighting of custom models.",
"neoforge.configgui.fullBoundingBoxLadders": "Full Bounding Box Ladders",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"neoforge:conditions": [
{
"type": "neoforge:feature_flags",
"flags": [
"custom_feature_flags_pack_test:test_flag"
]
}
],
"parent": "minecraft:recipes/root",
"criteria": {
"has_dirt": {
"conditions": {
"items": [
{
"items": "#minecraft:dirt"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "neotests_test_flag_condition:diamonds_from_dirt"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_dirt"
]
],
"rewards": {
"recipes": [
"neotests_test_flag_condition:diamonds_from_dirt"
]
}
}
Loading

0 comments on commit 57fd4ba

Please sign in to comment.