Java 类net.minecraft.nbt.NBTTagFloat 实例源码

项目:4Space-5    文件:ItemElectricBase.java   
/**
 * Gets the energy stored in the item. Energy is stored using item NBT
 */
@Override
public float getElectricityStored(ItemStack itemStack)
{
    if (itemStack.getTagCompound() == null)
    {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    float energyStored = 0f;
    if (itemStack.getTagCompound().hasKey("electricity"))
    {
        NBTBase obj = itemStack.getTagCompound().getTag("electricity");
        if (obj instanceof NBTTagDouble)
        {
            energyStored = ((NBTTagDouble) obj).func_150288_h();
        }
        else if (obj instanceof NBTTagFloat)
        {
            energyStored = ((NBTTagFloat) obj).func_150288_h();
        }
    }

    /** Sets the damage as a percentage to render the bar properly. */
    itemStack.setItemDamage((int) (100 - energyStored / this.getMaxElectricityStored(itemStack) * 100));
    return energyStored;
}
项目:TaleCraft    文件:NBTHelper.java   
private static void asJson(NBTBase tag, StringBuilder builder) {
    switch(tag.getId()) {
    case NBT.TAG_BYTE: builder.append(((NBTTagByte)tag).getByte()).append('b'); break;
    case NBT.TAG_SHORT: builder.append(((NBTTagShort)tag).getByte()).append('b'); break;
    case NBT.TAG_INT: builder.append(((NBTTagInt)tag).getInt()); break;
    case NBT.TAG_LONG: builder.append(((NBTTagLong)tag).getByte()).append('l'); break;
    case NBT.TAG_FLOAT: builder.append(((NBTTagFloat)tag).getFloat()).append('f'); break;
    case NBT.TAG_DOUBLE: builder.append(((NBTTagDouble)tag).getDouble()).append('d'); break;
    case NBT.TAG_STRING: builder.append('"').append(((NBTTagString)tag).getString()).append('"'); break;
    case NBT.TAG_BYTE_ARRAY: builder.append(Arrays.toString(((NBTTagByteArray)tag).getByteArray())); break;
    case NBT.TAG_INT_ARRAY: builder.append(Arrays.toString(((NBTTagIntArray)tag).getIntArray())); break;
    case NBT.TAG_COMPOUND: asJson((NBTTagCompound) tag, builder); break;
    case NBT.TAG_LIST: asJson((NBTTagList) tag, builder); break;
    }

}
项目:Easy-Editors    文件:NBTToJson.java   
private static StringBuilder any(StringBuilder sb, NBTBase nbt) {
    switch (nbt.getId()) {
    case Constants.NBT.TAG_COMPOUND:
        return compound(sb, (NBTTagCompound) nbt);
    case Constants.NBT.TAG_LIST:
        return list(sb, (NBTTagList) nbt);
    case Constants.NBT.TAG_INT_ARRAY:
        return intArray(sb, (NBTTagIntArray) nbt);
    case Constants.NBT.TAG_STRING:
        return string(sb, (NBTTagString) nbt);
    case Constants.NBT.TAG_DOUBLE:
        return _double(sb, (NBTTagDouble) nbt);
    case Constants.NBT.TAG_FLOAT:
        return _float(sb, (NBTTagFloat) nbt);
    default:
        return other(sb, nbt);
    }
}
项目:copycore    文件: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 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);
}
项目:CraftingManager    文件:ConvertNBTTagCompound.java   
public static Object getObject(NBTBase base)
{
    if(base instanceof NBTTagByte)
        return ((NBTTagByte)base).func_150290_f();
    if(base instanceof NBTTagShort)
        return ((NBTTagShort)base).func_150289_e();
    if(base instanceof NBTTagInt)
        return ((NBTTagInt)base).func_150287_d();
    if(base instanceof NBTTagLong)
        return ((NBTTagLong)base).func_150291_c();
    if(base instanceof NBTTagFloat)
        return ((NBTTagFloat)base).func_150288_h();
    if(base instanceof NBTTagDouble)
        return ((NBTTagDouble)base).func_150286_g();
    if(base instanceof NBTTagByteArray)
        return ((NBTTagByteArray)base).func_150292_c();
    if(base instanceof NBTTagString)
        return ((NBTTagString)base).func_150285_a_();
    if(base instanceof NBTTagList)
        return base;
    if(base instanceof NBTTagCompound)
        return ((NBTTagCompound)base);
    if(base instanceof NBTTagIntArray)
        return ((NBTTagIntArray)base).func_150302_c();
    return null;
}
项目:NBTEdit    文件:GuiEditNBT.java   
private static void setValidValue(Node<NamedNBT> node, String value){
    NamedNBT named = node.getObject();
    NBTBase base = named.getNBT();

    if (base instanceof NBTTagByte)
        named.setNBT(new NBTTagByte(ParseHelper.parseByte(value)));
    if (base instanceof NBTTagShort)
        named.setNBT(new NBTTagShort(ParseHelper.parseShort(value)));
    if (base instanceof NBTTagInt)
        named.setNBT(new NBTTagInt(ParseHelper.parseInt(value)));
    if (base instanceof NBTTagLong)
        named.setNBT(new NBTTagLong(ParseHelper.parseLong(value)));
    if(base instanceof NBTTagFloat)
        named.setNBT(new NBTTagFloat(ParseHelper.parseFloat(value)));
    if(base instanceof NBTTagDouble)
        named.setNBT(new NBTTagDouble(ParseHelper.parseDouble(value)));
    if(base instanceof NBTTagByteArray)
        named.setNBT(new NBTTagByteArray(ParseHelper.parseByteArray(value)));
    if(base instanceof NBTTagIntArray)
        named.setNBT(new NBTTagIntArray(ParseHelper.parseIntArray(value)));
    if (base instanceof NBTTagString)
        named.setNBT(new NBTTagString(value));
}
项目:4-Space-Legacy    文件:ItemElectric.java   
/** Gets the energy stored in the item. Energy is stored using item NBT */
@Override
public float getElectricityStored(ItemStack itemStack)
{
    if (itemStack.getTagCompound() == null)
    {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    float energyStored = 0f;
    if (itemStack.getTagCompound().hasKey("electricity"))
    {
        NBTBase obj = itemStack.getTagCompound().getTag("electricity");
        if (obj instanceof NBTTagDouble)
        {
            energyStored = (float) ((NBTTagDouble) obj).data;
        }
        else if (obj instanceof NBTTagFloat)
        {
            energyStored = ((NBTTagFloat) obj).data;
        }
    }

    /** Sets the damage as a percentage to render the bar properly. */
    itemStack.setItemDamage((int) (100 - (energyStored / this.getMaxElectricityStored(itemStack)) * 100));
    return energyStored;
}
项目:SimpleTransmutations    文件:ItemElectric.java   
/** Gets the energy stored in the item. Energy is stored using item NBT */
@Override
public float getElectricityStored(ItemStack itemStack)
{
    if (itemStack.getTagCompound() == null)
    {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    float energyStored = 0f;
    if (itemStack.getTagCompound().hasKey("electricity"))
    {
        NBTBase obj = itemStack.getTagCompound().getTag("electricity");
        if (obj instanceof NBTTagDouble)
        {
            energyStored = (float) ((NBTTagDouble) obj).data;
        }
        else if (obj instanceof NBTTagFloat)
        {
            energyStored = ((NBTTagFloat) obj).data;
        }
    }

    /** Sets the damage as a percentage to render the bar properly. */
    itemStack.setItemDamage((int) (100 - (energyStored / getMaxElectricityStored(itemStack)) * 100));
    return energyStored;
}
项目:EnderIO    文件:CapacitorHelper.java   
protected static @Nullable ICapacitorData getNBTCapacitorDataFromItemStack(@Nonnull ItemStack stack) {
  final NBTTagCompound nbtRoot = stack.getTagCompound();
  if (nbtRoot == null) {
    return null;
  }
  if (!nbtRoot.hasKey("eiocap", (new NBTTagCompound()).getId())) {
    return null;
  }
  final NBTTagCompound nbtTag = nbtRoot.getCompoundTag("eiocap");
  if (!nbtTag.hasKey("level", (new NBTTagFloat(0)).getId())) {
    return null;
  }
  final float capLevel = nbtTag.getFloat("level");
  if (capLevel < 0 || capLevel >= 10) {
    return null;
  }
  return new NBTCapacitorData(stack.getItem().getUnlocalizedName(stack), capLevel, nbtTag);
}
项目:DecompiledMinecraft    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:DecompiledMinecraft    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:DecompiledMinecraft    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:DecompiledMinecraft    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:BaseClient    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:BaseClient    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:BaseClient    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:BaseClient    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:connor41-etfuturum2    文件:Rotations.java   
public NBTTagList writeToNBT() {
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(x));
    nbttaglist.appendTag(new NBTTagFloat(y));
    nbttaglist.appendTag(new NBTTagFloat(z));
    return nbttaglist;
}
项目:Backmemed    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:Backmemed    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:Mods    文件:TF2Attribute.java   
public static float addValue(float value, NBTTagCompound attributelist, String effect) {
    for(String name : attributelist.getKeySet()) {
        NBTBase tag = attributelist.getTag(name);
        if (tag instanceof NBTTagFloat) {
            TF2Attribute attribute = attributes[Integer.parseInt(name)];
            if (attribute != null && attribute.effect.equals(effect))
                if (attribute.typeOfValue == Type.ADDITIVE)
                    value += ((NBTTagFloat) tag).getFloat();
                else
                    value *= ((NBTTagFloat) tag).getFloat();
        }
    }
    return value;
}
项目:CustomWorldGen    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (float f : numbers)
    {
        nbttaglist.appendTag(new NBTTagFloat(f));
    }

    return nbttaglist;
}
项目:CustomWorldGen    文件:Rotations.java   
public NBTTagList writeToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();
    nbttaglist.appendTag(new NBTTagFloat(this.x));
    nbttaglist.appendTag(new NBTTagFloat(this.y));
    nbttaglist.appendTag(new NBTTagFloat(this.z));
    return nbttaglist;
}
项目:ExtraUtilities    文件:WidgetTextData.java   
public static Object getNBTBaseData(final NBTBase nbt) {
    if (nbt == null) {
        return null;
    }
    switch (nbt.getId()) {
        case 1: {
            return ((NBTTagByte)nbt).func_150290_f();
        }
        case 2: {
            return ((NBTTagShort)nbt).func_150289_e();
        }
        case 3: {
            return ((NBTTagInt)nbt).func_150287_d();
        }
        case 4: {
            return ((NBTTagLong)nbt).func_150291_c();
        }
        case 5: {
            return ((NBTTagFloat)nbt).func_150288_h();
        }
        case 6: {
            return ((NBTTagDouble)nbt).func_150286_g();
        }
        case 8: {
            return ((NBTTagString)nbt).func_150285_a_();
        }
        case 10: {
            return nbt;
        }
        default: {
            return null;
        }
    }
}
项目:ExtraUtilities    文件:WidgetTextData.java   
public static NBTBase getNBTBase(final Object o) {
    if (o instanceof Integer) {
        return (NBTBase)new NBTTagInt((Integer)o);
    }
    if (o instanceof Short) {
        return (NBTBase)new NBTTagShort((Short)o);
    }
    if (o instanceof Long) {
        return (NBTBase)new NBTTagLong((Long)o);
    }
    if (o instanceof String) {
        return (NBTBase)new NBTTagString((String)o);
    }
    if (o instanceof Double) {
        return (NBTBase)new NBTTagDouble((Double)o);
    }
    if (o instanceof Float) {
        return (NBTBase)new NBTTagFloat((Float)o);
    }
    if (o instanceof NBTTagCompound) {
        return (NBTBase)o;
    }
    if (o instanceof Byte) {
        return (NBTBase)new NBTTagByte((Byte)o);
    }
    LogHelper.debug("Can't find type for " + o, new Object[0]);
    throw null;
}
项目:ExtraUtilities    文件:TileEntityBlockColorData.java   
public void readFromNBT(final NBTTagCompound par1NBTTagCompound) {
    super.readFromNBT(par1NBTTagCompound);
    for (int i = 0; i < 16; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (par1NBTTagCompound.hasKey("col" + i + "_" + j)) {
                if (par1NBTTagCompound.getTag("col" + i + "_" + j) instanceof NBTTagFloat) {
                    this.palette[i][j] = par1NBTTagCompound.getFloat("col" + i + "_" + j);
                }
            }
            else {
                this.palette[i][j] = BlockColor.initColor[i][j];
            }
        }
    }
}
项目:4Space-5    文件:SchematicEntity.java   
protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) {
    NBTTagList nbttaglist = new NBTTagList();
    float[] afloat = par1ArrayOfFloat;
    int i = par1ArrayOfFloat.length;

    for (int j = 0; j < i; ++j) {
        float f1 = afloat[j];
        nbttaglist.appendTag(new NBTTagFloat(f1));
    }

    return nbttaglist;
}
项目:4Space-5    文件:EntityLivingBase.java   
public void readEntityFromNBT(NBTTagCompound p_70037_1_) {
    ;
    ;
    setAbsorptionAmount(p_70037_1_.getFloat("AbsorptionAmount"));
    if ((p_70037_1_.hasKey("Attributes", 9)) && (this.worldObj != null)
            && (!this.worldObj.isRemote)) {
        SharedMonsterAttributes.func_151475_a(getAttributeMap(),
                p_70037_1_.getTagList("Attributes", 10));
    }
    if (p_70037_1_.hasKey("ActiveEffects", 9)) {
        NBTTagList nbttaglist = p_70037_1_.getTagList("ActiveEffects", 10);
        for (int i = 0; i < nbttaglist.tagCount(); i++) {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            PotionEffect potioneffect = PotionEffect
                    .readCustomPotionEffectFromNBT(nbttagcompound1);
            if (potioneffect != null) {
                this.activePotionsMap.put(
                        Integer.valueOf(potioneffect.getPotionID()),
                        potioneffect);
            }
        }
    }
    if (p_70037_1_.hasKey("HealF", 99)) {
        setHealth(p_70037_1_.getFloat("HealF"));
    } else {
        NBTBase nbtbase = p_70037_1_.getTag("Health");
        if (nbtbase == null) {
            setHealth(getMaxHealth());
        } else if (nbtbase.getId() == 5) {
            setHealth(((NBTTagFloat) nbtbase).func_150288_h());
        } else if (nbtbase.getId() == 2) {
            setHealth(((NBTTagShort) nbtbase).func_150289_e());
        }
    }
    this.hurtTime = p_70037_1_.getShort("HurtTime");
    this.deathTime = p_70037_1_.getShort("DeathTime");
    this.attackTime = p_70037_1_.getShort("AttackTime");
}
项目:wizards-of-lua    文件:NbtConverter.java   
private Map<Class<? extends NBTBase>, NbtMerger<? extends NBTBase>> getMergers() {
  if (mergers == null) {
    mergers = new HashMap<>();
    registerMerger(NBTTagByte.class, new NbtByteMerger(this));
    registerMerger(NBTTagCompound.class, new NbtCompoundMerger(this));
    registerMerger(NBTTagDouble.class, new NbtDoubleMerger(this));
    registerMerger(NBTTagFloat.class, new NbtFloatMerger(this));
    registerMerger(NBTTagInt.class, new NbtIntMerger(this));
    registerMerger(NBTTagList.class, new NbtListMerger(this));
    registerMerger(NBTTagLong.class, new NbtLongMerger(this));
    registerMerger(NBTTagShort.class, new NbtShortMerger(this));
    registerMerger(NBTTagString.class, new NbtStringMerger(this));
  }
  return mergers;
}
项目:wizards-of-lua    文件:NbtConverter.java   
public static Number toLua(NBTPrimitive nbt) {
  checkNotNull(nbt, "nbt == null!");
  if (nbt instanceof NBTTagDouble)
    return ((NBTTagDouble) nbt).getDouble();
  if (nbt instanceof NBTTagFloat)
    return ((NBTTagFloat) nbt).getDouble();
  return nbt.getLong();
}
项目:wizards-of-lua    文件:NbtFloatMerger.java   
@Override
public NBTTagFloat merge(NBTTagFloat nbt, Object data, String key, String path) {
  if (data instanceof Number) {
    return NbtConverter.toNbt(((Number) data).floatValue());
  }
  throw converter.conversionException(path, data, "number");
}
项目:metamorph    文件:MorphingStorage.java   
@Override
public NBTBase writeNBT(Capability<IMorphing> capability, IMorphing instance, EnumFacing side)
{
    NBTTagCompound tag = new NBTTagCompound();
    NBTTagList acquired = new NBTTagList();
    NBTTagList favorites = new NBTTagList();
    tag.setTag("lastHealthRatio", new NBTTagFloat(instance.getLastHealthRatio()));

    if (instance.getCurrentMorph() != null)
    {
        NBTTagCompound morph = new NBTTagCompound();
        instance.getCurrentMorph().toNBT(morph);

        tag.setTag("Morph", morph);
    }

    tag.setTag("Morphs", acquired);
    tag.setTag("Favorites", favorites);

    for (AbstractMorph acquiredMorph : instance.getAcquiredMorphs())
    {
        NBTTagCompound acquiredTag = new NBTTagCompound();

        acquiredMorph.toNBT(acquiredTag);
        acquired.appendTag(acquiredTag);
    }

    for (Integer index : instance.getFavorites())
    {
        favorites.appendTag(new NBTTagInt(index.intValue()));
    }

    return tag;
}
项目:Mekfarm    文件:AnimalFarmEntity.java   
static ItemStack packageAnimal(ItemStack packageStack, EntityAnimal animal) {
    ItemStack stackCopy = (packageStack == null) ? new ItemStack(ItemsRegistry.animalPackage) : packageStack.copy();

    stackCopy.setTagInfo("hasAnimal", new NBTTagInt(1));
    NBTTagCompound animalCompound = new NBTTagCompound();
    animal.writeEntityToNBT(animalCompound);
    stackCopy.setTagInfo("animal", animalCompound);
    stackCopy.setTagInfo("animalClass", new NBTTagString(animal.getClass().getName()));
    stackCopy.setTagInfo("animalHealth", new NBTTagFloat(animal.getHealth()));
    return stackCopy;
}
项目:justenoughdimensions    文件:JEDWorldProperties.java   
@Nonnull
private static NBTTagList writeFloats(float... values)
{
    NBTTagList tagList = new NBTTagList();

    for (float f : values)
    {
        tagList.appendTag(new NBTTagFloat(f));
    }

    return tagList;
}
项目:TaleCraft    文件:NBTListFloatTextFieldModel.java   
@Override
public void setText(String text) {
    this.text = text;

    try {
        float value = Float.parseFloat(text);
        list.set(index, new NBTTagFloat(value));
        valid = true;
    } catch(NumberFormatException ex) {
        valid = false;
    }
}
项目:morecommands    文件:NBTSettingsManager.java   
/**
 * Converts a {@link JsonElement} into an {@link NBTBase}
 * 
 * @param element the {@link JsonElement} to convert
 * @return the converted {@link NBTBase}
 */
