Bukkit myInventory 更改项目名称
Bukkit myInventory change item names
我制作了一个 minecraft bukkit 插件,它是一个游戏模式更改器 GUI,但我不知道如何更改我打开的清单中的方块名称。目前他们只说Iron_Block、Gold_block ...等
如果有人能帮助我那将非常有帮助
这是库存码位
public static Inventory myInventory = Bukkit.createInventory(null, 9, "GamemodeGUI");
static {
myInventory.setItem(0, new ItemStack(Material.IRON_BLOCK, 1)); //Survival
myInventory.setItem(1, new ItemStack(Material.DIAMOND_BLOCK, 1)); //Creative
myInventory.setItem(2, new ItemStack(Material.GOLD_BLOCK, 1)); //Adventure
myInventory.setItem(3, new ItemStack(Material.LAPIS_BLOCK, 1)); //Spectator
myInventory.setItem(8, new ItemStack(Material.STAINED_GLASS, 1)); //Cancel
}
通过将方法调用分配给变量来创建您的 ItemStack:
ItemStack iron = new ItemStack(Material.IRON_BLOCK, 1); //Can be added to your static block
自定义它以更改您想要的名称
public static void setItemStackName(ItemStack renamed, String customName) {
ItemMeta renamedMeta = renamed.getItemMeta();
renamedMeta.setDisplayName(customName);
renamed.setItemMeta(renamedMeta);
}
您还可以在 ItemMeta
中添加一个 传说 。这是物品的描述
renamedMeta.setLore(Arrays.asList("Line 1 lore", "Line 2", "..."));
然后将自定义 ItemStack 添加到库存
setItemStackName(iron, "Survival");
inventory.setItem(0, iron); //Pass your customized ItemStack to the method now
我制作了一个 minecraft bukkit 插件,它是一个游戏模式更改器 GUI,但我不知道如何更改我打开的清单中的方块名称。目前他们只说Iron_Block、Gold_block ...等
如果有人能帮助我那将非常有帮助
这是库存码位
public static Inventory myInventory = Bukkit.createInventory(null, 9, "GamemodeGUI");
static {
myInventory.setItem(0, new ItemStack(Material.IRON_BLOCK, 1)); //Survival
myInventory.setItem(1, new ItemStack(Material.DIAMOND_BLOCK, 1)); //Creative
myInventory.setItem(2, new ItemStack(Material.GOLD_BLOCK, 1)); //Adventure
myInventory.setItem(3, new ItemStack(Material.LAPIS_BLOCK, 1)); //Spectator
myInventory.setItem(8, new ItemStack(Material.STAINED_GLASS, 1)); //Cancel
}
通过将方法调用分配给变量来创建您的 ItemStack:
ItemStack iron = new ItemStack(Material.IRON_BLOCK, 1); //Can be added to your static block
自定义它以更改您想要的名称
public static void setItemStackName(ItemStack renamed, String customName) {
ItemMeta renamedMeta = renamed.getItemMeta();
renamedMeta.setDisplayName(customName);
renamed.setItemMeta(renamedMeta);
}
您还可以在 ItemMeta
中添加一个 传说 。这是物品的描述
renamedMeta.setLore(Arrays.asList("Line 1 lore", "Line 2", "..."));
然后将自定义 ItemStack 添加到库存
setItemStackName(iron, "Survival");
inventory.setItem(0, iron); //Pass your customized ItemStack to the method now