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

项目:MeeCreeps    文件:ChopTreeActionWorker.java   
@Override
public void readFromNBT(NBTTagCompound tag) {
    NBTTagList list = tag.getTagList("blocks", Constants.NBT.TAG_LONG);
    blocks.clear();
    for (int i = 0; i < list.tagCount(); i++) {
        blocks.add(BlockPos.fromLong(((NBTTagLong) list.get(i)).getLong()));
    }
    list = tag.getTagList("leaves", Constants.NBT.TAG_COMPOUND);
    leavesToTick.clear();
    for (int i = 0; i < list.tagCount(); i++) {
        NBTTagCompound tc = list.getCompoundTagAt(i);
        BlockPos pos = BlockPos.fromLong(tc.getLong("p"));
        int counter = tc.getInteger("c");
        leavesToTick.put(pos, counter);
    }
}
项目:ExPetrum    文件:CropStats.java   
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
    this.growthRanges[0].deserializeNBT(nbt.getCompoundTag("tGrowthRangeMinimal"));
    this.growthRanges[1].deserializeNBT(nbt.getCompoundTag("tGrowthRangeOptimal"));
    this.growthRanges[2].deserializeNBT(nbt.getCompoundTag("tGrowthRangePerfect"));
    this.humidityGrowthRange = Pair.of(nbt.getCompoundTag("hGrowthRange").getFloat("min"), nbt.getCompoundTag("hGrowthRange").getFloat("max"));
    this.generation = nbt.getInteger("generation");
    this.wild = nbt.getBoolean("wild");
    this.type = EnumCrop.values()[nbt.getByte("type")];
    this.plantedAt = new Calendar();
    if (nbt.hasKey("plantedAt"))
    {
        this.plantedAt.deserializeNBT((NBTTagLong) nbt.getTag("plantedAt"));
    }

    this.health = nbt.getFloat("health");
    this.growthRate = nbt.getFloat("growthRate");
    this.waterConsumption = nbt.getFloat("waterConsumption");
    this.growth = nbt.getFloat("growth");
    this.nutrientConsumption.clear();
    nbt.getTagList("nutrientConsumption", NBT.TAG_COMPOUND).forEach(tag -> this.nutrientConsumption.put(EnumPlantNutrient.values()[((NBTTagCompound)tag).getByte("nutrient")], ((NBTTagCompound)tag).getFloat("amount")));
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_merge__Can_create_new_Tag() {
  // Given:
  NBTTagCompound nbt = new NBTTagCompound();

  Table data = new DefaultTable();
  String key = "my_key";
  long value = 53;
  data.rawset(key, value);

  // When:
  NBTTagCompound actual = underTest.merge(nbt, data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(key);
  assertThat(actual.getTag(key)).isEqualTo(new NBTTagLong(value));
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_toNbtCompound__With_numeric_Value() {
  // Given:
  Table data = new DefaultTable();
  String key = "my_key";
  long value = 42;
  data.rawset(key, value);
  String keyString = String.valueOf(key);

  // When:
  NBTTagCompound actual = underTest.toNbtCompound(data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(keyString);
  assertThat(actual.getTag(keyString)).isEqualTo(new NBTTagLong(value));
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_toNbtCompound__With_Compound_Value() {
  // Given:
  Table data = new DefaultTable();
  String key = "my_key";
  Table value = new DefaultTable();
  data.rawset(key, value);
  String key2 = "my_key2";
  long value2 = 42;
  value.rawset(key2, value2);

  // When:
  NBTTagCompound actual = underTest.toNbtCompound(data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(key);
  assertThat(actual.getTag(key)).isExactlyInstanceOf(NBTTagCompound.class);
  NBTTagCompound actualValue = actual.getCompoundTag(key);
  assertThat(actualValue.getKeySet()).containsOnly(key2);
  assertThat(actualValue.getTag(key2)).isEqualTo(new NBTTagLong(value2));
}
项目:rangedpumps    文件:TilePump.java   
@Override
public void readFromNBT(NBTTagCompound tag) {
    super.readFromNBT(tag);

    if (tag.hasKey("Energy")) {
        energy.receiveEnergy(tag.getInteger("Energy"), false);
    }

    if (tag.hasKey("CurrentPos")) {
        currentPos = BlockPos.fromLong(tag.getLong("CurrentPos"));
    }

    if (tag.hasKey("Range")) {
        range = tag.getInteger("Range");
    }

    if (tag.hasKey("Surfaces")) {
        NBTTagList surfaces = tag.getTagList("Surfaces", Constants.NBT.TAG_LONG);

        for (NBTBase surface : surfaces) {
            this.surfaces.add(BlockPos.fromLong(((NBTTagLong) surface).getLong()));
        }
    }

    tank.readFromNBT(tag);
}
项目:TeleToro    文件:ItemTeletoryPortalLinker.java   
private void linkPortalWithOrigin(EntityPlayer player, World world, ItemStack stack, ControlBlockLocation thisPortal,
        PortalLinkerOrigin remoteInfo) {

    ControlBlockLocation remotePortal = findControllerBlock(world, remoteInfo.pos, STANDARD_SIZER);

    stack.setTagInfo("origin", new NBTTagLong(0));
    stack.setTagInfo("dimid", new NBTTagInt(0));

    if (remotePortal == null) {
        return;
    }

    linkPortalTo(world, thisPortal, remotePortal, remoteInfo.dimId, remoteInfo.side);
    linkPortalTo(world, remotePortal, thisPortal, player.dimension, getSide(player, thisPortal));

    playSound(player);
    stack.damageItem(1, player);
}
项目: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;
    }

}
项目: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;
}
项目:MobTotems    文件:ModMultiblockTileEntity.java   
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
    tagCompound = super.writeToNBT(tagCompound);
    tagCompound.setBoolean(IS_MASTER, isMaster);

    NBTTagList slaveList = new NBTTagList();
    for (BlockPos slavePos : slaves) {
        slaveList.appendTag(new NBTTagLong(slavePos.toLong()));
    }
    tagCompound.setTag(SLAVES, slaveList);

    if (masterPos != null) {
        tagCompound.setLong(MASTER_POS, masterPos.toLong());
    }
    return tagCompound;
}
项目:MobTotems    文件:ModMultiblockTileEntity.java   
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);
    isMaster = tagCompound.getBoolean(IS_MASTER);

    NBTTagList tagList = tagCompound.getTagList(SLAVES, Constants.NBT.TAG_LONG);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTBase tag = tagList.get(i);
        if (tag instanceof NBTTagLong) {
            BlockPos blockPos = BlockPos.fromLong(((NBTTagLong) tag).getLong());
            slaves.add(blockPos);
        }
    }

    masterPos = BlockPos.fromLong(tagCompound.getLong(MASTER_POS));
}
项目: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));
}
项目:ExPetrum    文件:CropStats.java   
public void createFromItemNBT(NBTTagCompound tag)
{
    this.uprootedAt = Optional.of(new Calendar());
    if (tag.hasKey("uprootedAt", NBT.TAG_LONG))
    {
        this.uprootedAt.get().deserializeNBT((NBTTagLong) tag.getTag("uprootedAt"));
    }

    this.deserializeNBT(tag);
}
项目:ExPetrum    文件:ExPFarmland.java   
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
    this.moistureLevel = nbt.getFloat("moisture");
    for (NBTBase tag : nbt.getTagList("nutrientData", NBT.TAG_COMPOUND))
    {
        NBTTagCompound tagCompound = (NBTTagCompound) tag;
        this.nutrientData.put(EnumPlantNutrient.values()[tagCompound.getByte("key")], tagCompound.getFloat("value"));
    }

    if (nbt.hasKey("calendar"))
    {
        this.timeKeeper.deserializeNBT((NBTTagLong) nbt.getTag("calendar"));
    }
}
项目:ExPetrum    文件:ExPCrop.java   
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
    this.stats = new CropStats();
    this.stats.deserializeNBT(nbt.getCompoundTag("stats"));
    this.isSick = nbt.getBoolean("eaten");
    this.timeKeeper.deserializeNBT((NBTTagLong) nbt.getTag("calendar"));
}
项目:ExPetrum    文件:ItemFood.java   
public Calendar getLastTickTime(ItemStack is)
{
    Calendar ret = new Calendar();
    if (is.getOrCreateSubCompound("exp.foodData").hasKey("lastTick"))
    {
        ret.deserializeNBT((NBTTagLong) is.getOrCreateSubCompound("exp.foodData").getTag("lastTick"));
    }

    return ret;
}
项目:ExPetrum    文件:PackInfo.java   
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
    this.packID = new UUID(nbt.getLong("idMost"), nbt.getLong("idLeast"));
    this.leaderUUID = new UUID(nbt.getLong("leaderMost"), nbt.getLong("leaderLeast"));
    this.entitiesSet.clear();
    Iterator<NBTBase> iter = nbt.getTagList("entities", Constants.NBT.TAG_LONG).iterator();
    while (iter.hasNext())
    {
        this.entitiesSet.add(new UUID(((NBTTagLong)iter.next()).getLong(), ((NBTTagLong)iter.next()).getLong()));
    }

    this.playerReps.clear();
    StreamSupport.stream(nbt.getTagList("playerReps", Constants.NBT.TAG_COMPOUND).spliterator(), false).map(n -> (NBTTagCompound)n).forEach(tag -> this.playerReps.put(new UUID(tag.getLong("keyMost"), tag.getLong("keyLeast")), tag.getFloat("value")));
}
项目: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;
}
项目:BetterWithAddons    文件:RotHandler.java   
@SubscribeEvent
public void rotAttachCapability(AttachCapabilitiesEvent<ItemStack> event)
{
    ItemStack stack = event.getObject();

    if(isRottingItem(stack) && MINECRAFT_DATE != -1) //All items instead?
    {
        NBTTagCompound compound = stack.getTagCompound();
        if(compound == null || !compound.hasKey(CREATION_TIME_TAG))
            stack.setTagInfo(CREATION_TIME_TAG,new NBTTagLong(MINECRAFT_DATE));
        //event.addCapability(ROT,new Rot());
    }
}
项目: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    文件:NbtLongMerger.java   
@Override
public NBTTagLong merge(NBTTagLong nbt, Object data, String key, String path) {
  if (data instanceof Number) {
    return NbtConverter.toNbt(((Number) data).longValue());
  }
  throw converter.conversionException(path, data, "number");
}
项目:TeleToro    文件:ItemTeletoryPortalLinker.java   
private void setOriginPortal(EntityPlayer player, ItemStack stack, ControlBlockLocation thisPortal) {
    stack.setTagInfo("origin", new NBTTagLong(thisPortal.pos.toLong()));
    stack.setTagInfo("dimid", new NBTTagInt(player.dimension));
    int side = getSide(player, thisPortal);
    stack.setTagInfo("side", new NBTTagInt(side));
    playSound(player);
}
项目:CraftingHarmonics    文件:SetManager.java   
/**
 * Converts the map to a NBT tag compound
 * @param map    The map to convert
 * @return       The output NBT
 */