public static NBTBase toNBTElement(JsonElement element) {
    if (element.isJsonArray()) {
        NBTTagList list = new NBTTagList();
        for (JsonElement elem : element.getAsJsonArray()) list.appendTag(toNBTElement(elem));
        return list;
    }
    else if (element.isJsonObject()) {
        NBTTagCompound compound = new NBTTagCompound();
        for (Map.Entry<String, JsonElement> entry : element.getAsJsonObject().entrySet()) compound.setTag(entry.getKey(), toNBTElement(entry.getValue()));
        return compound;
    }
    else if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isNumber()) {
        Number num = element.getAsJsonPrimitive().getAsNumber();

        if (num instanceof Byte) return new NBTTagByte(num.byteValue());
        else if (num instanceof Short) return new NBTTagShort(num.shortValue());
        else if (num instanceof Integer) return new NBTTagInt(num.intValue());
        else if (num instanceof Long) return new NBTTagLong(num.longValue());
        else if (num instanceof Float) return new NBTTagFloat(num.floatValue());
        else if (num instanceof Double) return new NBTTagDouble(num.doubleValue());
        else return new NBTTagDouble(num.doubleValue());
    }
    else if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) 
        return new NBTTagString(element.getAsJsonPrimitive().getAsString());
    else return null;
}
项目:NOVA-Core    文件:DataConverter.java   
/**
 * Reads an unknown object withPriority a known name from NBT
 * @param tag - tag to read the value from
 * @param key - name of the value
 * @return object or suggestionValue if nothing is found
 */
