-
Notifications
You must be signed in to change notification settings - Fork 81
/
IRecipeHelper.java
122 lines (107 loc) · 3.76 KB
/
IRecipeHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.progwml6.natura.library.data.recipe;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.item.Item;
import net.minecraft.tags.ITag.INamedTag;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.conditions.NotCondition;
import net.minecraftforge.common.crafting.conditions.TagEmptyCondition;
import net.minecraftforge.registries.IForgeRegistryEntry;
import slimeknights.mantle.recipe.data.ConsumerWrapperBuilder;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Interface for common resource location and condition methods
*/
public interface IRecipeHelper {
/* Location helpers */
/** Gets the ID of the mod adding recipes */
String getModId();
/**
* Gets a resource location for the mod
* @param name Location path
* @return Location for the mod
*/
default ResourceLocation modResource(String name) {
return new ResourceLocation(getModId(), name);
}
/**
* Gets a resource location string for Tinkers
* @param id Location path
* @return Location for Tinkers
*/
default String modPrefix(String id) {
return getModId() + ":" + id;
}
/**
* Prefixes the resource location path with the given value
* @param entry Item registry name to use
* @param prefix Prefix value
* @return Resource location path
*/
default ResourceLocation wrap(IForgeRegistryEntry<?> entry, String prefix, String suffix) {
ResourceLocation loc = Objects.requireNonNull(entry.getRegistryName());
return modResource(prefix + loc.getPath() + suffix);
}
/**
* Prefixes the resource location path with the given value
* @param entry Item registry name to use
* @param prefix Prefix value
* @return Resource location path
*/
default ResourceLocation wrap(Supplier<? extends IForgeRegistryEntry<?>> entry, String prefix, String suffix) {
return wrap(entry.get(), prefix, suffix);
}
/**
* Prefixes the resource location path with the given value
* @param entry Entry registry name to use
* @param prefix Prefix value
* @return Resource location path
*/
default ResourceLocation prefix(IForgeRegistryEntry<?> entry, String prefix) {
ResourceLocation loc = Objects.requireNonNull(entry.getRegistryName());
return modResource(prefix + loc.getPath());
}
/**
* Prefixes the resource location path with the given value
* @param entry Entry registry name to use
* @param prefix Prefix value
* @return Resource location path
*/
default ResourceLocation prefix(Supplier<? extends IForgeRegistryEntry<?>> entry, String prefix) {
return prefix(entry.get(), prefix);
}
/* Tags and conditions */
/**
* Gets a tag by name
* @param modId Mod ID for tag
* @param name Tag name
* @return Tag instance
*/
default INamedTag<Item> getTag(String modId, String name) {
return ItemTags.makeWrapperTag(modId + ":" + name);
}
/**
* Creates a condition for a tag existing
* @param name Forge tag name
* @return Condition for tag existing
*/
default ICondition tagCondition(String name) {
return new NotCondition(new TagEmptyCondition("forge", name));
}
/**
* Creates a consumer instance with the added conditions
* @param consumer Base consumer
* @param conditions Extra conditions
* @return Wrapped consumer
*/
default Consumer<IFinishedRecipe> withCondition(Consumer<IFinishedRecipe> consumer, ICondition... conditions) {
ConsumerWrapperBuilder builder = ConsumerWrapperBuilder.wrap();
for (ICondition condition : conditions) {
builder.addCondition(condition);
}
return builder.build(consumer);
}
}