Skip to content

Updated the simply_harvest script #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions programs/survival/simple_villagers.sc
Original file line number Diff line number Diff line change
@@ -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
127 changes: 65 additions & 62 deletions programs/survival/simply_harvest.sc
Original file line number Diff line number Diff line change
@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stay loaded is now implied, so no need to include non functional configs, right?

Copy link
Contributor Author

@Gnottero Gnottero Apr 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stay loaded is now implied, so no need to include non functional configs, right?

Oh, I didn't know it was default now. I'll fix it later (tonight hopefully)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the script removing the config block and also added another script, called simple_villagers, that allows the player to pickup villagers and place them back in the world

};

// 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