本文整理匯總了Java中net.minecraftforge.common.util.INBTSerializable類的典型用法代碼示例。如果您正苦於以下問題:Java INBTSerializable類的具體用法?Java INBTSerializable怎麽用?Java INBTSerializable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
INBTSerializable類屬於net.minecraftforge.common.util包,在下文中一共展示了INBTSerializable類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMessage
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@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;
}
示例2: createTag
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
/** 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);
}
示例3: writeNBT
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@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");
}
}
示例4: readNBT
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@Override
public void readNBT(Capability<T> capability, T instance, 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");
}
}
示例5: CapabilityDispatcher
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@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()]);
}
示例6: getTagValue
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
/** 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;
}
示例7: getTagList
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
/** 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());
}
示例8: writeNBT
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@Override
public NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side) {
return instance instanceof INBTSerializable ? ((INBTSerializable) instance).serializeNBT() : null;
}
示例9: readNBT
import net.minecraftforge.common.util.INBTSerializable; //導入依賴的package包/類
@Override
public void readNBT(Capability<T> capability, T instance, EnumFacing side, NBTBase nbt) {
if (instance instanceof INBTSerializable)
((INBTSerializable) instance).deserializeNBT(nbt);
}