Skip to content

Commit

Permalink
fix: centralized cable model calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
edayot committed Jul 8, 2024
1 parent 559fe31 commit ff6a9de
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 38 deletions.
4 changes: 3 additions & 1 deletion data/itemio/functions/impl/cable/destroy.mcfunction
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @public

tag @s remove itemio.network
tag @s remove itemio.cable.initialised


execute align xyz positioned ~.5 ~-.5 ~.5 as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] run function itemio:impl/cable/destroy/down
Expand All @@ -26,3 +27,4 @@ execute
function #itemio:event/network_update


execute as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..2] at @s run function itemio:impl/cable/update_model
2 changes: 0 additions & 2 deletions data/itemio/functions/impl/cable/destroy/down.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
scoreboard players remove @s itemio.math 1
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
3 changes: 1 addition & 2 deletions data/itemio/functions/impl/cable/destroy/east.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scoreboard players remove @s itemio.math 16
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
3 changes: 1 addition & 2 deletions data/itemio/functions/impl/cable/destroy/north.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scoreboard players remove @s itemio.math 8
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
3 changes: 1 addition & 2 deletions data/itemio/functions/impl/cable/destroy/south.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scoreboard players remove @s itemio.math 4
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
3 changes: 1 addition & 2 deletions data/itemio/functions/impl/cable/destroy/up.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scoreboard players remove @s itemio.math 2
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
3 changes: 1 addition & 2 deletions data/itemio/functions/impl/cable/destroy/west.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scoreboard players remove @s itemio.math 32
function #itemio:event/cable_update

execute if entity @s[tag=!itemio.network.already_regenerated] run function itemio:impl/cable/destroy/regen
10 changes: 5 additions & 5 deletions data/itemio/functions/impl/cable/init.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ scoreboard players set @s itemio.network_id.high 0


#Update network if for all cables connected
scoreboard players set #model_final itemio.math 0
scoreboard players set #success_connected itemio.math 0

execute align xyz positioned ~.5 ~-.5 ~.5 as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] run function itemio:impl/cable/init/down
Expand Down Expand Up @@ -42,9 +41,10 @@ execute
align xyz positioned ~.5 ~.5 ~.5
as @e[type=#itemio:network,tag=itemio.network,tag=!itemio.cable,distance=..0.5001]
run function itemio:impl/cable/init/gen_network

execute as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..2] at @s run function itemio:impl/cable/update_model


tag @s remove itemio.cable.me

#handeling custom model data
scoreboard players set @s itemio.math 0
scoreboard players operation @s itemio.math = #model_final itemio.math
function #itemio:event/cable_update

3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/down.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 2
scoreboard players add @s itemio.math 1
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/east.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 32
scoreboard players add @s itemio.math 16
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ scoreboard players operation @s itemio.network.process_queue %= #process_queue i


#tellraw @a ["Initial value : ",{"score":{"name":"#model_final","objective":"itemio.math"}}]
function itemio:impl/servo/calc_cable_model
#tellraw @a ["Final value : ",{"score":{"name":"#model_final","objective":"itemio.math"}}]
#tellraw @a ["% : ",{"score":{"name":"#model_final_temp","objective":"itemio.math"}}]

Expand Down
3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/north.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 4
scoreboard players add @s itemio.math 8
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/south.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 8
scoreboard players add @s itemio.math 4
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/up.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 1
scoreboard players add @s itemio.math 2
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
3 changes: 0 additions & 3 deletions data/itemio/functions/impl/cable/init/west.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
scoreboard players add #model_final itemio.math 16
scoreboard players add @s itemio.math 32
function #itemio:event/cable_update

execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 1.. run function itemio:impl/cable/init/regen
execute if score @e[tag=itemio.cable.me,limit=1] itemio.network_id.low matches 0 run function itemio:impl/cable/init/copy
Expand Down
5 changes: 4 additions & 1 deletion data/itemio/functions/impl/servo/destroy.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# @public

execute at @s as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] run function itemio:impl/cable/update_model
tag @s remove itemio.network
tag @s remove itemio.servo.initialised

execute as @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..2] at @s run function itemio:impl/cable/update_model

0 comments on commit ff6a9de

Please sign in to comment.