Skip to content
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

Add an updated copy of refill_hotbar.sc #413

Open
wants to merge 3 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
6 changes: 6 additions & 0 deletions programs/survival/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ Various scripts that modify various game elements, often replicating popular mod
If you run out of an item for any reason, it will be refilled from the hotbar, then shulker boxes in the hotbar.
Useful for large scale building, or afk sand placing around a monument.

### [replace_hotbar.1.20.5+.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/replace_hotbar.1.20.5%2B.sc):
#### Originally by gnembonmc; updated by WesleyJ-128
Exact same functionality as replace_hotbar.sc, but updated to work with in 1.20.5+ with the new item component
system.

### [replace_inventory.sc](https://github.com/gnembon/scarpet/blob/master/programs/survival/replace_inventory.sc):
#### By gnembonmc
There is a video on his channel about this.
Expand Down Expand Up @@ -447,4 +452,5 @@ Various scripts that modify various game elements, often replicating popular mod
Xendergo
ch-yx
Crec0
WesleyJ-128
(Many more hopefully!)
72 changes: 72 additions & 0 deletions programs/survival/hotbar_refill.1.20.5+.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
__on_player_uses_item(player, item_tuple, hand) ->
refill(player, hand, item_tuple);

__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) ->
refill(player, hand, item_tuple);

__on_player_breaks_block(player, block) ->
if (item = player ~ 'holds', refill(player, 'mainhand', item));

__on_player_interacts_with_entity(player, entity, hand) ->
if (item = query(player,'holds',hand), refill(player, hand, item));

__on_player_releases_item(player, item_tuple, hand) ->
refill(player, hand, item_tuple);

__on_player_finishes_using_item(player, item_tuple, hand) ->
refill(player, hand, item_tuple);

__on_player_attacks_entity(player, entity) ->
(
// weapon may break, or you may run out of bows in the offhand, possibly
// can you even attack with the offhand? don't know
for(l('mainhand', 'offhand'),
if (item = query(player, 'holds', _),
refill(player, _, item)
)
)
);

refill(player, hand, item_tuple) ->
(
if (!item_tuple, return());
slot = if(hand=='offhand',40, player ~ 'selected_slot');
schedule(0, '__refill_endtick', player, item_tuple, slot)
);

__refill_endtick(player, old_item, slot) ->
(
if(inventory_get(player,slot), return()); // player still has items on that slot - no need to pick new ones
item_name = old_item:0;
// first internal inventory slots
// loose items
for(range(35, 0, -1),
if ((inv_item = inventory_get(player, _)):0 == item_name, // we found it
inventory_set(player,slot,inv_item:1, inv_item:0, inv_item:2);
inventory_set(player, _, 0);
return()
)
);
// now search in sboxes
for(range(35, 0, -1), sbox_slot = _;
if ( (shulker_box = inventory_get(player, sbox_slot)):0 ~ 'shulker_box', // found a shulkerbox
sbox_items = shulker_box:2:'components':'minecraft:container[]';
// skip empty or uninitialized sboxes
if (sbox_items,
//making sure we have a list, since one element is a scalar response
if (type(sbox_items)!='list', sbox_items = l(sbox_items));
long_item_name = 'minecraft:'+item_name;
for (sbox_items,
if (_:'item':'id' == long_item_name, // found it
inventory_set(player,slot, _:'item':'count', _:'item':'id', _:'item');
data = shulker_box:2;
delete(sbox_items, _i);
put(data, 'components."minecraft:container"', sbox_items);
inventory_set(player, sbox_slot, shulker_box:1, shulker_box:0, data);
return()
)
)
)
)
)
)