From 559fe31552a04123ff1afcd805e8ad27a21f19bd Mon Sep 17 00:00:00 2001 From: edayot Date: Sat, 6 Jul 2024 23:48:58 +0200 Subject: [PATCH] feat: cables now connect to servos #26 --- .../functions/impl/cable/init.mcfunction | 9 ++-- .../impl/cable/init/gen_network.mcfunction | 7 +++ .../impl/cable/update_model.mcfunction | 43 ++++++++++++++++ data/itemio/functions/impl/load.mcfunction | 11 ++++ .../impl/servo/calc_cable_model.mcfunction | 37 ++++++++++++++ .../functions/impl/servo/destroy.mcfunction | 3 ++ .../functions/impl/servo/init.mcfunction | 51 ++++++++++++++----- .../tags/functions/calls/servos/destroy.json | 5 ++ 8 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 data/itemio/functions/impl/cable/update_model.mcfunction create mode 100644 data/itemio/functions/impl/servo/calc_cable_model.mcfunction create mode 100644 data/itemio/functions/impl/servo/destroy.mcfunction create mode 100644 data/itemio/tags/functions/calls/servos/destroy.json diff --git a/data/itemio/functions/impl/cable/init.mcfunction b/data/itemio/functions/impl/cable/init.mcfunction index 060e3311..2dc7d6cb 100644 --- a/data/itemio/functions/impl/cable/init.mcfunction +++ b/data/itemio/functions/impl/cable/init.mcfunction @@ -26,10 +26,7 @@ execute align xyz positioned ~1.5 ~.5 ~.5 as @e[type=#itemio:cables,tag=itemio.c execute if score #success_connected itemio.math matches 0 run function itemio:impl/cable/init/gen_new_id -#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 + #Update others network parts like servo @@ -47,3 +44,7 @@ execute run function itemio:impl/cable/init/gen_network 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 diff --git a/data/itemio/functions/impl/cable/init/gen_network.mcfunction b/data/itemio/functions/impl/cable/init/gen_network.mcfunction index 35d7c3a2..7b8ec28b 100644 --- a/data/itemio/functions/impl/cable/init/gen_network.mcfunction +++ b/data/itemio/functions/impl/cable/init/gen_network.mcfunction @@ -4,5 +4,12 @@ scoreboard players operation @s itemio.network_id.high = #temp_high itemio.math scoreboard players operation @s itemio.network.process_queue = #temp_low itemio.math scoreboard players operation @s itemio.network.process_queue %= #process_queue itemio.math + +#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"}}] + + scoreboard players set @s itemio.math 1 function #itemio:event/network_update diff --git a/data/itemio/functions/impl/cable/update_model.mcfunction b/data/itemio/functions/impl/cable/update_model.mcfunction new file mode 100644 index 00000000..900a8e4c --- /dev/null +++ b/data/itemio/functions/impl/cable/update_model.mcfunction @@ -0,0 +1,43 @@ + + +scoreboard players set #model_final itemio.math 0 + +execute + align xyz positioned ~.5 ~-.5 ~.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 2 +execute + align xyz positioned ~.5 ~1.5 ~.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 1 + +execute + align xyz positioned ~.5 ~.5 ~-.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 4 +execute + align xyz positioned ~.5 ~.5 ~1.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 8 + +execute + align xyz positioned ~-.5 ~.5 ~.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 16 +execute + align xyz positioned ~1.5 ~.5 ~.5 + if entity @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] + run scoreboard players add #model_final itemio.math 32 + + +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/servo/calc_cable_model + + + +#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 diff --git a/data/itemio/functions/impl/load.mcfunction b/data/itemio/functions/impl/load.mcfunction index a093284f..c9a0f883 100644 --- a/data/itemio/functions/impl/load.mcfunction +++ b/data/itemio/functions/impl/load.mcfunction @@ -9,6 +9,17 @@ gamerule maxCommandChainLength 2147483647 scoreboard objectives add itemio.math dummy +scoreboard players set #0 itemio.math 0 +scoreboard players set #1 itemio.math 1 +scoreboard players set #2 itemio.math 2 +scoreboard players set #4 itemio.math 4 +scoreboard players set #8 itemio.math 8 +scoreboard players set #16 itemio.math 16 +scoreboard players set #32 itemio.math 32 +scoreboard players set #64 itemio.math 64 +scoreboard players set #128 itemio.math 128 +scoreboard players set #256 itemio.math 256 + scoreboard objectives add itemio.io dummy scoreboard objectives add itemio.math.input dummy scoreboard objectives add itemio.math.output dummy diff --git a/data/itemio/functions/impl/servo/calc_cable_model.mcfunction b/data/itemio/functions/impl/servo/calc_cable_model.mcfunction new file mode 100644 index 00000000..5670356f --- /dev/null +++ b/data/itemio/functions/impl/servo/calc_cable_model.mcfunction @@ -0,0 +1,37 @@ +scoreboard players operation #model_final_temp itemio.math = #model_final itemio.math +execute + if data entity @s {Facing:0b} + run function ~/down: + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 1 +execute + if data entity @s {Facing:1b} + run function ~/up: + scoreboard players operation #model_final_temp itemio.math /= #2 itemio.math + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 2 +execute + if data entity @s {Facing:2b} + run function ~/north: + scoreboard players operation #model_final_temp itemio.math /= #8 itemio.math + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 8 +execute + if data entity @s {Facing:3b} + run function ~/south: + scoreboard players operation #model_final_temp itemio.math /= #4 itemio.math + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 4 + +execute + if data entity @s {Facing:4b} + run function ~/west: + scoreboard players operation #model_final_temp itemio.math /= #32 itemio.math + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 32 +execute + if data entity @s {Facing:5b} + run function ~/east: + scoreboard players operation #model_final_temp itemio.math /= #16 itemio.math + scoreboard players operation #model_final_temp itemio.math %= #2 itemio.math + execute if score #model_final_temp itemio.math matches 0 run scoreboard players add #model_final itemio.math 16 \ No newline at end of file diff --git a/data/itemio/functions/impl/servo/destroy.mcfunction b/data/itemio/functions/impl/servo/destroy.mcfunction new file mode 100644 index 00000000..2ebf6b44 --- /dev/null +++ b/data/itemio/functions/impl/servo/destroy.mcfunction @@ -0,0 +1,3 @@ +# @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 \ No newline at end of file diff --git a/data/itemio/functions/impl/servo/init.mcfunction b/data/itemio/functions/impl/servo/init.mcfunction index 3c8e471c..857b3a72 100644 --- a/data/itemio/functions/impl/servo/init.mcfunction +++ b/data/itemio/functions/impl/servo/init.mcfunction @@ -3,23 +3,50 @@ tag @s add itemio.network tag @s add itemio.servo.initialised scoreboard players set @s itemio.network_id.low 0 scoreboard players set @s itemio.network_id.high 0 -execute align xyz positioned ~.5 ~.5 ~.5 run tag @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] add itemio.cable.me -scoreboard players operation @s itemio.network_id.low = @e[tag=itemio.cable.me,limit=1] itemio.network_id.low -scoreboard players operation @s itemio.network_id.high = @e[tag=itemio.cable.me,limit=1] itemio.network_id.high - -scoreboard players operation @s itemio.network.process_queue = @s itemio.network_id.low -scoreboard players operation @s itemio.network.process_queue %= #process_queue itemio.math - -execute unless entity @e[tag=itemio.cable.me,limit=1] run scoreboard players set @s itemio.network.process_queue -1 +# initial value for scores +scoreboard players set @s itemio.math 0 scoreboard players set @s itemio.servo.cooldown 0 scoreboard players add @s itemio.servo.stack_limit 0 scoreboard players add @s itemio.servo.retry_limit 0 -execute if score @s itemio.servo.stack_limit matches ..0 run scoreboard players set @s itemio.servo.stack_limit 1 -execute if score @s itemio.servo.retry_limit matches ..0 run scoreboard players set @s itemio.servo.retry_limit 1 +execute unless score @s itemio.servo.stack_limit matches 0.. run scoreboard players set @s itemio.servo.stack_limit 1 +execute unless score @s itemio.servo.retry_limit matches 0.. run scoreboard players set @s itemio.servo.retry_limit 1 + +# copy network id to process queue +execute align xyz positioned ~.5 ~.5 ~.5 run tag @e[type=#itemio:cables,tag=itemio.cable.initialised,distance=..0.5001,limit=1,sort=nearest] add itemio.cable.me + +scoreboard players set #if_entity_exist itemio.math 0 +execute + if entity @e[tag=itemio.cable.me,limit=1] + run function ~/if_cable: + scoreboard players set @s itemio.math 1 + scoreboard players set #if_entity_exist itemio.math 1 + scoreboard players operation @s itemio.network_id.low = @e[tag=itemio.cable.me,limit=1] itemio.network_id.low + scoreboard players operation @s itemio.network_id.high = @e[tag=itemio.cable.me,limit=1] itemio.network_id.high + + scoreboard players operation @s itemio.network.process_queue = @s itemio.network_id.low + scoreboard players operation @s itemio.network.process_queue %= #process_queue itemio.math + + scoreboard players operation #model_final itemio.math = @e[tag=itemio.cable.me,limit=1] itemio.math + function itemio:impl/servo/calc_cable_model + execute + as @e[tag=itemio.cable.me,limit=1] + run function ./reload_model: + scoreboard players operation @s itemio.math = #model_final itemio.math + function #itemio:event/cable_update + + +# if not exist any cable then set process queue to -1 +execute + if score #if_entity_exist itemio.math matches 0 + run function ~/unless_cable: + scoreboard players set @s itemio.network.process_queue -1 + + + + + -scoreboard players set @s itemio.math 0 -execute unless score @s itemio.network_id.low matches 0 run scoreboard players set @s itemio.math 1 function #itemio:event/network_update tag @e[tag=itemio.cable.me] remove itemio.cable.me diff --git a/data/itemio/tags/functions/calls/servos/destroy.json b/data/itemio/tags/functions/calls/servos/destroy.json new file mode 100644 index 00000000..3a9e41a8 --- /dev/null +++ b/data/itemio/tags/functions/calls/servos/destroy.json @@ -0,0 +1,5 @@ +{ + "values": [ + "itemio:impl/calls/servo/destroy" + ] +}