Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add new painter example #198

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Adds a scoreboard objective to track when a player uses a brush item
scoreboard objectives add bs.example.painter.use_brush minecraft.used:minecraft.brush
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
@@ -0,0 +1,2 @@
# Removes the scoreboard objective when the datapack is unloaded
scoreboard objectives remove bs.example.painter.use_brush
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Determines the mapping set used for block conversion based on the player's active advancement.
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
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_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".
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
function #bs.block:set_block
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Clears the player's inventory.
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.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.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}'], \
]

# Replaces additional hotbar slots with various blocks to use in the offhand.
item replace entity @s hotbar.5 with minecraft:birch_planks
item replace entity @s hotbar.6 with minecraft:spruce_planks
item replace entity @s hotbar.7 with minecraft:cyan_wool
item replace entity @s hotbar.8 with minecraft:orange_wool
Original file line number Diff line number Diff line change
@@ -0,0 +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 }}

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"bs.example.painter:__load__"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"bs.example.painter:replace_items"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"bs.example.painter:__tick__"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"bs.example.painter:__unload__"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
{
"id": "#bs.example.painter:load",
"required": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
{
"id": "#bs.example.painter:tick",
"required": false
}
]
}
Loading