-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: More Condition stuff, plus recipe condition
- Loading branch information
1 parent
a9b980e
commit 3a206f6
Showing
9 changed files
with
109 additions
and
18 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
10 changes: 7 additions & 3 deletions
10
src/main/java/net/zepalesque/zenith/api/condition/Condition.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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/net/zepalesque/zenith/api/condition/DevEnvironmentCondition.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,26 @@ | ||
package net.zepalesque.zenith.api.condition; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import net.neoforged.fml.loading.FMLLoader; | ||
|
||
public class DevEnvironmentCondition implements Condition<DevEnvironmentCondition> { | ||
|
||
public static final DevEnvironmentCondition INSTANCE = new DevEnvironmentCondition(); | ||
|
||
public static final Codec<DevEnvironmentCondition> CODEC = MapCodec.unit(INSTANCE).stable().codec(); | ||
|
||
private DevEnvironmentCondition() { | ||
} | ||
|
||
@Override | ||
public boolean test() { | ||
return !FMLLoader.isProduction(); | ||
} | ||
|
||
@Override | ||
public Codec<DevEnvironmentCondition> codec() { | ||
return CODEC; | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/net/zepalesque/zenith/recipe/condition/ConditionCondition.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,42 @@ | ||
package net.zepalesque.zenith.recipe.condition; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.Holder; | ||
import net.neoforged.neoforge.common.conditions.ICondition; | ||
import net.zepalesque.zenith.api.condition.Condition; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class ConditionCondition implements ICondition { | ||
|
||
public static Codec<ConditionCondition> CODEC = RecordCodecBuilder.create( | ||
builder -> builder | ||
.group(Condition.CODEC.fieldOf("condition").forGetter(cc -> cc.condition)) | ||
.apply(builder, ConditionCondition::new)); | ||
|
||
public final Holder<Condition<?>> condition; | ||
|
||
public ConditionCondition(Holder<Condition<?>> pCondition) | ||
{ | ||
this.condition = pCondition; | ||
} | ||
|
||
@Override | ||
public boolean test(IContext context) { | ||
Optional<Condition<?>> optional = this.condition.unwrap().right(); | ||
return optional.isEmpty() || optional.get().test(); | ||
} | ||
|
||
|
||
@Override | ||
public Codec<? extends ICondition> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "data_condition(" + Objects.requireNonNullElse(this.condition, "null") + ")"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/net/zepalesque/zenith/recipe/condition/ZenithRecipeConditions.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,16 @@ | ||
package net.zepalesque.zenith.recipe.condition; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.neoforged.neoforge.common.conditions.ICondition; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.neoforged.neoforge.registries.NeoForgeRegistries; | ||
import net.zepalesque.zenith.Zenith; | ||
|
||
public class ZenithRecipeConditions { | ||
|
||
public static final DeferredRegister<Codec<? extends ICondition>> CODECS = DeferredRegister.create(NeoForgeRegistries.Keys.CONDITION_CODECS, Zenith.MODID); | ||
|
||
public static final DeferredHolder<Codec<? extends ICondition>, Codec<ConditionCondition>> ZCOND_PREDICATE = CODECS.register("when", () -> ConditionCondition.CODEC); | ||
|
||
} |