private static NBTTagCompound convertMapToCompoundNbt(Map<String, Long> map) {
    NBTTagCompound output = new NBTTagCompound();
    for(Map.Entry<String, Long> entry : map.entrySet()) {
        output.setTag(entry.getKey(), new NBTTagLong(entry.getValue()));
    }
    return output;
}
项目: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;
}
项目:copycore    文件:NbtUtils.java   
/** Returns the primitive value of a tag, casted to the return type. */
public static <T> T getTagValue(NBTBase tag) {
    if (tag == null)
        throw new IllegalArgumentException("tag is null");
    if (tag instanceof NBTTagByte)      return (T)(Object)((NBTTagByte)tag).func_150290_f();
    if (tag instanceof NBTTagShort)     return (T)(Object)((NBTTagShort)tag).func_150289_e();
    if (tag instanceof NBTTagInt)       return (T)(Object)((NBTTagInt)tag).func_150287_d();
    if (tag instanceof NBTTagLong)      return (T)(Object)((NBTTagLong)tag).func_150291_c();
    if (tag instanceof NBTTagFloat)     return (T)(Object)((NBTTagFloat)tag).func_150288_h();
    if (tag instanceof NBTTagDouble)    return (T)(Object)((NBTTagDouble)tag).func_150286_g();
    if (tag instanceof NBTTagString)    return (T)((NBTTagString)tag).func_150285_a_();
    if (tag instanceof NBTTagByteArray) return (T)((NBTTagByteArray)tag).func_150292_c();
    if (tag instanceof NBTTagIntArray)  return (T)((NBTTagIntArray)tag).func_150302_c();
    throw new IllegalArgumentException(NBTBase.NBTTypes[tag.getId()] + " isn't a primitive NBT tag");
}
项目:MobTotems    文件:ModMultiblockInventoryTileEntity.java   
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
    tagCompound = super.writeToNBT(tagCompound);
    tagCompound.setBoolean(IS_MASTER, isMaster);

    NBTTagList slaveList = new NBTTagList();
    for (BlockPos slavePos : slaves) {
        slaveList.appendTag(new NBTTagLong(slavePos.toLong()));
    }
    tagCompound.setTag(SLAVES, slaveList);
    return tagCompound;
}
项目:MobTotems    文件:ModMultiblockInventoryTileEntity.java   
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);
    isMaster = tagCompound.getBoolean(IS_MASTER);

    slaves.clear();
    NBTTagList tagList = tagCompound.getTagList(SLAVES, Constants.NBT.TAG_LONG);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTBase tag = tagList.get(i);
        if (tag instanceof NBTTagLong) {
            BlockPos blockPos = BlockPos.fromLong(((NBTTagLong) tag).getLong());
            slaves.add(blockPos);
        }
    }
}
项目:projectzulu1.7.10-pre-1.3a    文件:NBTWriter.java   
private static NBTBase createChildTag(byte childtag, String... values) {
    switch (childtag) {
    /* Container Tags */
    case 9:
        return new NBTTagList();
    case 10:
        return new NBTTagCompound();
        /* Value Tags: operations[2] should contain value */
    case 1:
        return new NBTTagByte(Byte.parseByte(values[0].trim()));
    case 2:
        return new NBTTagShort(Short.parseShort(values[0].trim()));
    case 3:
        return new NBTTagInt(Integer.parseInt(values[0].trim()));
    case 4:
        return new NBTTagLong(Long.parseLong(values[0].trim()));
    case 5:
        return new NBTTagFloat(Float.parseFloat(values[0].trim()));
    case 6:
        return new NBTTagDouble(Double.parseDouble(values[0].trim()));
    case 7:
        byte[] byteArray = new byte[values.length];
        for (int i = 2; i < values.length; i++) {
            byteArray[i - 2] = (byte) ParsingHelper.parseFilteredInteger(values[i], 0, "ByteArray");
        }
        return new NBTTagByteArray(byteArray);
    case 8:
        return new NBTTagString("");
    case 11:
        int[] intArray = new int[values.length - 2];
        for (int i = 2; i < values.length; i++) {
            intArray[i - 2] = (int) ParsingHelper.parseFilteredInteger(values[i], 0, "ByteArray");
        }
        return new NBTTagIntArray(intArray);
    default:
        ProjectZuluLog.severe("Unrecognised childtag tagId %s", childtag);
        throw new IllegalArgumentException();
    }
}
项目:NBTEdit    文件:NBTStringHelper.java   
public static NBTBase newTag(byte type){
    switch (type)
    {
    case 0:
        return new NBTTagEnd();
    case 1:
        return new NBTTagByte((byte) 0);
    case 2:
        return new NBTTagShort();
    case 3:
        return new NBTTagInt(0);
    case 4:
        return new NBTTagLong(0);
    case 5:
        return new NBTTagFloat(0);
    case 6:
        return new NBTTagDouble(0);
    case 7:
        return new NBTTagByteArray(new byte[0]);
    case 8:
        return new NBTTagString("");
    case 9:
        return new NBTTagList();
    case 10:
        return new NBTTagCompound();
    case 11:
        return new NBTTagIntArray(new int[0]);
    default:
        return null;
    }
}
项目:NBTEdit    文件:NBTStringHelper.java   
public static String toString(NBTBase base) {
    switch(base.getId()) {
    case 1:
        return "" + ((NBTTagByte)base).func_150290_f();
    case 2:
        return "" + ((NBTTagShort)base).func_150289_e();
    case 3:
        return "" + ((NBTTagInt)base).func_150287_d();
    case 4:
        return "" + ((NBTTagLong)base).func_150291_c();
    case 5:
        return "" + ((NBTTagFloat)base).func_150288_h();
    case 6:
        return "" + ((NBTTagDouble)base).func_150286_g();
    case 7:
        return base.toString();
    case 8:
        return ((NBTTagString)base).func_150285_a_();
    case 9:
        return "(TagList)";
    case 10:
        return "(TagCompound)";
    case 11:
        return base.toString();
    default:
        return "?";
    }
}
项目:RuneCraftery    文件:NBTTagCompound.java   
public long func_74763_f(String p_74763_1_) {
   try {
      return !this.field_74784_a.containsKey(p_74763_1_)?0L:((NBTTagLong)this.field_74784_a.get(p_74763_1_)).field_74753_a;
   } catch (ClassCastException var3) {
      throw new ReportedException(this.func_82581_a(p_74763_1_, 4, var3));
   }
}
项目:RuneCraftery    文件:NBTBase.java   
public static NBTBase func_74733_a(byte p_74733_0_, String p_74733_1_) {
   switch(p_74733_0_) {
   case 0:
      return new NBTTagEnd();
   case 1:
      return new NBTTagByte(p_74733_1_);
   case 2:
      return new NBTTagShort(p_74733_1_);
   case 3:
      return new NBTTagInt(p_74733_1_);
   case 4:
      return new NBTTagLong(p_74733_1_);
   case 5:
      return new NBTTagFloat(p_74733_1_);
   case 6:
      return new NBTTagDouble(p_74733_1_);
   case 7:
      return new NBTTagByteArray(p_74733_1_);
   case 8:
      return new NBTTagString(p_74733_1_);
   case 9:
      return new NBTTagList(p_74733_1_);
   case 10:
      return new NBTTagCompound(p_74733_1_);
   case 11:
      return new NBTTagIntArray(p_74733_1_);
   default:
      return null;
   }
}
项目:projectzulu1.7.10    文件:NBTWriter.java   
private static NBTBase createChildTag(byte childtag, String... values) {
    switch (childtag) {
    /* Container Tags */
    case 9:
        return new NBTTagList();
    case 10:
        return new NBTTagCompound();
        /* Value Tags: operations[2] should contain value */
    case 1:
        return new NBTTagByte(Byte.parseByte(values[0].trim()));
    case 2:
        return new NBTTagShort(Short.parseShort(values[0].trim()));
    case 3:
        return new NBTTagInt(Integer.parseInt(values[0].trim()));
    case 4:
        return new NBTTagLong(Long.parseLong(values[0].trim()));
    case 5:
        return new NBTTagFloat(Float.parseFloat(values[0].trim()));
    case 6:
        return new NBTTagDouble(Double.parseDouble(values[0].trim()));
    case 7:
        byte[] byteArray = new byte[values.length];
        for (int i = 2; i < values.length; i++) {
            byteArray[i - 2] = (byte) ParsingHelper.parseFilteredInteger(values[i], 0, "ByteArray");
        }
        return new NBTTagByteArray(byteArray);
    case 8:
        return new NBTTagString("");
    case 11:
        int[] intArray = new int[values.length - 2];
        for (int i = 2; i < values.length; i++) {
            intArray[i - 2] = (int) ParsingHelper.parseFilteredInteger(values[i], 0, "ByteArray");
        }
        return new NBTTagIntArray(intArray);
    default:
        ProjectZuluLog.severe("Unrecognised childtag tagId %s", childtag);
        throw new IllegalArgumentException();
    }
}
项目:OpenPeripheral-Addons    文件:TerminalUtils.java   
public static Long extractGuid(NBTTagCompound tag) {
    NBTBase guidTag = tag.getTag("guid");
    if (guidTag instanceof NBTTagString) {
        String value = ((NBTTagString)guidTag).func_150285_a_();
        return Long.parseLong(value.toLowerCase(), 36);
    } else if (guidTag instanceof NBTTagLong) return ((NBTPrimitive)guidTag).func_150291_c();

    return null;
}
项目:MinecraftScripting    文件:TAG_Base.java   
/**
 * Called to create a script visible NBT Tag.
 */
