Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package gregtechlite.gtlitecore.api.extension

import gregtech.api.items.metaitem.MetaItem
import gregtech.api.items.metaitem.MetaOreDictItem
import gregtech.api.metatileentity.MetaTileEntity
import net.minecraft.block.Block
import net.minecraft.block.state.IBlockState
import net.minecraft.item.Item
import net.minecraft.item.ItemStack

// region Item Stack Copying

/**
* Copies the [ItemStack] with new stack size.
*
* @param count New stack size of copying ItemStack.
* @return Copied ItemStack with a [count].
* @param count The new stack size of the [ItemStack].
*/
fun ItemStack.copy(count: Int = 1): ItemStack
{
Expand All @@ -18,14 +25,71 @@ fun ItemStack.copy(count: Int = 1): ItemStack
/**
* Copies the [ItemStack] with new stack size.
*
* @param meta Metadata of ItemStack.
* @param count New stack size of copying ItemStack.
* @return Copied ItemStack with a [count] and [meta].
* @param meta The metadata of the [ItemStack].
* @param count The new stack size of the [ItemStack].
*/
fun ItemStack.copy(meta: Int, count: Int = 1): ItemStack
{
val stack = copy()
stack.itemDamage = meta
stack.count = count
return stack
}
}

// endregion

// region Item Stack Shortcut

/**
* Gets the [ItemStack] of the standard [Item].
*
* @param meta The metadata of the [ItemStack].
* @param count The stack size of the [ItemStack].
*/
fun Item.stack(meta: Int = 0): ItemStack = getStack(meta = meta)

/**
* Gets the [ItemStack] of the standard [Item].
*
* @param count The stack size of the [ItemStack].
* @param meta The metadata of the [ItemStack].
*/
fun Item.getStack(count: Int = 1, meta: Int = 0): ItemStack {
return ItemStack(this, count, meta)
}

fun MetaItem<*>.MetaValueItem.stack(): ItemStack = getStack()

fun MetaItem<*>.MetaValueItem.getStack(count: Int = 1): ItemStack = getStackForm(count)

fun MetaItem<*>.MetaValueItem.addOreDicts(vararg oreDictNames: String): MetaItem<*>.MetaValueItem
{
for (oreDictName in oreDictNames)
addOreDict(oreDictName)
return this
}

fun MetaOreDictItem.OreDictValueItem.stack(): ItemStack = getStack(1)

fun MetaOreDictItem.OreDictValueItem.getStack(count: Int): ItemStack = getItemStack(count)

fun Block.stack(): ItemStack = getStack(1)

fun Block.getStack(count: Int = 1, meta: Int = 0)
= ItemStack(this, count, meta)

fun MetaTileEntity.stack(): ItemStack = getStack()

fun MetaTileEntity.getStack(count: Int = 1) = stackForm.copy(count)

// endregion

// region Item Stack Convert

/**
* Transformed a [IBlockState] to [ItemStack] with [amount].
*/
fun IBlockState.toItem(amount: Int = 1): ItemStack
= ItemStack(block, amount, block.getMetaFromState(this))

// endregion

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,95 @@
@file:Suppress("FunctionName")
package gregtechlite.gtlitecore.api.extension

import gregtech.api.metatileentity.multiblock.CleanroomType
import gregtech.api.recipes.GTRecipeHandler
import gregtech.api.recipes.RecipeBuilder
import gregtech.api.recipes.RecipeMap
import gregtech.api.recipes.builders.ResearchRecipeBuilder
import net.minecraft.block.Block
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraftforge.fluids.FluidStack

// Short-circuit number converts for RecipeBuilder#EUt.
// region DSL Context

@Suppress("FunctionName")
fun <T: RecipeBuilder<T>> RecipeBuilder<T>.EUt(eut: Int): T
{
return EUt(eut.toLong())
}
/**
* Registers a recipe for the [RecipeMap].
*
* This method is Kotlin style DSL for GTCEu [RecipeBuilder] for recipe registries.
*
* @param builder The corresponding [RecipeBuilder] of the [RecipeMap].
*/
fun <T: RecipeBuilder<T>> RecipeMap<T>.addRecipe(builder: T.() -> Unit)
= recipeBuilder().apply(builder).buildAndRegister()

@Suppress("FunctionName")
fun <T: ResearchRecipeBuilder<T>> ResearchRecipeBuilder<T>.EUt(eut: Int): T
{
return EUt(eut.toLong())
}
// endregion

// region Recipe Input Shortcut

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.inputs(item: Item, amount: Int = 1, meta: Int = 0): T
= inputs(ItemStack(item, amount, meta))

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.inputs(block: Block, amount: Int = 1, meta: Int = 0): T
= inputs(ItemStack(block, amount, meta))

// endregion

// region Recipe Output Shortcut

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.outputs(item: Item, amount: Int = 1, meta: Int = 0): T
= outputs(ItemStack(item, amount, meta))

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.outputs(block: Block, amount: Int = 1, meta: Int = 0): T
= outputs(ItemStack(block, amount, meta))

// endregion

// region Recipe EUt Shortcut

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.EUt(eut: Int): T = EUt(eut.toLong())

fun <T: ResearchRecipeBuilder<T>> ResearchRecipeBuilder<T>.EUt(eut: Int): T = EUt(eut.toLong())

// endregion

// region Recipe Duration Shortcut

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.duration(duration: Long): T
{
return duration(duration.toInt())
}
= duration(duration.toInt())

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.duration(duration: Double): T
= duration(duration.toInt())

// endregion

// region Recipe Condition Shortcut

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.cleanroom(): T
= cleanroom(CleanroomType.CLEANROOM)

fun <T: RecipeBuilder<T>> RecipeBuilder<T>.sterileCleanroom(): T
= cleanroom(CleanroomType.STERILE_CLEANROOM)

// endregion

// region Recipe Removal Shortcut

fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg itemInputs: ItemStack)
= GTRecipeHandler.removeRecipesByInputs(this, *itemInputs)

fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg fluidInputs: FluidStack)
= GTRecipeHandler.removeRecipesByInputs(this, *fluidInputs)

fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(itemInputs: Array<ItemStack>, fluidInputs: Array<FluidStack>)
= GTRecipeHandler.removeRecipesByInputs(this, itemInputs, fluidInputs)

fun <T: RecipeBuilder<T>> RecipeMap<T>.removeRecipe(vararg itemInputs: Item): Boolean
{
return duration(duration.toInt())
}
val items = mutableListOf<ItemStack>()
for (itemInput in itemInputs)
items.add(ItemStack(itemInput))
return removeRecipe(*items.toTypedArray())
}

// endregion
Loading