Skip to content

Commit 4256a62

Browse files
Add biomeTag recipe condition (#4419)
Co-authored-by: Jurre Groenendijk <jurre@jilles.com>
1 parent ea90a9a commit 4256a62

6 files changed

Lines changed: 94 additions & 2 deletions

File tree

docs/content/Modpacks/Changes/v7.5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,5 @@ Addon mods which explicitly attempt to construct, copy, or apply their own Modif
118118
(not using the standard builder or kjs functions) will need to either add the additional `int` parameter to the end of
119119
their constructor calls, or the additional `recipe.groupColor` to their copy calls.
120120

121+
## Added BiomeTagCondition
122+
Added a new RecipeCondition called BiomeTagCondition for needing a specific biome tag. This can be used with KubeJS using `.biomeTag("biome")`.

docs/content/Modpacks/Recipes/Recipe-Conditions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ These conditions can be used in both Java and KubeJS recipes. However, custom co
1212
### Base Conditons
1313

1414
- Biome: `.biome("namespace:biome_id")`
15-
- Locks a recipe behind being inside a certain biome, works with any biome a pack has loaded.
16-
For example, you could do `.biome("minecraft:plains")`.
15+
- Locks a recipe behind being inside a certain biome, works with any biome a pack has loaded.
16+
For example, you could use `minecraft:plains`. We also have `biomeTag("minecraft:biome")`.
1717
- Dimension: `.dimension("namespace:dimension_id")`
1818
- Locks a recipe being behind a certain dimension, the gas collector is a good example of this.
1919
- For example, you could do `.dimension("minecraft:the_end")`

src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeConditions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ private GTRecipeConditions() {}
2121

2222
// spotless:off
2323
public static final RecipeConditionType<BiomeCondition> BIOME = register("biome", BiomeCondition::new, BiomeCondition.CODEC);
24+
public static final RecipeConditionType<BiomeTagCondition> BIOME_TAG = register("biome_tag", BiomeTagCondition::new, BiomeTagCondition.CODEC);
2425
public static final RecipeConditionType<DimensionCondition> DIMENSION = register("dimension", DimensionCondition::new, DimensionCondition.CODEC);
2526
public static final RecipeConditionType<PositionYCondition> POSITION_Y = register("pos_y", PositionYCondition::new, PositionYCondition.CODEC);
2627
public static final RecipeConditionType<RainingCondition> RAINING = register("rain", RainingCondition::new, RainingCondition.CODEC);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.gregtechceu.gtceu.common.recipe.condition;
2+
3+
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
4+
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
5+
import com.gregtechceu.gtceu.api.recipe.RecipeCondition;
6+
import com.gregtechceu.gtceu.api.recipe.condition.RecipeConditionType;
7+
import com.gregtechceu.gtceu.common.data.GTRecipeConditions;
8+
9+
import net.minecraft.core.Holder;
10+
import net.minecraft.core.registries.Registries;
11+
import net.minecraft.network.chat.Component;
12+
import net.minecraft.resources.ResourceLocation;
13+
import net.minecraft.tags.TagKey;
14+
import net.minecraft.world.level.Level;
15+
import net.minecraft.world.level.biome.Biome;
16+
17+
import com.mojang.serialization.Codec;
18+
import com.mojang.serialization.codecs.RecordCodecBuilder;
19+
import lombok.Getter;
20+
import lombok.NoArgsConstructor;
21+
import org.jetbrains.annotations.NotNull;
22+
23+
@NoArgsConstructor
24+
public class BiomeTagCondition extends RecipeCondition<BiomeTagCondition> {
25+
26+
public static final Codec<BiomeTagCondition> CODEC = RecordCodecBuilder
27+
.create(instance -> RecipeCondition.isReverse(instance)
28+
.and(TagKey.codec(Registries.BIOME).fieldOf("biome_tag").forGetter(val -> val.biome))
29+
.apply(instance, BiomeTagCondition::new));
30+
31+
public final static BiomeTagCondition INSTANCE = new BiomeTagCondition();
32+
@Getter
33+
private TagKey<Biome> biome = TagKey.create(Registries.BIOME, new ResourceLocation("dummy"));
34+
35+
public BiomeTagCondition(boolean isReverse, TagKey<Biome> biome) {
36+
super(isReverse);
37+
this.biome = biome;
38+
}
39+
40+
public BiomeTagCondition(TagKey<Biome> biome) {
41+
this.biome = biome;
42+
}
43+
44+
@Override
45+
public RecipeConditionType<BiomeTagCondition> getType() {
46+
return GTRecipeConditions.BIOME_TAG;
47+
}
48+
49+
@Override
50+
public boolean isOr() {
51+
return true;
52+
}
53+
54+
@Override
55+
public Component getTooltips() {
56+
return Component.translatable("recipe.condition.biome.tooltip",
57+
Component.translatableWithFallback(biome.location().toLanguageKey("biome"),
58+
biome.location().toString()));
59+
}
60+
61+
@Override
62+
public boolean testCondition(@NotNull GTRecipe recipe, @NotNull RecipeLogic recipeLogic) {
63+
Level level = recipeLogic.machine.self().getLevel();
64+
if (level == null) return false;
65+
Holder<Biome> biome = level.getBiome(recipeLogic.machine.self().getPos());
66+
return biome.is(this.biome);
67+
}
68+
69+
@Override
70+
public BiomeTagCondition createTemplate() {
71+
return new BiomeTagCondition();
72+
}
73+
}

src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,14 @@ public GTRecipeBuilder biome(ResourceKey<Biome> biome) {
11491149
return biome(biome, false);
11501150
}
11511151

1152+
public GTRecipeBuilder biomeTag(TagKey<Biome> biome, boolean reverse) {
1153+
return addCondition(new BiomeTagCondition(biome).setReverse(reverse));
1154+
}
1155+
1156+
public GTRecipeBuilder biomeTag(TagKey<Biome> biome) {
1157+
return biomeTag(biome, false);
1158+
}
1159+
11521160
public GTRecipeBuilder rain(float level, boolean reverse) {
11531161
return addCondition(new RainingCondition(level).setReverse(reverse));
11541162
}

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,14 @@ public GTRecipeJS biome(ResourceKey<Biome> biome) {
974974
return biome(biome, false);
975975
}
976976

977+
public GTRecipeJS biomeTag(ResourceLocation biome, boolean reverse) {
978+
return addCondition(new BiomeTagCondition(TagKey.create(Registries.BIOME, biome)).setReverse(reverse));
979+
}
980+
981+
public GTRecipeJS biomeTag(ResourceLocation biome) {
982+
return biomeTag(biome, false);
983+
}
984+
977985
public GTRecipeJS rain(float level, boolean reverse) {
978986
return addCondition(new RainingCondition(level).setReverse(reverse));
979987
}

0 commit comments

Comments
 (0)