-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.21.4] Encourage more usage of IConditionBuider (#1716)
- Loading branch information
1 parent
4d3958a
commit 79d86eb
Showing
26 changed files
with
232 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/java/net/neoforged/neoforge/common/conditions/IConditionBuilder.java
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
src/main/java/net/neoforged/neoforge/common/conditions/ItemExistsCondition.java
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
src/main/java/net/neoforged/neoforge/common/conditions/NeoForgeConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.common.conditions; | ||
|
||
import java.util.List; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.flag.FeatureFlag; | ||
import net.minecraft.world.flag.FeatureFlagSet; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
|
||
public final class NeoForgeConditions { | ||
public static ICondition and(ICondition... values) { | ||
return new AndCondition(List.of(values)); | ||
} | ||
|
||
public static ICondition never() { | ||
return NeverCondition.INSTANCE; | ||
} | ||
|
||
public static ICondition always() { | ||
return AlwaysCondition.INSTANCE; | ||
} | ||
|
||
public static ICondition not(ICondition value) { | ||
return new NotCondition(value); | ||
} | ||
|
||
public static ICondition or(ICondition... values) { | ||
return new OrCondition(List.of(values)); | ||
} | ||
|
||
public static <TRegistry> ICondition registered(ResourceKey<TRegistry> registryKey) { | ||
return new RegisteredCondition<>(registryKey); | ||
} | ||
|
||
public static <TRegistry> ICondition registered(ResourceKey<? extends Registry<TRegistry>> registryType, ResourceLocation registryName) { | ||
return registered(ResourceKey.create(registryType, registryName)); | ||
} | ||
|
||
public static ICondition registered(ResourceLocation registryTypeName, ResourceLocation registryName) { | ||
return registered(ResourceKey.createRegistryKey(registryTypeName), registryName); | ||
} | ||
|
||
public static ICondition itemRegistered(ResourceLocation itemName) { | ||
return registered(Registries.ITEM, itemName); | ||
} | ||
|
||
public static ICondition itemRegistered(String namespace, String path) { | ||
return itemRegistered(ResourceLocation.fromNamespaceAndPath(namespace, path)); | ||
} | ||
|
||
public static ICondition itemRegistered(String itemName) { | ||
return itemRegistered(ResourceLocation.parse(itemName)); | ||
} | ||
|
||
public static ICondition modLoaded(String modid) { | ||
return new ModLoadedCondition(modid); | ||
} | ||
|
||
public static <TRegistry> ICondition tagEmpty(TagKey<TRegistry> tag) { | ||
return new TagEmptyCondition<>(tag); | ||
} | ||
|
||
public static <TRegistry> ICondition tagEmpty(ResourceKey<? extends Registry<TRegistry>> tagType, ResourceLocation tagName) { | ||
return tagEmpty(TagKey.create(tagType, tagName)); | ||
} | ||
|
||
public static ICondition itemTagEmpty(ResourceLocation tagName) { | ||
return tagEmpty(Registries.ITEM, tagName); | ||
} | ||
|
||
public static ICondition itemTagEmpty(String namespace, String tagPath) { | ||
return itemTagEmpty(ResourceLocation.fromNamespaceAndPath(namespace, tagPath)); | ||
} | ||
|
||
public static ICondition itemTagEmpty(String tagName) { | ||
return itemTagEmpty(ResourceLocation.parse(tagName)); | ||
} | ||
|
||
public static ICondition featureFlagsEnabled(FeatureFlagSet requiredFeatures) { | ||
return new FeatureFlagsEnabledCondition(requiredFeatures); | ||
} | ||
|
||
public static ICondition featureFlagsEnabled(FeatureFlag... requiredFlags) { | ||
if (requiredFlags.length == 0) { | ||
throw new IllegalArgumentException("FeatureFlagsEnabledCondition requires at least one feature flag."); | ||
} | ||
if (requiredFlags.length == 1) { | ||
return new FeatureFlagsEnabledCondition(FeatureFlagSet.of(requiredFlags[0])); | ||
} else { | ||
return new FeatureFlagsEnabledCondition(FeatureFlagSet.of(requiredFlags[0], ArrayUtils.remove(requiredFlags, 0))); | ||
} | ||
} | ||
|
||
private NeoForgeConditions() { | ||
// NOOP - Utility class, never to be constructed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.