Skip to content

Commit

Permalink
Update custom roleplay data
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanmanning committed Jul 30, 2024
1 parent 9b43504 commit 7dee988
Show file tree
Hide file tree
Showing 34 changed files with 360 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"display": {
"icon": {
"id": "minecraft:book"
},
"title": "Custom Roleplay Data",
"frame": "challenge",
"description": ["",{"text":"Adds the ability to change the CustomModelData of items in order to change item textures via resource packs. ","color":"gold"},{"text":"Datapack by: ","color":"green"},{"text":"MukiTanuki\n","color":"aqua"},{"text":"Enter","color":"green"},{"text":" ","color":"gold"},{"text":"/trigger CustomModelData set #","color":"yellow"},{"text":" to set model data.\n","color":"gold"},{"text":"Enter","color":"green"},{"text":" ","color":"gold"},{"text":"/function custom_roleplay_data:admin","color":"yellow"},{"text":" and use auto-complete to set config options.","color":"gold"}],
"background": "minecraft:textures/block/black_concrete.png",
"show_toast": false,
"announce_to_chat": false
},
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
},
"rewards": {
"functions": "custom_roleplay_data:enable"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Description: Function that repeats every second
# Called by: custom_roleplay_data:init
# Entity @s: none
#
# reschedules
schedule function custom_roleplay_data:second 1s
#
# trigger detection
#
execute as @a[scores={CustomModelData=0..}] if items entity @s weapon.mainhand * run function custom_roleplay_data:trigger
# resets trigger
execute as @a run function custom_roleplay_data:enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Description: Sets the data for item in-hand
# Called by: custom_roleplay_data:trigger
# Entity @s: none
#
# Sets CustomModelData to item
item modify entity @s weapon.mainhand custom_roleplay_data:copy_data
title @s actionbar \
[\
{\
"text": "Set CustomModelData to ", "color": "green"\
}, \
{\
"score": {\
"name": "@s",\
"objective": "CustomModelData"\
},\
"color": "aqua"\
}\
]
# removes required xp
function custom_roleplay_data:subtract_levels with storage custom_roleplay_data:config {}
# plays sound
execute at @s run playsound minecraft:block.anvil.use player @s ~ ~ ~ 0.4 0.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Description: trigger to set CustomModelData
# Called by: custom_roleplay_data:second
# Entity @s: none
#
# Sets a tag marker for items so they don't overwrite existing CustomModelData
execute if items entity @s weapon.mainhand *\
[\
!minecraft:custom_model_data,\
!minecraft:custom_data~{CustomRoleplayData:1b}\
] run \
item modify entity @s weapon.mainhand custom_roleplay_data:marker_nbt
execute if items entity @s weapon.mainhand *\
[\
minecraft:custom_model_data,\
!minecraft:custom_data={CustomRoleplayData:1b}\
] run \
title @s actionbar \
{\
"text": "Can't set CustomModelData for this item!", \
"color": "red"\
}
# checks for xp
execute if items entity @s weapon.mainhand *[minecraft:custom_data~{CustomRoleplayData:1b}] \
unless score @s crd_xp >= #min_level crd_xp_dummy run \
title @s actionbar \
[\
{\
"text": "Requires at least ",\
"color": "red"\
},\
{\
"score": { \
"name": "#min_level", \
"objective": "crd_xp_dummy" \
}, \
"color": "aqua"\
}, \
{\
"text": " level(s)!", \
"color": "red"\
}\
]
# Sets the CustomModelData for the item
execute if items entity @s weapon.mainhand *[minecraft:custom_data~{CustomRoleplayData:1b}] \
if score @s crd_xp >= #min_level crd_xp_dummy run \
function custom_roleplay_data:set_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"function": "minecraft:set_custom_model_data",
"value": {
"type": "minecraft:score",
"target": {
"type": "context",
"target": "this"
},
"score": "CustomModelData"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"function": "minecraft:set_custom_data",
"tag": "{CustomRoleplayData:1b}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"display": {
"icon": {
"id": "minecraft:book"
},
"title": "Custom Roleplay Data",
"frame": "challenge",
"description": ["",{"text":"Adds the ability to change the CustomModelData of items in order to change item textures via resource packs. ","color":"gold"},{"text":"Datapack by: ","color":"green"},{"text":"MukiTanuki\n","color":"aqua"},{"text":"Enter","color":"green"},{"text":" ","color":"gold"},{"text":"/trigger CustomModelData set #","color":"yellow"},{"text":" to set model data.\n","color":"gold"},{"text":"Enter","color":"green"},{"text":" ","color":"gold"},{"text":"/function custom_roleplay_data:admin","color":"yellow"},{"text":" and use auto-complete to set config options.","color":"gold"}],
"background": "minecraft:textures/block/black_concrete.png",
"show_toast": false,
"announce_to_chat": false
},
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
},
"rewards": {
"functions": "custom_roleplay_data:enable"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Description: Display admin options in chat
# Called by: Player
# Entity @s: Player
#
tellraw @s \
[\
{\
"text":"Custom Roleplay Data - Admin Options",\
"color":"yellow",\
"bold":true\
}\
]
tellraw @s \
[\
{\
"text":"Datapack by MukiTanuki", \
"color": "aqua", \
"clickEvent": {\
"action": "open_url", \
"value": "https://twitter.com/MukiTanuki"\
}\
}\
]
tellraw @s \
[\
{\
"text":"Min required levels: ",\
"color":"aqua",\
"hoverEvent": {\
"action":"show_text",\
"contents": [\
{\
"text":"Sets the number of minimum levels required to set CustomModelData.\nSet to 0 to disable level requirement.",\
"color":"yellow"\
}\
]\
},\
"clickEvent":{\
"action":"suggest_command",\
"value":"/function custom_roleplay_data:set_required_level { level: <REPLACE WITH MIN REQUIRED LEVEL> }"\
}\
},\
{\
"score":{\
"name":"#min_level",\
"objective":"crd_xp_dummy"\
},\
"color":"green"\
}\
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Description: Function that repeats every second
# Called by: custom_roleplay_data:init
# Entity @s: none
#
# reschedules
schedule function custom_roleplay_data:second 1s
#
# trigger detection
#
execute as @a[scores={CustomModelData=0..}] if items entity @s weapon.mainhand * run function custom_roleplay_data:trigger
# resets trigger
execute as @a run function custom_roleplay_data:enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Description: Sets the data for item in-hand
# Called by: custom_roleplay_data:trigger
# Entity @s: none
#
# Sets CustomModelData to item
item modify entity @s weapon.mainhand custom_roleplay_data:copy_data
title @s actionbar \
[\
{\
"text": "Set CustomModelData to ", "color": "green"\
}, \
{\
"score": {\
"name": "@s",\
"objective": "CustomModelData"\
},\
"color": "aqua"\
}\
]
# removes required xp
function custom_roleplay_data:subtract_levels with storage custom_roleplay_data:config {}
# plays sound
execute at @s run playsound minecraft:block.anvil.use player @s ~ ~ ~ 0.4 0.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Description: Subtracts levels from scoreboard
# Called by: custom_roleplay_data:set_data
# Entity @s: player
# Parameters:
# level (int): level to subtract from the player
#
$xp add @s -$(level) levels
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Description: trigger to set CustomModelData
# Called by: custom_roleplay_data:second
# Entity @s: none
#
# Sets a tag marker for items so they don't overwrite existing CustomModelData
execute if items entity @s weapon.mainhand *\
[\
!minecraft:custom_model_data,\
!minecraft:custom_data~{CustomRoleplayData:1b}\
] run \
item modify entity @s weapon.mainhand custom_roleplay_data:marker_nbt
execute if items entity @s weapon.mainhand *\
[\
minecraft:custom_model_data,\
!minecraft:custom_data={CustomRoleplayData:1b}\
] run \
title @s actionbar \
{\
"text": "Can't set CustomModelData for this item!", \
"color": "red"\
}
# checks for xp
execute if items entity @s weapon.mainhand *[minecraft:custom_data~{CustomRoleplayData:1b}] \
unless score @s crd_xp >= #min_level crd_xp_dummy run \
title @s actionbar \
[\
{\
"text": "Requires at least ",\
"color": "red"\
},\
{\
"score": { \
"name": "#min_level", \
"objective": "crd_xp_dummy" \
}, \
"color": "aqua"\
}, \
{\
"text": " level(s)!", \
"color": "red"\
}\
]
# Sets the CustomModelData for the item
execute if items entity @s weapon.mainhand *[minecraft:custom_data~{CustomRoleplayData:1b}] \
if score @s crd_xp >= #min_level crd_xp_dummy run \
function custom_roleplay_data:set_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"function": "minecraft:set_custom_model_data",
"value": {
"type": "minecraft:score",
"target": {
"type": "context",
"target": "this"
},
"score": "CustomModelData"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"function": "minecraft:set_custom_data",
"tag": "{CustomRoleplayData:1b}"
}
]
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Description: Enables trigger
# Called by: advancment custom_model_data:custom_model_data
# Entity @s: none
#
scoreboard players set @s CustomModelData -2147483648
scoreboard players enable @s CustomModelData
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Description: Sets up datapack
# Called by: #minecraft:load
# Entity @s: none
#
# adds trigger scoreboard
scoreboard objectives add CustomModelData trigger
scoreboard players set @a CustomModelData -2147483648
scoreboard players enable @a CustomModelData
# xp level
scoreboard objectives add crd_xp level
scoreboard objectives add crd_xp_dummy dummy
# min xp required
execute unless score #min_level crd_xp_dummy matches 0.. run scoreboard players set #min_level crd_xp_dummy 1
execute store result storage custom_roleplay_data:config level int 1 run scoreboard players get #min_level crd_xp_dummy
# initializes second function
function custom_roleplay_data:second
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Description: Sets the required level
# Called by: disenchantment:disenchant_item and disenchant_book
# Entity @s: player
# Parameters:
# level (int): min level required for custom_roleplay_data
#
$scoreboard players set #min_level crd_xp_dummy $(level)
$data merge storage custom_roleplay_data:config { level: $(level)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"custom_roleplay_data:init"
]
}
Loading

0 comments on commit 7dee988

Please sign in to comment.