Skip to content

Commit

Permalink
Implement registryName generation method; Remove hidden items from in…
Browse files Browse the repository at this point in the history
…ventory tabs
  • Loading branch information
juraj-hrivnak committed Oct 10, 2023
1 parent 6531d05 commit 318f802
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
30 changes: 21 additions & 9 deletions groovy/classes/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@ package classes

import com.cleanroommc.groovyscript.api.IIngredient
import com.cleanroommc.groovyscript.helper.GroovyHelper
import com.cleanroommc.tabulator.common.TabulatorAPI

import net.minecraft.util.text.translation.I18n
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly

import org.codehaus.groovy.runtime.StackTraceUtils

/**
* Utils
*/
class Utils {

/**
* Remove items
* Remove and hide items
*/
static void remove(IIngredient... inputs) {
static void rmh(IIngredient... inputs) {
inputs.each { input ->
// Hide from JEI
mods.jei.hide(input)

// Remove from every creative tab
// removeItem()

input.matchingStacks.each { itemStack ->
// ToolTip
// Replace tooltip
itemStack.replaceToolTip("${Colors.RED}${Formats.BOLD}(${Formats.RESET}%itemName%${Colors.RED}${Formats.BOLD})")

if (GroovyHelper.isDebug()) {
// Add debug tooltip (Dev only)
itemStack.addToolTip("Hidden & removed from " +
StackTraceUtils.deepSanitize(new Exception()).stackTrace[3].fileName)
} else {
// Remove from every creative tab (Production only)
TabulatorAPI.removeItem()
}

// Remove recipe
itemStack.removeRecipe()
}
Expand All @@ -46,4 +47,15 @@ class Utils {
return I18n.translateToLocal(key)
}

private static int generatedRecipes = 0

/**
* Generate resource location
*/
static ResourceLocation generateRegistryName(ItemStack input) {
String suffix = "${input.itemRaw.registryName.path}_${input.metadata}_no.${generatedRecipes}"
generatedRecipes++
return new ResourceLocation(GroovyHelper.getPackId(), suffix)
}

}
21 changes: 11 additions & 10 deletions groovy/postInit/woodworking/Woodworking.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import classes.Colors
import classes.Formats
import classes.Replacer
import classes.Utils
import classes.io.Replacer

import com.cleanroommc.groovyscript.api.IIngredient
import com.cleanroommc.groovyscript.helper.recipe.RecipeName
Expand Down Expand Up @@ -156,7 +157,7 @@ for (x in woodworking) {
log.toMcIngredient(),
1 as int[],
8 as int[]
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)

mods.mekanism.Sawmill.add(log, rawLumber * 8, item('pyrotech:rock:7'), 0.5)
Expand All @@ -168,7 +169,7 @@ for (x in woodworking) {
300,
sawmillBlades.toMcIngredient(),
1
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)

ModuleTechMachine.Registries.BRICK_SAWMILL_RECIPES.registerEntry(
Expand All @@ -178,7 +179,7 @@ for (x in woodworking) {
60,
sawmillBlades.toMcIngredient(),
1
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)
}

Expand Down Expand Up @@ -218,7 +219,7 @@ for (x in woodworking) {
debarkedLog.toMcIngredient(),
1 as int[],
8 as int[]
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)

mods.mekanism.Sawmill.add(debarkedLog, rawLumber * 8, item('pyrotech:rock:7'), 0.5)
Expand All @@ -230,7 +231,7 @@ for (x in woodworking) {
300,
sawmillBlades.toMcIngredient(),
1
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)

ModuleTechMachine.Registries.BRICK_SAWMILL_RECIPES.registerEntry(
Expand All @@ -240,7 +241,7 @@ for (x in woodworking) {
60,
sawmillBlades.toMcIngredient(),
1
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(rawLumber))
)
}

Expand Down Expand Up @@ -282,7 +283,7 @@ for (x in woodworking) {
200,
sawmillBlades.toMcIngredient(),
0
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(lumber))
)

ModuleTechMachine.Registries.BRICK_SAWMILL_RECIPES.registerEntry(
Expand All @@ -292,7 +293,7 @@ for (x in woodworking) {
20,
sawmillBlades.toMcIngredient(),
0
).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
).setRegistryName(Utils.generateRegistryName(lumber))
)

// Chest recipes
Expand Down Expand Up @@ -324,7 +325,7 @@ for (x in woodworking) {
// ore('firewood').toMcIngredient(),
// 1 as int[],
// 4 as int[]
// ).setRegistryName(new ResourceLocation('groovyscript', RecipeName.generate()))
// ).setRegistryName(Utils.generateRegistryName(item('minecraft:stick')))
// )

// 1 log => 8 lumber = 16 sticks
Expand Down

0 comments on commit 318f802

Please sign in to comment.