<commit_before>"""
    entities
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
from mceditlib import nbt
from mceditlib.blocktypes import VERSION_1_7, VERSION_1_8
from mceditlib.blocktypes.itemtypes import ItemType
from mceditlib.geometry import Vector
from mceditlib import nbtattr

log = logging.getLogger(__name__)


class NoParentError(RuntimeError):
    """
    Raised when setting the `id` of an ItemStack with no parent.
    """

class ItemRef(nbtattr.NBTCompoundRef):
    def __init__(self, rootTag=None, parent=None):
        if rootTag is None:
            rootTag = nbt.TAG_Compound()
            nbtattr.SetNBTDefaults(self)

        super(ItemRef, self).__init__(rootTag, parent)

    Damage = nbtattr.NBTAttr("Damage", nbt.TAG_Short, 0)
    Count = nbtattr.NBTAttr("Count", nbt.TAG_Byte, 1)
    tag = nbtattr.NBTAttr("tag", nbt.TAG_Compound)

    @property
    def id(self):
        idTag = self.rootTag["id"]
        if idTag.tagID == nbt.ID_SHORT:
            if self.blockTypes is None:
                log.warn("No blocktypes available, returning id")
                return idTag.value
            try:
                itemType = self.blockTypes.itemTypes[idTag.value]
                return itemType.internalName
            except KeyError:
                log.warn("No ItemType defined for %s, returning id" % idTag.value)
                return idTag.value
        else:
            return idTag.value

    @id.setter
    def id(self, value):
        if "id" not in self.rootTag:
            # no id tag - freshly minted item tag
            # get proper tag type from blocktypes
            if self.blockTypes is None:
                raise NoParentError("ItemRef must be parented to a world before assigning id for the first time.")
            if self.blockTypes.itemStackVersion == VERSION_1_7:
                self.rootTag["id"] = nbt.TAG_Short(0)
            elif self.blockTypes.itemStackVersion == VERSION_1_8:
                self.rootTag["id"] = nbt.TAG_String("minecraft:air")
            else:
                raise AssertionError("Unexpected itemStackVersion: %s", self.blockTypes.itemStackVersion)

        idTag = self.rootTag["id"]
        if isinstance(value, ItemType):
            if idTag.tagID == nbt.ID_STRING:
                idTag.value = value.internalName
            else:
                idTag.value = value.ID
            if value.meta is not None:
                self.Damage = value.meta
        elif isinstance(value, int):
            if idTag.tagID == nbt.ID_SHORT:
                self.rootTag["id"].value = value
            elif idTag.tagID == nbt.ID_STRING:
                if self.blockTypes is None:
                    raise NoParentError("ItemStack must be parented to a world before assigning numeric IDs to an 1.8 ItemStack.")

                itemType = self.blockTypes.itemTypes[value]
                self.rootTag["id"].value = itemType.internalName
        elif isinstance(value, basestring):
            if idTag.tagID == nbt.ID_STRING:
                self.rootTag["id"].value = value
            elif idTag.tagID == nbt.ID_SHORT:
                if self.blockTypes is None:
                    raise NoParentError("ItemStack must be parented to a world before assigning textual IDs to an 1.7 ItemStack.")

                itemType = self.blockTypes.itemTypes[value]
                self.rootTag["id"].value = itemType.ID
        else:
            raise TypeError("Invalid type for ItemStackRef.id: %r", type(value))

        self.dirty = True

    @property
    def itemType(self):
        if self.blockTypes is None:
            raise ValueError("Cannot get itemType for this item. BlockTypes not set. ")
        try:
            itemType = self.blockTypes.itemTypes[self.rootTag["id"].value, self.Damage]
            return itemType
        except KeyError:
            raise ValueError("Cannot get itemType for this item. BlockTypes has no item for %s." % self.rootTag["id"].value)

    @itemType.setter
    def itemType(self, value):
        if not isinstance(value, ItemType):
            raise TypeError("Expected ItemType, got %r", type(value))
        self.id = value

    @property
    def raw_id(self):
        return self.rootTag["id"].value

    @raw_id.setter
    def raw_id(self, value):
        if isinstance(value, int):
            self.rootTag["id"] = nbt.TAG_Short(value)
        elif isinstance(value, basestring):
            self.rootTag["id"] = nbt.TAG_String(value)
        else:
            raise TypeError("Invalid type for ItemStack.id: %r", type(value))

        self.dirty = True

    @staticmethod
    def tagIsItem(tag):
        if tag.tagID != nbt.ID_COMPOUND:
            return False
        return "id" in tag and "Damage" in tag and "Count" in tag<commit_msg>Error messages: ItemStackRef -> ItemRef<commit_after>"""
    entities
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
from mceditlib import nbt
from mceditlib.blocktypes import VERSION_1_7, VERSION_1_8
from mceditlib.blocktypes.itemtypes import ItemType
from mceditlib.geometry import Vector
from mceditlib import nbtattr

