Quellcode durchsuchen

奖励物品系统重构

00ll00 vor 5 Jahren
Ursprung
Commit
29c9cdc677

+ 1 - 1
data/item/functions/bonus_item/add_score.mcfunction

@@ -1,5 +1,5 @@
 #as player
-execute store result score #bonus_add_score mem run data get block 0 0 0 RecordItem.tag.bonus_add_score
+execute store result score #bonus_add_score mem run data get storage item:bouns item.tag.bonus_add_score
 
 # 正常的加分
 execute if score #bonus_add_score mem matches ..10 run scoreboard players operation @s total_score += #bonus_add_score mem

+ 4 - 0
data/item/functions/bonus_item/bonus_item_tag.json

@@ -9,5 +9,9 @@
     "bonus_give_items":[
         {"id":"minecraft:stone","Count":64,"tag":{"is_bonus":true,"display":{"Name":"\"普通的石头\""}}},
         {"id":"minecraft:arrow","Count":64,"tag":{"is_bonus":true}}
+    ],
+    "bonus_random_bounds":[
+        {"type":"normal","level":"white","count":2},
+        {"type":"score","level":"green","count":1}
     ]
 }

+ 4 - 19
data/item/functions/bonus_item/call.mcfunction

@@ -1,24 +1,9 @@
 # 当玩家拾取到奖励物品时触发
 # as player
 
-# 将玩家拾取到的原物品替换到原点的唱片机里
-data modify block 0 0 0 RecordItem set from entity @s Inventory[{"tag":{"bonus_new":1b}}]
+# 获取玩家待处理奖励物品列表
+data modify storage item:bouns item_buff set value []
+data modify storage item:bouns item_buff append from entity @s Inventory[{"tag":{"bonus_new":1b}}]
 clear @s #item:bonus{"bonus_new":1b}
 
-# 播放音效
-function lib:sounds/hit
-
-# 显示拾取提示(获得得分的提示由 add_score 显示)
-execute unless data block 0 0 0 RecordItem.tag.bonus_add_score run tellraw @a ["",{"text": ">> ","color":"aqua","bold": true},{"selector": "@s","color":"aqua"}," 获得了 ",{"nbt": "RecordItem.tag.item_name","block": "0 0 0","interpret": true}]
-
-# 如果有 return 标签则退回物品(最先执行)
-execute if data block 0 0 0 RecordItem.tag{"bonus_return":1b} run function item:bonus_item/return_item
-
-# 如果有 add_score 标签则增加积分
-execute if data block 0 0 0 RecordItem.tag.bonus_add_score run function item:bonus_item/add_score
-
-# 如果有 give_items 标签则给予物品
-execute if data block 0 0 0 RecordItem.tag.bonus_give_items[0] run function item:bonus_item/give_items
-
-# 执行特定函数
-execute if score $state mem matches 7 run function item:bonus_item/pickup_1
+execute unless data storage item:bouns item_buff[0] run function item:bonus_item/call_each

+ 27 - 0
data/item/functions/bonus_item/call_each.mcfunction

@@ -0,0 +1,27 @@
+# 处理单个奖励物品
+# as player
+
+# 获取当前物品
+data modify storage item:bouns item set from storage item:bouns item_buff[0]
+data remove storage item:bouns item_buff[0]
+
+# 播放音效
+function lib:sounds/hit
+
+# 显示拾取提示(获得得分的提示由 add_score 显示,获得随机物品则该物品不显示)
+execute unless data storage item:bouns item.tag.bonus_add_score unless data storage item:bouns item.tag.bonus_random_bounds[0] run tellraw @a ["",{"text": ">> ","color":"aqua","bold": true},{"selector": "@s","color":"aqua"}," 获得了 ",{"nbt": "item.tag.item_name","storage":"item:bouns","interpret": true}]
+
+# 如果有 return 标签则退回物品(最先执行)
+execute if data storage item:bouns item.tag{"bonus_return":1b} run function item:bonus_item/return_item
+
+# 如果有 add_score 标签则增加积分
+execute if data storage item:bouns item.tag.bonus_add_score run function item:bonus_item/add_score
+
+# 如果有 give_items 标签则给予物品
+execute if data storage item:bouns item.tag.bonus_give_items[0] run function item:bonus_item/give_items
+
+# 如果有 random_bounds 标签则返还随机物品
+execute if data storage item:bouns item.tag.bonus_random_bounds[0] run function item:bonus_item/random_bounds
+
+# 执行特定函数
+execute if score $state mem matches 7 run function item:bonus_item/pickup_1

+ 5 - 5
data/item/functions/bonus_item/give_items.mcfunction

