player is sneaking
set {_Block} to block at player's target block
nbt of {_Block} has nbt tag "custom;GeneratorType"
if nbt of event-block has nbt tag "custom;Owner":
set {_Generators::Owner} to uuid tag "custom;Owner" of nbt of event-block
if {_Generators::Owner} = player's uuid:
set {_GeneratorType} to string tag "custom;GeneratorType" of nbt of {_Block}
copy {Generators::Blocks::*} to {_Generators::Blocks::*}
sort {_Generators::Blocks::*} by int tag "Price" of custom nbt of input
set {_AmountOfLoop} to 0
loop {_Generators::Blocks::*}:
set {_NextTier} to first element of (uncolored name of loop-value split at " ")
#send "&4%{_NextTier}%" to player
add 1 to {_AmountOfLoop}
if {_AmountOfLoop} = size of {_Generators::Blocks::*}:
send "Cannot upgrade more! Max generator!" to player
stop
else if {_StopLoop} is set:
set {_NextTier} to first element of (uncolored name of loop-value split at " ")
#send "Next Tier: &5%{_NextTier}%" to player
stop loop
else if {_NextTier} is {_GeneratorType}:
set {_StopLoop} to true```
#Works perfect, but feels cluttered. Any suggestions to improve it?
1 messages · Page 1 of 1 (latest)
- Seems some local vars are 'throwaway variables'; used only once and you dont even need them, for example,
if {_Generators::Owner} = player's uuid:
if (uuid tag "custom;Owner" of (nbt of event-block)) = (player's uuid):```
2. use the `loop-iteration` expression instead of `{_AmountOfLoop}`
3. the best way to un-clutter code is to add empty lines as padding between sections