Search in sources :

Example 11 with NBTTagIntArray

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

the class DebugHelper method addNBTToTree.

@SuppressWarnings("rawtypes")
private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    if (nbt == null) {
        return;
    }
    if (nbt instanceof NBTTagByte) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).func_150290_f()));
        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).func_150292_c()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + Byte.toString(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).func_150286_g()));
        node.add(type);
    } else if (nbt instanceof NBTTagFloat) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).func_150288_h()));
        node.add(type);
    } else if (nbt instanceof NBTTagInt) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).func_150287_d()));
        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).func_150302_c()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagList) {
        List internal = ((NBTTagList) nbt).tagList;
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (Object object : internal) {
            if (object instanceof NBTBase) {
                DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
                addNBTToTree((NBTBase) object, nbtNode);
                content.add(nbtNode);
                i++;
            }
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagCompound) {
        Map internal = ((NBTTagCompound) nbt).tagMap;
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        for (Object objectKey : internal.keySet()) {
            if (internal.get(objectKey) instanceof NBTBase) {
                DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(objectKey);
                addNBTToTree((NBTBase) internal.get(objectKey), 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).func_150291_c()));
        node.add(type);
    } else if (nbt instanceof NBTTagShort) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).func_150289_e()));
        node.add(type);
    } else if (nbt instanceof NBTTagString) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
        type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).func_150285_a_() + "'"));
        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) 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) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) Map(java.util.Map) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagLong(net.minecraft.nbt.NBTTagLong)

Example 12 with NBTTagIntArray

use of net.minecraft.nbt.NBTTagIntArray in project VoodooCraft by Mod-DevCafeTeam.

the class CapabilityGlyphs method serializeNBT.

@Override
public NBTTagCompound serializeNBT() {
    NBTTagCompound nbt = new NBTTagCompound();
    int[] ids = new int[knownGlyphs.size()];
    for (int i = 0; i < knownGlyphs.size(); i++) ids[i] = knownGlyphs.get(i).ordinal();
    NBTTagIntArray glyphIDs = new NBTTagIntArray(ids);
    nbt.setTag("glyphs", glyphIDs);
    return nbt;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray)

Example 13 with NBTTagIntArray

use of net.minecraft.nbt.NBTTagIntArray in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class StorageAirshipCounter method readNBT.

@Override
public void readNBT(Capability<IAirshipCounterCapability> capability, IAirshipCounterCapability instance, EnumFacing side, NBTBase nbt) {
    NBTTagIntArray tag = (NBTTagIntArray) nbt;
    instance.setAirshipCount(tag.getIntArray()[0]);
    instance.setAirshipCountEver(tag.getIntArray()[1]);
}
Also used : NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray)

Example 14 with NBTTagIntArray

use of net.minecraft.nbt.NBTTagIntArray in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ControlEventsCommon method onAttachCapabilityEventItem.

@SubscribeEvent
public void onAttachCapabilityEventItem(AttachCapabilitiesEvent event) {
    if (event instanceof AttachCapabilitiesEvent.Item) {
        AttachCapabilitiesEvent.Item itemEvent = (AttachCapabilitiesEvent.Item) event;
        ItemStack stack = itemEvent.getItemStack();
        if (itemEvent.getItem() instanceof ItemRelayWire) {
            //				System.out.println("Obama?");
            event.addCapability(new ResourceLocation(ValkyrienWarfareControlMod.MODID, "LastRelay"), new ICapabilitySerializable<NBTTagIntArray>() {

                ICapabilityLastRelay inst = ValkyrienWarfareControlMod.lastRelayCapability.getDefaultInstance();

                @Override
                public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                    return capability == ValkyrienWarfareControlMod.lastRelayCapability;
                }

                @Override
                public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                    return capability == ValkyrienWarfareControlMod.lastRelayCapability ? ValkyrienWarfareControlMod.lastRelayCapability.<T>cast(inst) : null;
                }

                @Override
                public NBTTagIntArray serializeNBT() {
                    return (NBTTagIntArray) ValkyrienWarfareControlMod.lastRelayCapability.getStorage().writeNBT(ValkyrienWarfareControlMod.lastRelayCapability, inst, null);
                }

                @Override
                public void deserializeNBT(NBTTagIntArray nbt) {
                    ValkyrienWarfareControlMod.lastRelayCapability.getStorage().readNBT(ValkyrienWarfareControlMod.lastRelayCapability, inst, null, nbt);
                }
            });
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) ItemRelayWire(ValkyrienWarfareControl.Item.ItemRelayWire) ResourceLocation(net.minecraft.util.ResourceLocation) ICapabilityLastRelay(ValkyrienWarfareControl.Capability.ICapabilityLastRelay) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with NBTTagIntArray

use of net.minecraft.nbt.NBTTagIntArray in project SpongeCommon by SpongePowered.

the class NbtTranslator method fromTagBase.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object fromTagBase(NBTBase base, byte type) {
    switch(type) {
        case NbtDataUtil.TAG_BYTE:
            return ((NBTTagByte) base).getByte();
        case NbtDataUtil.TAG_SHORT:
            return (((NBTTagShort) base)).getShort();
        case NbtDataUtil.TAG_INT:
            return ((NBTTagInt) base).getInt();
        case NbtDataUtil.TAG_LONG:
            return ((NBTTagLong) base).getLong();
        case NbtDataUtil.TAG_FLOAT:
            return ((NBTTagFloat) base).getFloat();
        case NbtDataUtil.TAG_DOUBLE:
            return ((NBTTagDouble) base).getDouble();
        case NbtDataUtil.TAG_BYTE_ARRAY:
            return ((NBTTagByteArray) base).getByteArray();
        case NbtDataUtil.TAG_STRING:
            return ((NBTTagString) base).getString();
        case NbtDataUtil.TAG_LIST:
            NBTTagList list = (NBTTagList) base;
            byte listType = (byte) list.getTagType();
            int count = list.tagCount();
            List objectList = Lists.newArrayListWithCapacity(count);
            for (int i = 0; i < list.tagCount(); i++) {
                objectList.add(fromTagBase(list.get(i), listType));
            }
            return objectList;
        case NbtDataUtil.TAG_COMPOUND:
            return getViewFromCompound((NBTTagCompound) base);
        case NbtDataUtil.TAG_INT_ARRAY:
            return ((NBTTagIntArray) base).getIntArray();
        default:
            return null;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray)

Aggregations

NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)20 NBTTagList (net.minecraft.nbt.NBTTagList)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 NBTTagString (net.minecraft.nbt.NBTTagString)11 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagInt (net.minecraft.nbt.NBTTagInt)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 NBTBase (net.minecraft.nbt.NBTBase)7 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 Map (java.util.Map)5 JsonElement (com.google.gson.JsonElement)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JsonPrimitive (com.google.gson.JsonPrimitive)2 TByteArrayList (gnu.trove.list.array.TByteArrayList)2