Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"fabric:load_conditions": [
{
"condition": "fabric:not",
"value": {
"condition": "fabric:true"
}
"condition": "fabric:false"
}
],
"parent": "minecraft:recipes/root",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"fabric:load_conditions": [
{
"condition": "fabric:not",
"value": {
"condition": "fabric:true"
}
"condition": "fabric:false"
}
],
"criteria": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
{
"condition": "fabric:not",
"value": {
"condition": "fabric:not",
"value": {
"condition": "fabric:true"
}
"condition": "fabric:false"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
{
"condition": "fabric:not",
"value": {
"condition": "fabric:not",
"value": {
"condition": "fabric:true"
}
"condition": "fabric:false"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"fabric:load_conditions": [
{
"condition": "fabric:not",
"value": {
"condition": "fabric:true"
}
"condition": "fabric:false"
}
],
"type": "minecraft:crafting_shapeless",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
private static final ResourceCondition ALWAYS_LOADED = ResourceConditions.alwaysTrue();
private static final ResourceCondition NEVER_LOADED = ResourceConditions.not(ALWAYS_LOADED);
private static final ResourceCondition NEVER_LOADED = ResourceConditions.alwaysFalse();

@Override
public void addJsonKeySortOrders(JsonKeySortOrderCallback callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.fabricmc.fabric.impl.resource.conditions.conditions.AllModsLoadedResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.AndResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.AnyModsLoadedResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.FalseResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.FeaturesEnabledResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.NotResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.OrResourceCondition;
Expand Down Expand Up @@ -83,6 +84,13 @@ public static ResourceCondition alwaysTrue() {
return new TrueResourceCondition();
}

/**
* A condition that always passes. Has ID {@code fabric:false}.
*/
public static ResourceCondition alwaysFalse() {
return new FalseResourceCondition();
}

/**
* A condition that passes if {@code condition} does not pass. Has ID {@code fabric:not} and
* takes one field, {@code value}, which is a resource condition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.fabricmc.fabric.impl.resource.conditions.conditions.AllModsLoadedResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.AndResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.AnyModsLoadedResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.FalseResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.FeaturesEnabledResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.NotResourceCondition;
import net.fabricmc.fabric.impl.resource.conditions.conditions.OrResourceCondition;
Expand All @@ -34,6 +35,7 @@

public class DefaultResourceConditionTypes {
public static final ResourceConditionType<TrueResourceCondition> TRUE = createResourceConditionType("true", TrueResourceCondition.CODEC);
public static final ResourceConditionType<FalseResourceCondition> FALSE = createResourceConditionType("false", FalseResourceCondition.CODEC);
public static final ResourceConditionType<NotResourceCondition> NOT = createResourceConditionType("not", NotResourceCondition.CODEC);
public static final ResourceConditionType<OrResourceCondition> OR = createResourceConditionType("or", OrResourceCondition.CODEC);
public static final ResourceConditionType<AndResourceCondition> AND = createResourceConditionType("and", AndResourceCondition.CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class ResourceConditionsImpl implements ModInitializer {
@Override
public void onInitialize() {
ResourceConditions.register(DefaultResourceConditionTypes.TRUE);
ResourceConditions.register(DefaultResourceConditionTypes.FALSE);
ResourceConditions.register(DefaultResourceConditionTypes.NOT);
ResourceConditions.register(DefaultResourceConditionTypes.AND);
ResourceConditions.register(DefaultResourceConditionTypes.OR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.impl.resource.conditions.conditions;

import com.mojang.serialization.MapCodec;
import org.jspecify.annotations.Nullable;

import net.minecraft.resources.RegistryOps;

import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditionType;
import net.fabricmc.fabric.impl.resource.conditions.DefaultResourceConditionTypes;

public class FalseResourceCondition implements ResourceCondition {
public static final MapCodec<FalseResourceCondition> CODEC = MapCodec.unit(FalseResourceCondition::new);

@Override
public ResourceConditionType<?> getType() {
return DefaultResourceConditionTypes.FALSE;
}

@Override
public boolean test(RegistryOps.@Nullable RegistryInfoLookup registryInfo) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void beforeAll() {
@Test
public void logics() {
ResourceCondition alwaysTrue = ResourceConditions.alwaysTrue();
ResourceCondition alwaysFalse = ResourceConditions.not(alwaysTrue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a separate test for not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still used in DataGeneratorTestEntrypoint, if it's needed elsewhere suggestions are welcome, I'm not too familiar with gametests.

ResourceCondition alwaysFalse = ResourceConditions.alwaysFalse();
ResourceCondition trueAndTrue = ResourceConditions.and(alwaysTrue, alwaysTrue);
ResourceCondition trueAndFalse = ResourceConditions.and(alwaysTrue, alwaysFalse);
ResourceCondition emptyAnd = ResourceConditions.and();
Expand Down
Loading