log = logging.getLogger(__name__)


class NoParentError(RuntimeError):
    """
    Raised when setting the `id` of an ItemStack with no parent.
    """

class ItemRef(nbtattr.NBTCompoundRef):
    def __init__(self, rootTag=None, parent=None):
        if rootTag is None:
            rootTag = nbt.TAG_Compound()
            nbtattr.SetNBTDefaults(self)

        super(ItemRef, self).__init__(rootTag, parent)

    Damage = nbtattr.NBTAttr("Damage", nbt.TAG_Short, 0)
    Count = nbtattr.NBTAttr("Count", nbt.TAG_Byte, 1)
    tag = nbtattr.NBTAttr("tag", nbt.TAG_Compound)

    @property
    def id(self):
        idTag = self.rootTag["id"]
        if idTag.tagID == nbt.ID_SHORT:
            if self.blockTypes is None:
                log.warn("No blocktypes available, returning id")
                return idTag.value
            try:
                itemType = self.blockTypes.itemTypes[idTag.value]
                return itemType.internalName
            except KeyError:
                log.warn("No ItemType defined for %s, returning id" % idTag.value)
                return idTag.value
        else:
            return idTag.value

    @id.setter
    def id(self, value):
        if "id" not in self.rootTag:
            # no id tag - freshly minted item tag
            # get proper tag type from blocktypes
            if self.blockTypes is None:
                raise NoParentError("ItemRef must be parented to a world before assigning id for the first time.")
            if self.blockTypes.itemStackVersion == VERSION_1_7:
                self.rootTag["id"] = nbt.TAG_Short(0)
            elif self.blockTypes.itemStackVersion == VERSION_1_8:
                self.rootTag["id"] = nbt.TAG_String("minecraft:air")
            else:
                raise AssertionError("Unexpected itemStackVersion: %s", self.blockTypes.itemStackVersion)

        idTag = self.rootTag["id"]
        if isinstance(value, ItemType):
            if idTag.tagID == nbt.ID_STRING:
                idTag.value = value.internalName
            else:
                idTag.value = value.ID
            if value.meta is not None:
                self.Damage = value.meta
        elif isinstance(value, int):
            if idTag.tagID == nbt.ID_SHORT:
                self.rootTag["id"].value = value
            elif idTag.tagID == nbt.ID_STRING:
                if self.blockTypes is None:
                    raise NoParentError("ItemRef must be parented to a world before assigning numeric IDs to an 1.8 ItemStack.")

                itemType = self.blockTypes.itemTypes[value]
                self.rootTag["id"].value = itemType.internalName
        elif isinstance(value, basestring):
            if idTag.tagID == nbt.ID_STRING:
                self.rootTag["id"].value = value
            elif idTag.tagID == nbt.ID_SHORT:
                if self.blockTypes is None:
                    raise NoParentError("ItemRef must be parented to a world before assigning textual IDs to an 1.7 ItemStack.")

                itemType = self.blockTypes.itemTypes[value]
                self.rootTag["id"].value = itemType.ID
        else:
            raise TypeError("Invalid type for ItemRef.id: %r", type(value))

        self.dirty = True

    @property
    def itemType(self):
        ID = self.rootTag["id"].value
        if self.blockTypes is None:
            raise ValueError("Cannot get itemType for this item. BlockTypes not set. ")
        try:
            itemType = self.blockTypes.itemTypes[ID, self.Damage]
            return itemType
        except KeyError:
            raise ValueError("Cannot get itemType for this item. BlockTypes has no item for %s." % ID)

    @itemType.setter
    def itemType(self, value):
        if not isinstance(value, ItemType):
            raise TypeError("Expected ItemType, got %r", type(value))
        self.id = value

    @property
    def raw_id(self):
        return self.rootTag["id"].value

    @raw_id.setter
    def raw_id(self, value):
        if isinstance(value, int):
            self.rootTag["id"] = nbt.TAG_Short(value)
        elif isinstance(value, basestring):
            self.rootTag["id"] = nbt.TAG_String(value)
        else:
            raise TypeError("Invalid type for ItemRef.id: %r", type(value))

        self.dirty = True

    @staticmethod
    def tagIsItem(tag):
        if tag.tagID != nbt.ID_COMPOUND:
            return False
        return "id" in tag and "Damage" in tag and "Count" in tag
{'fraction_non_alphanumeric': 0.09236823029926478, 'fraction_numerical': 0.0031065548306927616, 'mean_word_length': 2.1044680167148826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6489070', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2741, 'n_words': 752}