-
Notifications
You must be signed in to change notification settings - Fork 169
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
Gnottero
wants to merge
4
commits into
gnembon:master
Choose a base branch
from
Gnottero:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
|
||
// 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know it was default now. I'll fix it later (tonight hopefully)
There was a problem hiding this comment.
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