From 5076c9986d3b922a2b6dbe39d46b414f3a759c7b Mon Sep 17 00:00:00 2001 From: Gnottero Date: Fri, 4 Apr 2025 00:22:09 +0200 Subject: [PATCH 1/3] Updated the simply_harvest script --- programs/survival/simply_harvest.sc | 127 ++++++++++++++-------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/programs/survival/simply_harvest.sc b/programs/survival/simply_harvest.sc index f4dced8a..2351703d 100644 --- a/programs/survival/simply_harvest.sc +++ b/programs/survival/simply_harvest.sc @@ -1,74 +1,77 @@ -/// -// Simply Harvest -// by Gnottero & BisUmTo -// (Carpet Mod 1.4.20) +// +// by Gnottero +// (Carpet Mod 1.4.169) +// Allows the player to harvest crops by right-clicking (setting the age of the crop back to zero) +// Compatible with minecraft 1.21 and with any crop + nether warts // -// Allows the player to right-click on a crop to harvest it. The "Fortune" enchantment affects drops -/// -__config() -> {'stay_loaded' -> true, 'scope' -> 'global'}; - -global_seeds = { - 'wheat' -> 'wheat_seeds', - 'potatoes' -> 'potato', - 'carrots' -> 'carrot', - 'beetroots' -> 'beetroot_seeds', - 'nether_wart' -> 'nether_wart' +__config() -> { + 'stay_loaded' -> true }; -// variable indicating that harvesting occurred -global_harvesting = false; + +// [Begin] Scarpet Events __on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) -> ( - if(hand=='offhand' || player~'gamemode_id' == 3, return()); - if(block_tags(block,'crops') || block == 'nether_wart', + if (hand != 'mainhand', return()); + if (!canHarvest(player, item_tuple, hand, block), return()); + age = block_state(block, 'age'); + try( + block_state(str('%s[age=%d]', block, number(age) + 1)), + 'unknown_block', + harvestCrop(player, item_tuple, hand, block); + ); +); + +// [End] Scarpet Events + + +// [Begin] Custom Functions + +canHarvest(player, item_tuple, hand, block) -> ( + + if (query(player, 'gamemode_id') == 3, return(false)); + if (block_tags(block)~'crops' == null && block != 'nether_wart', return(false)); + if (query(player, 'gamemode_id') == 2, ( - crop_age = block_state(block, 'age'); - if(((crop_age == 7 && (block == 'wheat' || block == 'potatoes' || block == 'carrots')) || (crop_age == 3 && (block == 'beetroots' || block == 'nether_wart'))), - ( - can_destroy = item_tuple:2:'CanDestroy[]'; - if(type(can_destroy) != 'list', can_destroy = [can_destroy]); - if(player~'gamemode_id' == 2 && can_destroy~('minecraft:' + block) == null, return()); - harvest(player, pos(block)); - if(player~'gamemode_id' == 1, set(pos(block), block, 'age', 0); return()); - global_harvesting = true; - schedule(0,_(outer(block)) -> ( - global_harvesting = false; - for(entity_area('item', pos(block), [2, 2, 2]), - if(query(_, 'age') <= 1 && query(_, 'item'):0 == global_seeds:str(block), - nbt = query(_, 'nbt'); - nbt:'Item.Count' = nbt:'Item.Count' - 1; - modify(_, 'nbt', nbt); - set(pos(block), block, 'age', 0); - return(); - ) - ); - ) - ); - // reset hand slot to prevent using up blocks - // apparently mainhand can get checked right away - // harvesting was just set to true, no need to check - if(hand == 'mainhand', - // visually update inventory - inventory_set(player, slot = player~'selected_slot', inventory_get(player, slot):1); - // cancel the rest of the event to prevent the item from being used - return('cancel') - ) - ); + canBreak = parse_nbt(item_tuple:2:'components'):'minecraft:can_break'; + if (type(canBreak) != null, + blockList = getBreakableBlocks(canBreak); + return(blockList~block != null); ); - ); + return(false); + ), + return(true) ); ); -// reset hand slot to prevent using up blocks -// offhand requires this event for some reason -__on_player_placing_block(player, item_tuple, hand, block) -> -( - // only applies while harvesting - if(global_harvesting && hand == 'offhand', - // visually update inventory - inventory_set(player, slot = 40, inventory_get(player, slot):1); - // cancel the rest of the event to prevent the item from being used - return('cancel') - ); + +harvestCrop(player, item_tuple, hand, block) -> ( + harvest(player, pos(block)); + set(pos(block), block, 'age', 0); + modify(player, 'swing', hand); ); + + +getBreakableBlocks(components) -> ( + blockList = []; + if (type(components) == 'list', + ( + for (components, + if (_:'blocks'~'#minecraft:', + reduce(block_list(replace(_:'blocks', '#', '')), blockList += _, 0), + blockList += replace(_:'blocks', 'minecraft:', ''); + ); + ) + ), + ( + if (components:'blocks'~'#minecraft:', + reduce(block_list(replace(components:'blocks', '#', '')), blockList += _, 0), + blockList += replace(components:'blocks', 'minecraft:', ''); + ); + ) + ); + return(blockList) +); + +// [End] Custom Functions \ No newline at end of file From 1115fde333b00bdb78f52664b81c9a4974cae9d2 Mon Sep 17 00:00:00 2001 From: Gnottero Date: Mon, 28 Apr 2025 01:58:15 +0200 Subject: [PATCH 2/3] Removed configs in simply_harvest and added the simply_villagers script --- programs/survival/simple_villagers.sc | 45 +++++++++++++++ programs/survival/simply_harvest copy.sc | 73 ++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 programs/survival/simple_villagers.sc create mode 100644 programs/survival/simply_harvest copy.sc diff --git a/programs/survival/simple_villagers.sc b/programs/survival/simple_villagers.sc new file mode 100644 index 00000000..7b8005da --- /dev/null +++ b/programs/survival/simple_villagers.sc @@ -0,0 +1,45 @@ +// +// by Gnottero +// (Carpet Mod 1.4.169) +// Allows the player to pickup villagers by shift-right clicking on them +// Compatible with minecraft 1.21 +// + + +// [Begin] Scarpet Events + +__on_player_interacts_with_entity(player, entity, hand) -> ( + if (!query(player, 'sneaking'), return()); + if (hand != 'mainhand', return()); + if (query(player, 'holds') != null, return()); + if (query(entity, 'type') != 'villager', return()); + itemizeVillager(entity); +); + +__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) -> ( + if (!query(player, 'sneaking'), return()); + if (hand != 'mainhand', return()); + if (item_tuple:0 != 'clock', return()); + if (item_tuple:2:'components.minecraft:custom_data.VillagerData' == null, return()); + placeVillager(player, item_tuple, block, face); +); + +// [End] Scarpet Events + +// [Begin] Custom Functions + +itemizeVillager(entity) -> ( + villagerData = query(entity, 'nbt'); + clockItem = spawn('item', pos(entity), str('{Item:{id:"minecraft:clock",count:1,components:{"minecraft:enchantment_glint_override":true,"minecraft:lore":[{"color":"gray","italic":false,"text":"- Profession: %s"},{"color":"gray","italic":false,"text":"- Level: %d"}],"minecraft:item_name":"Packed Villager","minecraft:custom_data":{VillagerData: %s}}}}', title(replace(villagerData:'VillagerData.profession', 'minecraft:', '')), villagerData:'VillagerData.level', villagerData)); + particle('cloud', pos(entity) + [0, query(entity, 'eye_height'), 0]); + modify(entity, 'remove'); +); + +placeVillager(player, item_tuple, block, face) -> ( + entity = spawn('villager', pos_offset(pos(block), face, 1) + [0.5, 0, 0.5], item_tuple:2:'components.minecraft:custom_data.VillagerData'); + particle('cloud', pos(entity) + [0, query(entity, 'eye_height'), 0]); + modify(player, 'swing'); + inventory_set(player, query(player, 'selected_slot'), 0); +); + +// [End] Custom Functions \ No newline at end of file diff --git a/programs/survival/simply_harvest copy.sc b/programs/survival/simply_harvest copy.sc new file mode 100644 index 00000000..1b1ab04f --- /dev/null +++ b/programs/survival/simply_harvest copy.sc @@ -0,0 +1,73 @@ +// +// by Gnottero +// (Carpet Mod 1.4.169) +// Allows the player to harvest crops by right-clicking (setting the age of the crop back to zero) +// Compatible with minecraft 1.21 and with any crop + nether warts +// + + +// [Begin] Scarpet Events + +__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) -> ( + if (hand != 'mainhand', return()); + if (!canHarvest(player, item_tuple, hand, block), return()); + age = block_state(block, 'age'); + try( + block_state(str('%s[age=%d]', block, number(age) + 1)), + 'unknown_block', + harvestCrop(player, item_tuple, hand, block); + ); +); + +// [End] Scarpet Events + + +// [Begin] Custom Functions + +canHarvest(player, item_tuple, hand, block) -> ( + + if (query(player, 'gamemode_id') == 3, return(false)); + if (block_tags(block)~'crops' == null && block != 'nether_wart', return(false)); + if (query(player, 'gamemode_id') == 2, + ( + canBreak = parse_nbt(item_tuple:2:'components'):'minecraft:can_break'; + if (type(canBreak) != null, + blockList = getBreakableBlocks(canBreak); + return(blockList~block != null); + ); + return(false); + ), + return(true) + ); +); + + +harvestCrop(player, item_tuple, hand, block) -> ( + harvest(player, pos(block)); + set(pos(block), block, 'age', 0); + modify(player, 'swing', hand); +); + + +getBreakableBlocks(components) -> ( + blockList = []; + if (type(components) == 'list', + ( + for (components, + if (_:'blocks'~'#minecraft:', + reduce(block_list(replace(_:'blocks', '#', '')), blockList += _, 0), + blockList += replace(_:'blocks', 'minecraft:', ''); + ); + ) + ), + ( + if (components:'blocks'~'#minecraft:', + reduce(block_list(replace(components:'blocks', '#', '')), blockList += _, 0), + blockList += replace(components:'blocks', 'minecraft:', ''); + ); + ) + ); + return(blockList) +); + +// [End] Custom Functions \ No newline at end of file From 47a1e59e9b8cd7affe6d0417f56993016091440c Mon Sep 17 00:00:00 2001 From: Gnottero Date: Mon, 28 Apr 2025 02:03:19 +0200 Subject: [PATCH 3/3] Removed simple_harvest copy --- programs/survival/simply_harvest copy.sc | 73 ------------------------ 1 file changed, 73 deletions(-) delete mode 100644 programs/survival/simply_harvest copy.sc diff --git a/programs/survival/simply_harvest copy.sc b/programs/survival/simply_harvest copy.sc deleted file mode 100644 index 1b1ab04f..00000000 --- a/programs/survival/simply_harvest copy.sc +++ /dev/null @@ -1,73 +0,0 @@ -// -// by Gnottero -// (Carpet Mod 1.4.169) -// Allows the player to harvest crops by right-clicking (setting the age of the crop back to zero) -// Compatible with minecraft 1.21 and with any crop + nether warts -// - - -// [Begin] Scarpet Events - -__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) -> ( - if (hand != 'mainhand', return()); - if (!canHarvest(player, item_tuple, hand, block), return()); - age = block_state(block, 'age'); - try( - block_state(str('%s[age=%d]', block, number(age) + 1)), - 'unknown_block', - harvestCrop(player, item_tuple, hand, block); - ); -); - -// [End] Scarpet Events - - -// [Begin] Custom Functions - -canHarvest(player, item_tuple, hand, block) -> ( - - if (query(player, 'gamemode_id') == 3, return(false)); - if (block_tags(block)~'crops' == null && block != 'nether_wart', return(false)); - if (query(player, 'gamemode_id') == 2, - ( - canBreak = parse_nbt(item_tuple:2:'components'):'minecraft:can_break'; - if (type(canBreak) != null, - blockList = getBreakableBlocks(canBreak); - return(blockList~block != null); - ); - return(false); - ), - return(true) - ); -); - - -harvestCrop(player, item_tuple, hand, block) -> ( - harvest(player, pos(block)); - set(pos(block), block, 'age', 0); - modify(player, 'swing', hand); -); - - -getBreakableBlocks(components) -> ( - blockList = []; - if (type(components) == 'list', - ( - for (components, - if (_:'blocks'~'#minecraft:', - reduce(block_list(replace(_:'blocks', '#', '')), blockList += _, 0), - blockList += replace(_:'blocks', 'minecraft:', ''); - ); - ) - ), - ( - if (components:'blocks'~'#minecraft:', - reduce(block_list(replace(components:'blocks', '#', '')), blockList += _, 0), - blockList += replace(components:'blocks', 'minecraft:', ''); - ); - ) - ); - return(blockList) -); - -// [End] Custom Functions \ No newline at end of file