Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Optimise carrot-on-a-stick-item durability management
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jul 1, 2020
1 parent 896c635 commit ac7244a
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# called by block/eckspei_locker/output_experience/eckspei_rod_check

# get item
data modify entity @s HandItems[0] set from block ~ ~ ~ Items[{Slot:12b}]
data modify storage ttb:temp item_durability_update set from block ~ ~ ~ Items[{Slot:12b}]

# add durability
execute store result score @s ttb_durab run data get entity @s HandItems[0].tag.ttb.durability
scoreboard players add @s ttb_durab 1
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
scoreboard players add #durability ttb_data 1

# remove experience
scoreboard players remove @s ttb_ecks_loc_exp 1
Expand All @@ -15,14 +15,11 @@ scoreboard players set @s ttb_model_cmd 18
execute in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update

# store item back into container
data modify block ~ ~ ~ Items[{Slot:12b}] merge from entity @s HandItems[0]
data modify block ~ ~ ~ Items[{Slot:12b}] merge from storage ttb:temp item_durability_update

# remove item from entity
data remove entity @s HandItems[0]
data remove storage ttb:temp item_durability_update

# audiovisuals
particle totem_of_undying ~ ~ ~ .25 .25 .25 .2 2 normal @a

execute store result score @s ttb_durab run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.durability
execute store result score @s ttb_durab_max run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.max_durability
execute if score @s ttb_durab = @s ttb_durab_max run function ttb:block/eckspei_locker/output_experience/finished
execute if score #durability ttb_data = #durability_max ttb_data run function ttb:block/eckspei_locker/output_experience/finished
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# called by block/eckspei_locker/tick

execute store result score @s ttb_durab run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.durability
execute store result score @s ttb_durab_max run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.max_durability
execute store result score #durability ttb_data run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.durability
execute store result score #durability_max ttb_data run data get block ~ ~ ~ Items[{Slot:12b}].tag.ttb.max_durability

execute unless score @s ttb_durab >= @s ttb_durab_max run function ttb:block/eckspei_locker/output_experience/eckspei_rod
execute unless score #durability ttb_data >= #durability_max ttb_data run function ttb:block/eckspei_locker/output_experience/eckspei_rod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
execute if score @s ttb_relic_damage >= $threshold ttb_relic_damage run particle soul_fire_flame ~ ~ ~ 0 0 0 0.1 50 normal @a

data modify storage ttb:temp item_durability_update set from entity @s SelectedItem
execute store result score @s ttb_durab run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score @s ttb_durab_max run data get storage ttb:temp item_durability_update.tag.ttb.max_durability
execute if score @s ttb_relic_damage >= $threshold ttb_relic_damage if data storage ttb:temp item_durability_update{tag:{ttb:{item:'staff'}}} if score @s ttb_durab < @s ttb_durab_max run function ttb:item/staff/durability/recharge/bright_relic
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score #durability_max ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.max_durability
execute if score @s ttb_relic_damage >= $threshold ttb_relic_damage if data storage ttb:temp item_durability_update{tag:{ttb:{item:'staff'}}} if score #durability ttb_data < #durability_max ttb_data run function ttb:item/staff/durability/recharge/bright_relic
data remove storage ttb:temp item_durability_update
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#recharge
data modify storage ttb:temp item_durability_update set from entity @s SelectedItem
execute store result score @s ttb_durab run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score @s ttb_durab_max run data get storage ttb:temp item_durability_update.tag.ttb.max_durability
execute if data storage ttb:temp item_durability_update{tag:{ttb:{item:'staff'}}} if score @s ttb_durab < @s ttb_durab_max run function ttb:item/staff/durability/recharge/dark_relic
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score #durability_max ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.max_durability
execute if data storage ttb:temp item_durability_update{tag:{ttb:{item:'staff'}}} if score #durability ttb_data < #durability_max ttb_data run function ttb:item/staff/durability/recharge/dark_relic
data remove storage ttb:temp item_durability_update
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag @s add ttb_use_crtstck
execute if data storage ttb:temp item_durability_update{tag:{ttb:{item:'staff'}}} run function ttb:item/staff/durability/check
tag @s remove ttb_use_crtstck
# eckspei rod?
execute if data storage ttb:temp item_durability_update{tag:{ttb:{item:'eckspei_rod'}}} unless score @s ttb_durab matches 0 run function ttb:item/eckspei_rod/use
execute if data storage ttb:temp item_durability_update{tag:{ttb:{item:'eckspei_rod'}}} unless score #durability ttb_data matches 0 run function ttb:item/eckspei_rod/use

