微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

net.minecraftforge.common.util.INBTSerializable的实例源码

项目:MobHunter    文件MessageCapability.java   
@Override
public IMessage onMessage(final MessageCapability message,MessageContext ctx)
{
    IThreadListener mainThread = minecraft.getminecraft();
    mainThread.addScheduledTask(new Runnable()
    {
        @Override
        public void run()
        {
            minecraft mc = minecraft.getminecraft();
            EntityPlayerSP player = mc.player;
            Object capability = player.getCapability(message.capabilityType.getCapability(),null);
            if(capability != null && capability instanceof INBTSerializable)
                ((INBTSerializable) capability).deserializeNBT(message.capabilityNBT);

            //Refresh GuiQuest if open
            if(message.capabilityType == EnumCapability.QUEST && mc.currentScreen != null && mc.currentScreen instanceof GuiQuest)
                ((GuiQuest) mc.currentScreen).updateQuest(null);
            //Refresh GuiQuestList if open
            if(mc.currentScreen != null && mc.currentScreen instanceof GuiQuestList)
                ((GuiQuestList) mc.currentScreen).refreshButtons();
        }
    });
    return null;
}
项目:WearableBackpacks    文件NbtUtils.java   
/** Creates and returns a primitive NBT tag from a value.
 *  If the value already is an NBT tag,it is returned instead. */
public static NBTBase createTag(Object value) {
    if (value == null)
        throw new IllegalArgumentException("value is null");

    if (value instanceof NBTBase) return (NBTBase)value;
    if (value instanceof INBTSerializable)
        return ((INBTSerializable<?>)value).serializeNBT();
    if (value instanceof Collection) return ((Collection<?>)value).stream()
        .map(NbtUtils::createTag).collect(toList());

    if (value instanceof Byte)    return new NBTTagByte((Byte)value);
    if (value instanceof Short)   return new NBTTagShort((Short)value);
    if (value instanceof Integer) return new NBTTagInt((Integer)value);
    if (value instanceof Long)    return new NBTTagLong((Long)value);
    if (value instanceof Float)   return new NBTTagFloat((Float)value);
    if (value instanceof Double)  return new NBTTagDouble((Double)value);
    if (value instanceof String)  return new NBTTagString((String)value);
    if (value instanceof byte[])  return new NBTTagByteArray((byte[])value);
    if (value instanceof int[])   return new NBTTagIntArray((int[])value);

    throw new IllegalArgumentException("Can't create an NBT tag of value: " + value);
}
项目:ProjectEon    文件EonCapabilities.java   
@Nullable
@Override
public NBTBase writeNBT(Capability<T> capability,T instance,EnumFacing side) {
    if(instance instanceof INBTSerializable) {
        return ((INBTSerializable)instance).serializeNBT();
    } else {
        throw new IllegalArgumentException("Can not serialize to an instance that isn't a INBTSerializable implementation");
    }
}
项目:ProjectEon    文件EonCapabilities.java   
@Override
public void readNBT(Capability<T> capability,EnumFacing side,NBTBase nbt) {
    if(instance instanceof INBTSerializable) {
        ((INBTSerializable)instance).deserializeNBT(nbt);
    } else {
        throw new IllegalArgumentException("Can not deserialize to an instance that isn't a INBTSerializable implementation");
    }
}
项目:CustomWorldGen    文件Capabilitydispatcher.java   
@SuppressWarnings("unchecked")
public Capabilitydispatcher(Map<ResourceLocation,ICapabilityProvider> list,ICapabilityProvider parent)
{
    List<ICapabilityProvider> lstCaps = Lists.newArrayList();
    List<INBTSerializable<NBTBase>> lstWriters = Lists.newArrayList();
    List<String> lstNames = Lists.newArrayList();

    if (parent != null) // Parents go first!
    {
        lstCaps.add(parent);
        if (parent instanceof INBTSerializable)
        {
            lstWriters.add((INBTSerializable<NBTBase>)parent);
            lstNames.add("Parent");
        }
    }

    for (Map.Entry<ResourceLocation,ICapabilityProvider> entry : list.entrySet())
    {
        ICapabilityProvider prov = entry.getValue();
        lstCaps.add(prov);
        if (prov instanceof INBTSerializable)
        {
            lstWriters.add((INBTSerializable<NBTBase>)prov);
            lstNames.add(entry.getKey().toString());
        }
    }

    caps = lstCaps.toArray(new ICapabilityProvider[lstCaps.size()]);
    writers = lstWriters.toArray(new INBTSerializable[lstWriters.size()]);
    names = lstNames.toArray(new String[lstNames.size()]);
}
项目:WearableBackpacks    文件NbtUtils.java   
/** Returns the specified NBT serializable value
 *  instance deserialized from the specified NBT tag. */
public static <N extends NBTBase,T extends INBTSerializable<N>> T getTagValue(N tag,T value) {
    if (tag == null) throw new IllegalArgumentException("tag is null");
    if (value == null) throw new IllegalArgumentException("value is null");
    value.deserializeNBT(tag);
    return value;
}
项目:WearableBackpacks    文件NbtUtils.java   
/** Returns a list of NBT serializable values instantiated
 *  using the value supplier from the specified NBT list. */
@SuppressWarnings("unchecked")
public static <N extends NBTBase,T extends INBTSerializable<N>> List<T> getTagList(
    NBTTagList list,supplier<T> valuesupplier) {
    return stream(list)
        .map(tag -> getTagValue((N)tag,valuesupplier.get()))
        .collect(Collectors.toList());
}
项目:Alchemy    文件AlchemyCapability.java   
@Override
public NBTBase writeNBT(Capability<T> capability,EnumFacing side) {
    return instance instanceof INBTSerializable ? ((INBTSerializable) instance).serializeNBT() : null;
}
项目:Alchemy    文件AlchemyCapability.java   
@Override
public void readNBT(Capability<T> capability,NBTBase nbt) {
    if (instance instanceof INBTSerializable)
        ((INBTSerializable) instance).deserializeNBT(nbt);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。