Split ItemRef off of ItemStackRef

This commit is contained in:
David Vierra 2015-07-09 16:25:58 -10:00
parent 3112a27885
commit 55794970ce
3 changed files with 10 additions and 10 deletions

View File

@ -122,18 +122,17 @@ class NoParentError(RuntimeError):
Raised when setting the `id` of an ItemStack with no parent.
"""
class ItemStackRef(nbtattr.NBTCompoundRef):
class ItemRef(nbtattr.NBTCompoundRef):
def __init__(self, rootTag=None, parent=None):
if rootTag is None:
rootTag = nbt.TAG_Compound()
nbtattr.SetNBTDefaults(self)
super(ItemStackRef, self).__init__(rootTag, parent)
super(ItemRef, self).__init__(rootTag, parent)
Damage = nbtattr.NBTAttr("Damage", nbt.TAG_Short, 0)
Count = nbtattr.NBTAttr("Count", nbt.TAG_Byte, 1)
Slot = nbtattr.NBTAttr("Slot", nbt.TAG_Byte)
tag = nbtattr.NBTAttr("tag", nbt.TAG_Compound, 1)
@property
def id(self):
@ -200,7 +199,6 @@ class ItemStackRef(nbtattr.NBTCompoundRef):
raise TypeError("Expected ItemType, got %r", type(value))
self.id = value
@property
def raw_id(self):
return self.rootTag["id"].value
@ -217,11 +215,13 @@ class ItemStackRef(nbtattr.NBTCompoundRef):
self.dirty = True
@staticmethod
def tagIsItemStack(tag):
def tagIsItem(tag):
if tag.tagID != nbt.ID_COMPOUND:
return False
return "id" in tag and "Damage" in tag and "Count" in tag
class ItemStackRef(ItemRef):
Slot = nbtattr.NBTAttr("Slot", nbt.TAG_Byte)
class SlotsListProxy(nbtattr.NBTListProxy):
def putItemInSlot(self, item, slot):

View File

@ -15,7 +15,7 @@ import numpy
from mceditlib.anvil.adapter import VERSION_1_7, VERSION_1_8
from mceditlib.anvil.entities import PCEntityRef, PCTileEntityRef, \
ItemStackRef
ItemStackRef, ItemRef
from mceditlib.exceptions import PlayerNotFound, LevelFormatError
from mceditlib.selection import BoundingBox
from mceditlib.fakechunklevel import FakeChunkedLevelAdapter, FakeChunkData
@ -233,7 +233,7 @@ class SchematicFileAdapter(FakeChunkedLevelAdapter):
def getItemStackVersionFromEntities(self):
for listTag in self.rootTag["Entities"], self.rootTag["TileEntities"]:
for name, tag, path in nbt.walk(listTag):
if ItemStackRef.tagIsItemStack(tag):
if ItemRef.tagIsItem(tag):
if tag["id"].tagID == nbt.ID_STRING:
return VERSION_1_8
if tag["id"].tagID == nbt.ID_SHORT:

View File

@ -85,10 +85,10 @@ class DrawerItemStackRef(nbtattr.NBTCompoundRef):
self.dirty = True
@staticmethod
def tagIsItemStack(tag):
def tagIsItem(tag):
if tag.tagID != nbt.ID_COMPOUND:
return False
return "Item" in tag and "Damage" in tag and "Count" in tag
return "Item" in tag and "Meta" in tag and "Count" in tag
class DrawerSlotsListProxy(nbtattr.NBTListProxy):