Search in sources :

Example 6 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project LogisticsPipes by RS485.

the class DebugHelper method addNBTToTree.

private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws SecurityException, IllegalArgumentException {
    if (nbt == null) {
        return;
    }
    if (nbt instanceof NBTTagByte) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).getByte()));
        node.add(type);
    } else if (nbt instanceof NBTTagByteArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByteArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (byte byt : ((NBTTagByteArray) nbt).getByteArray()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        node.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagDouble) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagDouble");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagDouble) nbt).getDouble()));
        node.add(type);
    } else if (nbt instanceof NBTTagFloat) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).getFloat()));
        node.add(type);
    } else if (nbt instanceof NBTTagInt) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).getInt()));
        node.add(type);
    } else if (nbt instanceof NBTTagIntArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagIntArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (int byt : ((NBTTagIntArray) nbt).getIntArray()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagList) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (NBTBase object : (NBTTagList) nbt) {
            DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
            addNBTToTree(object, nbtNode);
            content.add(nbtNode);
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagCompound) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        for (String key : ((NBTTagCompound) nbt).getKeySet()) {
            NBTBase value = ((NBTTagCompound) nbt).getTag(key);
            DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(key);
            addNBTToTree(value, nbtNode);
            content.add(nbtNode);
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagLong) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagLong");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagLong) nbt).getLong()));
        node.add(type);
    } else if (nbt instanceof NBTTagShort) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).getShort()));
        node.add(type);
    } else if (nbt instanceof NBTTagString) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
        type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).getString() + "'"));
        node.add(type);
    } else {
        throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagLong(net.minecraft.nbt.NBTTagLong)

Example 7 with NBTTagFloat

use of net.minecraft.nbt.NBTTagFloat in project SimplyJetpacks by Tonius.

the class ItemMysteriousPotato method onItemUse.

@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int meta, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof TileEntityMobSpawner) {
            NBTTagCompound tag = new NBTTagCompound();
            tile.writeToNBT(tag);
            tag.setString("EntityId", "Zombie");
            NBTTagList spawnPotentials = new NBTTagList();
            NBTTagCompound zombieSpawn = new NBTTagCompound();
            zombieSpawn.setString("Type", "Zombie");
            zombieSpawn.setInteger("Weight", 1);
            NBTTagCompound zombieSpawnProperties = new NBTTagCompound();
            zombieSpawnProperties.setString("id", "Zombie");
            NBTTagList equipment = new NBTTagList();
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(ModItems.jetpackPotato.writeToNBT(new NBTTagCompound()));
            zombieSpawnProperties.setTag("Equipment", equipment);
            NBTTagList dropChances = new NBTTagList();
            for (int i = 0; i <= 4; i++) {
                dropChances.appendTag(new NBTTagFloat(0.0F));
            }
            zombieSpawnProperties.setTag("DropChances", dropChances);
            zombieSpawn.setTag("Properties", zombieSpawnProperties);
            spawnPotentials.appendTag(zombieSpawn);
            tag.setTag("SpawnPotentials", spawnPotentials);
            tag.setShort("SpawnCount", (short) 2);
            tag.setShort("SpawnRange", (short) 8);
            tag.setShort("Delay", (short) -1);
            tag.setShort("MinSpawnDelay", (short) 30);
            tag.setShort("MaxSpawnDelay", (short) 60);
            tag.setShort("MaxNearbyEntities", (short) 10);
            tag.setShort("RequiredPlayerRange", (short) 96);
            tile.readFromNBT(tag);
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 8 with NBTTagFloat

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

the class ItemElectricHoeMP method getElectricityStored.

@Override
public float getElectricityStored(ItemStack itemStack) {
    if (!itemStack.hasTagCompound()) {
        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 9 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.hasTagCompound()) {
        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 10 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.hasTagCompound()) {
        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)

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