From a8abe8db9919d4ad772d6023cbd2bff347bc36e0 Mon Sep 17 00:00:00 2001 From: BJTMastermind Date: Thu, 19 Aug 2021 12:20:27 -0400 Subject: [PATCH] Moved datapack out of extra folder --- .../functions/break/spawn_drop.mcfunction | 45 +++++++++++++++++++ data/custom_blocks/functions/main.mcfunction | 4 ++ .../place/check_for_block.mcfunction | 9 ++++ .../functions/place/place_block.mcfunction | 41 +++++++++++++++++ .../functions/place/reset_storage.mcfunction | 10 +++++ .../functions/place/set_storage.mcfunction | 17 +++++++ data/custom_blocks/functions/setup.mcfunction | 11 +++++ data/custom_blocks/predicates/is_placer.json | 11 +++++ .../predicates/selected_placer.json | 11 +++++ data/custom_blocks/tags/blocks/placers.json | 7 +++ data/custom_blocks/tags/items/placers.json | 7 +++ data/minecraft/tags/functions/load.json | 5 +++ data/minecraft/tags/functions/tick.json | 5 +++ pack.mcmeta | 6 +++ 14 files changed, 189 insertions(+) create mode 100644 data/custom_blocks/functions/break/spawn_drop.mcfunction create mode 100644 data/custom_blocks/functions/main.mcfunction create mode 100644 data/custom_blocks/functions/place/check_for_block.mcfunction create mode 100644 data/custom_blocks/functions/place/place_block.mcfunction create mode 100644 data/custom_blocks/functions/place/reset_storage.mcfunction create mode 100644 data/custom_blocks/functions/place/set_storage.mcfunction create mode 100644 data/custom_blocks/functions/setup.mcfunction create mode 100644 data/custom_blocks/predicates/is_placer.json create mode 100644 data/custom_blocks/predicates/selected_placer.json create mode 100644 data/custom_blocks/tags/blocks/placers.json create mode 100644 data/custom_blocks/tags/items/placers.json create mode 100644 data/minecraft/tags/functions/load.json create mode 100644 data/minecraft/tags/functions/tick.json create mode 100644 pack.mcmeta diff --git a/data/custom_blocks/functions/break/spawn_drop.mcfunction b/data/custom_blocks/functions/break/spawn_drop.mcfunction new file mode 100644 index 0000000..c1cf76a --- /dev/null +++ b/data/custom_blocks/functions/break/spawn_drop.mcfunction @@ -0,0 +1,45 @@ +# Reset Storage +data remove storage custom_blocks:drop_block id +data remove storage custom_blocks:drop_block DisplayName +data remove storage custom_blocks:drop_block Lore +data remove storage custom_blocks:drop_block CustomModelData +data remove storage custom_blocks:drop_block CustomName +data remove storage custom_blocks:drop_block Tags +data remove storage custom_blocks:drop_block SetblockCommand + +# Check If Custom Block Has Been Broken Then Store Block Info In Storage +execute as @e[type=armor_stand,tag=customBlock] at @s if block ~ ~ ~ air run tag @s add spawn_drop +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block id set from entity @s ArmorItems[3].id +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block DisplayName set from entity @s ArmorItems[3].tag.display.Name +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block Lore set from entity @s ArmorItems[3].tag.display.Lore +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block CustomModelData set from entity @s ArmorItems[3].tag.CustomModelData +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block CustomName set from entity @s CustomName +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block Tags set from entity @s ArmorItems[3].tag.BlockProperties.Tags +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,predicate=custom_blocks:is_placer] at @s run data modify storage custom_blocks:drop_block SetblockCommand set from entity @s ArmorItems[3].tag.BlockProperties.SetblockCommand + +# Apply Block Info To Item +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.id set from storage custom_blocks:drop_block id +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.display.Name set from storage custom_blocks:drop_block DisplayName +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.display.Lore set from storage custom_blocks:drop_block Lore +# Set Model If Normal +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=!up,tag=!down] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.CustomModelData set from storage custom_blocks:drop_block CustomModelData +# Set Model To Normal If Up +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=up,tag=!down] at @s store result score +ModelID SetModel run data get storage custom_blocks:drop_block CustomModelData +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=up,tag=!down] at @s run scoreboard players operation +ModelID SetModel -= +Plus1 cbapiConstent +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=up,tag=!down] at @s store result storage custom_blocks:drop_block CustomModelData int 1 run scoreboard players get +ModelID SetModel +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=up,tag=!down] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.CustomModelData set from storage custom_blocks:drop_block CustomModelData +# Set Model To Normal If Down +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=!up,tag=down] at @s store result score +ModelID SetModel run data get storage custom_blocks:drop_block CustomModelData +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=!up,tag=down] at @s run scoreboard players operation +ModelID SetModel -= +Plus2 cbapiConstent +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=!up,tag=down] at @s store result storage custom_blocks:drop_block CustomModelData int 1 run scoreboard players get +ModelID SetModel +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop,tag=!up,tag=down] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.CustomModelData set from storage custom_blocks:drop_block CustomModelData + +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.BlockEntityTag.Lock set value "CustomBlocks:Block" +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.BlockProperties.CustomName set from storage custom_blocks:drop_block CustomName +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.BlockProperties.Tags set from storage custom_blocks:drop_block Tags +execute as @e[type=armor_stand,tag=customBlock,tag=spawn_drop] at @s run data modify entity @e[type=item,distance=..1,sort=nearest,limit=1] Item.tag.BlockProperties.SetblockCommand set from storage custom_blocks:drop_block SetblockCommand + +# Kill Armor Stand +execute as @e[type=armor_stand,tag=customBlock] at @s if block ~ ~ ~ air run kill @s + + diff --git a/data/custom_blocks/functions/main.mcfunction b/data/custom_blocks/functions/main.mcfunction new file mode 100644 index 0000000..aa13708 --- /dev/null +++ b/data/custom_blocks/functions/main.mcfunction @@ -0,0 +1,4 @@ +execute as @a run function custom_blocks:place/set_storage +function custom_blocks:break/spawn_drop + + diff --git a/data/custom_blocks/functions/place/check_for_block.mcfunction b/data/custom_blocks/functions/place/check_for_block.mcfunction new file mode 100644 index 0000000..848a28a --- /dev/null +++ b/data/custom_blocks/functions/place/check_for_block.mcfunction @@ -0,0 +1,9 @@ +# Detects Custom Block And Places It +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=north]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=north]{Lock:"CustomBlocks:Block"} +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=south]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=south]{Lock:"CustomBlocks:Block"} +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=east]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=east]{Lock:"CustomBlocks:Block"} +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=west]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=west]{Lock:"CustomBlocks:Block"} +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=up]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=up]{Lock:"CustomBlocks:Block"} +execute at @a run fill ~5 ~6 ~5 ~-5 ~-4 ~-5 command_block[facing=down]{auto:1b,Command:"function custom_blocks:place/place_block"} replace #custom_blocks:placers[facing=down]{Lock:"CustomBlocks:Block"} + + diff --git a/data/custom_blocks/functions/place/place_block.mcfunction b/data/custom_blocks/functions/place/place_block.mcfunction new file mode 100644 index 0000000..84c5d28 --- /dev/null +++ b/data/custom_blocks/functions/place/place_block.mcfunction @@ -0,0 +1,41 @@ +# Places The Base Block Armor Stand +execute if block ~ ~ ~ command_block[facing=north] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[0.0f,0.0f],Tags:["customBlock","placing"]} +execute if block ~ ~ ~ command_block[facing=south] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[180.0f,0.0f],Tags:["customBlock","placing"]} +execute if block ~ ~ ~ command_block[facing=east] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[90.0f,0.0f],Tags:["customBlock","placing"]} +execute if block ~ ~ ~ command_block[facing=west] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[-90.0f,0.0f],Tags:["customBlock","placing"]} +execute if block ~ ~ ~ command_block[facing=up] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[0.0f,0.0f],Tags:["customBlock","placing","up"]} +execute if block ~ ~ ~ command_block[facing=down] align xyz positioned ~0.5 ~ ~0.5 run summon armor_stand ~ ~ ~ {Invisible:1b,NoGravity:1b,Marker:1b,ArmorItems:[{},{},{},{id:"minecraft:stone",Count:1b}],Rotation:[0.0f,0.0f],Tags:["customBlock","placing","down"]} + +# Updates The Base Block To Include All The Block Info From Storage +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].id set from storage custom_blocks:current_block id +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.display.Name set from storage custom_blocks:current_block DisplayName +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.display.Lore set from storage custom_blocks:current_block Lore +# Set Model If Normal +execute as @e[type=armor_stand,tag=placing,tag=!up,tag=!down] at @s run data modify entity @s ArmorItems[3].tag.CustomModelData set from storage custom_blocks:current_block CustomModelData +# Set Model If Facing Up +execute as @e[type=armor_stand,tag=placing,tag=up,tag=!down] at @s store result score +ModelID SetModel run data get storage custom_blocks:current_block CustomModelData +execute as @e[type=armor_stand,tag=placing,tag=up,tag=!down] at @s run scoreboard players operation +ModelID SetModel += +Plus1 cbapiConstent +execute as @e[type=armor_stand,tag=placing,tag=up,tag=!down] at @s store result storage custom_blocks:current_block CustomModelData int 1 run scoreboard players get +ModelID SetModel +execute as @e[type=armor_stand,tag=placing,tag=up,tag=!down] at @s run data modify entity @s ArmorItems[3].tag.CustomModelData set from storage custom_blocks:current_block CustomModelData +# Set Model If Facing Down +execute as @e[type=armor_stand,tag=placing,tag=!up,tag=down] at @s store result score +ModelID SetModel run data get storage custom_blocks:current_block CustomModelData +execute as @e[type=armor_stand,tag=placing,tag=!up,tag=down] at @s run scoreboard players operation +ModelID SetModel += +Plus2 cbapiConstent +execute as @e[type=armor_stand,tag=placing,tag=!up,tag=down] at @s store result storage custom_blocks:current_block CustomModelData int 1 run scoreboard players get +ModelID SetModel +execute as @e[type=armor_stand,tag=placing,tag=!up,tag=down] at @s run data modify entity @s ArmorItems[3].tag.CustomModelData set from storage custom_blocks:current_block CustomModelData + +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.BlockEntityTag.Lock set value "CustomBlocks:Block" +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.BlockProperties.CustomName set from storage custom_blocks:current_block CustomName +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.BlockProperties.Tags set from storage custom_blocks:current_block Tags +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s CustomName set from storage custom_blocks:current_block CustomName +execute as @e[type=armor_stand,tag=placing] at @s run data modify entity @s ArmorItems[3].tag.BlockProperties.SetblockCommand set from storage custom_blocks:current_block SetblockCommand + +# Remove Temporary Tag And Set Base Block +setblock ~ ~ ~ stone +setblock ~ ~ ~ command_block{Command:""} +execute as @e[type=armor_stand,tag=placing] at @s run data modify block ~ ~ ~ Command set from storage custom_blocks:current_block SetblockCommand +execute as @e[type=armor_stand,tag=placing] at @s run data merge block ~ ~ ~ {auto:1b} +execute as @e[type=armor_stand,tag=placing] at @s run tag @e[type=armor_stand,tag=placing] remove placing + +# Resets Storage After Player Places Custom Block Or Deselects It +execute as @a[gamemode=!creative,predicate=custom_blocks:selected_placer] run function custom_blocks:place/reset_storage + diff --git a/data/custom_blocks/functions/place/reset_storage.mcfunction b/data/custom_blocks/functions/place/reset_storage.mcfunction new file mode 100644 index 0000000..fadbf0b --- /dev/null +++ b/data/custom_blocks/functions/place/reset_storage.mcfunction @@ -0,0 +1,10 @@ +# Resets Block Info Storage +data remove storage custom_blocks:current_block id +data remove storage custom_blocks:current_block DisplayName +data remove storage custom_blocks:current_block Lore +data remove storage custom_blocks:current_block CustomModelData +data remove storage custom_blocks:current_block CustomName +data remove storage custom_blocks:current_block Tags +data remove storage custom_blocks:current_block SetblockCommand +scoreboard players set +ModelID SetModel 0 + diff --git a/data/custom_blocks/functions/place/set_storage.mcfunction b/data/custom_blocks/functions/place/set_storage.mcfunction new file mode 100644 index 0000000..6f1048f --- /dev/null +++ b/data/custom_blocks/functions/place/set_storage.mcfunction @@ -0,0 +1,17 @@ +# Resets Storage After Player Places Custom Block Or Deselects It +execute as @a[gamemode=creative,predicate=custom_blocks:selected_placer] run function custom_blocks:place/reset_storage + +# Saves All Block Info Into A Storage For When Placing +data modify storage custom_blocks:current_block CustomModelData set from entity @s SelectedItem.tag.CustomModelData +execute if entity @s[predicate=custom_blocks:selected_placer] run data modify storage custom_blocks:current_block id set from entity @s SelectedItem.id +data modify storage custom_blocks:current_block DisplayName set from entity @s SelectedItem.tag.display.Name +data modify storage custom_blocks:current_block Lore set from entity @s SelectedItem.tag.display.Lore +data modify storage custom_blocks:current_block CustomName set from entity @s SelectedItem.tag.BlockProperties.CustomName +data modify storage custom_blocks:current_block Tags set from entity @s SelectedItem.tag.BlockProperties.Tags +data modify storage custom_blocks:current_block SetblockCommand set from entity @s SelectedItem.tag.BlockProperties.SetblockCommand + + +# Runs The Check Block Function +function custom_blocks:place/check_for_block + + diff --git a/data/custom_blocks/functions/setup.mcfunction b/data/custom_blocks/functions/setup.mcfunction new file mode 100644 index 0000000..db9eb6d --- /dev/null +++ b/data/custom_blocks/functions/setup.mcfunction @@ -0,0 +1,11 @@ +gamerule commandBlockOutput false +gamerule logAdminCommands false + +scoreboard objectives add SetModel dummy +scoreboard objectives add cbapiConstent dummy + +scoreboard players set +ModelID SetModel 0 +scoreboard players set +Plus1 cbapiConstent 1 +scoreboard players set +Plus2 cbapiConstent 2 + + diff --git a/data/custom_blocks/predicates/is_placer.json b/data/custom_blocks/predicates/is_placer.json new file mode 100644 index 0000000..303a659 --- /dev/null +++ b/data/custom_blocks/predicates/is_placer.json @@ -0,0 +1,11 @@ +{ + "condition": "entity_properties", + "entity": "this", + "predicate": { + "equipment": { + "head": { + "tag": "custom_blocks:placers" + } + } + } +} \ No newline at end of file diff --git a/data/custom_blocks/predicates/selected_placer.json b/data/custom_blocks/predicates/selected_placer.json new file mode 100644 index 0000000..2cd6505 --- /dev/null +++ b/data/custom_blocks/predicates/selected_placer.json @@ -0,0 +1,11 @@ +{ + "condition": "entity_properties", + "entity": "this", + "predicate": { + "equipment": { + "mainhand": { + "tag": "custom_blocks:placers" + } + } + } +} \ No newline at end of file diff --git a/data/custom_blocks/tags/blocks/placers.json b/data/custom_blocks/tags/blocks/placers.json new file mode 100644 index 0000000..ed1cb6c --- /dev/null +++ b/data/custom_blocks/tags/blocks/placers.json @@ -0,0 +1,7 @@ +{ + "values": [ + "minecraft:furnace", + "minecraft:dropper", + "minecraft:dispenser" + ] +} \ No newline at end of file diff --git a/data/custom_blocks/tags/items/placers.json b/data/custom_blocks/tags/items/placers.json new file mode 100644 index 0000000..ed1cb6c --- /dev/null +++ b/data/custom_blocks/tags/items/placers.json @@ -0,0 +1,7 @@ +{ + "values": [ + "minecraft:furnace", + "minecraft:dropper", + "minecraft:dispenser" + ] +} \ No newline at end of file diff --git a/data/minecraft/tags/functions/load.json b/data/minecraft/tags/functions/load.json new file mode 100644 index 0000000..7e80a69 --- /dev/null +++ b/data/minecraft/tags/functions/load.json @@ -0,0 +1,5 @@ +{ + "values": [ + "custom_blocks:setup" + ] +} \ No newline at end of file diff --git a/data/minecraft/tags/functions/tick.json b/data/minecraft/tags/functions/tick.json new file mode 100644 index 0000000..c02584b --- /dev/null +++ b/data/minecraft/tags/functions/tick.json @@ -0,0 +1,5 @@ +{ + "values": [ + "custom_blocks:main" + ] +} \ No newline at end of file diff --git a/pack.mcmeta b/pack.mcmeta new file mode 100644 index 0000000..171d1c6 --- /dev/null +++ b/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 6, + "description": "Allows you to add new blocks easily" + } +}