Skip to content

Commit 9a4b0f2

Browse files
authored
refactor: Use DSL instead of default Recipe Builder for all recipes (#71)
* build DSL context for the recipe builder * shortcut recipe removal & add vararg format removal * fix a little type dir overflow typo * chain recipe dump pt.1 * add GTCEu plank adapter * add recipe output shortcut * chain recipe dump pt.2 & fusion recipe clean up * chain recipe dump pt.3 * circuit recipe dump * component recipe dump * food processing recipe dump * merge some extension and expand it * clean up machine recipes usage * some machine recipes dump * machine recipe dump finished * machine casing recipe dump * ore processing recipe dump * clean up CoAL recipes * recipe producer dump * clean up misc recipes * recipe handler & integration recipe dump * some missing DSL convert dump * fix some param hack
1 parent 5b6ef3d commit 9a4b0f2

File tree

250 files changed

+33873
-33193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+33873
-33193
lines changed

src/main/kotlin/gregtechlite/gtlitecore/api/extension/IBlockStateExt.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package gregtechlite.gtlitecore.api.extension
22

3+
import gregtech.api.items.metaitem.MetaItem
4+
import gregtech.api.items.metaitem.MetaOreDictItem
5+
import gregtech.api.metatileentity.MetaTileEntity
6+
import net.minecraft.block.Block
7+
import net.minecraft.block.state.IBlockState
8+
import net.minecraft.item.Item
39
import net.minecraft.item.ItemStack
410

11+
// region Item Stack Copying
12+
513
/**
614
* Copies the [ItemStack] with new stack size.
715
*
8-
* @param count New stack size of copying ItemStack.
9-
* @return Copied ItemStack with a [count].
16+
* @param count The new stack size of the [ItemStack].
1017
*/
1118
fun ItemStack.copy(count: Int = 1): ItemStack
1219
{
@@ -18,14 +25,71 @@ fun ItemStack.copy(count: Int = 1): ItemStack
1825
/**
1926
* Copies the [ItemStack] with new stack size.
2027
*
21-
* @param meta Metadata of ItemStack.
22-
* @param count New stack size of copying ItemStack.
23-
* @return Copied ItemStack with a [count] and [meta].
28+
* @param meta The metadata of the [ItemStack].
29+
* @param count The new stack size of the [ItemStack].
2430
*/
2531
fun ItemStack.copy(meta: Int, count: Int = 1): ItemStack
2632
{
2733
val stack = copy()
2834
stack.itemDamage = meta
2935
stack.count = count
3036
return stack
31-
}
37+
}
38+
39+
// endregion
40+
41+
// region Item Stack Shortcut
42+
43+
/**
44+
* Gets the [ItemStack] of the standard [Item].
45+
*
46+
* @param meta The metadata of the [ItemStack].
47+
* @param count The stack size of the [ItemStack].
48+
*/
49+
fun Item.stack(meta: Int = 0): ItemStack = getStack(meta = meta)
50+
51+
/**
52+
* Gets the [ItemStack] of the standard [Item].
53+
*
54+
* @param count The stack size of the [ItemStack].
55+
* @param meta The metadata of the [ItemStack].
56+
*/
57+
fun Item.getStack(count: Int = 1, meta: Int = 0): ItemStack {
58+
return ItemStack(this, count, meta)
59+
}
60+
61+
fun MetaItem<*>.MetaValueItem.stack(): ItemStack = getStack()
62+
63+
fun MetaItem<*>.MetaValueItem.getStack(count: Int = 1): ItemStack = getStackForm(count)
64+
65+
fun MetaItem<*>.MetaValueItem.addOreDicts(vararg oreDictNames: String): MetaItem<*>.MetaValueItem
66+
{
67+
for (oreDictName in oreDictNames)
68+
addOreDict(oreDictName)
69+
return this
70+
}
71+
72+
fun MetaOreDictItem.OreDictValueItem.stack(): ItemStack = getStack(1)
73+
74+
fun MetaOreDictItem.OreDictValueItem.getStack(count: Int): ItemStack = getItemStack(count)
75+
76+
fun Block.stack(): ItemStack = getStack(1)
77+
78+
fun Block.getStack(count: Int = 1, meta: Int = 0)
79+
= ItemStack(this, count, meta)
80+
81+
fun MetaTileEntity.stack(): ItemStack = getStack()
82+
83+
fun MetaTileEntity.getStack(count: Int = 1) = stackForm.copy(count)
84+
85+
// endregion
86+
87+
// region Item Stack Convert
88+
89+
/**
90+
* Transformed a [IBlockState] to [ItemStack] with [amount].
91+
*/
92+
fun IBlockState.toItem(amount: Int = 1): ItemStack
93+
= ItemStack(block, amount, block.getMetaFromState(this))
94+
95+
// endregion

src/main/kotlin/gregtechlite/gtlitecore/api/extension/MetaValueItemExt.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,95 @@
1+
@file:Suppress("FunctionName")
12
package gregtechlite.gtlitecore.api.extension
23

4+
import gregtech.api.metatileentity.multiblock.CleanroomType
5+
import gregtech.api.recipes.GTRecipeHandler
36
import gregtech.api.recipes.RecipeBuilder
7+
import gregtech.api.recipes.RecipeMap
48
import gregtech.api.recipes.builders.ResearchRecipeBuilder
9+
import net.minecraft.block.Block
10+
import net.minecraft.item.Item
11+
import net.minecraft.item.ItemStack
12+
import net.minecraftforge.fluids.FluidStack
513

6-
// Short-circuit number converts for RecipeBuilder#EUt.
14+
// region DSL Context
715

8-
@Suppress("FunctionName")
9-
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.EUt(eut: Int): T
10-
{
11-
return EUt(eut.toLong())
12-
}
16+
/**
17+
* Registers a recipe for the [RecipeMap].
18+
*
19+
* This method is Kotlin style DSL for GTCEu [RecipeBuilder] for recipe registries.
20+
*
21+
* @param builder The corresponding [RecipeBuilder] of the [RecipeMap].
22+
*/
23+
fun <T: RecipeBuilder<T>> RecipeMap<T>.addRecipe(builder: T.() -> Unit)
24+
= recipeBuilder().apply(builder).buildAndRegister()
1325

14-
@Suppress("FunctionName")
15-
fun <T: ResearchRecipeBuilder<T>> ResearchRecipeBuilder<T>.EUt(eut: Int): T
16-
{
17-
return EUt(eut.toLong())
18-
}
26+
// endregion
27+
28+
// region Recipe Input Shortcut
29+
30+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.inputs(item: Item, amount: Int = 1, meta: Int = 0): T
31+
= inputs(ItemStack(item, amount, meta))
32+
33+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.inputs(block: Block, amount: Int = 1, meta: Int = 0): T
34+
= inputs(ItemStack(block, amount, meta))
35+
36+
// endregion
37+
38+
// region Recipe Output Shortcut
39+
40+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.outputs(item: Item, amount: Int = 1, meta: Int = 0): T
41+
= outputs(ItemStack(item, amount, meta))
42+
43+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.outputs(block: Block, amount: Int = 1, meta: Int = 0): T
44+
= outputs(ItemStack(block, amount, meta))
45+
46+
// endregion
47+
48+
// region Recipe EUt Shortcut
49+
50+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.EUt(eut: Int): T = EUt(eut.toLong())
51+
52+
fun <T: ResearchRecipeBuilder<T>> ResearchRecipeBuilder<T>.EUt(eut: Int): T = EUt(eut.toLong())
53+
54+
// endregion
55+
56+
// region Recipe Duration Shortcut
1957

2058
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.duration(duration: Long): T
21-
{
22-
return duration(duration.toInt())
23-
}
59+
= duration(duration.toInt())
2460

2561
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.duration(duration: Double): T
62+
= duration(duration.toInt())
63+
64+
// endregion
65+
66+
// region Recipe Condition Shortcut
67+
68+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.cleanroom(): T
69+
= cleanroom(CleanroomType.CLEANROOM)
70+
71+
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.sterileCleanroom(): T
72+
= cleanroom(CleanroomType.STERILE_CLEANROOM)
73+
74+
// endregion
75+
76+
// region Recipe Removal Shortcut
77+
78+
fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg itemInputs: ItemStack)
79+
= GTRecipeHandler.removeRecipesByInputs(this, *itemInputs)
80+
81+
fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg fluidInputs: FluidStack)
82+
= GTRecipeHandler.removeRecipesByInputs(this, *fluidInputs)
83+
84+
fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(itemInputs: Array<ItemStack>, fluidInputs: Array<FluidStack>)
85+
= GTRecipeHandler.removeRecipesByInputs(this, itemInputs, fluidInputs)
86+
87+
fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg itemInputs: Item): Boolean
2688
{
27-
return duration(duration.toInt())
28-
}
89+
val items = mutableListOf<ItemStack>()
90+
for (itemInput in itemInputs)
91+
items.add(ItemStack(itemInput))
92+
return removeRecipe(*items.toTypedArray())
93+
}
94+
95+
// endregion

0 commit comments

Comments
 (0)