public static TAG_Base createFromNative(NBTBase base) {
    if (base instanceof NBTTagByte)
        return new TAG_Byte((NBTTagByte)base);
    if (base instanceof NBTTagByteArray)
        return new TAG_Byte_Array((NBTTagByteArray)base);
    if (base instanceof NBTTagCompound)
        return new TAG_Compound((NBTTagCompound)base);
    if (base instanceof NBTTagDouble)
        return new TAG_Double((NBTTagDouble)base);
    if (base instanceof NBTTagFloat)
        return new TAG_Float((NBTTagFloat)base);
    if (base instanceof NBTTagInt)
        return new TAG_Int((NBTTagInt)base);
    if (base instanceof NBTTagIntArray)
        return new TAG_Int_Array((NBTTagIntArray)base);
    if (base instanceof NBTTagList)
        return new TAG_List((NBTTagList)base);
    if (base instanceof NBTTagLong)
        return new TAG_Long((NBTTagLong)base);
    if (base instanceof NBTTagShort)
        return new TAG_Short((NBTTagShort)base);
    if (base instanceof NBTTagString)
        return new TAG_String((NBTTagString)base);
    return null;

}
项目:BaseClient    文件:NbtTagValue.java   
private static String getValue(NBTBase p_getValue_0_)
{
    if (p_getValue_0_ == null)
    {
        return null;
    }
    else if (p_getValue_0_ instanceof NBTTagString)
    {
        NBTTagString nbttagstring = (NBTTagString)p_getValue_0_;
        return nbttagstring.getString();
    }
    else if (p_getValue_0_ instanceof NBTTagInt)
    {
        NBTTagInt nbttagint = (NBTTagInt)p_getValue_0_;
        return Integer.toString(nbttagint.getInt());
    }
    else if (p_getValue_0_ instanceof NBTTagByte)
    {
        NBTTagByte nbttagbyte = (NBTTagByte)p_getValue_0_;
        return Byte.toString(nbttagbyte.getByte());
    }
    else if (p_getValue_0_ instanceof NBTTagShort)
    {
        NBTTagShort nbttagshort = (NBTTagShort)p_getValue_0_;
        return Short.toString(nbttagshort.getShort());
    }
    else if (p_getValue_0_ instanceof NBTTagLong)
    {
        NBTTagLong nbttaglong = (NBTTagLong)p_getValue_0_;
        return Long.toString(nbttaglong.getLong());
    }
    else if (p_getValue_0_ instanceof NBTTagFloat)
    {
        NBTTagFloat nbttagfloat = (NBTTagFloat)p_getValue_0_;
        return Float.toString(nbttagfloat.getFloat());
    }
    else if (p_getValue_0_ instanceof NBTTagDouble)
    {
        NBTTagDouble nbttagdouble = (NBTTagDouble)p_getValue_0_;
        return Double.toString(nbttagdouble.getDouble());
    }
    else
    {
        return p_getValue_0_.toString();
    }
}