-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 3.1. See readme diff for features.
- Loading branch information
Showing
13 changed files
with
205 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,9 @@ | ||
# Makes all entities (not players) holding a magnet announce themselves in chat. | ||
|
||
#execute as @e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}, sort=random] at @s run say I am holding a magnet. | ||
|
||
# Make entities glow | ||
effect give @e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}] minecraft:glowing 30 0 true | ||
|
||
# Command that lists them all + helper text | ||
tellraw @s ["",{"text":"Loaded entities holding magnets:\n","bold":true,"color":"yellow"},{"text":" ["},{"selector":"@e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}]"},{"text":"]\n\nThey have all been given glowing for 30 seconds.\nTo teleport to one of them hover over them in the list to get their UUID, then type: "},{"text":"/tp <uuid>","color":"yellow","clickEvent":{"action":"suggest_command","value":"/tp UUID"},"hoverEvent":{"action":"show_text","contents":"Suggest command"}},{"text":"\nYou should probably copy-paste them in from your log file.\n\nAlternatively, you can select them for commands via:\n"},{"text":"@e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}]","color":"yellow","clickEvent":{"action":"copy_to_clipboard","value":"@e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}]"},"hoverEvent":{"action":"show_text","contents":"Click to Copy"}}] |
This file contains 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,32 @@ | ||
# Mark setup as ran | ||
scoreboard players set ranSetup m_internals 1 | ||
tellraw @a ["",{"text":"\n"},{"text":"Ran magnet default config setup.","italic":true}] | ||
|
||
# init magnetization player interval to every 5 ticks (0.25 seconds) | ||
scoreboard players set m_player_interval m_options 5 | ||
|
||
# init magnetization mob interval to every 20 ticks (1 second) | ||
scoreboard players set m_mob_interval m_options 20 | ||
|
||
# Works in players' main and offhand | ||
scoreboard players set playerHands m_options 1 | ||
|
||
# Works in players' equip slots (legs) | ||
scoreboard players set playerEquip m_options 1 | ||
|
||
# Works on armor stands | ||
scoreboard players set armorStand m_options 1 | ||
|
||
# Works on all mobs (can cause considerable server lag) | ||
scoreboard players set allMobs_Laggy m_options 0 | ||
|
||
# Plays sound on items | ||
scoreboard players set playItemSound m_options 1 | ||
|
||
# Shows hud text when a magnet is equipped | ||
scoreboard players set enabledActionbarText m_options 1 | ||
|
||
# Display particles | ||
scoreboard players set particlesOnHolder m_options 1 | ||
scoreboard players set particlesOnItem m_options 1 | ||
|
This file contains 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,7 +1,45 @@ | ||
# Print load message | ||
tellraw @a ["",{"text":"\u2714","color":"dark_green"},{"text":" Magnet datapack loaded.\nGet some iron and go craft a "},{"text":"Magnet","color":"yellow"},{"text":".\nMore info "},{"text":"here","underlined":true,"clickEvent":{"action":"open_url","value":"http://bit.ly/MagnetDatapack"}},{"text":"."}] | ||
tellraw @a ["",{"text":"\u2714","color":"dark_green"},{"text":" Magnet datapack loaded.\nGet some iron and go craft a "},{"text":"Magnet","color":"yellow"},{"text":".\nMore info "},{"text":"here","underlined":true,"clickEvent":{"action":"open_url","value":"http://bit.ly/MagnetDatapack"}},{"text":".\nTo configure the datapack, click "}, {"text":"[here]","color":"yellow","clickEvent":{"action":"run_command","value":"/function magnet:toggle_options_pane"},"hoverEvent":{"action":"show_text","contents":"Toggle options pane"}},{"text":"\nor type: "},{"text":"/function magnet:toggle_options_pane","color":"yellow","clickEvent":{"action":"suggest_command","value":"/function magnet:toggle_options_pane"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"\n "}] | ||
|
||
# Set up scoreboard values for tracking crafting of chainmail leggings | ||
scoreboard objectives add m_craft_leggings minecraft.crafted:minecraft.chainmail_leggings | ||
scoreboard objectives add m_count_magnets dummy | ||
scoreboard objectives add m_count_reg_legs dummy | ||
scoreboard objectives add m_count_reg_legs dummy | ||
|
||
# Set up scoreboard values for timed magnetization and internal settings | ||
scoreboard objectives add m_internals dummy "Magnet Internal" | ||
|
||
# Set up options scoreboard | ||
scoreboard objectives add m_options dummy "Magnet Datapack" | ||
scoreboard objectives modify m_options displayname {"text":"Magnet Datapack","bold":true,"color":"yellow"} | ||
|
||
# Set up team coloration for options menu | ||
#team add magnet_internal "magnet internal" | ||
team add magnet_option "magnet option" | ||
#team modify magnet_internal color gray | ||
team modify magnet_option color gold | ||
#team join magnet_internal m_timer_player | ||
#team join magnet_internal m_timer_mob | ||
#team join magnet_internal ranSetup | ||
team join magnet_option playerHands | ||
team join magnet_option playerEquip | ||
team join magnet_option armorStand | ||
team join magnet_option allMobs_Laggy | ||
team join magnet_option m_mob_interval | ||
team join magnet_option m_player_interval | ||
team join magnet_option playItemSound | ||
team join magnet_option particlesOnHolder | ||
team join magnet_option particlesOnItem | ||
team join magnet_option enabledActionbarText | ||
|
||
#scoreboard objectives setdisplay sidebar m_options | ||
#scoreboard objectives setdisplay sidebar m_internals | ||
|
||
# Set up trackers for if setup has been run and if options pane is currently open. | ||
# If undefined, it can't be checked against by 'execute matches' (has null value) so make it val *= val, which makes it 0 if null and has no effect if it's 1 | ||
scoreboard players operation ranSetup m_internals *= ranSetup m_internals | ||
scoreboard players operation optionsOpen m_internals *= optionsOpen m_internals | ||
|
||
# If setup never ran, run setup script | ||
execute if score ranSetup m_internals matches 0 run function magnet:default_configs | ||
|
This file contains 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,9 +1,19 @@ | ||
# Cause all items within 10 blocks of the caller to play a sound for the nearest player. The sound has a minimum volume and ramps up as the player gets closer. | ||
execute as @e[type=minecraft:item, distance=0..10] at @s run playsound minecraft:entity.experience_bottle.throw player @p ~ ~ ~ .01 2 .002 | ||
execute if score playItemSound m_options matches 1 run execute as @e[type=minecraft:item, distance=0..10] at @s run playsound minecraft:entity.experience_bottle.throw player @p ~ ~ ~ .01 2 .002 | ||
|
||
# Displays particles on the function's caller if there is an item in magnet range | ||
execute as @s at @s if entity @e[distance=0..5, type=item] run particle minecraft:portal ~ ~.25 ~ .001 0 .001 1 2 normal | ||
# TODO: consider swapping to nautilus particle | ||
execute if score particlesOnHolder m_options matches 1 run execute as @s at @s if entity @e[distance=0..5, type=item] run particle minecraft:portal ~ ~.25 ~ 0 0 0 3 2 normal | ||
# consider swapping to `nautilus` particle | ||
|
||
# Show actionbar text to caller | ||
execute if score enabledActionbarText m_options matches 1 run title @s actionbar {"text":"Magnet Equipped","color":"gray"} | ||
|
||
# Item attraction range is 5 blocks | ||
|
||
# Particles on item | ||
execute if score particlesOnItem m_options matches 1 run execute as @e[limit=1,sort=nearest,distance=0..5,type=minecraft:item] at @s if entity @e[distance=0..5, type=item] run particle minecraft:reverse_portal ~ ~.25 ~ 0 0 0 0.1 3 normal | ||
|
||
# Teleport nearest item entity to the function's caller | ||
tp @e[limit=1,sort=nearest,distance=0..5,type=minecraft:item] @s | ||
tp @e[limit=1,sort=nearest,distance=0..5,type=minecraft:item] @s | ||
# Move 1 block towards the holder's feet (broken) | ||
#execute as @e[limit=1,sort=nearest,distance=0..5,type=minecraft:item] run execute facing entity @s feet as @e[type=item] at @s run tp ^ ^ ^1 |
This file contains 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,13 +1,12 @@ | ||
# Detect magnet equipped in player offhand | ||
execute as @a[nbt={Inventory:[{Slot: -106b, tag: {isMagnet:1b}}]}] at @s run function magnet:magnetize_item | ||
# Detect magnet equipped in player leggings slot | ||
execute as @a[nbt={Inventory:[{Slot: 101b, tag: {isMagnet:1b}}]}] at @s run function magnet:magnetize_item | ||
# Detect players that have crafted at least one pair of leggings and deal with that | ||
execute as @e[type=minecraft:player,scores={m_craft_leggings=1..}] if score @s m_craft_leggings matches 1.. run function magnet:while001_crafted_legs | ||
|
||
# Detect magnet held in player main hand | ||
execute as @a[nbt={SelectedItem:{tag: {isMagnet:1b}}}] at @s run function magnet:magnetize_item | ||
# Increment global timers by 1 | ||
scoreboard players add m_timer_player m_internals 1 | ||
scoreboard players add m_timer_mob m_internals 1 | ||
|
||
# Detect magnet in mobs' leggings armor slot. Random sort so that mobs 'fight' for items and if multiple have magnets they are more likely to suck up gear that others don't need | ||
execute as @e[nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}, sort=random] at @s run function magnet:magnetize_item | ||
# If player timer exceeds m_player_interval, set it back to zero | ||
execute if score m_timer_player m_internals >= m_player_interval m_options run function magnet:on_player_interval | ||
|
||
# Detect players that have crafted at least one pair of leggings and deal with that | ||
execute as @e[type=minecraft:player,scores={m_craft_leggings=1..}] if score @s m_craft_leggings matches 1.. run function magnet:while001_crafted_legs | ||
# If mob timer exceeds m_mob_interval, set it back to zero | ||
execute if score m_timer_mob m_internals >= m_player_interval m_options run function magnet:on_mob_interval |
This file contains 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,10 @@ | ||
# reset the interval counter back to zero | ||
scoreboard players set m_timer_mob m_internals 0 | ||
|
||
#Random sort so that mobs 'fight' for items and if multiple have magnets they are more likely to suck up gear that others don't need | ||
|
||
# Detect magnet in armor stands' leggings armor slot. Exclude if all mobs is on | ||
execute unless score allMobs_Laggy m_options matches 1 if score armorStand m_options matches 1 run execute as @e[type=minecraft:armor_stand, nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}, sort=random] at @s run function magnet:magnetize_item | ||
|
||
# Detect magnet in any mobs' leggings armor slot. | ||
execute if score allMobs_Laggy m_options matches 1 run execute as @e[type=!minecraft:player,nbt={ArmorItems:[{}, {tag: {isMagnet:1b}}, {}, {}]}, sort=random] at @s run function magnet:magnetize_item |
This file contains 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,10 @@ | ||
# reset the interval counter back to zero | ||
scoreboard players set m_timer_player m_internals 0 | ||
|
||
# Detect magnet held in player main hand | ||
execute if score playerHands m_options matches 1 run execute as @a[nbt={SelectedItem:{tag: {isMagnet:1b}}}] at @s run function magnet:magnetize_item | ||
# Detect magnet equipped in player offhand | ||
execute if score playerHands m_options matches 1 run execute as @a[nbt={Inventory:[{Slot: -106b, tag: {isMagnet:1b}}]}] at @s run function magnet:magnetize_item | ||
|
||
# Detect magnet equipped in player leggings slot | ||
execute if score playerEquip m_options matches 1 run execute as @a[nbt={Inventory:[{Slot: 101b, tag: {isMagnet:1b}}]}] at @s run function magnet:magnetize_item |
This file contains 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,2 @@ | ||
function magnet:uninstall | ||
reload |
This file contains 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,30 @@ | ||
# copy this instant into a scratchpad variable for OR statement | ||
#scoreboard players operation instant m_internals = m_timer_player m_internals | ||
|
||
# if the options menu is open and something hasn't already happened, set the flag to close the options | ||
#execute if score instant m_internals = m_timer_player m_options if score optionsOpen m_internals matches 1 run scoreboard players set instant m_internals -1 | ||
|
||
# set toggler depending on if the options is open or not | ||
# open: | ||
execute if score optionsOpen m_internals matches 1 run scoreboard players set toggle m_internals 1 | ||
# closed: | ||
execute if score optionsOpen m_internals matches 0 run scoreboard players set toggle m_internals 0 | ||
|
||
# if the options panel is closed, open it | ||
execute if score toggle m_internals matches 0 run scoreboard objectives setdisplay sidebar m_options | ||
execute if score toggle m_internals matches 0 run scoreboard players set optionsOpen m_internals 1 | ||
execute if score toggle m_internals matches 0 run tellraw @s ["",{"text":"\n\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550[Magnet Options]\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\nTo change a setting, run a variation of the following command:\n"},{"text":"/scoreboard players set ","color":"yellow","clickEvent":{"action":"suggest_command","value":"/scoreboard players set OPTION m_options VALUE"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"<option name>","italic":true,"color":"yellow","clickEvent":{"action":"suggest_command","value":"/scoreboard players set OPTION m_options VALUE"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":" m_options ","color":"yellow","clickEvent":{"action":"suggest_command","value":"/scoreboard players set OPTION m_options VALUE"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"<value>","italic":true,"color":"yellow","clickEvent":{"action":"suggest_command","value":"/scoreboard players set OPTION m_options VALUE"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"\n\nFor example, to turn off magnet sounds, use:\n"},{"text":"/scoreboard players set playItemSound m_options 0","color":"yellow","clickEvent":{"action":"suggest_command","value":"/scoreboard players set playItemSound m_options 0"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"\n\nTo close this menu again, click "},{"text":"[here]","color":"yellow","clickEvent":{"action":"run_command","value":"/function magnet:toggle_options_pane"},"hoverEvent":{"action":"show_text","contents":"Toggle options pane"}},{"text":"\nor type: "},{"text":"/function magnet:toggle_options_pane","color":"yellow","clickEvent":{"action":"suggest_command","value":"/function magnet:toggle_options_pane"},"hoverEvent":{"action":"show_text","contents":"Click to suggest"}},{"text":"\n\nMore info can be found "},{"text":"[here]","color":"yellow","clickEvent":{"action":"open_url","value":"http://bit.ly/MagnetDatapack"},"hoverEvent":{"action":"show_text","contents":"Open help page"}},{"text":".\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"}] | ||
|
||
# if the options panel is opened, close it | ||
execute if score toggle m_internals matches 1 run scoreboard objectives setdisplay sidebar | ||
execute if score toggle m_internals matches 1 run scoreboard players set optionsOpen m_internals 0 | ||
|
||
# message player | ||
#execute unless score optionsOpen m_internals matches 1 run tellraw @s {"text":"opened options"} | ||
#execute unless score optionsOpen m_internals matches 1 run say Opened Magnet options pane | ||
|
||
# show on sidebar | ||
#execute unless score optionsOpen m_internals matches 1 run scoreboard objectives setdisplay sidebar m_options | ||
|
||
|
||
#execute unless score optionsOpen m_internals matches 1 run scoreboard players set optionsOpen m_internals 1 |
This file contains 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,9 @@ | ||
scoreboard objectives remove m_internals | ||
scoreboard objectives remove m_options | ||
|
||
scoreboard objectives remove m_count_magnets | ||
scoreboard objectives remove m_count_reg_legs | ||
scoreboard objectives remove m_craft_leggings | ||
|
||
team remove magnet_internal | ||
team remove magnet_option |
This file contains 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,6 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 3, | ||
"description": "Makes chainmail leggings that are held and renamed to 'Magnet' act as an item magnet in a 5 block radius. Makes items within 10 blocks make noise." | ||
"description": "More info here: http://bit.ly/MagnetDatapack" | ||
} | ||
} |