public Object load(NBTTagCompound tag, String key) {
    if (tag != null && key != null) {
        NBTBase saveTag = tag.getTag(key);

        if (saveTag instanceof NBTTagFloat) {
            return tag.getFloat(key);
        } else if (saveTag instanceof NBTTagDouble) {
            return tag.getDouble(key);
        } else if (saveTag instanceof NBTTagInt) {
            return tag.getInteger(key);
        } else if (saveTag instanceof NBTTagString) {
            if (tag.getBoolean(key + "::nova.isBigInteger")) {
                return new BigInteger(tag.getString(key));
            } else if (tag.getBoolean(key + "::nova.isBigDecimal")) {
                return new BigDecimal(tag.getString(key));
            } else {
                return tag.getString(key);
            }
        } else if (saveTag instanceof NBTTagShort) {
            return tag.getShort(key);
        } else if (saveTag instanceof NBTTagByte) {
            if (tag.getBoolean(key + "::nova.isBoolean")) {
                return tag.getBoolean(key);
            } else {
                return tag.getByte(key);
            }
        } else if (saveTag instanceof NBTTagLong) {
            return tag.getLong(key);
        } else if (saveTag instanceof NBTTagByteArray) {
            return tag.getByteArray(key);
        } else if (saveTag instanceof NBTTagIntArray) {
            return tag.getIntArray(key);
        } else if (saveTag instanceof NBTTagCompound) {
            NBTTagCompound innerTag = tag.getCompoundTag(key);
            return toNova(innerTag);
        }
    }
    return null;
}
项目:NOVA-Core    文件:DataConverter.java   
/**
 * Reads an unknown object withPriority a known name from NBT
 * @param tag - tag to read the value from
 * @param key - name of the value
 * @return object or suggestionValue if nothing is found
 */