# post
data remove storage ttb:temp item_durability_update
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# called by item/carrot_on_a_stick/durability/update positioned ~ ~-1 ~

# set shulker box
setblock ~ ~ ~ yellow_shulker_box{Items:[{Slot:0b,id:"barrier",Count:1b,tag:{CustomModelData:6830001}}]}

# get if offhand
execute store result score #is_usage_offhand ttb_data run data remove storage ttb:temp item_durability_update.Slot

# set shulker box item
data modify block ~ ~ ~ Items[0] set from storage ttb:temp item_durability_update

# loot to respective hand
execute unless score #is_usage_offhand ttb_data matches 1 run loot replace entity @s weapon.mainhand 1 mine ~ ~ ~ air{drop_contents:1b}
execute if score #is_usage_offhand ttb_data matches 1 run loot replace entity @s weapon.offhand 1 mine ~ ~ ~ air{drop_contents:1b}

# remove shulker box
setblock ~ ~ ~ air
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# called by item/carrot_on_a_stick/durability/update

scoreboard players add @s ttb_model_cmd 6830000
execute store result block ~ ~-1 ~ Items[0].tag.CustomModelData int 1 run scoreboard players get @s ttb_model_cmd
execute store result storage ttb:temp item_durability_update.tag.CustomModelData int 1 run scoreboard players get @s ttb_model_cmd
scoreboard players reset @s ttb_model_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,25 @@

# pre
forceload add ~ ~
execute store result score #durability_max ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.max_durability

# get copy
setblock ~ ~-1 ~ yellow_shulker_box{Items:[{Slot:0b,id:"barrier",Count:1b,tag:{CustomModelData:6830001}}]}
execute store result score #is_usage_offhand ttb_data run data remove storage ttb:temp item_durability_update.Slot
data modify block ~ ~-1 ~ Items[0] set from storage ttb:temp item_durability_update
execute unless data storage ttb:temp item_durability_update run data modify block ~ ~-1 ~ Items[0] set from entity @s HandItems[0]

# pre
execute store result score @s ttb_durab_max run data get block ~ ~-1 ~ Items[0].tag.ttb.max_durability

