2015-02-24 35 views
-2

我只是想知道是否有一種方法來給或重命名已經在地面上的胸部容器?重命名放置的容器

我的意思是不使用NMS。但是,spigot API編輯名稱?

回答

1

它沒有API,但它可能與NMS。我前段時間製作了這個方法,它可以讓你命名任何tile實體。

你給它一個正常的bukkit塊和將應用於該塊的名稱。名稱可以有§着色字符。

使用此代碼,如果您想避免NMS和CB導入,則可以使用反射製作版本。

import net.minecraft.server.v1_8_R1.INamableTileEntity; 
import net.minecraft.server.v1_8_R1.TileEntity; 
import net.minecraft.server.v1_8_R1.TileEntityBrewingStand; 
import net.minecraft.server.v1_8_R1.TileEntityChest; 
import net.minecraft.server.v1_8_R1.TileEntityCommand; 
import net.minecraft.server.v1_8_R1.TileEntityDispenser; 
import net.minecraft.server.v1_8_R1.TileEntityEnchantTable; 
import net.minecraft.server.v1_8_R1.TileEntityFurnace; 
import net.minecraft.server.v1_8_R1.TileEntityHopper; 

import org.bukkit.block.Block; 
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; 

public static void setName(String name, Block block) { 
    final CraftWorld world = (CraftWorld) block.getWorld(); 
    final TileEntity nmsTileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ()); 

    if (nmsTileEntity instanceof INamableTileEntity) { 
     if (nmsTileEntity instanceof TileEntityChest) { 
      ((TileEntityChest) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityFurnace) { 
      ((TileEntityFurnace) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityDispenser) { 
      ((TileEntityDispenser) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityHopper) { 
      ((TileEntityHopper) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityBrewingStand) { 
      ((TileEntityBrewingStand) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityEnchantTable) { 
      ((TileEntityEnchantTable) nmsTileEntity).a(name); 
     } else if (nmsTileEntity instanceof TileEntityCommand) { 
      ((TileEntityCommand) nmsTileEntity).getCommandBlock().setName(name); 
     } 

     nmsTileEntity.update(); 
    } 
} 
+0

我發現這不是在1.7的工作,似乎1.7沒有「INAMBLETileEntity」 – 1461748123 2015-02-25 09:56:22