Search in sources :

Example 16 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project MorePlanets by SteveKunG.

the class ItemElectricShovelMP method getElectricityStored.

@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).getFloat();
        } else if (obj instanceof NBTTagFloat) {
            energyStored = ((NBTTagFloat) obj).getFloat();
        }
    }
    itemStack.setItemDamage((int) (100 - energyStored / this.getMaxElectricityStored(itemStack) * 100));
    return energyStored;
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 17 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project MorePlanets by SteveKunG.

the class ItemElectricAxeMP method getElectricityStored.

@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).getFloat();
        } else if (obj instanceof NBTTagFloat) {
            energyStored = ((NBTTagFloat) obj).getFloat();
        }
    }
    itemStack.setItemDamage((int) (100 - energyStored / this.getMaxElectricityStored(itemStack) * 100));
    return energyStored;
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 18 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project MorePlanets by SteveKunG.

the class ItemElectricPickaxeMP method getElectricityStored.

@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).getFloat();
        } else if (obj instanceof NBTTagFloat) {
            energyStored = ((NBTTagFloat) obj).getFloat();
        }
    }
    itemStack.setItemDamage((int) (100 - energyStored / this.getMaxElectricityStored(itemStack) * 100));
    return energyStored;
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 19 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project MorePlanets by SteveKunG.

the class ItemElectricSwordMP method getElectricityStored.

@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).getFloat();
        } else if (obj instanceof NBTTagFloat) {
            energyStored = ((NBTTagFloat) obj).getFloat();
        }
    }
    itemStack.setItemDamage((int) (100 - energyStored / this.getMaxElectricityStored(itemStack) * 100));
    return energyStored;
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 20 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project BuildCraft by BuildCraft.

the class NbtSquisherTester method genNbt.

private static NBTTagCompound genNbt(int bptSize) {
    Random rand = new Random(0x517123);
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setByte("primitive|byte", (byte) 1);
    nbt.setShort("primitive|short", (short) 2);
    nbt.setInteger("primitive|int", 4);
    nbt.setLong("primitive|long", 6);
    nbt.setFloat("primitive|float", 10.01f);
    nbt.setDouble("primitive|double", 11.11010101010101001010);
    nbt.setByteArray("array|byte", new byte[] { 12, 13, 14 });
    nbt.setIntArray("array|int", new int[] { 15000, 160000, 17000, 180000 });
    nbt.setString("string", "OMG A VALUE");
    NBTTagList list = new NBTTagList();
    list.appendTag(new NBTTagFloat(19.91f));
    list.appendTag(new NBTTagFloat(19.45f));
    list.appendTag(new NBTTagFloat(19.41f));
    list.appendTag(new NBTTagFloat(19.32f));
    list.appendTag(new NBTTagFloat(19.76f));
    nbt.setTag("complex|list", list);
    nbt.setTag("complex|tag", new NBTTagCompound());
    NBTTagCompound compound = new NBTTagCompound();
    compound.setBoolean("a", false);
    compound.setDouble("b", 20.02);
    nbt.setTag("complex|compound", compound);
    String[] names = { "minecraft:air", "minecraft:log", "minecraft:torch", "minecraft:stone", "minecraft:fence" };
    int[] metas = { 1, 16, 5, 7, 4 };
    NBTTagCompound[] blocks = new NBTTagCompound[sum(metas)];
    int block = 0;
    for (int b = 0; b < names.length; b++) {
        NBTTagCompound blockNbt = new NBTTagCompound();
        blockNbt.setString("id", names[b]);
        blocks[block++] = blockNbt.copy();
        for (int m = 1; m < metas[b]; m++) {
            blockNbt.setByte("meta", (byte) m);
            blocks[block++] = blockNbt.copy();
        }
    }
    NBTTagCompound air = blocks[0];
    NBTTagList bpt = new NBTTagList();
    int chests = 0;
    for (int i = 0; i < bptSize; i++) {
        double r = rand.nextDouble();
        final NBTTagCompound toUse;
        if (r < 0.4) {
            toUse = air;
        } else if (r < 0.9999) {
            toUse = blocks[rand.nextInt(blocks.length)];
        } else {
            toUse = genRandomChest(rand);
            chests++;
        }
        bpt.appendTag(toUse);
    }
    System.out.println(chests + " random chests in a " + Math.cbrt(bptSize) + " bpt");
    nbt.setTag("bpt", bpt);
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) Random(java.util.Random) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagFloat (net.minecraft.nbt.NBTTagFloat)27 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)24 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)21 NBTBase (net.minecraft.nbt.NBTBase)18 NBTTagList (net.minecraft.nbt.NBTTagList)13 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)9 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)9 NBTTagString (net.minecraft.nbt.NBTTagString)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagInt (net.minecraft.nbt.NBTTagInt)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Map (java.util.Map)3 TByteArrayList (gnu.trove.list.array.TByteArrayList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2