public Object load(NBTTagCompound tag, String key) {
    if (tag != null && key != null) {
        NBTBase saveTag = tag.getTag(key);

        if (saveTag instanceof NBTTagFloat) {
            return tag.getFloat(key);
        } else if (saveTag instanceof NBTTagDouble) {
            return tag.getDouble(key);
        } else if (saveTag instanceof NBTTagInt) {
            return tag.getInteger(key);
        } else if (saveTag instanceof NBTTagString) {
            if (tag.getBoolean(key + "::nova.isBigInteger")) {
                return new BigInteger(tag.getString(key));
            } else if (tag.getBoolean(key + "::nova.isBigDecimal")) {
                return new BigDecimal(tag.getString(key));
            } else {
                return tag.getString(key);
            }
        } else if (saveTag instanceof NBTTagShort) {
            return tag.getShort(key);
        } else if (saveTag instanceof NBTTagByte) {
            if (tag.getBoolean(key + "::nova.isBoolean")) {
                return tag.getBoolean(key);
            } else {
                return tag.getByte(key);
            }
        } else if (saveTag instanceof NBTTagLong) {
            return tag.getLong(key);
        } else if (saveTag instanceof NBTTagByteArray) {
            return tag.getByteArray(key);
        } else if (saveTag instanceof NBTTagIntArray) {
            return tag.getIntArray(key);
        } else if (saveTag instanceof NBTTagCompound) {
            NBTTagCompound innerTag = tag.getCompoundTag(key);
            return toNova(innerTag);
        }
    }
    return null;
}
项目:TickDynamic    文件:Entity.java   
/**
 * Returns a new NBTTagList filled with the specified floats
 */
protected NBTTagList newFloatNBTList(float ... p_70049_1_)
{
    NBTTagList nbttaglist = new NBTTagList();
    float[] afloat = p_70049_1_;
    int i = p_70049_1_.length;

    for (int j = 0; j < i; ++j)
    {
        float f1 = afloat[j];
        nbttaglist.appendTag(new NBTTagFloat(f1));
    }

    return nbttaglist;
}
项目:Connected    文件:SchematicEntity.java   
protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) {
    NBTTagList nbttaglist = new NBTTagList();
    float[] afloat = par1ArrayOfFloat;
    int i = par1ArrayOfFloat.length;

    for (int j = 0; j < i; ++j) {
        float f1 = afloat[j];
        nbttaglist.appendTag(new NBTTagFloat(f1));
    }

    return nbttaglist;
}