# update copy
## custom durability
### item data
execute if score @s ttb_durab > @s ttb_durab_max run scoreboard players operation @s ttb_durab = @s ttb_durab_max
scoreboard players set @s[scores={ttb_durab=..-1}] ttb_durab 0
execute store result block ~ ~-1 ~ Items[0].tag.ttb.durability int 1 run scoreboard players get @s ttb_durab
### item lore
setblock ~ ~ ~ oak_sign{Text1:'[{"text":"","italic":false,"color":"gray"},[{"translate":"item.durability","with":[{"nbt":"Items[0].tag.ttb.durability","block":"~ ~-1 ~"},{"nbt":"Items[0].tag.ttb.max_durability","block":"~ ~-1 ~"}]}]]'}
data modify block ~ ~-1 ~ Items[0].tag.display.Lore[0] set from block ~ ~ ~ Text1
# item durability data
execute unless score #durability ttb_data > #durability_max ttb_data store result storage ttb:temp item_durability_update.tag.ttb.durability int 1 run scoreboard players get #durability ttb_data
execute if score #durability ttb_data > #durability_max ttb_data store result storage ttb:temp item_durability_update.tag.ttb.durability int 1 run scoreboard players get #durability_max ttb_data
# item lore
setblock ~ ~ ~ oak_sign{Text1:'[{"text":"","italic":false,"color":"gray"},[{"translate":"item.durability","with":[{"nbt":"item_durability_update.tag.ttb.durability","storage":"ttb:temp"},{"nbt":"item_durability_update.tag.ttb.max_durability","storage":"ttb:temp"}]}]]'}
data modify storage ttb:temp item_durability_update.tag.display.Lore[0] set from block ~ ~ ~ Text1
setblock ~ ~ ~ air
# vanilla damage value
scoreboard players operation @s ttb_durab_max -= @s ttb_durab
scoreboard players operation @s ttb_durab_max *= #100 ttb_gamerules
execute store result score @s ttb_durab run data get block ~ ~-1 ~ Items[0].tag.ttb.max_durability
scoreboard players operation @s ttb_durab_max /= @s ttb_durab
scoreboard players operation @s ttb_durab_max *= $carrot_on_a_stick_dur ttb_durab
scoreboard players operation @s ttb_durab_max /= #100 ttb_gamerules
execute store result block ~ ~-1 ~ Items[0].tag.Damage int 1 run scoreboard players get @s ttb_durab_max
scoreboard players operation #durability_as_coas_damage ttb_data = #durability_max ttb_data
scoreboard players operation #durability_as_coas_damage ttb_data -= #durability ttb_data
scoreboard players operation #durability_as_coas_damage ttb_data *= #100 ttb_gamerules
scoreboard players operation #durability_as_coas_damage ttb_data /= #durability_max ttb_data
scoreboard players operation #durability_as_coas_damage ttb_data *= carrot_on_a_stick_durability ttb_data
scoreboard players operation #durability_as_coas_damage ttb_data /= #100 ttb_gamerules
execute store result storage ttb:temp item_durability_update.tag.Damage int 1 run scoreboard players get #durability_as_coas_damage ttb_data

# post
execute if score @s ttb_model_cmd matches 0.. run function ttb:item/carrot_on_a_stick/durability/set_custom_model_data
execute unless score #is_usage_offhand ttb_data matches 1 run loot replace entity @s weapon.mainhand 1 mine ~ ~-1 ~ air{drop_contents:1b}
execute if score #is_usage_offhand ttb_data matches 1 run loot replace entity @s weapon.offhand 1 mine ~ ~-1 ~ air{drop_contents:1b}
setblock ~ ~-1 ~ air
execute unless entity @s[tag=ttb_machine] positioned ~ ~-1 ~ run function ttb:item/carrot_on_a_stick/durability/replace_hand
forceload remove ~ ~
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ data modify storage ttb:temp item_durability_update set from entity @s SelectedI
execute unless data storage ttb:temp item_durability_update{id:'minecraft:carrot_on_a_stick'} run data modify storage ttb:temp item_durability_update set from entity @s Inventory[{Slot:-106b}]

# get current durability
execute store result score @s ttb_durab run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# called by item/eckspei_rod/use

xp add @s 1 points
scoreboard players remove @s ttb_durab 1
scoreboard players remove #durability ttb_data 1
scoreboard players remove #eckspei_rod_xp_loop ttb_data 1

execute unless score #eckspei_rod_xp_loop ttb_data matches 0 unless score @s ttb_durab matches 0 run function ttb:item/eckspei_rod/add_experience
execute unless score #eckspei_rod_xp_loop ttb_data matches 0 unless score #durability ttb_data matches 0 run function ttb:item/eckspei_rod/add_experience
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ scoreboard players operation #eckspei_rod_xp_loop ttb_data = eckspei_rod_xp_per
function ttb:item/eckspei_rod/add_experience

# update item data
execute if score @s ttb_durab matches 0 run scoreboard players set @s ttb_model_cmd 17
execute if score #durability ttb_data matches 0 run scoreboard players set @s ttb_model_cmd 17
execute in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

data modify storage ttb:temp item.restoration_tome.repair_item set from storage ttb:temp block.tempest_crafter.input[{tag:{ttb:{staff:{}}}}]

