重命名放置的容器
Renaming placed containers
我只是想知道有没有办法给已经在地面上的箱子之类的容器命名或重命名?
我的意思是不使用NMS。但是龙头 API 来编辑名称?
没有 API,但可以通过 NMS 实现。我前段时间做了这个方法,它允许你命名任何瓦片实体。
你给它一个普通的 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();
}
}
我只是想知道有没有办法给已经在地面上的箱子之类的容器命名或重命名?
我的意思是不使用NMS。但是龙头 API 来编辑名称?
没有 API,但可以通过 NMS 实现。我前段时间做了这个方法,它允许你命名任何瓦片实体。
你给它一个普通的 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();
}
}