Java Code Examples for net.minecraft.nbt.NBTBase#getId()

The following examples show how to use net.minecraft.nbt.NBTBase#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiEditSingleNBT.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private static String getValue(NBTBase base) {
    switch (base.getId()) {
        case 7: {
            String s = "";
            for (byte b : ((NBTTagByteArray) base).func_150292_c()) {
                s = s + b + " ";
            }
            return s;
        }
        case 9: {
            return "TagList";
        }
        case 10: {
            return "TagCompound";
        }
        case 11: {
            String i = "";
            for (int a : ((NBTTagIntArray) base).func_150302_c()) {
                i = i + a + " ";
            }
            return i;
        }
    }
    return NBTStringHelper.toString(base);
}
 
Example 2
Source File: ItemArmourStand.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void merge(NBTTagCompound nbt, NBTTagCompound other) {
	Iterator<String> iterator = other.func_150296_c().iterator();

	while (iterator.hasNext()) {
		String s = iterator.next();
		NBTBase nbtbase = other.getTag(s);

		if (nbtbase.getId() == 10) {
			if (nbt.hasKey(s, 10)) {
				NBTTagCompound nbttagcompound1 = nbt.getCompoundTag(s);
				merge(nbttagcompound1, (NBTTagCompound) nbtbase);
			} else
				nbt.setTag(s, nbtbase.copy());
		} else
			nbt.setTag(s, nbtbase.copy());
	}
}
 
Example 3
Source File: GuiEditNBT.java    From NBTEdit with GNU General Public License v3.0 6 votes vote down vote up
private static String getValue(NBTBase base){
	switch(base.getId()){
	case 7:
		String s = "";
		for (byte b : ((NBTTagByteArray)base).func_150292_c() /*byteArray*/){
			s += b + " ";
		}
		return s;
	case 9:
		return "TagList";
	case 10:
		return "TagCompound";
	case 11:
		String i = "";
		for (int a : ((NBTTagIntArray)base).func_150302_c() /*intArray*/){
			i += a + " ";
		}
		return i;
	default: 
		return NBTStringHelper.toString(base);
	}
}
 
Example 4
Source File: NBTHelper.java    From wailanbt with MIT License 6 votes vote down vote up
public static String NBTToString(NBTBase tag) {
    switch (tag.getId()) {
        case 0:
        case 3:
        case 7:
        case 9:
        case 10:
        case 11:
            return tag.toString();
        case 1:
        case 2:
        case 4:
        case 5:
        case 6:
            return StringUtils.substring(tag.toString(), 0, -1);
        case 8:
            return StringUtils.substring(tag.toString(), 1, -1);
        default:
            return "__ERROR__";

    }
}
 
Example 5
Source File: NBTStringHelper.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(NBTBase base) {
    switch (GuiNBTNode.NBT_ICON_MAPPING[base.getId() - 1]) {
        case 0: {
            return "(TagCompound)";
        }
        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 ((NBTTagString) base).func_150285_a_();
        }
        case 8: {
            return "(TagList)";
        }
        case 9: {
            return base.toString();
        }
        case 10: {
            return base.toString();
        }
    }
    return "?";
}
 
Example 6
Source File: GuiNBTTree.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private boolean canAddToParent(NBTBase parent, NBTBase child) {
    if (parent instanceof NBTTagCompound) {
        return true;
    }
    if (parent instanceof NBTTagList) {
        NBTTagList list = (NBTTagList) parent;
        return list.tagCount() == 0 || list.func_150303_d() == child.getId();
    }
    return false;
}
 
Example 7
Source File: NbtUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void writeTag(NBTBase tag, String tagName, DataOutput output) throws IOException
{
    output.writeByte(tag.getId());

    if (tag.getId() != 0)
    {
        output.writeUTF(tagName);
        ((IMixinNBTBase) tag).invokeWrite(output);
    }
}
 
Example 8
Source File: CommandNbt.java    From AgriCraft with MIT License 5 votes vote down vote up
private void listNbt(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull NBTTagCompound tag) throws CommandException {
    for (String key : tag.getKeySet()) {
        final NBTBase entry = tag.getTag(key);
        final String type = NBTBase.NBT_TYPES[entry.getId()];
        MessageUtil.messagePlayer(player, "`l`3{0}`r `b{1}`r: `2{2}`r", type, key, entry);
    }
}
 
Example 9
Source File: CommandNbt.java    From AgriCraft with MIT License 5 votes vote down vote up
private void getNbt(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull NBTTagCompound tag, @Nonnull String key) throws CommandException {
    if (tag.hasKey(key)) {
        final NBTBase entry = tag.getTag(key);
        final String type = NBTBase.NBT_TYPES[entry.getId()];
        MessageUtil.messagePlayer(player, "`l`3{0}`r `b{1}`r: `2{2}`r", type, key, entry);
    } else {
        throw new CommandException("Active player stack does not have NBT tag: \"%s\"!", key);
    }
}
 