execute store result score @s ttb_durab run data get storage ttb:temp item.restoration_tome.repair_item.tag.ttb.durability
execute store result score @s ttb_durab_max run data get storage ttb:temp item.restoration_tome.repair_item.tag.ttb.max_durability
execute store result score #durability ttb_data run data get storage ttb:temp item.restoration_tome.repair_item.tag.ttb.durability
execute store result score #durability_max ttb_data run data get storage ttb:temp item.restoration_tome.repair_item.tag.ttb.max_durability

execute unless score @s ttb_durab = @s ttb_durab_max run function ttb:item/restoration_tome/restore/staff
execute unless score #durability ttb_data = #durability_max ttb_data run function ttb:item/restoration_tome/restore/staff
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
#update copy
## custom durability
### item data
scoreboard players operation @s ttb_durab = @s ttb_durab_max
execute store result block ~ ~-1 ~ Items[{Slot:0b}].tag.ttb.durability int 1 run scoreboard players get @s ttb_durab
scoreboard players operation #durability ttb_data = #durability_max ttb_data
execute store result block ~ ~-1 ~ Items[{Slot:0b}].tag.ttb.durability int 1 run scoreboard players get #durability ttb_data
### item lore
setblock ~ ~ ~ oak_sign{Text1:'[{"text":"","italic":false,"color":"gray"},[{"translate":"item.durability","with":[{"nbt":"Items[{Slot:0b}].tag.ttb.durability","block":"~ ~-1 ~"},{"nbt":"Items[{Slot:0b}].tag.ttb.max_durability","block":"~ ~-1 ~"}]}]]'}
data modify block ~ ~-1 ~ Items[{Slot:0b}].tag.display.Lore[0] set from block ~ ~ ~ Text1
setblock ~ ~ ~ air
# vanilla damage value
scoreboard players operation @s ttb_durab_max -= @s ttb_durab
scoreboard players operation @s ttb_durab_max *= #100 ttb_gamerules
execute store result score @s ttb_durab run data get entity @s Items[{Slot:0b}].tag.ttb.durability
scoreboard players operation @s ttb_durab_max /= @s ttb_durab
scoreboard players operation @s ttb_durab_max *= $carrot_on_a_stick_dur ttb_durab
scoreboard players operation @s ttb_durab_max /= #100 ttb_gamerules
execute store result block ~ ~-1 ~ Items[{Slot:0b}].tag.Damage int 1 run scoreboard players get @s ttb_durab_max
scoreboard players operation #durability_max ttb_data -= #durability ttb_data
scoreboard players operation #durability_max ttb_data *= #100 ttb_gamerules
execute store result score #durability ttb_data run data get entity @s Items[{Slot:0b}].tag.ttb.durability
scoreboard players operation #durability_max ttb_data /= #durability ttb_data
scoreboard players operation #durability_max ttb_data *= carrot_on_a_stick_durability ttb_data
scoreboard players operation #durability_max ttb_data /= #100 ttb_gamerules
execute store result block ~ ~-1 ~ Items[{Slot:0b}].tag.Damage int 1 run scoreboard players get #durability_max ttb_data

#debug
tellraw @a[tag=ttb_debug,distance=..6] ["Staff durability: ",[{"nbt":"Items[{Slot:0b}].tag.ttb.durability","entity":"@s"},"/",{"nbt":"Items[{Slot:0b}].tag.ttb.max_durability","entity":"@s"}]]
2 changes: 1 addition & 1 deletion ttb_data/data/ttb/functions/item/staff/break.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#called by item/staff/use_right
#called by item/staff/durability/check

execute anchored eyes positioned ^ ^ ^.5 positioned ~ ~.03 ~ run particle item stick ~ ~ ~ .1 .1 .1 0 12 normal @a
playsound entity.item.break player @a[distance=..16] ~ ~ ~ .75 1 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# called by entity/player/used_item/carrot_on_a_stick | entity/player/hurt_entity

