2024-12-10 17:52:20|Myriagame |source:minecraft skins
This tutorial is set by the author's setting without permission.
Project goal
Implement the effect as shown in the figure.
Photo information explanation (from left to right): The number of items contained in the drop objects, the items contained, the time to disappear naturally (unit: second, take it down)
serverEvents.tick (event => {// Write the code of the project here
})
Code analysis
1. Obtain and traverse the server of the server, and determine whether its type is Minecraft: Item.
Event.server.entities.Foreach (Entity => {{If (entity.type == "minecraft: item") {{
// Write the code of step 2 here
}
}
)
2. Get the NBT data of the drop.
// Get the time to get the remaining time disappearing (unit: second, take it up)var restlife = math.trunc ((6000-entity.age)/(20))
// Obtain the items contained in the dropped object
let ID = (Entity.nbt ["item"] ["ID"]))
// The number of items contained in the dropped object
let amont = Entity.nbt ["item"] ["count"]
3. String string string, and set its Customname display.
// Set the custom name as visibleEntity.customNamevisible = TRUE
// Set the custom name
Entity.customName = Component.green
So far, the main code of the project is completed, but at this time we still cannot get the name of the localization of the item.(As shown in the red line part)
Get the localization name of items
We only need to create an Itemstack object and get its display name.I tried it for 3 hours before I found this solution
let localName = item.of (id) .getdisplayName (). GetString ()complete codeserverEvents.tick (event => {Event.server.entities.Foreach (Entity => {{
If (entity.type == "minecraft: item") {{
// Get the time to get the remaining time to disappear from the fall (unit: second, take it up)
Var restlife = math.trunc ((6000-entity.age)/(20))
// Obtain the items contained in the dropped object
Let ID = (Entity.nbt ["item"] ["ID"]))
// The number of items contained in the dropped object
Let amont = Entity.nbt ["item"] ["count"]
// Get the localized name of the items contained in the dropped object
Let localName = item.of (id) .getdisplayName (). GetString ()
// show
Entity.customNamevisible = True Entity.CustomName = Component.green (`$ {amont} x $ {id} $ {restlife}`)
}
})
})
Code applicable version
Kubejs 6
National Service DNF Dark Ni
2025-01-28 09:19:27The new screenshot of the be
2025-01-28 09:18:57The 15th anniversary wallpap
2025-01-28 09:18:273DM Xuanyuan Sinicization Gr
2025-01-28 09:17:57French magazine is the first
2025-01-28 09:17:27The sneak game "Republic" wi
2025-01-28 09:16:57The story between humans and
2025-01-28 09:16:27Capture "Trinity 3: Artifact
2025-01-28 09:15:27Wind direction change "Myste
2025-01-28 09:14:57DICE's new project "Dream" w
2025-01-28 09:14:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:27Pirate Minecraft Skins
Minecraft Skins
2024-12-10 04:11:26Master Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25King Minecraft Skins
Minecraft Skins
2024-12-10 04:11:25Guide Minecraft Skins
Minecraft Skins
2024-12-10 04:11:24Dark Knight Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Sparta Minecraft Skins
Minecraft Skins
2024-12-10 04:11:23Moncraft Skins of the War
Minecraft Skins
2024-12-10 04:11:22Red Witch Minecraft Skins
Minecraft Skins
2024-12-10 04:11:22Golden Cavaliers Minecraft S
Minecraft Skins
2024-12-10 04:11:22