From 9ec98b47bb1897023cc0a2078461d6c47c58d38a Mon Sep 17 00:00:00 2001 From: Redeix <59435925+Redeix@users.noreply.github.com> Date: Tue, 22 Jul 2025 05:51:09 -0500 Subject: [PATCH] Brick interaction events and new function for interacting with blocks (#1416) * - Yeast recipe conflict fix * - Fixed seed oil voiding in barrels. And item weight inconsistency. * - Reduced loading screen logo size by 4MB * - Update Changelog * - Compressed loading screen images to maybe help with ram * - Added default gui scale to make the main menu look better on first launch * - Update Changelog * - Added utility script for adding circuits to existing recipes * fixed changelog conflict Signed-off-by: Redeix <59435925+Redeix@users.noreply.github.com> * - Added harvest baskets * - Fixed baked potato recipe mixing from oven * - Allowed elytras to be repaired regardless of damage * - Fixed sea water barrel recipe * - Gave plants tags to bushes so they can have other uses * - Pushed stubborn models * - updated Changelog * - Changelog typo * - Integrated Ad Astra wood * - Updated changelog * - Treated chipboard composite barrel lang * - Some Tacz fixes * - Jar dupe fix * - tacz data * - updated changelog * - we hate git * - Loading screen and main menu optimizations * - image push * - I think I got the title screen looking good on all resolutions * - Updated Changelog * - Added scale fix to loading screen too * - Fix pixel alignment * - Recipes, tags, assets+ for railgun * - Brick interaction events and new function for interacting with blocks * - Added parameter boolean to decide if blockstate should be copied --------- Signed-off-by: Redeix <59435925+Redeix@users.noreply.github.com> Signed-off-by: Pyritie Co-authored-by: Pyritie --- kubejs/server_scripts/tfg/events.js | 171 ++++++++++++++++++ kubejs/server_scripts/tfg/tags.js | 30 +++ .../startup_scripts/createdeco/constants.js | 13 ++ kubejs/startup_scripts/tfg/constants.js | 64 ++++++- 4 files changed, 277 insertions(+), 1 deletion(-) diff --git a/kubejs/server_scripts/tfg/events.js b/kubejs/server_scripts/tfg/events.js index 2e7ba18f3..782b69322 100644 --- a/kubejs/server_scripts/tfg/events.js +++ b/kubejs/server_scripts/tfg/events.js @@ -242,4 +242,175 @@ function getTFGPersistentDataRoot(player) } }) }) +//#endregion + +//#region Block Interactions + +/** + * Function for replacing a block with another block by crouch-right-clicking with a tool. + * + * If input and output is null recipe will just return. + * + * @param {*} event + * @param {string} inputBlock -Block ID to be replaced. Accepts a Tag, but not recommended. + * @param {string} outputBlock -Block ID of the replacement. + * @param {string} toolId -Item ID of the tool. + * @param {boolean} damageTool -Sets wether the tool should be damaged on use. + * @param {string} soundId -Sound ID to be used as the flair sound effect. Can be null. + * @param {string} particleId -SimpleParticleType ID to be used as the flair particle. Can be null. + * @param {boolean} copyBlockstate - Sets wether the blockstate should be copied from the input block to the output block. + */ +function transformBlockWithTool(event, inputBlock, outputBlock, toolId, damageTool, soundId, particleId, copyBlockstate) { + const { server, item, player, block } = event; + + if (!inputBlock || !outputBlock) {return}; + + if (inputBlock.startsWith('#')) { + if (!block.hasTag(inputBlock.substring(1))) return; + } else { + if (block.id.toString() !== inputBlock) return; + } + + if (toolId.startsWith('#')) { + if (item.isEmpty() || !player.mainHandItem.hasTag(toolId.substring(1))) {return}; + } else { + if (item.isEmpty() || player.mainHandItem.id !== toolId) {return}; + } + + if (!player.crouching) {return}; + + let state = block.getBlockState().toString(); + if (state.includes('[') && copyBlockstate == true) { + state = state.substring(state.indexOf('[')); + } else { + state = ''; + } + + if (soundId) { + server.runCommandSilent(`playsound ${soundId} player ${player.username} ${player.x} ${player.y} ${player.z} 1 2 1`) + } + if (particleId) { + server.runCommandSilent(`particle ${particleId} ${block.x} ${block.y + 0.8} ${block.z} 0.1 0.1 0.1 0.6 10`) + } + player.swing(); + + if (!player.isCreative() && damageTool) { + item.damageValue++; + if (item.damageValue >= item.maxDamage) { + server.runCommandSilent(`playsound minecraft:item.shield.break player ${player.username} ${player.x} ${player.y} ${player.z} 1 1 1`); + item.count--; + } + } + + const dim = block.level.name.getString(); + server.runCommandSilent(`execute in ${dim} run fill ${block.x} ${block.y} ${block.z} ${block.x} ${block.y} ${block.z} air`); + server.runCommandSilent(`execute in ${dim} run setblock ${block.x} ${block.y} ${block.z} ${outputBlock}${state}`); +}; + +/** + * Function for replacing a block with another block by crouch-right-clicking with an item. + * + * If input and output is null recipe will just return. + * + * @param {*} event + * @param {string} inputBlock -Block ID to be replaced. Accepts a Tag, but not recommended. + * @param {string} outputBlock -Block ID of the replacement. + * @param {string} itemId -Item ID of the consumed item. Accepts Tags. + * @param {boolean} consumeItem -Sets wether the item should be comsumed or not. + * @param {number} consumeAmount -Number of items to consume, can't be greater than stacksize. + * @param {string} soundId -Sound ID to be used as the flair sound effect. Can be null. + * @param {string} particleId -SimpleParticleType ID to be used as the flair particle. Can be null. + * @param {boolean} copyBlockstate - Sets wether the blockstate should be copied from the input block to the output block. + */ +function transformBlockWithItem(event, inputBlock, outputBlock, itemId, consumeItem, consumeAmount, soundId, particleId, copyBlockstate) { + const { server, item, player, block } = event; + + if (!inputBlock || !outputBlock) {return}; + + if (inputBlock.startsWith('#')) { + if (!block.hasTag(inputBlock.substring(1))) return; + } else { + if (block.id.toString() !== inputBlock) return; + } + + if (itemId.startsWith('#')) { + if (item.isEmpty() || !player.mainHandItem.hasTag(itemId.substring(1))) {return}; + } else { + if (item.isEmpty() || player.mainHandItem.id != itemId) {return}; + } + if (!player.crouching) {return}; + + var state = block.getBlockState().toString() + if (state.includes('[') && copyBlockstate == true){ + state = state.substring(block.getBlockState().toString().indexOf('[')); + } else { + state = '' + } + + if (!player.isCreative() && consumeItem === true) { + if (item.count < consumeAmount) { + player.tell(`Item count is too low. Held amount = ${item.count}, required amount = ${consumeAmount}`) + return; + } + item.count -= consumeAmount; + } + if (soundId) { + server.runCommandSilent(`playsound ${soundId} player ${player.username} ${player.x} ${player.y} ${player.z} 1 2 1`) + } + if (particleId) { + server.runCommandSilent(`particle ${particleId} ${block.x} ${block.y + 0.8} ${block.z} 0.1 0.1 0.1 0.6 10`) + } + player.swing() + event.server.runCommandSilent(`execute in ${event.block.level.name.getString()} run fill ${block.x} ${block.y} ${block.z} ${block.x} ${block.y} ${block.z} air`) + event.server.runCommandSilent(`execute in ${event.block.level.name.getString()} run setblock ${block.x} ${block.y} ${block.z} ${outputBlock}${state}`) +}; + +// Declare Events +BlockEvents.rightClicked(event => { + //Brick index events + for (const b of global.BRICK_INDEX) { + //brick -> cracked + transformBlockWithTool(event, b.brick, b.cracked_brick, '#forge:tools/hammers',true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.brick_stairs, b.cracked_stairs, '#forge:tools/hammers',true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.brick_slab, b.cracked_slab, '#forge:tools/hammers', true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.brick_wall, b.cracked_wall, '#forge:tools/hammers',true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + //brick -> mossy + transformBlockWithItem(event, b.brick, b.mossy_brick, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick, b.mossy_brick, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_stairs, b.mossy_stairs, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_stairs, b.mossy_stairs, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_slab, b.mossy_slab, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_slab, b.mossy_slab, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_wall, b.mossy_wall, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.brick_wall, b.mossy_wall, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + //cracked -> mossy + transformBlockWithItem(event, b.cracked_brick, b.mossy_brick, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_brick, b.mossy_brick, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_stairs, b.mossy_stairs, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_stairs, b.mossy_stairs, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_slab, b.mossy_slab, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_slab, b.mossy_slab, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_wall, b.mossy_wall, '#tfc:compost_greens_low', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.cracked_wall, b.mossy_wall, 'gtceu:plant_ball', true, 1, 'minecraft:block.moss.hit', 'minecraft:item_slime', true); + //mossy -> cracked + transformBlockWithTool(event, b.mossy_brick, b.cracked_brick, '#forge:tools/hammers', true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.mossy_stairs, b.cracked_stairs, '#forge:tools/hammers', true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.mossy_slab, b.cracked_slab, '#forge:tools/hammers', true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + transformBlockWithTool(event, b.mossy_wall, b.cracked_wall, '#forge:tools/hammers', true, 'minecraft:block.copper.hit', 'minecraft:crit', true); + //mossy -> brick + transformBlockWithTool(event, b.mossy_brick, b.brick, '#forge:tools/knives', true, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.mossy_brick, b.brick, 'tfc:groundcover/pumice', true, 1, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithTool(event, b.mossy_stairs, b.brick_stairs, '#forge:tools/knives', true, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.mossy_stairs, b.brick_stairs, 'tfc:groundcover/pumice', true, 1, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithTool(event, b.mossy_slab, b.brick_slab, '#forge:tools/knives', true, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.mossy_slab, b.brick_slab, 'tfc:groundcover/pumice', true, 1, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithTool(event, b.mossy_wall, b.brick_wall, '#forge:tools/knives', true, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + transformBlockWithItem(event, b.mossy_wall, b.mossy_wall, 'tfc:groundcover/pumice', true, 1, 'minecraft:item.axe.wax_off', 'minecraft:item_slime', true); + //cracked -> brick + transformBlockWithItem(event, b.cracked_brick, b.brick, 'tfc:mortar', true, 1, 'minecraft:item.ink_sac.use', 'minecraft:effect', true); + transformBlockWithItem(event, b.cracked_stairs, b.brick_stairs, 'tfc:mortar', true, 1, 'minecraft:item.ink_sac.use', 'minecraft:effect', true); + transformBlockWithItem(event, b.cracked_slab, b.brick_slab, 'tfc:mortar', true, 1, 'minecraft:item.ink_sac.use', 'minecraft:effect', true); + transformBlockWithItem(event, b.cracked_wall, b.brick_wall, 'tfc:mortar', true, 1, 'minecraft:item.ink_sac.use', 'minecraft:effect', true); + } +}); //#endregion \ No newline at end of file diff --git a/kubejs/server_scripts/tfg/tags.js b/kubejs/server_scripts/tfg/tags.js index 8d2d3a687..667b30fb3 100644 --- a/kubejs/server_scripts/tfg/tags.js +++ b/kubejs/server_scripts/tfg/tags.js @@ -150,6 +150,36 @@ const registerTFGItemTags = (event) => { // Universal Circuits global.UNIVERSAL_CIRCUIT_TIERS.forEach(tier => { event.add(`gtceu:circuits/${tier}`, `tfg:${tier}_universal_circuit`); }) + // Brick Index + const BRICK_KEYS = [ + "brick", + "brick_stairs", + "brick_slab", + "brick_wall", + "cracked_brick", + "cracked_stairs", + "cracked_slab", + "cracked_wall", + "mossy_brick", + "mossy_stairs", + "mossy_slab", + "mossy_wall", + "smooth_brick", + "smooth_stairs", + "smooth_slab", + "smooth_wall", + "chiseled_brick" + ]; + + global.BRICK_INDEX.forEach(brickObj => { + BRICK_KEYS.forEach(key => { + const id = brickObj[key]; + if (typeof id === 'string' && id) { + event.add('tfg:brick_index', id); + } + }); + }); + // Crafting components event.add('tfg:aluminium_oxide', '#forge:dusts/bauxite') event.add('tfg:aluminium_oxide', '#forge:dusts/sapphire') diff --git a/kubejs/startup_scripts/createdeco/constants.js b/kubejs/startup_scripts/createdeco/constants.js index ef39c50aa..d5eb9c398 100644 --- a/kubejs/startup_scripts/createdeco/constants.js +++ b/kubejs/startup_scripts/createdeco/constants.js @@ -1,6 +1,7 @@ // priority: 0 "use strict"; +/** @global */ global.CREATEDECO_DISABLED_ITEMS = [ 'createdeco:andesite_sheet', 'createdeco:zinc_sheet', @@ -10,3 +11,15 @@ global.CREATEDECO_DISABLED_ITEMS = [ 'createdeco:industrial_iron_nugget', 'createdeco:industrial_iron_ingot', ]; + +/** @global */ +global.CREATE_DECO_BRICK_TYPES = [ + 'dusk', + 'scarlet', + 'umber', + 'verdant', + 'blue', + 'pearl', + 'dean', + 'red' +] diff --git a/kubejs/startup_scripts/tfg/constants.js b/kubejs/startup_scripts/tfg/constants.js index 903106aca..97e70a2bf 100644 --- a/kubejs/startup_scripts/tfg/constants.js +++ b/kubejs/startup_scripts/tfg/constants.js @@ -116,4 +116,66 @@ global.FOOD_FRUIT = [ {name: 'melon_slice', id: 'tfc:food/melon_slice', saturation: 0.2, water: 5, fruit: 0.8, decay: 2.25}, {name: 'fig', id: 'firmalife:food/fig', saturation: 1, water: 5, fruit: 0.9, decay: 1}, {name: 'pineapple', id: 'firmalife:food/pineapple', saturation: 1, water: 1, fruit: 0.8, decay: 4.5} -]; \ No newline at end of file +]; + +/** @global */ +global.BRICK_INDEX = global.TFC_STONE_TYPES.map(tfc_stone => ({ + brick_type: tfc_stone, + brick: `tfc:rock/bricks/${tfc_stone}`, brick_stairs: `tfc:rock/bricks/${tfc_stone}_stairs`, brick_slab: `tfc:rock/bricks/${tfc_stone}_slab`, brick_wall: `tfc:rock/bricks/${tfc_stone}_wall`, + cracked_brick: `tfc:rock/cracked_bricks/${tfc_stone}`, cracked_stairs: `tfc:rock/cracked_bricks/${tfc_stone}_stairs`, cracked_slab: `tfc:rock/cracked_bricks/${tfc_stone}_slab`, cracked_wall: `tfc:rock/cracked_bricks/${tfc_stone}_wall`, + mossy_brick: `tfc:rock/mossy_bricks/${tfc_stone}`, mossy_stairs: `tfc:rock/mossy_bricks/${tfc_stone}_stairs`, mossy_slab: `tfc:rock/mossy_bricks/${tfc_stone}_slab`, mossy_wall: `tfc:rock/mossy_bricks/${tfc_stone}_wall`, + smooth_brick: `tfc:rock/smooth/${tfc_stone}`, smooth_stairs: `tfc:rock/smooth/${tfc_stone}_stairs`, smooth_slab: `tfc:rock/smooth/${tfc_stone}_slab`, smooth_wall: `tfc:rock/smooth/${tfc_stone}_wall`, + chiseled_brick: `tfc:rock/chiseled/${tfc_stone}` +})); +global.CREATE_DECO_BRICK_TYPES.slice(0, -1).forEach(create_brick => { + global.BRICK_INDEX.push({ + brick_type: create_brick, + brick: `createdeco:${create_brick}_bricks`, brick_stairs: `createdeco:${create_brick}_brick_stairs`, brick_slab: `createdeco:${create_brick}_brick_slab`, brick_wall: `createdeco:${create_brick}_brick_wall`, + cracked_brick: `createdeco:cracked_${create_brick}_bricks`, cracked_stairs: `createdeco:cracked_${create_brick}_brick_stairs`, cracked_slab: `createdeco:cracked_${create_brick}_brick_slab`, cracked_wall: `createdeco:cracked_${create_brick}_brick_wall`, + mossy_brick: `createdeco:mossy_${create_brick}_bricks`, mossy_stairs: `createdeco:mossy_${create_brick}_brick_stairs`, mossy_slab: `createdeco:mossy_${create_brick}_brick_slab`, mossy_wall: `createdeco:mossy_${create_brick}_brick_wall`, + smooth_brick: `createdeco:corner_${create_brick}_bricks`, smooth_stairs: `createdeco:corner_${create_brick}_brick_stairs`, smooth_slab: `createdeco:corner_${create_brick}_brick_slab`, smooth_wall: `createdeco:corner_${create_brick}_brick_wall`, + chiseled_brick: `createdeco:tiled_${create_brick}_bricks` + }) +}); +global.BRICK_INDEX = global.BRICK_INDEX.concat([ + // { + // brick_type: '', + // brick: '', brick_stairs: '', brick_slab: '', brick_wall: '', + // cracked_brick: '', cracked_stairs: '', cracked_slab: '', cracked_wall: '', + // mossy_brick: '', mossy_stairs: '', mossy_slab: '', mossy_wallL: '', + // smooth_brick: '', smooth_stairs: '', smooth_slab: '', smooth_wall: '', + // chiseled_brick: '' + // }, + { + brick_type: 'red', + brick: 'minecraft:bricks', brick_stairs: 'minecraft:brick_stairs', brick_slab: 'minecraft:brick_slab', brick_wall: 'minecraft:brick_wall', + cracked_brick: 'createdeco:cracked_red_bricks', cracked_stairs: 'createdeco:cracked_red_brick_stairs', cracked_slab: 'createdeco:cracked_red_brick_slab', cracked_wall: 'createdeco:cracked_red_brick_wall', + mossy_brick: 'createdeco:mossy_red_bricks', mossy_stairs: 'createdeco:mossy_red_brick_stairs', mossy_slab: 'createdeco:mossy_red_brick_slab', mossy_wall: 'createdeco:mossy_red_brick_wall', + smooth_brick: 'createdeco:corner_red_bricks', smooth_stairs: 'createdeco:corner_red_brick_stairs', smooth_slab: 'createdeco:corner_red_brick_slab', smooth_wall: 'createdeco:corner_red_brick_wall', + chiseled_brick: 'createdeco:tiled_red_bricks' + }, + { + brick_type: 'light_concrete', + brick: 'gtceu:light_concrete_bricks', brick_stairs: null, brick_slab: null, brick_wall: null, + cracked_brick: 'gtceu:cracked_light_concrete_bricks', cracked_stairs: null, cracked_slab: null, cracked_wall: null, + mossy_brick: 'gtceu:mossy_light_concrete_bricks', mossy_stairs: null, mossy_slab: null, mossy_wall: null, + smooth_brick: 'gtceu:polished_light_concrete', smooth_stairs: null, smooth_slab: null, smooth_wall: null, + chiseled_brick: 'gtceu:chiseled_light_concrete' + }, + { + brick_type: 'dark_concrete', + brick: 'gtceu:dark_concrete_bricks', brick_stairs: null, brick_slab: null, brick_wall: null, + cracked_brick: 'gtceu:cracked_dark_concrete_bricks', cracked_stairs: null, cracked_slab: null, cracked_wall: null, + mossy_brick: 'gtceu:mossy_dark_concrete_bricks', mossy_stairs: null, mossy_slab: null, mossy_wall: null, + smooth_brick: 'gtceu:polished_dark_concrete', smooth_stairs: null, smooth_slab: null, smooth_wall: null, + chiseled_brick: 'gtceu:chiseled_dark_concrete' + }, + { + brick_type: 'red_granite', + brick: 'gtceu:red_granite_bricks', brick_stairs: null, brick_slab: null, brick_wall: null, + cracked_brick: 'gtceu:cracked_red_granite_bricks', cracked_stairs: null, cracked_slab: null, cracked_wall: null, + mossy_brick: 'gtceu:mossy_red_granite_bricks', mossy_stairs: null, mossy_slab: null, mossy_wall: null, + smooth_brick: 'gtceu:polished_red_granite', smooth_stairs: null, smooth_slab: null, smooth_wall: null, + chiseled_brick: 'gtceu:chiseled_red_granite' + } +]) \ No newline at end of file