├── LICENSE ├── README.md └── main ├── CotUtils.zs ├── EventUtils.zs ├── EventUtilsCot.zs ├── GrassUtils.zs ├── GrassUtilsCot.zs ├── IngredientHelper.zs ├── Logger.zs ├── LoggerCot.zs ├── RecipeUtils.zs ├── StringHelper.zs ├── StringHelperCot.zs ├── classes ├── ConditionedItemStack.zs └── MaterialSystemHelper.zs └── scriptLoaderMessageHandler ├── ContentTweaker.zs ├── CraftTweaker.zs └── Preinit.zs /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 youyihj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GrassUtils 2 | 3 | A bunch of utils to make crafttweaker and contenttweaker easy to use.(MC 1.12.2) 4 | 5 | 提供了一些工具来方便地使用CoT和CrT(MC1.12.2) 6 | 7 | ## Mod Dependencies 8 | 9 | [Crafttweaker](https://www.curseforge.com/minecraft/mc-mods/crafttweaker) 10 | 11 | [ZenUtils](https://www.curseforge.com/minecraft/mc-mods/zenutil) 12 | 13 | [Contenttweaker](https://www.curseforge.com/minecraft/mc-mods/contenttweaker)(Optional 可选) 14 | -------------------------------------------------------------------------------- /main/CotUtils.zs: -------------------------------------------------------------------------------- 1 | #loader contenttweaker 2 | #priority 30000 3 | import mods.contenttweaker.VanillaFactory; 4 | import mods.contenttweaker.Block; 5 | import mods.contenttweaker.Item; 6 | import mods.contenttweaker.CreativeTab; 7 | import mods.contenttweaker.Fluid; 8 | import mods.contenttweaker.Color; 9 | import mods.contenttweaker.BlockMaterial; 10 | import mods.contenttweaker.SoundType; 11 | import mods.contenttweaker.SoundEvent; 12 | import crafttweaker.creativetabs.ICreativeTab; 13 | import scripts.grassUtils.StringHelperCot as StringHelper; 14 | import scripts.grassUtils.classes.MaterialSystemHelper.MaterialSystemHelper; 15 | import scripts.grassUtils.LoggerCot as Logger; 16 | 17 | static enumRarityLevel as string[] = ["COMMON", "UNCOMMON", "RARE", "EPIC"]; 18 | static tab as CreativeTab = null; 19 | 20 | function addNormalItem(name as string) { 21 | Logger.sendInfo("Adding item " ~ name); 22 | var itemt as Item = VanillaFactory.createItem(name); 23 | if (!isNull(tab)){ 24 | itemt.creativeTab = tab; 25 | } 26 | itemt.register(); 27 | } 28 | 29 | function addRareItem(name as string, glow as bool, rarityLevel as int) { 30 | Logger.sendInfo("Adding rare item " ~ name); 31 | var itemt as Item = VanillaFactory.createItem(name); 32 | itemt.glowing = glow; 33 | itemt.rarity = enumRarityLevel[rarityLevel]; 34 | if (!isNull(tab)){ 35 | itemt.creativeTab = tab; 36 | } 37 | itemt.register(); 38 | } 39 | 40 | function addFluid(name as string,color as int,temperature as int,viscosity as int,density as int,luminosity as int,isLava as bool){ 41 | Logger.sendInfo("Adding fluid " ~ name); 42 | var fluidt as Fluid = VanillaFactory.createFluid(name, color); 43 | fluidt.temperature = temperature; //default 300 44 | fluidt.viscosity = viscosity; //default 1000 45 | fluidt.density = density; //default 1000 46 | fluidt.luminosity = luminosity; //default 0 47 | if (isLava) { 48 | fluidt.material = ; 49 | fluidt.stillLocation = "base:fluids/molten"; 50 | fluidt.flowingLocation = "base:fluids/molten_flowing"; 51 | } else { 52 | fluidt.material = ; 53 | fluidt.stillLocation = "base:fluids/liquid"; 54 | fluidt.flowingLocation = "base:fluids/liquid_flow"; 55 | } 56 | fluidt.register(); 57 | } 58 | 59 | function addBlock(name as string,blockMaterial as BlockMaterial,hardness as float,resistance as float,blockSoundType as SoundType,lightValue as int,gravity as bool,toolClass as string,toolLevel as int){ 60 | Logger.sendInfo("Adding block " ~ name); 61 | var blockt as Block = VanillaFactory.createBlock(name,blockMaterial); 62 | blockt.setBlockHardness(hardness); 63 | blockt.setBlockResistance(resistance); 64 | blockt.setBlockSoundType(blockSoundType); 65 | blockt.setLightValue(lightValue); 66 | blockt.gravity = gravity; 67 | blockt.setToolClass(toolClass); 68 | blockt.setToolLevel(toolLevel); 69 | if (!isNull(tab)){ 70 | blockt.creativeTab = tab; 71 | } 72 | blockt.register(); 73 | } 74 | 75 | function addCreativeTabAndNormalItem(creativeTabID as string, itemID as string) { 76 | Logger.sendInfo("Adding creative tab " ~ creativeTabID ~ " with item " ~ itemID); 77 | var item as Item = VanillaFactory.createItem(itemID); 78 | var creativetab as CreativeTab = VanillaFactory.createCreativeTab(creativeTabID, item); 79 | creativetab.register(); 80 | item.creativeTab = creativetab; 81 | item.register(); 82 | tab = creativetab; 83 | } 84 | 85 | function getMaterialSystemHelper(id as string) as MaterialSystemHelper { 86 | return MaterialSystemHelper(id); 87 | } 88 | -------------------------------------------------------------------------------- /main/EventUtils.zs: -------------------------------------------------------------------------------- 1 | #priority 32766 2 | import crafttweaker.item.IItemStack; 3 | import crafttweaker.world.IWorld; 4 | import crafttweaker.world.IBlockPos; 5 | import crafttweaker.data.IData; 6 | import crafttweaker.player.IPlayer; 7 | import crafttweaker.world.IFacing; 8 | import scripts.grassUtils.Logger; 9 | import crafttweaker.event.PlayerTickEvent; 10 | import crafttweaker.event.PlayerRespawnEvent; 11 | 12 | static storageData as IData[string] = {}; 13 | 14 | function getOffset(pos as IBlockPos, x as int, y as int, z as int) as IBlockPos{ 15 | var offset as IBlockPos = pos; 16 | 17 | if (x > 0) { 18 | offset = offset.getOffset(IFacing.east(), x); 19 | } else if (x < 0) { 20 | offset = offset.getOffset(IFacing.west(), -x); 21 | } 22 | 23 | if (y > 0) { 24 | offset = offset.getOffset(IFacing.up(), y); 25 | } else if (y < 0) { 26 | offset = offset.getOffset(IFacing.down(), -y); 27 | } 28 | 29 | if (z > 0) { 30 | offset = offset.getOffset(IFacing.south(), z); 31 | } else if (z < 0) { 32 | offset = offset.getOffset(IFacing.north(), -z); 33 | } 34 | 35 | return offset; 36 | } 37 | 38 | function spawnItem(world as IWorld, item as IItemStack, pos as IBlockPos) as bool{ 39 | return world.spawnEntity(item.createEntityItem(world, pos)); 40 | } 41 | 42 | /* Use PlayerPersisted sub tag instead 43 | function enablePlayerDataKeeper() { 44 | events.onPlayerTick(function(event as PlayerTickEvent) { 45 | val player as IPlayer = event.player; 46 | if (!player.world.remote && player.fake) { 47 | storageData[player.id] = player.data; 48 | } 49 | }); 50 | 51 | events.onPlayerRespawn(function(event as PlayerRespawnEvent) { 52 | val player as IPlayer = event.player; 53 | if (!player.world.remote && !isNull(storageData[player.id])) { 54 | player.update(storageData[player.id]); 55 | } 56 | }); 57 | } */ 58 | 59 | function defaultDataHandler(data as IData, player as IPlayer) as bool { 60 | val map = data.asMap(); 61 | if (isNull(map) || map.length != 1) { 62 | Logger.sendError("Invalid data argment!"); 63 | return false; 64 | } 65 | val playerData as IData = player.data; 66 | val key as string = map.keys[0]; 67 | if (!(playerData in key)) { 68 | Logger.sendInfo(key ~ " tag is not found! Adding a tag with value " ~ map.values[0]); 69 | player.update(playerData + data); 70 | Logger.sendInfo("Added " ~ key ~ " tag"); 71 | return true; 72 | } 73 | return false; 74 | } 75 | 76 | function secondsTicker(world as IWorld, seconds as float) as bool { 77 | val ticks as int = 20 * seconds; 78 | return world.time % ticks == 0; 79 | } 80 | -------------------------------------------------------------------------------- /main/EventUtilsCot.zs: -------------------------------------------------------------------------------- 1 | #loader contenttweaker 2 | #priority 32766 3 | 4 | import mods.contenttweaker.BlockPos; 5 | import crafttweaker.item.IItemStack; 6 | import crafttweaker.world.IWorld; 7 | import crafttweaker.world.IBlockPos; 8 | import scripts.grassUtils.LoggerCot as Logger; 9 | 10 | function getOffset(pos as BlockPos, x as int, y as int, z as int) as BlockPos{ 11 | var offset as BlockPos = pos; 12 | if (x > 0) { 13 | offset = offset.getOffset("east", x); 14 | } else if (x < 0) { 15 | offset = offset.getOffset("west", -x); 16 | } 17 | 18 | if (y > 0) { 19 | offset = offset.getOffset("up", y); 20 | } else if (y < 0) { 21 | offset = offset.getOffset("down", -y); 22 | } 23 | 24 | if (z > 0) { 25 | offset = offset.getOffset("south", z); 26 | } else if (z < 0) { 27 | offset = offset.getOffset("north", -z); 28 | } 29 | 30 | return offset; 31 | } 32 | 33 | function spawnItem(world as IWorld, item as IItemStack, pos as IBlockPos) as bool{ 34 | return world.spawnEntity(item.createEntityItem(world, pos)); 35 | } 36 | 37 | function secondsTicker(world as IWorld, seconds as float) as bool { 38 | val ticks as int = 20 * seconds; 39 | return world.time % ticks == 0; 40 | } -------------------------------------------------------------------------------- /main/GrassUtils.zs: -------------------------------------------------------------------------------- 1 | #priority 29998 2 | import scripts.grassUtils.RecipeUtils; 3 | import scripts.grassUtils.Logger; 4 | 5 | static pi as double = 3.14159265358979324; 6 | static e as double = 2.71828182845904524; 7 | 8 | function loggerRecipes() { 9 | Logger.sendInfo("Have Tweaked " ~ RecipeUtils.tweakedRecipesAmount ~ " recipes!"); 10 | } 11 | 12 | function i18n(key as string) as string{ 13 | return game.localize(key); 14 | } 15 | 16 | function i18nValued(key as string, values as string[]) as string { 17 | var value as string = i18n(key); 18 | var temp as string = ""; 19 | var i as int = 0; 20 | while (i < value.length) { 21 | var j as string = value[i]; 22 | var k as string = ""; 23 | var t as int = 0; 24 | if (i + 2 <= value.length) { 25 | k = value.substring(i, i + 2); 26 | } 27 | if (k == "%s") { 28 | temp ~= values[t]; 29 | t += 1; 30 | i += 1; 31 | } else { 32 | temp ~= j; 33 | } 34 | i += 1; 35 | } 36 | return temp; 37 | } -------------------------------------------------------------------------------- /main/GrassUtilsCot.zs: -------------------------------------------------------------------------------- 1 | #loader contenttweaker 2 | #priority 29998 3 | 4 | import scripts.grassUtils.LoggerCot as Logger; 5 | 6 | static pi as double = 3.14159265358979324; 7 | static e as double = 2.71828182845904524; 8 | 9 | function i18n(key as string) as string{ 10 | return game.localize(key); 11 | } 12 | 13 | function i18nValued(key as string, values as string[]) as string { 14 | var value as string = i18n(key); 15 | var temp as string = ""; 16 | var i as int = 0; 17 | var t as int = 0; 18 | while (i < value.length) { 19 | var j as string = value[i]; 20 | var k as string = ""; 21 | if (i + 2 <= value.length) { 22 | k = value.substring(i, i + 2); 23 | } 24 | if (k == "%s") { 25 | temp ~= values[t]; 26 | t += 1; 27 | i += 1; 28 | } else { 29 | temp ~= j; 30 | } 31 | i += 1; 32 | } 33 | return temp; 34 | } -------------------------------------------------------------------------------- /main/IngredientHelper.zs: -------------------------------------------------------------------------------- 1 | #priority 30005 2 | import crafttweaker.item.IItemStack; 3 | import crafttweaker.item.IIngredient; 4 | import crafttweaker.oredict.IOreDictEntry; 5 | 6 | function getItem(arg as IIngredient) as IItemStack { 7 | val amount = arg.amount; 8 | return arg.items[0].withAmount(amount); 9 | } 10 | 11 | function getItems(arg as IIngredient[]) as IItemStack[] { 12 | var temp as IItemStack[] = []; 13 | for i in arg { 14 | temp += getItem(i); 15 | } 16 | return temp; 17 | } -------------------------------------------------------------------------------- /main/Logger.zs: -------------------------------------------------------------------------------- 1 | #priority 32768 2 | 3 | static LOGGER_ID as string = "[" ~ "GrassUtils" ~ "]" ~ " "; 4 | 5 | function sendInfo(message as string) { 6 | print(LOGGER_ID ~ message); 7 | } 8 | 9 | function sendWarning(message as string) { 10 | logger.logWarning(LOGGER_ID ~ message); 11 | } 12 | 13 | function sendCommand(message as string) { 14 | logger.logCommand(LOGGER_ID ~ message); 15 | } 16 | 17 | function sendError(message as string) { 18 | logger.logError(LOGGER_ID ~ message); 19 | } -------------------------------------------------------------------------------- /main/LoggerCot.zs: -------------------------------------------------------------------------------- 1 | #priority 32768 2 | #loader contenttweaker 3 | 4 | static LOGGER_ID as string = "[" ~ "GrassUtils" ~ "]" ~ " "; 5 | 6 | function sendInfo(message as string) { 7 | print(LOGGER_ID ~ message); 8 | } 9 | 10 | function sendWarning(message as string) { 11 | logger.logWarning(LOGGER_ID ~ message); 12 | } 13 | 14 | function sendCommand(message as string) { 15 | logger.logCommand(LOGGER_ID ~ message); 16 | } 17 | 18 | function sendError(message as string) { 19 | logger.logError(LOGGER_ID ~ message); 20 | } -------------------------------------------------------------------------------- /main/RecipeUtils.zs: -------------------------------------------------------------------------------- 1 | #loader crafttweaker 2 | #priority 30000 3 | import crafttweaker.item.IItemStack; 4 | import crafttweaker.item.IIngredient; 5 | import crafttweaker.data.IData; 6 | import crafttweaker.oredict.IOreDictEntry; 7 | import crafttweaker.recipes.ICraftingRecipe; 8 | import scripts.grassUtils.StringHelper; 9 | import scripts.grassUtils.classes.ConditionedItemStack.ConditionedItemStack; 10 | 11 | static tweakedRecipesAmount as int = 0; 12 | 13 | //修改合成,先删后加,第一个参数true表有序,false无序,需要二维数组(即使是无序) 14 | function recipeTweak(isShaped as bool,out as IItemStack,input as IIngredient[][]) as int{ 15 | var recipeName as string = StringHelper.getItemNameWithUnderline(out); 16 | if (out.hasTag) { 17 | recipeName ~= ("_withtag_" ~ tweakedRecipesAmount); 18 | } 19 | recipes.remove(out.withAmount(1),true); 20 | if (isShaped) { 21 | recipes.addShaped(recipeName,out,input); 22 | } else { 23 | recipes.addShapeless(recipeName,out,input[0]); 24 | } 25 | tweakedRecipesAmount += 1; 26 | return tweakedRecipesAmount; 27 | } 28 | 29 | function createSurround(core as IIngredient,surrounded as IIngredient) as IIngredient[][] { 30 | return [[surrounded,surrounded,surrounded], 31 | [surrounded,core,surrounded], 32 | [surrounded,surrounded,surrounded]]; 33 | } 34 | 35 | function createFull3(input as IIngredient) as IIngredient[][] { 36 | return [[input,input,input], 37 | [input,input,input], 38 | [input,input,input]]; 39 | } 40 | 41 | function createFull2(input as IIngredient) as IIngredient[][] { 42 | return [[input,input],[input,input]]; 43 | } 44 | 45 | function createCross(five as IIngredient, four as IIngredient) as IIngredient[][] { 46 | return [[five, four, five], 47 | [four, five, four], 48 | [five, four, five]]; 49 | } 50 | 51 | function createCrossWithCore(core as IIngredient, a as IIngredient, b as IIngredient) as IIngredient[][] { 52 | return [[a, b, a], 53 | [b, core, b], 54 | [a, b, a]]; 55 | } 56 | 57 | function createLeftSlash(input as IIngredient) as IIngredient[][] { 58 | return [[input, null, null], 59 | [null, input, null], 60 | [null, null, input]]; 61 | } 62 | 63 | function createRightSlash(input as IIngredient) as IIngredient[][] { 64 | return [[null, null, input], 65 | [null, input, null], 66 | [input, null, null]]; 67 | } 68 | 69 | // 删除 ICraftingRecipe 70 | function remove(recipe as ICraftingRecipe) { 71 | recipes.removeByRecipeName(recipe.fullResourceDomain); 72 | } 73 | 74 | //删除工作台与熔炉合成,并在JEI内隐藏 75 | function removeAllRecipe(input as IItemStack) as bool { 76 | recipes.remove(input); 77 | furnace.remove(input); 78 | furnace.setFuel(input, 0); 79 | mods.jei.JEI.removeAndHide(input); 80 | return true; 81 | } 82 | //数组复数删除 83 | function removeAllRecipes(input as IItemStack[]) as bool { 84 | for item in input { 85 | removeAllRecipe(item); 86 | } 87 | return true; 88 | } 89 | 90 | function getConditions(stack as IItemStack) as ConditionedItemStack { 91 | return ConditionedItemStack(stack); 92 | } 93 | 94 | //从矿辞中提取金属名,但处理金属名为多个单词的如DarkSteel,会出bug,返回Steel 95 | function getMetalName(arg as IOreDictEntry) as string { 96 | var input as string = arg.name; 97 | var temp as string = ""; 98 | var i as int = input.length - 1; 99 | while (i >= 0) { 100 | temp = input[i] ~ temp; 101 | if (input[i].toUpperCase() == input[i]) { 102 | return temp; 103 | } 104 | i -= 1; 105 | } 106 | return "Invalid"; 107 | } 108 | 109 | //从矿辞中提取金属名,需要部件名参数 110 | function getMetalNameNew(ore as IOreDictEntry, partName as string) as string { 111 | var name as string = ore.name; 112 | if (name.length > 0 && partName.length > 0) { 113 | if (name.contains(partName)) { 114 | return name.substring(partName.length); 115 | } 116 | } 117 | return null; 118 | } 119 | -------------------------------------------------------------------------------- /main/StringHelper.zs: -------------------------------------------------------------------------------- 1 | #loader crafttweaker 2 | #priority 32767 3 | 4 | import crafttweaker.item.IItemStack; 5 | import crafttweaker.liquid.ILiquidStack; 6 | 7 | function getItemName(input as IItemStack) as string { 8 | val id as string = input.definition.id; 9 | val meta as int = input.metadata; 10 | return (meta == 0) ? id : (id ~ meta); 11 | } 12 | 13 | function getLiquidName(input as ILiquidStack) as string { 14 | return input.definition.name; 15 | } 16 | 17 | function getItemNameWithUnderline(input as IItemStack) as string { 18 | var mod as string = input.definition.owner; 19 | var id as string = input.definition.id.split(":")[1]; 20 | var meta as int = input.metadata; 21 | if (meta == 0){ 22 | return (mod + "_" + id); 23 | } else return (mod + "_" + id + "_" + meta); 24 | } 25 | 26 | function toLowerCamelCase(arg as string) as string { 27 | if (arg.contains("_")) { //snake case 28 | var splitResult as string[] = arg.split("_"); 29 | var temp as string = ""; 30 | for i, j in splitResult { 31 | if (i == 0) { 32 | temp ~= j; 33 | } else if (i >= 1) { 34 | temp ~= (j[0].toUpperCase() ~ j.substring(1)); 35 | } 36 | } 37 | return temp; 38 | } else if (arg[0].toLowerCase() != arg[0]) { //upper camel case 39 | return arg[0].toLowerCase() ~ arg.substring(1); 40 | } else return arg; //lower camel case or invalid case 41 | } 42 | 43 | function toUpperCamelCase(arg as string) as string { 44 | if (arg.contains("_")) { //snake case 45 | var splitResult as string[] = arg.split("_"); 46 | var temp as string = ""; 47 | for i, j in splitResult { 48 | temp ~= (j[0].toUpperCase() ~ j.substring(1)); 49 | } 50 | return temp; 51 | } else if (arg[0].toUpperCase() != arg[0]) { //lower camel case 52 | return arg[0].toUpperCase() ~ arg.substring(1); 53 | } else return arg; //upper camel case or invalid case 54 | } 55 | 56 | function toSnakeCase(arg as string) as string { 57 | if (arg.contains("_")) { //snake case 58 | return arg; 59 | } else { //camel case 60 | var temp as string = arg[0]; 61 | for i in 1 .. arg.length { 62 | if (arg[i].toLowerCase() != arg[i]) { 63 | temp ~= "_"; 64 | } 65 | temp ~= arg[i]; 66 | } 67 | return temp.toLowerCase(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /main/StringHelperCot.zs: -------------------------------------------------------------------------------- 1 | #loader contenttweaker 2 | #priority 32767 3 | 4 | import crafttweaker.item.IItemStack; 5 | import crafttweaker.liquid.ILiquidStack; 6 | 7 | function getItemName(input as IItemStack) as string { 8 | val id as string = input.definition.id; 9 | val meta as int = input.metadata; 10 | return (meta == 0) ? id : (id ~ meta); 11 | } 12 | 13 | function getLiquidName(input as ILiquidStack) as string { 14 | return input.definition.name; 15 | } 16 | 17 | function getItemNameWithUnderline(input as IItemStack) as string { 18 | var mod as string = input.definition.owner; 19 | var id as string = input.definition.id.split(":")[1]; 20 | var meta as int = input.metadata; 21 | if (meta == 0){ 22 | return (mod + "_" + id); 23 | } else return (mod + "_" + id + "_" + meta); 24 | } 25 | 26 | function toLowerCamelCase(arg as string) as string { 27 | if (arg.contains("_")) { //snake case 28 | var splitResult as string[] = arg.split("_"); 29 | var temp as string = ""; 30 | for i, j in splitResult { 31 | if (i == 0) { 32 | temp ~= j; 33 | } else if (i >= 1) { 34 | temp ~= (j[0].toUpperCase() ~ j.substring(1)); 35 | } 36 | } 37 | return temp; 38 | } else if (arg[0].toLowerCase() != arg[0]) { //upper camel case 39 | return arg[0].toLowerCase() ~ arg.substring(1); 40 | } else return arg; //lower camel case or invalid case 41 | } 42 | 43 | function toUpperCamelCase(arg as string) as string { 44 | if (arg.contains("_")) { //snake case 45 | var splitResult as string[] = arg.split("_"); 46 | var temp as string = ""; 47 | for i, j in splitResult { 48 | temp ~= (j[0].toUpperCase() ~ j.substring(1)); 49 | } 50 | return temp; 51 | } else if (arg[0].toUpperCase() != arg[0]) { //lower camel case 52 | return arg[0].toUpperCase() ~ arg.substring(1); 53 | } else return arg; //upper camel case or invalid case 54 | } 55 | 56 | function toSnakeCase(arg as string) as string { 57 | if (arg.contains("_")) { //snake case 58 | return arg; 59 | } else { //camel case 60 | var temp as string = arg[0]; 61 | for i in 1 .. arg.length { 62 | if (arg[i].toLowerCase() != arg[i]) { 63 | temp ~= "_"; 64 | } 65 | temp ~= arg[i]; 66 | } 67 | return temp.toLowerCase(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /main/classes/ConditionedItemStack.zs: -------------------------------------------------------------------------------- 1 | #priority 32767 2 | import crafttweaker.item.IItemStack; 3 | import crafttweaker.item.IIngredient; 4 | import crafttweaker.item.IItemCondition; 5 | import crafttweaker.data.IData; 6 | 7 | 8 | zenClass ConditionedItemStack { 9 | var stack as IItemStack = null; 10 | zenConstructor(para as IItemStack) { 11 | stack = para; 12 | } 13 | function setStack(stack as IItemStack) { 14 | this.stack = stack; 15 | } 16 | function onlyEmptyTag() as IItemStack { 17 | return this.stack.only(function(item) { 18 | return (item.tag == {}); 19 | }); 20 | } 21 | function withLore(para as string[]) as IItemStack { 22 | return this.stack.only(function(item) { 23 | val data as string = item.tag.asString(); 24 | var result as bool = true; 25 | for i in para { 26 | if (result) { 27 | result &= data.contains(i); 28 | } else break; 29 | } 30 | return result; 31 | }); 32 | } 33 | } -------------------------------------------------------------------------------- /main/classes/MaterialSystemHelper.zs: -------------------------------------------------------------------------------- 1 | #priority 30001 2 | #loader contenttweaker 3 | import mods.contenttweaker.MaterialSystem; 4 | import mods.contenttweaker.Material; 5 | import mods.contenttweaker.Part; 6 | import mods.contenttweaker.PartBuilder; 7 | import mods.contenttweaker.MaterialPart; 8 | import mods.contenttweaker.RegisterMaterialPart; 9 | import mods.contenttweaker.PartDataPiece; 10 | import mods.contenttweaker.MaterialPartData; 11 | import mods.contenttweaker.PartType; 12 | import mods.contenttweaker.IItemColorSupplier; 13 | import mods.contenttweaker.IBlockColorSupplier; 14 | import scripts.grassUtils.StringHelperCot as StringHelper; 15 | import scripts.grassUtils.LoggerCot as Logger; 16 | 17 | zenClass MaterialSystemHelper { 18 | zenConstructor(arg as string) { 19 | this.id = arg; 20 | } 21 | var materialList as Material[string] = {}; 22 | var partList as string[] = []; 23 | val id as string; 24 | 25 | function getLogID() as string { 26 | return "Material System Helper " ~ this.id ~ ": "; 27 | } 28 | 29 | function registerMaterial(name as string, color as int) as Material { 30 | val id as string = StringHelper.toUpperCamelCase(name); 31 | var material as Material = null; 32 | if (this.hasMaterial(id)) { 33 | Logger.sendInfo(this.getLogID() ~ "Found Material " ~ name ~ " is already registered! Skip registering."); 34 | material = MaterialSystem.getMaterial(id); 35 | this.materialList[id] = material; 36 | return material; 37 | } 38 | Logger.sendInfo(this.getLogID() ~ "Registering material " ~ name); 39 | material = MaterialSystem.getMaterialBuilder().setName(id).setColor(color).build(); 40 | this.materialList[id] = material; 41 | return material; 42 | } 43 | 44 | function hasMaterial(key as string) as bool { 45 | return this.getAllMaterials().keys has key; 46 | } 47 | 48 | function getMaterial(key as string) as Material { 49 | val id as string = StringHelper.toUpperCamelCase(key); 50 | if (!this.hasMaterial(id)) Logger.sendError(this.getLogID() ~ "cannot find material: " ~ key); 51 | return MaterialSystem.getMaterial(key); 52 | } 53 | 54 | function getAllMaterials() as Material[string] { 55 | return MaterialSystem.getMaterials(); 56 | } 57 | 58 | function addMaterial(key as string) as Material { 59 | val id as string = StringHelper.toUpperCamelCase(key); 60 | Logger.sendInfo(this.getLogID() ~ "Add registered material " ~ key); 61 | this.materialList[id] = this.getMaterial(id); 62 | return this.getMaterial(id); 63 | } 64 | 65 | function addPart(partID as string) as string { 66 | Logger.sendInfo(this.getLogID() ~ "Add registered part " ~ partID); 67 | this.partList += StringHelper.toSnakeCase(partID); 68 | return partID; 69 | } 70 | 71 | function registerNormalPart(name as string, type as string, hasOverlay as bool) as Part { 72 | Logger.sendInfo(this.getLogID() ~ "Registering normal part " ~ name); 73 | val id as string = StringHelper.toSnakeCase(name); 74 | val oreDictID as string = StringHelper.toLowerCamelCase(name); 75 | val temp as PartBuilder = MaterialSystem.getPartBuilder().setName(id).setPartType(MaterialSystem.getPartType(type)).setOreDictName(oreDictID); 76 | var part as Part = hasOverlay ? temp.setHasOverlay(true).build() : temp.build(); 77 | this.partList += part.getName(); 78 | return part; 79 | } 80 | 81 | function registerSpecialPart(name as string, hasOverlay as bool, fx as RegisterMaterialPart) as Part { 82 | // TODO 83 | Logger.sendWarning(this.getLogID() ~ "Registering special part is NOT supported."); 84 | return null; 85 | } 86 | 87 | function getPart(key as string) as Part { 88 | return MaterialSystem.getPart(key); 89 | } 90 | 91 | function getAllParts() as Part[string] { 92 | return MaterialSystem.getParts(); 93 | } 94 | 95 | function registerMaterialPart(materialID as string, partID as string) /* as MaterialPart */{ 96 | Logger.sendInfo(this.getLogID() ~ "Registering material part: " ~ materialID ~ "_" ~ partID); 97 | /* return */ this.materialList[materialID].registerPart(partID); 98 | } 99 | 100 | function registerMaterialPartsByPart(partID as string) /* as MaterialPart[] */{ 101 | Logger.sendInfo(this.getLogID() ~ "Registering material parts: " ~ "any_" ~ partID); 102 | /* return */ this.getPart(partID).registerToMaterials(this.materialList.values); 103 | } 104 | 105 | function registerMaterialPartsByMaterial(materialID as string) /* as MaterialPart[] */{ 106 | Logger.sendInfo(this.getLogID() ~ "Registering material parts: " ~ materialID ~ "_any"); 107 | /* return */ this.materialList[materialID].registerParts(this.partList); 108 | } 109 | 110 | function registerAllMaterialParts() { 111 | for material in materialList { 112 | for part in partList { 113 | this.registerMaterialPart(material, part); 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /main/scriptLoaderMessageHandler/ContentTweaker.zs: -------------------------------------------------------------------------------- 1 | #priority 32768 2 | #loader contenttweaker 3 | 4 | function getMessageKey(freq as int) as string { 5 | return "grassutils.message." ~ freq; 6 | } 7 | 8 | function send(freq as int, message as string) as void { 9 | game.setLocalization(getMessageKey(freq), message); 10 | } 11 | 12 | function receive(freq as int) as string { 13 | return game.localize(getMessageKey(freq)); 14 | } 15 | -------------------------------------------------------------------------------- /main/scriptLoaderMessageHandler/CraftTweaker.zs: -------------------------------------------------------------------------------- 1 | #priority 32768 2 | #loader crafttweaker 3 | 4 | function getMessageKey(freq as int) as string { 5 | return "grassutils.message." ~ freq; 6 | } 7 | 8 | function send(freq as int, message as string) as void { 9 | game.setLocalization(getMessageKey(freq), message); 10 | } 11 | 12 | function receive(freq as int) as string { 13 | return game.localize(getMessageKey(freq)); 14 | } 15 | -------------------------------------------------------------------------------- /main/scriptLoaderMessageHandler/Preinit.zs: -------------------------------------------------------------------------------- 1 | #priority 32768 2 | #loader preinit 3 | 4 | function getMessageKey(freq as int) as string { 5 | return "grassutils.message." ~ freq; 6 | } 7 | 8 | function send(freq as int, message as string) as void { 9 | game.setLocalization(getMessageKey(freq), message); 10 | } 11 | 12 | function receive(freq as int) as string { 13 | return game.localize(getMessageKey(freq)); 14 | } 15 | --------------------------------------------------------------------------------