# usage
execute if score @s[tag=ttb_use_crtstck] ttb_durab matches 1.. run function ttb:item/staff/use_right
execute if score @s[tag=ttb_hurt_entity] ttb_durab matches 1.. run function ttb:item/staff/use_left
execute if entity @s[tag=ttb_use_crtstck] if score #durability ttb_data matches 1.. run function ttb:item/staff/use_right
execute if entity @s[tag=ttb_hurt_entity] if score #durability ttb_data matches 1.. run function ttb:item/staff/use_left

# depletion
execute in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update
execute if data storage ttb:temp item_durability_update{tag:{ttb:{durability:0}}} run function ttb:item/staff/break
execute if entity @s[gamemode=!creative,gamemode=!spectator] run function ttb:item/staff/durability/deplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# called by item/staff/durability/check

scoreboard players remove #durability ttb_data 1
execute if score #durability ttb_data matches 1.. in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update
execute unless score #durability ttb_data matches 1.. run function ttb:item/staff/break
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ particle soul_fire_flame ~ ~ ~ 0 0 0 0.25 50 normal @a
particle end_rod ~ ~ ~ .25 1 .25 .1 100 normal @a

#functionality
execute store result score @s ttb_durab run data get storage ttb:temp item_durability_update.tag.ttb.durability
scoreboard players add @s ttb_durab 3
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
scoreboard players add #durability ttb_data 3

execute in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ particle effect ~ ~ ~ 1 1 1 0.01 200 normal @a
playsound entity.wither.ambient player @a[distance=..16] ~ ~ ~ 2 0.5 1

# add durability
execute store result score @s ttb_durab run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score $to_add ttb_durab_max run data get storage ttb:temp item_durability_update.tag.ttb.max_durability
execute store result score #durability ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.durability
execute store result score #durability_to_add ttb_data run data get storage ttb:temp item_durability_update.tag.ttb.max_durability

scoreboard players operation $to_add ttb_durab_max /= #2 ttb_gamerules
scoreboard players add $to_add ttb_durab_max 1
scoreboard players operation #durability_to_add ttb_data /= #2 ttb_gamerules
scoreboard players add #durability_to_add ttb_data 1

scoreboard players operation @s ttb_durab += $to_add ttb_durab_max
scoreboard players reset $to_add ttb_durab_max
scoreboard players operation #durability ttb_data += #durability_to_add ttb_data
scoreboard players reset #durability_to_add ttb_data

execute in overworld positioned 29999984 255 29999984 run function ttb:item/carrot_on_a_stick/durability/update

Expand Down
1 change: 0 additions & 1 deletion ttb_data/data/ttb/functions/item/staff/use_left.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

execute anchored eyes positioned ^ ^ ^ run function ttb:item/staff/get_hit_entity

scoreboard players remove @s[gamemode=!creative,gamemode=!spectator] ttb_durab 1
execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'repulsion'}}}} as @e[type=!player,type=!#ttb:sprite,tag=ttb_hit_entity,limit=1] at @s run function ttb:item/staff/repulsion/use_left
# execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'relativity'}}}} as @e[type=!player,type=!#ttb:sprite,tag=ttb_hit_entity,limit=1] at @s run function ttb:item/staff/relativity/use_left
# execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'extraction'}}}} as @e[type=!player,type=!#ttb:sprite,tag=ttb_hit_entity,limit=1] at @s run function ttb:item/staff/extraction/use_left
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#called by item/staff/durability/check

scoreboard players remove @s[gamemode=!creative,gamemode=!spectator] ttb_durab 1
execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'repulsion'}}}} run function ttb:item/staff/repulsion/use_right
execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'relativity'}}}} run function ttb:item/staff/relativity/use_right
execute if data storage ttb:temp item_durability_update{tag:{ttb:{staff:{id:'extraction'}}}} run function ttb:item/staff/extraction/use_right
Expand Down
Loading

0 comments on commit ac7244a

Please sign in to comment.