本文整理汇总了Java中net.minecraft.item.ItemStack.serializeNBT方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.serializeNBT方法的具体用法?Java ItemStack.serializeNBT怎么用?Java ItemStack.serializeNBT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.serializeNBT方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
ItemStack held = player.getHeldItemMainhand();
if(held.isEmpty()) {
held = player.getHeldItemOffhand();
}
if(held.isEmpty()) {
player.sendMessage(new TextComponentTranslation("command.modularmachinery.hand.empty"));
return;
}
Item i = held.getItem();
StringBuilder sb = new StringBuilder();
sb.append(i.getRegistryName().toString());
if(i.getHasSubtypes()) {
sb.append("@").append(held.getItemDamage());
}
NBTTagCompound cmp = held.serializeNBT();
if(cmp.hasKey("tag")) {
String json = NBTJsonSerializer.serializeNBT(cmp.getTag("tag"));
if(!json.isEmpty()) {
sb.append(" (with nbt: ").append(json).append(" )");
}
}
String str = sb.toString();
player.sendMessage(new TextComponentString(str));
ModularMachinery.NET_CHANNEL.sendTo(new PktCopyToClipboard(str), player);
int burn = TileEntityFurnace.getItemBurnTime(held);
if(burn > 0) {
player.sendMessage(new TextComponentString("Fuel BurnTime: " + burn));
}
}