From f91f992775d3e276c26c6a344435113ad10bf53b Mon Sep 17 00:00:00 2001 From: BJTMastermind Date: Mon, 25 Oct 2021 22:14:06 -0400 Subject: [PATCH] Added "FrameModel" tag to fix issue #2 --- .../functions/break/spawn_drop.mcfunction | 1 + .../check_add_item_from_frame.mcfunction | 4 ++++ .../check_removed_item_from_frame.mcfunction | 15 +++++++++++++++ .../item_frame/update_item_in_frame.mcfunction | 10 ++++++++++ .../item_frame/update_item_out_frame.mcfunction | 9 +++++++++ data/custom_blocks/functions/main.mcfunction | 3 +++ data/custom_blocks/functions/setup.mcfunction | 3 ++- .../predicates/frame_item_player_placed.json | 7 +++++++ .../tags/entity_types/item_frames.json | 6 ++++++ 9 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 data/custom_blocks/functions/item_frame/check_add_item_from_frame.mcfunction create mode 100644 data/custom_blocks/functions/item_frame/check_removed_item_from_frame.mcfunction create mode 100644 data/custom_blocks/functions/item_frame/update_item_in_frame.mcfunction create mode 100644 data/custom_blocks/functions/item_frame/update_item_out_frame.mcfunction create mode 100644 data/custom_blocks/predicates/frame_item_player_placed.json create mode 100644 data/custom_blocks/tags/entity_types/item_frames.json diff --git a/data/custom_blocks/functions/break/spawn_drop.mcfunction b/data/custom_blocks/functions/break/spawn_drop.mcfunction index 10db3de..4b7c458 100644 --- a/data/custom_blocks/functions/break/spawn_drop.mcfunction +++ b/data/custom_blocks/functions/break/spawn_drop.mcfunction @@ -4,6 +4,7 @@ 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 CustomModelDataVertical +data remove storage custom_blocks:drop_block FrameModel data remove storage custom_blocks:drop_block CustomName data remove storage custom_blocks:drop_block Tags data remove storage custom_blocks:drop_block SetblockCommand diff --git a/data/custom_blocks/functions/item_frame/check_add_item_from_frame.mcfunction b/data/custom_blocks/functions/item_frame/check_add_item_from_frame.mcfunction new file mode 100644 index 0000000..eb46c22 --- /dev/null +++ b/data/custom_blocks/functions/item_frame/check_add_item_from_frame.mcfunction @@ -0,0 +1,4 @@ +# Checks if the item frame has a custom block placed by the player in it then updates the item +execute as @e[type=#custom_blocks:item_frames,tag=!updated,predicate=custom_blocks:frame_item_player_placed] run function custom_blocks:item_frame/update_item_in_frame + + diff --git a/data/custom_blocks/functions/item_frame/check_removed_item_from_frame.mcfunction b/data/custom_blocks/functions/item_frame/check_removed_item_from_frame.mcfunction new file mode 100644 index 0000000..556d04a --- /dev/null +++ b/data/custom_blocks/functions/item_frame/check_removed_item_from_frame.mcfunction @@ -0,0 +1,15 @@ +# Resets compare storage +data remove storage custom_blocks:nbt_compare + +# Get nbt tags to compare and save result to #match in cbCompareResult +execute at @e[type=#custom_blocks:item_frames,tag=updated,predicate=!custom_blocks:frame_item_player_placed] as @e[type=item,predicate=custom_blocks:is_placer,distance=..3,limit=1] run data modify storage custom_blocks:nbt_compare nbt set from entity @s Item.tag.CustomModelData +execute store success score #match cbCompareResult at @e[type=#custom_blocks:item_frames,tag=updated,predicate=!custom_blocks:frame_item_player_placed] as @e[type=item,predicate=custom_blocks:is_placer,distance=..3,limit=1] run data modify storage custom_blocks:nbt_compare nbt set from entity @s Item.tag.BlockProperties.FrameModel + +# Update item back to its default state +execute if score #match cbCompareResult matches 0 at @e[type=#custom_blocks:item_frames,tag=updated,predicate=!custom_blocks:frame_item_player_placed] as @e[type=item,predicate=custom_blocks:is_placer,distance=..3,limit=1] run function custom_blocks:item_frame/update_item_out_frame + +# Reset cbCompareResult and remove tag from item frame +scoreboard players set #match cbCompareResult 1 +execute as @e[type=#custom_blocks:item_frames,tag=updated,predicate=!custom_blocks:frame_item_player_placed] run tag @s remove updated + + diff --git a/data/custom_blocks/functions/item_frame/update_item_in_frame.mcfunction b/data/custom_blocks/functions/item_frame/update_item_in_frame.mcfunction new file mode 100644 index 0000000..c0b3372 --- /dev/null +++ b/data/custom_blocks/functions/item_frame/update_item_in_frame.mcfunction @@ -0,0 +1,10 @@ +# Called from item_frame_check.mcfunction + +# Updates item display for item frame and adds a tag to prevent loop +data modify entity @s Item.tag.CustomModelDataNorm set from entity @s Item.tag.CustomModelData +data modify entity @s Item.tag.CustomModelData set from entity @s Item.tag.BlockProperties.FrameModel +data modify entity @s Item.tag.displayName set from entity @s Item.tag.display.Name +data modify entity @s Item.tag.display.Name set value "" +tag @s add updated + + diff --git a/data/custom_blocks/functions/item_frame/update_item_out_frame.mcfunction b/data/custom_blocks/functions/item_frame/update_item_out_frame.mcfunction new file mode 100644 index 0000000..d9792b4 --- /dev/null +++ b/data/custom_blocks/functions/item_frame/update_item_out_frame.mcfunction @@ -0,0 +1,9 @@ +# Called from check_removed_item_from_frame.mcfunction + +# Update item back to its default state +data modify entity @s Item.tag.CustomModelData set from entity @s Item.tag.CustomModelDataNorm +data modify entity @s Item.tag.display.Name set from entity @s Item.tag.displayName +data remove entity @s Item.tag.CustomModelDataNorm +data remove entity @s Item.tag.displayName + + diff --git a/data/custom_blocks/functions/main.mcfunction b/data/custom_blocks/functions/main.mcfunction index aa13708..0736c4a 100644 --- a/data/custom_blocks/functions/main.mcfunction +++ b/data/custom_blocks/functions/main.mcfunction @@ -1,4 +1,7 @@ execute as @a run function custom_blocks:place/set_storage function custom_blocks:break/spawn_drop +function custom_blocks:item_frame/check_add_item_from_frame +function custom_blocks:item_frame/check_removed_item_from_frame + diff --git a/data/custom_blocks/functions/setup.mcfunction b/data/custom_blocks/functions/setup.mcfunction index 33c654b..dba7926 100644 --- a/data/custom_blocks/functions/setup.mcfunction +++ b/data/custom_blocks/functions/setup.mcfunction @@ -1,4 +1,5 @@ gamerule commandBlockOutput false gamerule logAdminCommands false - +scoreboard objectives add cbCompareResult dummy +scoreboard players set #match cbCompareResult 1 diff --git a/data/custom_blocks/predicates/frame_item_player_placed.json b/data/custom_blocks/predicates/frame_item_player_placed.json new file mode 100644 index 0000000..3de7830 --- /dev/null +++ b/data/custom_blocks/predicates/frame_item_player_placed.json @@ -0,0 +1,7 @@ +{ + "condition": "entity_properties", + "entity": "this", + "predicate": { + "nbt": "{Item:{tag:{BlockEntityTag:{Lock:\"CustomBlocks:Block\"}}}}" + } +} diff --git a/data/custom_blocks/tags/entity_types/item_frames.json b/data/custom_blocks/tags/entity_types/item_frames.json new file mode 100644 index 0000000..0b7bd58 --- /dev/null +++ b/data/custom_blocks/tags/entity_types/item_frames.json @@ -0,0 +1,6 @@ +{ + "values": [ + "minecraft:item_frame", + "minecraft:glow_item_frame" + ] +}