Skip to content

Commit

Permalink
♻️ Update painter example for the 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiome committed Jun 13, 2024
1 parent 9628bbb commit 905d3af
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"criteria": {
"requirement": {
"trigger": "minecraft:using_item",
"conditions": {
"item": {
"items": "minecraft:brush",
"predicates": {
"minecraft:custom_data": "{\"bs.example.painter:brush\":true}"
}
}
}
}
},
"rewards": {
"function": "bs.example.painter:use_brush"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# We use both an advancement and an objective for educational purposes and to handle potential limitations:
# - Advancements allow continuous usage but may fail with certain blocks like signs.
# - Scores work universally but cannot be used continuously.

# Run the use_brush function if the brush is used.
execute as @a[scores={bs.example.painter.use_brush=1..}] run function bs.example.painter:use_brush
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Determines the mapping set used for block conversion based on the player's active advancement.
execute if entity @s[advancements={bs.example.painter:use_brush={color=true}}] run data modify storage bs:example painter set value { mapping_set: "bs.colors" }
execute if entity @s[advancements={bs.example.painter:use_brush={magic=true}}] run data modify storage bs:example painter set value { mapping_set: "bs.shapes" }
execute if items entity @s weapon minecraft:brush[minecraft:custom_data~{"bs.example.painter:brush_type":"color"}] run data modify storage bs:example painter set value { mapping_registry: "bs.colors" }
execute if items entity @s weapon minecraft:brush[minecraft:custom_data~{"bs.example.painter:brush_type":"magic"}] run data modify storage bs:example painter set value { mapping_registry: "bs.shapes" }

# Gets the ID of the item in the player's offhand, assuming it matches a block ID. If no ID is found, return early.
execute store success score #success bs.data run data modify storage bs:example painter.type set from entity @s Inventory[{Slot:-106b}].id
Expand All @@ -9,9 +9,10 @@ execute if score #success bs.data matches 0 run return fail
# Gets all data related to the block at the current location, including its state and NBTs.
function #bs.block:get_block

# Replaces the block type with the mapped type from the mapping_set. For example, if the mapping_set is "color",
# Replaces the block type with the mapped type from the mapping_registry. For example, if the mapping_registry is "color",
# the item is "orange_wool", and the block in the world is "white_carpet", the resulting block will be "orange_carpet".
function #bs.block:replace_mapped_type with storage bs:example painter
execute if data storage bs:example painter{mapping_registry:"bs.colors"} run function #bs.block:map_type with storage bs:example painter
execute if data storage bs:example painter{mapping_registry:"bs.shapes"} run function #bs.block:mix_type with storage bs:example painter

# Sets the newly replaced block into the world at the current location.
data modify storage bs:in block.set_block set from storage bs:out block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ clear @s

# Replaces the first hotbar slot with the color brush item.
item replace entity @s hotbar.0 with minecraft:brush[ \
minecraft:custom_data={ "bs.example:color_brush": true }, \
minecraft:custom_data={ "bs.example.painter:brush": true, "bs.example.painter:brush_type": "color" }, \
minecraft:item_name='["",{"text":"PAINT BRUSH","color":"gold","bold":true,"italic":true},{"text":" - Right click to use","color":"gray"}]', \
minecraft:lore=['{"text":"A brushstroke of imagination.","color":"dark_gray","italic":false}','""','{"text":"Imbue the aimed block with the color","color":"gray","italic":false}','{"text":"of the block held in your offhand.","color":"gray","italic":false}'], \
]

# Replaces the second hotbar slot with the magic brush item.
item replace entity @s hotbar.1 with minecraft:brush[ \
minecraft:custom_data={ "bs.example:magic_brush": true }, \
minecraft:custom_data={ "bs.example.painter:brush": true, "bs.example.painter:brush_type": "magic" }, \
minecraft:item_name='["",{"text":"MAGIC BRUSH","color":"light_purple","bold":true,"italic":true},{"text":" - Right click to use","color":"gray"}]', \
minecraft:lore=['{"text":"A brushstroke of creation.","color":"dark_gray","italic":false}','""','{"text":"Imbue the aimed block with the properties","color":"gray","italic":false}','{"text":"of the block held in your offhand.","color":"gray","italic":false}'], \
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Executes a function to replace the block the player is aiming at, within a maximum distance of 5 blocks.
function #bs.view:at_aimed_block { run: "function bs.example.painter:replace_block", with: { max_distance: 5 }}

# Revokes the brush use advancement. This must be done after everything else to keep track of which brush was used.
# Resets the brush use score and revokes the advancement.
scoreboard players reset @s bs.example.painter.use_brush
advancement revoke @s only bs.example.painter:use_brush

This file was deleted.

0 comments on commit 905d3af

Please sign in to comment.