Skip to content

Commit eb1b617

Browse files
committed
Add shapeless focus holder filling recipe
1 parent 1a7a9ea commit eb1b617

File tree

5 files changed

+99
-3
lines changed

5 files changed

+99
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "hexdebug:focus_holder_filling_shapeless",
3+
"category": "misc"
4+
}

Common/src/main/kotlin/gay/object/hexdebug/recipes/FocusHolderFillingShapedRecipe.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class FocusHolderFillingShapedRecipe(
2727
result: ItemStack,
2828
showNotification: Boolean,
2929
) : ShapedRecipe(id, group, category, width, height, recipeItems, result, showNotification) {
30-
override fun getSerializer() = HexDebugRecipeSerializers.FOCUS_HOLDER_FILLING_SHAPED.value
31-
3230
override fun matches(container: CraftingContainer, level: Level): Boolean {
3331
if (!super.matches(container, level)) return false
3432
for (ingredient in container.items) {
@@ -51,6 +49,8 @@ class FocusHolderFillingShapedRecipe(
5149
return result
5250
}
5351

52+
override fun getSerializer() = HexDebugRecipeSerializers.FOCUS_HOLDER_FILLING_SHAPED.value
53+
5454
companion object {
5555
private fun fromShapedRecipe(recipe: ShapedRecipe): FocusHolderFillingShapedRecipe {
5656
return recipe.run {
@@ -62,7 +62,9 @@ class FocusHolderFillingShapedRecipe(
6262
width = width,
6363
height = height,
6464
recipeItems = ingredients,
65-
result = getResultItem(null).apply { putIotaStack(ItemStack(HexItems.FOCUS)) },
65+
result = getResultItem(null).apply {
66+
putIotaStack(ItemStack(HexItems.FOCUS))
67+
},
6668
showNotification = showNotification(),
6769
)
6870
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package gay.`object`.hexdebug.recipes
2+
3+
import at.petrak.hexcasting.common.lib.HexItems
4+
import gay.`object`.hexdebug.items.FocusHolderBlockItem.Companion.hasIotaStack
5+
import gay.`object`.hexdebug.items.FocusHolderBlockItem.Companion.putIotaStack
6+
import gay.`object`.hexdebug.registry.HexDebugBlocks
7+
import gay.`object`.hexdebug.registry.HexDebugRecipeSerializers
8+
import net.minecraft.core.NonNullList
9+
import net.minecraft.core.RegistryAccess
10+
import net.minecraft.resources.ResourceLocation
11+
import net.minecraft.world.inventory.CraftingContainer
12+
import net.minecraft.world.item.ItemStack
13+
import net.minecraft.world.item.crafting.CraftingBookCategory
14+
import net.minecraft.world.item.crafting.CustomRecipe
15+
import net.minecraft.world.item.crafting.Ingredient
16+
import net.minecraft.world.level.Level
17+
18+
class FocusHolderFillingShapelessRecipe(id: ResourceLocation, category: CraftingBookCategory) : CustomRecipe(id, category) {
19+
private val resultItem = ItemStack(HexDebugBlocks.FOCUS_HOLDER.item).apply {
20+
putIotaStack(ItemStack(HexItems.FOCUS))
21+
}
22+
23+
override fun matches(container: CraftingContainer, level: Level): Boolean {
24+
return findItems(container) != null
25+
}
26+
27+
override fun assemble(container: CraftingContainer, registryAccess: RegistryAccess): ItemStack {
28+
val (holder, focus) = findItems(container) ?: return ItemStack.EMPTY
29+
return holder.copyWithCount(1).apply {
30+
putIotaStack(focus)
31+
}
32+
}
33+
34+
override fun getIngredients(): NonNullList<Ingredient> = NonNullList.of(
35+
Ingredient.of(HexDebugBlocks.FOCUS_HOLDER.item),
36+
Ingredient.of(HexItems.FOCUS),
37+
)
38+
39+
override fun getResultItem(registryAccess: RegistryAccess) = resultItem
40+
41+
override fun canCraftInDimensions(width: Int, height: Int): Boolean {
42+
return width * height >= 2
43+
}
44+
45+
override fun getSerializer() = HexDebugRecipeSerializers.FOCUS_HOLDER_FILLING_SHAPELESS.value
46+
47+
private fun findItems(container: CraftingContainer): Pair<ItemStack, ItemStack>? {
48+
var holder: ItemStack? = null
49+
var focus: ItemStack? = null
50+
51+
for (itemStack in container.items) {
52+
if (itemStack.isEmpty) continue
53+
54+
when (itemStack.item) {
55+
HexDebugBlocks.FOCUS_HOLDER.item -> {
56+
if (holder != null || itemStack.hasIotaStack) return null
57+
holder = itemStack
58+
}
59+
HexItems.FOCUS -> {
60+
if (focus != null) return null
61+
focus = itemStack
62+
}
63+
else -> return null
64+
}
65+
}
66+
67+
return Pair(
68+
holder ?: return null,
69+
focus ?: return null,
70+
)
71+
}
72+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package gay.`object`.hexdebug.registry
22

33
import gay.`object`.hexdebug.recipes.FocusHolderFillingShapedRecipe
4+
import gay.`object`.hexdebug.recipes.FocusHolderFillingShapelessRecipe
45
import net.minecraft.core.registries.BuiltInRegistries
56
import net.minecraft.core.registries.Registries
67
import net.minecraft.world.item.crafting.RecipeSerializer
8+
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer
9+
710
object HexDebugRecipeSerializers : HexDebugRegistrar<RecipeSerializer<*>>(
811
Registries.RECIPE_SERIALIZER,
912
{ BuiltInRegistries.RECIPE_SERIALIZER },
1013
) {
1114
val FOCUS_HOLDER_FILLING_SHAPED = register("focus_holder_filling_shaped") {
1215
FocusHolderFillingShapedRecipe.Serializer()
1316
}
17+
18+
val FOCUS_HOLDER_FILLING_SHAPELESS = register("focus_holder_filling_shapeless") {
19+
SimpleCraftingRecipeSerializer(::FocusHolderFillingShapelessRecipe)
20+
}
1421
}

Forge/src/main/kotlin/gay/object/hexdebug/forge/datagen/HexDebugRecipes.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import gay.`object`.hexdebug.HexDebug
88
import gay.`object`.hexdebug.datagen.recipes.FocusHolderFillingShapedRecipeBuilder
99
import gay.`object`.hexdebug.registry.HexDebugBlocks
1010
import gay.`object`.hexdebug.registry.HexDebugItems
11+
import gay.`object`.hexdebug.registry.HexDebugRecipeSerializers
12+
import gay.`object`.hexdebug.registry.RegistrarEntry
1113
import net.minecraft.data.PackOutput
1214
import net.minecraft.data.recipes.FinishedRecipe
1315
import net.minecraft.data.recipes.RecipeCategory
1416
import net.minecraft.data.recipes.ShapedRecipeBuilder
17+
import net.minecraft.data.recipes.SpecialRecipeBuilder
1518
import net.minecraft.world.item.Items
19+
import net.minecraft.world.item.crafting.RecipeSerializer
1620
import net.minecraft.world.level.ItemLike
1721
import java.util.function.Consumer
1822

@@ -75,6 +79,9 @@ class HexDebugRecipes(output: PackOutput) : PaucalRecipeProvider(output, HexDebu
7579
.pattern(" LG")
7680
.unlockedBy("has_item", hasItem(HexItems.FOCUS))
7781
.save(writer, HexDebug.id("focus_holder_filling_shaped/new_focus"))
82+
83+
// existing focus holder with existing focus
84+
specialRecipe(writer, HexDebugRecipeSerializers.FOCUS_HOLDER_FILLING_SHAPELESS)
7885
}
7986

8087
@Suppress("SameParameterValue")
@@ -89,4 +96,8 @@ class HexDebugRecipes(output: PackOutput) : PaucalRecipeProvider(output, HexDebu
8996
.pattern(" CC")
9097
.pattern(" UC")
9198
.pattern("L ")
99+
100+
private fun specialRecipe(writer: Consumer<FinishedRecipe>, entry: RegistrarEntry<RecipeSerializer<*>>) {
101+
SpecialRecipeBuilder(entry.value).save(writer, entry.id.toString())
102+
}
92103
}

0 commit comments

Comments
 (0)