Example 10
Source File: NBTStringHelper.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
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 "?";
	}
}
 
Example 11
Source File: GuiNBTTree.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
private boolean canAddToParent(NBTBase parent, NBTBase child) {
	if (parent instanceof NBTTagCompound)
		return true;
	if (parent instanceof NBTTagList){
		NBTTagList list = (NBTTagList) parent;
		return list.tagCount() == 0 || list.func_150303_d() == child.getId();
	}
	return false;
}
 
Example 12
Source File: NBTHelper.java    From wailanbt with MIT License 5 votes vote down vote up
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
@Deprecated
public static String NBTTypeToString(NBTBase n, String id) {
    switch (n.getId()) {
        case 10:
            NBTTagCompound tagCompound = (NBTTagCompound) n;
            if (tagCompound.hasKey(id)) {
                NBTBase tag = ((NBTTagCompound) n).getTag(id);
                return NBTToString(tag);
            } else {
                return "__ERROR__";
            }
        case 9:
            NBTTagList tagList = (NBTTagList) n;
            Integer idInt = Integer.valueOf(id);
            switch (tagList.func_150303_d()) {
                case 10:
                    return (tagList.getCompoundTagAt(idInt).toString());
                case 9:
                    return StringUtils.substring(tagList.getStringTagAt(idInt),1,-1);
                default:
                    return "__ERROR__";
            }
        default:
            return "__ERROR__";
    }
}
 
Example 13
Source File: LitematicaSchematic.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean readSubRegionsFromTag(NBTTagCompound tag, int version)
{
    tag = tag.getCompoundTag("Regions");

    for (String regionName : tag.getKeySet())
    {
        if (tag.getTag(regionName).getId() == Constants.NBT.TAG_COMPOUND)
        {
            NBTTagCompound regionTag = tag.getCompoundTag(regionName);
            BlockPos regionPos = NBTUtils.readBlockPos(regionTag.getCompoundTag("Position"));
            BlockPos regionSize = NBTUtils.readBlockPos(regionTag.getCompoundTag("Size"));

            if (regionPos != null && regionSize != null)
            {
                this.subRegions.put(regionName, new SubRegion(regionPos, regionSize));

                if (version >= 2)
                {
                    this.blockEntities.put(regionName, this.readBlockEntitiesFromListTag(regionTag.getTagList("TileEntities", Constants.NBT.TAG_COMPOUND)));
                    this.entities.put(regionName, this.readEntitiesFromListTag(regionTag.getTagList("Entities", Constants.NBT.TAG_COMPOUND)));
                }
                else if (version == 1)
                {
                    this.blockEntities.put(regionName, this.readTileEntitiesFromNBT_v1(regionTag.getTagList("TileEntities", Constants.NBT.TAG_COMPOUND)));
                    this.entities.put(regionName, this.readEntitiesFromNBT_v1(regionTag.getTagList("Entities", Constants.NBT.TAG_COMPOUND)));
                }

                if (version >= 3)
                {
                    this.pendingBlockTicks.put(regionName, this.readBlockTicksFromNBT(regionTag.getTagList("PendingBlockTicks", Constants.NBT.TAG_COMPOUND)));
                }

                NBTBase nbtBase = regionTag.getTag("BlockStates");

                // There are no convenience methods in NBTTagCompound yet in 1.12, so we'll have to do it the ugly way...
                if (nbtBase != null && nbtBase.getId() == Constants.NBT.TAG_LONG_ARRAY)
                {
                    Vec3i size = new Vec3i(Math.abs(regionSize.getX()), Math.abs(regionSize.getY()), Math.abs(regionSize.getZ()));
                    NBTTagList paletteTag = regionTag.getTagList("BlockStatePalette", Constants.NBT.TAG_COMPOUND);
                    long[] blockStateArr = ((IMixinNBTTagLongArray) nbtBase).getArray();
                    int paletteSize = paletteTag.tagCount();

                    LitematicaBlockStateContainerFull container = LitematicaBlockStateContainerFull.createContainer(paletteSize, blockStateArr, size);

                    if (container == null)
                    {
                        InfoUtils.printErrorMessage("litematica.error.schematic_read_from_file_failed.region_container",
                                regionName, this.getFile() != null ? this.getFile().getName() : "<null>");
                        return false;
                    }

                    this.readPaletteFromLitematicaFormatTag(paletteTag, container.getPalette());
                    this.blockContainers.put(regionName, container);
                }
                else
                {
                    return false;
                }
            }
        }
    }

    return true;
}