Skip to content

Commit

Permalink
Added "FrameModel" tag to fix issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
BJTMastermind authored Oct 26, 2021
1 parent d65344a commit f91f992
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/custom_blocks/functions/break/spawn_drop.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Original file line number Diff line number Diff line change
@@ -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


Original file line number Diff line number Diff line change
@@ -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


Original file line number Diff line number Diff line change
@@ -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


3 changes: 3 additions & 0 deletions data/custom_blocks/functions/main.mcfunction
Original file line number Diff line number Diff line change
@@ -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


3 changes: 2 additions & 1 deletion data/custom_blocks/functions/setup.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gamerule commandBlockOutput false
gamerule logAdminCommands false


scoreboard objectives add cbCompareResult dummy
scoreboard players set #match cbCompareResult 1
7 changes: 7 additions & 0 deletions data/custom_blocks/predicates/frame_item_player_placed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"condition": "entity_properties",
"entity": "this",
"predicate": {
"nbt": "{Item:{tag:{BlockEntityTag:{Lock:\"CustomBlocks:Block\"}}}}"
}
}
6 changes: 6 additions & 0 deletions data/custom_blocks/tags/entity_types/item_frames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"minecraft:item_frame",
"minecraft:glow_item_frame"
]
}

0 comments on commit f91f992

Please sign in to comment.