Skip to content

Commit 1d9f36c

Browse files
committed
Initial work towards ICatalystMatcher system
1 parent cc82818 commit 1d9f36c

9 files changed

Lines changed: 273 additions & 18 deletions

File tree

build.gradle

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ println("Version: ${version}");
3131
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
3232

3333
configurations {
34-
shadow.extendsFrom library
34+
library
3535
implementation.extendsFrom library
36+
shade.extendsFrom library
3637
}
3738

3839
sourceSets {
@@ -70,12 +71,8 @@ sourceSets {
7071
}
7172

7273
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
74+
7375
minecraft {
74-
// The mappings can be changed at any time, and must be in the following format.
75-
// snapshot_YYYYMMDD Snapshot are built nightly.
76-
// stable_# Stables are built at the discretion of the MCP team.
77-
// Use non-default mappings at your own risk. they may not always work.
78-
// Simply re-run your setup task after changing the mappings to update your workspace.
7976
mappings channel: 'official', version: minecraft_version
8077
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
8178
def resourcesDir = sourceSets.main.resources.srcDirs.first().absolutePath
@@ -277,23 +274,34 @@ processTestResources {
277274
duplicatesStrategy = DuplicatesStrategy.WARN
278275
}
279276

277+
assemble {
278+
dependsOn shadowJar
279+
}
280+
280281
reobf {
281282
shadowJar {}
282283
}
283284

285+
tasks.withType(Jar).configureEach {
286+
destinationDir = file("$rootDir/build-out")
287+
}
288+
284289
shadowJar {
290+
classifier ""
291+
configurations = [project.configurations.shade]
285292
exclude "LICENSE*"
286293
finalizedBy 'reobfShadowJar'
287294
minimize()
288295
relocate 'io.reactivex', 'dev.compactmods.crafting.lib.reactivex'
296+
relocate 'org.reactivestreams', 'dev.compactmods.crafting.lib.reactivestreams'
289297
}
290298

291299
jar {
292-
classifier("slim")
300+
classifier "slim"
301+
293302
from sourceSets.api.output
294303
from sourceSets.main.output
295304

296-
destinationDir = file("$rootDir/build-out")
297305
finalizedBy('reobfJar')
298306

299307
manifest {
@@ -311,15 +319,13 @@ jar {
311319
task apiJar(type: Jar) {
312320
// Sources included because of MinecraftForge/ForgeGradle#369
313321
from sourceSets.api.output
314-
destinationDirectory = file("$rootDir/build-out")
315322
classifier("api")
316323
}
317324

318325
task testJar(type: Jar) {
319326
from sourceSets.api.output
320327
from sourceSets.main.output
321328
from sourceSets.test.output
322-
destinationDirectory = file("$rootDir/build-out")
323329
classifier("tests")
324330
}
325331

@@ -332,11 +338,9 @@ publishing {
332338
maven(MavenPublication) {
333339
artifactId = mod_id
334340
artifacts {
335-
artifact jar
341+
artifact(jar)
336342
artifact(shadowJar)
337-
artifact(apiJar) {
338-
classifier = "api"
339-
}
343+
artifact(apiJar)
340344
artifact(testJar)
341345
}
342346
}
@@ -346,9 +350,7 @@ publishing {
346350
artifacts {
347351
artifact(jar)
348352
artifact(shadowJar)
349-
artifact(apiJar) {
350-
classifier = "api"
351-
}
353+
artifact(apiJar)
352354
artifact(testJar)
353355
}
354356
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dev.compactmods.crafting.api.catalyst;
2+
3+
import com.mojang.serialization.Codec;
4+
import net.minecraftforge.registries.IForgeRegistryEntry;
5+
6+
public interface CatalystType<Matcher extends ICatalystMatcher> extends IForgeRegistryEntry<CatalystType<?>> {
7+
8+
Codec<Matcher> getCodec();
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.compactmods.crafting.api.catalyst;
2+
3+
import net.minecraft.item.ItemStack;
4+
5+
public interface ICatalystMatcher {
6+
7+
boolean matches(ItemStack stack);
8+
9+
CatalystType<?> getType();
10+
}

src/main/java/dev/compactmods/crafting/Registration.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.compactmods.crafting;
22

33
import java.util.function.Supplier;
4+
import dev.compactmods.crafting.api.catalyst.CatalystType;
45
import dev.compactmods.crafting.api.recipe.layers.RecipeLayerType;
56
import dev.compactmods.crafting.field.block.FieldCraftingPreviewBlock;
67
import dev.compactmods.crafting.field.tile.FieldCraftingPreviewTile;
@@ -14,6 +15,8 @@
1415
import dev.compactmods.crafting.proxies.item.FieldProxyItem;
1516
import dev.compactmods.crafting.recipes.MiniaturizationRecipe;
1617
import dev.compactmods.crafting.recipes.MiniaturizationRecipeSerializer;
18+
import dev.compactmods.crafting.recipes.catalyst.ItemStackCatalystMatcher;
19+
import dev.compactmods.crafting.recipes.catalyst.ItemTagCatalystMatcher;
1720
import dev.compactmods.crafting.recipes.layers.FilledComponentRecipeLayer;
1821
import dev.compactmods.crafting.recipes.layers.HollowComponentRecipeLayer;
1922
import dev.compactmods.crafting.recipes.layers.MixedComponentRecipeLayer;
@@ -56,9 +59,15 @@ public class Registration {
5659
public static DeferredRegister<RecipeLayerType<?>> RECIPE_LAYERS = DeferredRegister.create((Class) RecipeLayerType.class, CompactCrafting.MOD_ID);
5760
public static IForgeRegistry<RecipeLayerType<?>> RECIPE_LAYER_TYPES;
5861

62+
public static DeferredRegister<CatalystType<?>> CATALYSTS = DeferredRegister.create((Class) CatalystType.class, CompactCrafting.MOD_ID);
63+
public static IForgeRegistry<CatalystType<?>> CATALYST_TYPES;
64+
5965
static {
6066
RECIPE_LAYERS.makeRegistry("recipe_layers", () -> new RegistryBuilder<RecipeLayerType<?>>()
6167
.tagFolder("recipe_layers"));
68+
69+
CATALYSTS.makeRegistry("catalyst_types", () -> new RegistryBuilder<CatalystType<?>>()
70+
.tagFolder("catalyst_types"));
6271
}
6372

6473
// ================================================================================================================
@@ -167,6 +176,17 @@ public class Registration {
167176

168177
// endregion ======================================================================================================
169178

179+
// ================================================================================================================
180+
// region CATALYST TYPES
181+
// ================================================================================================================
182+
public static final RegistryObject<CatalystType<ItemStackCatalystMatcher>> ITEM_STACK_CATALYST =
183+
CATALYSTS.register("item", ItemStackCatalystMatcher::new);
184+
185+
public static final RegistryObject<CatalystType<ItemTagCatalystMatcher>> TAGGED_ITEM_CATALYST =
186+
CATALYSTS.register("tag", ItemTagCatalystMatcher::new);
187+
188+
// endregion ======================================================================================================
189+
170190
// region =========================================================================================================
171191

172192
public static void init() {
@@ -181,12 +201,19 @@ public static void init() {
181201
MINIATURIZATION_RECIPE_TYPE.register();
182202

183203
RECIPE_LAYERS.register(eventBus);
204+
CATALYSTS.register(eventBus);
184205
}
185206

186207
@SubscribeEvent
187208
@SuppressWarnings("unused")
188-
public static void onRegistration(RegistryEvent.Register<RecipeLayerType<?>> evt) {
209+
public static void layerRegistration(RegistryEvent.Register<RecipeLayerType<?>> evt) {
189210
RECIPE_LAYER_TYPES = evt.getRegistry();
190211
}
212+
213+
@SubscribeEvent
214+
@SuppressWarnings("unused")
215+
public static void catalystRegistration(RegistryEvent.Register<CatalystType<?>> evt) {
216+
CATALYST_TYPES = evt.getRegistry();
217+
}
191218
// endregion ======================================================================================================
192219
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.compactmods.crafting.recipes.catalyst;
2+
3+
import com.mojang.datafixers.util.Pair;
4+
import com.mojang.serialization.Codec;
5+
import com.mojang.serialization.DataResult;
6+
import com.mojang.serialization.DynamicOps;
7+
import dev.compactmods.crafting.Registration;
8+
import dev.compactmods.crafting.api.catalyst.CatalystType;
9+
import dev.compactmods.crafting.api.catalyst.ICatalystMatcher;
10+
import net.minecraft.util.ResourceLocation;
11+
12+
public class CatalystMatcherCodec implements Codec<CatalystType<?>> {
13+
14+
/**
15+
* You probably want {@link CatalystMatcherCodec#MATCHER_CODEC} instead.
16+
*/
17+
public static final CatalystMatcherCodec INSTANCE = new CatalystMatcherCodec();
18+
public static final Codec<ICatalystMatcher> MATCHER_CODEC = INSTANCE.dispatchStable(ICatalystMatcher::getType, CatalystType::getCodec);
19+
20+
@Override
21+
public <T> DataResult<T> encode(CatalystType<?> input, DynamicOps<T> ops, T prefix) {
22+
ResourceLocation key = input.getRegistryName();
23+
if(key == null)
24+
return DataResult.error("Unknown registry element " + input);
25+
26+
T toMerge = ops.createString(key.toString());
27+
return ops.mergeToPrimitive(prefix, toMerge);
28+
}
29+
30+
@Override
31+
public <T> DataResult<Pair<CatalystType<?>, T>> decode(DynamicOps<T> ops, T input) {
32+
return ResourceLocation.CODEC.decode(ops, input).flatMap(CatalystMatcherCodec::handleDecodeResult);
33+
}
34+
35+
private static <CatalystMatcher> DataResult<Pair<CatalystType<?>, CatalystMatcher>> handleDecodeResult(Pair<ResourceLocation, CatalystMatcher> pair) {
36+
ResourceLocation id = pair.getFirst();
37+
if(!Registration.CATALYST_TYPES.containsKey(id))
38+
return DataResult.error("Unknown registry key: " + id);
39+
40+
return DataResult.success(pair.mapFirst(Registration.CATALYST_TYPES::getValue));
41+
}
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package dev.compactmods.crafting.recipes.catalyst;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import dev.compactmods.crafting.Registration;
6+
import dev.compactmods.crafting.api.catalyst.CatalystType;
7+
import dev.compactmods.crafting.api.catalyst.ICatalystMatcher;
8+
import net.minecraft.item.Item;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.util.ResourceLocation;
11+
import net.minecraftforge.registries.ForgeRegistries;
12+
import net.minecraftforge.registries.ForgeRegistryEntry;
13+
14+
public class ItemStackCatalystMatcher extends ForgeRegistryEntry<CatalystType<?>>
15+
implements ICatalystMatcher, CatalystType<ItemStackCatalystMatcher> {
16+
17+
public static final Codec<ItemStackCatalystMatcher> CODEC = RecordCodecBuilder.create(i -> i.group(
18+
ResourceLocation.CODEC.fieldOf("item").forGetter(ItemStackCatalystMatcher::getItemId)
19+
).apply(i, ItemStackCatalystMatcher::new));
20+
21+
private final Item item;
22+
23+
public ItemStackCatalystMatcher() {
24+
this.item = null;
25+
}
26+
27+
public ItemStackCatalystMatcher(ResourceLocation item) {
28+
this.item = ForgeRegistries.ITEMS.getValue(item);
29+
}
30+
31+
public ResourceLocation getItemId() {
32+
return item.getRegistryName();
33+
}
34+
35+
// TODO - Expand
36+
public boolean matches(ItemStack stack) {
37+
return stack.getItem() == item;
38+
}
39+
40+
@Override
41+
public CatalystType<?> getType() {
42+
return Registration.ITEM_STACK_CATALYST.get();
43+
}
44+
45+
@Override
46+
public Codec<ItemStackCatalystMatcher> getCodec() {
47+
return CODEC;
48+
}
49+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package dev.compactmods.crafting.recipes.catalyst;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import dev.compactmods.crafting.Registration;
6+
import dev.compactmods.crafting.api.catalyst.CatalystType;
7+
import dev.compactmods.crafting.api.catalyst.ICatalystMatcher;
8+
import net.minecraft.item.Item;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.tags.ITag;
11+
import net.minecraft.tags.TagCollectionManager;
12+
import net.minecraftforge.registries.ForgeRegistryEntry;
13+
14+
public class ItemTagCatalystMatcher extends ForgeRegistryEntry<CatalystType<?>>
15+
implements ICatalystMatcher, CatalystType<ItemTagCatalystMatcher> {
16+
17+
private static final Codec<ItemTagCatalystMatcher> CODEC = RecordCodecBuilder.create(i -> i.group(
18+
ITag.codec(() -> TagCollectionManager.getInstance().getItems())
19+
.fieldOf("tag").forGetter(ItemTagCatalystMatcher::getTag)
20+
).apply(i, ItemTagCatalystMatcher::new));
21+
22+
private final ITag<Item> tag;
23+
24+
public ItemTagCatalystMatcher() {
25+
this.tag = null;
26+
}
27+
28+
public ItemTagCatalystMatcher(ITag<Item> tag) {
29+
this.tag = tag;
30+
}
31+
32+
private ITag<Item> getTag() {
33+
return tag;
34+
}
35+
36+
@Override
37+
public boolean matches(ItemStack stack) {
38+
return stack.getItem().is(tag);
39+
}
40+
41+
@Override
42+
public CatalystType<?> getType() {
43+
return Registration.TAGGED_ITEM_CATALYST.get();
44+
}
45+
46+
@Override
47+
public Codec<ItemTagCatalystMatcher> getCodec() {
48+
return CODEC;
49+
}
50+
}

0 commit comments

Comments
 (0)