@@ -1,9 +1,9 @@
 #as player
-setblock 0 0 1 jukebox replace
-data modify block 0 0 1 RecordItem set from block 0 0 0 RecordItem.tag.bonus_give_items[0]
-setblock 0 0 1 air destroy
+setblock 0 0 0 jukebox replace
+data modify block 0 0 0 RecordItem set from storage item:bouns item.tag.bonus_give_items[0]
+setblock 0 0 0 air destroy
 tag @s add item_op
 execute as @e[tag=!bonus_old,tag=!item_new,type=item,nbt={"Item":{"tag":{"is_bonus":1b}}},limit=1] run function item:bonus_item/tp
 tag @s remove item_op
-data remove block 0 0 0 RecordItem.tag.bonus_give_items[0]
-execute if data block 0 0 0 RecordItem.tag.bonus_give_items[0] run function item:bonus_item/give_items
+data remove storage item:bouns item.tag.bonus_give_items[0]
+execute if data storage item:bouns item.tag.bonus_give_items[0] run function item:bonus_item/give_items

+ 8 - 0
data/item/functions/bonus_item/random_bounds.mcfunction

@@ -0,0 +1,8 @@
+#as player
+setblock 0 0 1 shulker_box replace
+data modify storage item:bonus random_bounds set from storage item:bouns item.tag.bonus_random_bounds[0]
+data remove storage item:bouns item.tag.bonus_random_bounds[0]
+execute store result score $item.random.count mem run data get storage item:bonus random_bounds.count
+execute if score $item.random.count mem matches 1.. if data storage item:bonus random_bounds{"type":"normal"} run function item:bonus_item/random_normal
+execute if score $item.random.count mem matches 1.. if data storage item:bonus random_bounds{"type":"score"} run function item:bonus_item/random_score
+execute if data storage item:bouns item.tag.bonus_random_bounds[0] run function item:bonus/random_bounds

+ 8 - 0
data/item/functions/bonus_item/random_normal.mcfunction

@@ -0,0 +1,8 @@
+#as player
+scoreboard players remove $item.random.count mem 1
+execute if data storage item:bonus random_bounds{"level":"white"} run loot replace block 0 0 1 container.0 loot item:gameparty/normal/white
+execute if data storage item:bonus random_bounds{"level":"green"} run loot replace block 0 0 1 container.0 loot item:gameparty/normal/green
+execute if data storage item:bonus random_bounds{"level":"blue"} run loot replace block 0 0 1 container.0 loot item:gameparty/normal/blue
+execute if data storage item:bonus random_bounds{"level":"purple"} run loot replace block 0 0 1 container.0 loot item:gameparty/normal/purple
+data modify storage item:bouns item_buff prepend from block 0 0 1 Items[{"Slot":0b}]
+execute if score $item.random.count mem matches 1.. run function item:bonus_item/random_normal

+ 8 - 0
data/item/functions/bonus_item/random_score.mcfunction

@@ -0,0 +1,8 @@
+#as player
+scoreboard players remove $item.random.count mem 1
+execute if data storage item:bonus random_bounds{"level":"white"} run loot replace block 0 0 1 container.0 loot item:gameparty/score/white
+execute if data storage item:bonus random_bounds{"level":"green"} run loot replace block 0 0 1 container.0 loot item:gameparty/score/green
+execute if data storage item:bonus random_bounds{"level":"blue"} run loot replace block 0 0 1 container.0 loot item:gameparty/score/blue
+execute if data storage item:bonus random_bounds{"level":"purple"} run loot replace block 0 0 1 container.0 loot item:gameparty/score/purple
+data modify storage item:bouns item_buff prepend from block 0 0 1 Items[{"Slot":0b}]
+execute if score $item.random.count mem matches 1.. run function item:bonus_item/random_score

+ 4 - 4
data/item/functions/bonus_item/return_item.mcfunction

@@ -1,7 +1,7 @@
-setblock 0 0 1 jukebox replace
-data modify block 0 0 1 RecordItem set from block 0 0 0 RecordItem
-data modify block 0 0 1 RecordItem.tag.bonus_new set value 0b
-setblock 0 0 1 air destroy
+setblock 0 0 0 jukebox replace
+data modify block 0 0 0 RecordItem set from storage item:bouns item
+data modify block 0 0 0 RecordItem.tag.bonus_new set value 0b
+setblock 0 0 0 air destroy
 tag @s add item_op
 execute as @e[tag=!bonus_old,tag=!item_new,type=item,nbt={"Item":{"tag":{"is_bonus":1b}}},limit=1] run function item:bonus_item/tp
 tag @s remove item_op