From 8078e16327ed1ce5e3391a6f4ee6a7404a936f07 Mon Sep 17 00:00:00 2001 From: L_glandieres Date: Sat, 30 Mar 2024 19:39:22 +0100 Subject: [PATCH] prevent placing lobby bases too close to the worldborder and too close to eachother --- .../villager/check_placement.mcfunction | 30 +++++++++++++++++++ .../villager/placed_child.mcfunction | 9 +++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/check_placement.mcfunction diff --git a/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/check_placement.mcfunction b/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/check_placement.mcfunction new file mode 100644 index 00000000..db4eeb7e --- /dev/null +++ b/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/check_placement.mcfunction @@ -0,0 +1,30 @@ + +# Cancel lobby villager placement if too close to worldborder or too close to others bases + + +# Worldborder proximity : +execute store result score @s pos.x run data get entity @s Pos[0] +execute store result score @s pos.z run data get entity @s Pos[2] + +scoreboard players operation WBGap data = WBbyTwo data +scoreboard players operation WBGap data -= 2 const + +scoreboard players operation -WBGap data = -WBbyTwo data +scoreboard players operation -WBGap data += 2 const + +execute if score @s pos.x > WBGap data run tag @s add worldborder_obstruction +execute if score @s pos.x < -WBGap data run tag @s add worldborder_obstruction +execute if score @s pos.z > WBGap data run tag @s add worldborder_obstruction +execute if score @s pos.z < -WBGap data run tag @s add worldborder_obstruction + +execute if entity @s[tag=worldborder_obstruction] run tellraw @a[tag=player_place_base] ["",{"text":"[BS] ","color":"gold"},{"translate":"blazing_scaffolding.base.near_worldborder","color":"red"}] +execute if entity @s[tag=worldborder_obstruction] run kill @s + +# other bases proximity +execute if entity @e[type=villager,tag=respawn_villager, distance=..20] run tag @s add base_obstruction + +execute if entity @s[tag=base_obstruction] run tellraw @a[tag=player_place_base] ["",{"text":"[BS] ","color":"gold"},{"translate":"blazing_scaffolding.base.near_other_bases","color":"red"}] +execute if entity @s[tag=base_obstruction] run kill @s + +#confirmation message +execute if entity @s[tag=!worldborder_obstruction,tag=!base_obstruction] run tellraw @a[tag=player_place_base] ["",{"text":"[BS] ","color":"gold"},{"translate":"blazing_scaffolding.base.placement_set"}] diff --git a/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/placed_child.mcfunction b/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/placed_child.mcfunction index 4b49f996..9e33577c 100644 --- a/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/placed_child.mcfunction +++ b/datapacks/Scaffolding Rush/data/scaffolding_rush/functions/villager/placed_child.mcfunction @@ -1,4 +1,11 @@ -$execute as @e[type=marker,tag=villager.spawner.$(color)] at @s run function scaffolding_rush:villager/summon/$(color) + +$tag @e[type=marker,tag=villager.spawner.$(color)] add processed + +execute if score #lobby.active data matches 1 run tag @s add player_place_base +execute if score #lobby.active data matches 1 as @e[type=marker,tag=processed] at @s run function scaffolding_rush:villager/check_placement +tag @s remove player_place_base + +$execute as @e[type=marker,tag=processed] at @s run function scaffolding_rush:villager/summon/$(color) $execute if score #lobby.active data matches 1 \ as @e[tag=$(color)_villager,tag=respawn_villager] \