Esempio n. 1
0
func (item *Item) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = item.PointObject.UnmarshalNbt(tag); err != nil {
		return
	}

	itemInfo, ok := tag.Lookup("Item").(*nbt.Compound)
	if !ok {
		return errors.New("bad item data")
	}

	// Grab the basic item data
	id, idOk := itemInfo.Lookup("id").(*nbt.Short)
	count, countOk := itemInfo.Lookup("Count").(*nbt.Byte)
	data, dataOk := itemInfo.Lookup("Damage").(*nbt.Short)
	if !idOk || !countOk || !dataOk {
		return errors.New("bad item data")
	}

	item.Slot = Slot{
		ItemTypeId: ItemTypeId(id.Value),
		Count:      ItemCount(count.Value),
		Data:       ItemData(data.Value),
	}

	return nil
}
Esempio n. 2
0
func (inv *Inventory) UnmarshalNbt(tag *nbt.Compound) (err error) {
	itemList, ok := tag.Lookup("Items").(*nbt.List)
	if !ok {
		return errors.New("bad inventory - not a list")
	}

	for _, slotTagITag := range itemList.Value {
		slotTag, ok := slotTagITag.(*nbt.Compound)
		if !ok {
			return errors.New("inventory slot not a compound")
		}

		var slotIdTag *nbt.Byte
		if slotIdTag, ok = slotTag.Lookup("Slot").(*nbt.Byte); !ok {
			return errors.New("Slot ID not a byte")
		}
		slotId := SlotId(slotIdTag.Value)

		if err = inv.SlotUnmarshalNbt(slotTag, slotId); err != nil {
			return
		}
	}

	return nil
}
Esempio n. 3
0
func (music *musicTileEntity) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = music.tileEntity.UnmarshalNbt(tag); err != nil {
		return
	}

	if noteTag, ok := tag.Lookup("note").(*nbt.Byte); !ok {
		return errors.New("missing or incorrect type for Music note")
	} else {
		music.note = NotePitch(noteTag.Value)
	}

	return nil
}
Esempio n. 4
0
func (recordPlayer *recordPlayerTileEntity) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = recordPlayer.tileEntity.UnmarshalNbt(tag); err != nil {
		return
	}

	if recordTag, ok := tag.Lookup("Record").(*nbt.Int); !ok {
		return errors.New("missing or incorrect type for RecordPlayer Record")
	} else {
		recordPlayer.record = recordTag.Value
	}

	return nil
}
Esempio n. 5
0
func (sign *signTileEntity) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = sign.tileEntity.UnmarshalNbt(tag); err != nil {
		return
	}

	var textTags [4]*nbt.String
	var ok bool

	if textTags[0], ok = tag.Lookup("Text1").(*nbt.String); !ok {
		return errors.New("tile entity sign missing or bad type Text1")
	}
	if textTags[1], ok = tag.Lookup("Text2").(*nbt.String); !ok {
		return errors.New("tile entity sign missing or bad type Text2")
	}
	if textTags[2], ok = tag.Lookup("Text3").(*nbt.String); !ok {
		return errors.New("tile entity sign missing or bad type Text3")
	}
	if textTags[3], ok = tag.Lookup("Text4").(*nbt.String); !ok {
		return errors.New("tile entity sign missing or bad type Text4")
	}

	for i, textTag := range textTags {
		sign.text[i] = textTag.Value
	}

	return nil
}
Esempio n. 6
0
func (mobSpawner *mobSpawnerTileEntity) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = mobSpawner.tileEntity.UnmarshalNbt(tag); err != nil {
		return
	}

	if entityIdTag, ok := tag.Lookup("EntityId").(*nbt.String); !ok {
		return errors.New("missing or incorrect type for MobSpawner EntityId")
	} else {
		mobSpawner.entityMobType = entityIdTag.Value
	}

	if delayTag, ok := tag.Lookup("Delay").(*nbt.Short); !ok {
		return errors.New("missing or incorrect type for MobSpawner Delay")
	} else {
		mobSpawner.delay = Ticks(delayTag.Value)
	}

	return nil
}
Esempio n. 7
0
func (obj *PointObject) UnmarshalNbt(tag *nbt.Compound) (err error) {
	// Position within the chunk
	if obj.position, err = nbtutil.ReadAbsXyz(tag, "Pos"); err != nil {
		return
	}
	obj.LastSentPosition = *obj.position.ToAbsIntXyz()

	// Motion
	if obj.velocity, err = nbtutil.ReadAbsVelocity(tag, "Motion"); err != nil {
		return
	}
	obj.LastSentVelocity = *obj.velocity.ToVelocity()

	if onGround, ok := tag.Lookup("OnGround").(*nbt.Byte); ok {
		obj.onGround = onGround.Value != 0
	}

	return nil
}
Esempio n. 8
0
func (object *Object) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = object.PointObject.UnmarshalNbt(tag); err != nil {
		return
	}

	var typeName string
	if entityObjectId, ok := tag.Lookup("id").(*nbt.String); !ok {
		return errors.New("missing object type id")
	} else {
		typeName = entityObjectId.Value
	}

	var ok bool
	if object.ObjTypeId, ok = ObjTypeByName[typeName]; !ok {
		return errors.New("unknown object type id")
	}

	// TODO load orientation

	return
}
Esempio n. 9
0
func (inv *FurnaceInventory) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = inv.Inventory.UnmarshalNbt(tag); err != nil {
		return
	}

	if burnTimeTag, ok := tag.Lookup("BurnTime").(*nbt.Short); !ok {
		return errors.New("Bad or missing BurnTime tag in Furnace NBT")
	} else {
		inv.burnTime = Ticks(burnTimeTag.Value)

		// We don't know what the burnTimeMax was, as it is not stored, so taking
		// BurnTime for this value as well.
		inv.burnTimeMax = inv.burnTime
	}

	if cookTimeTag, ok := tag.Lookup("CookTime").(*nbt.Short); !ok {
		return errors.New("Bad or missing CookTime tag in Furnace NBT")
	} else {
		inv.cookTime = Ticks(cookTimeTag.Value)
	}

	return nil
}
Esempio n. 10
0
func (s *Slot) UnmarshalNbt(tag *nbt.Compound) (err error) {
	var ok bool
	var idTag, damageTag *nbt.Short
	var countTag *nbt.Byte

	if idTag, ok = tag.Lookup("id").(*nbt.Short); !ok {
		return errors.New("id tag not Short")
	}
	if countTag, ok = tag.Lookup("Count").(*nbt.Byte); !ok {
		return errors.New("Count tag not Byte")
	}
	if damageTag, ok = tag.Lookup("Damage").(*nbt.Short); !ok {
		return errors.New("Damage tag not Short")
	}

	s.ItemTypeId = ItemTypeId(idTag.Value)
	s.Count = ItemCount(countTag.Value)
	s.Data = ItemData(damageTag.Value)

	return
}
Esempio n. 11
0
func (mob *Mob) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if err = mob.PointObject.UnmarshalNbt(tag); err != nil {
		return
	}

	if mob.look, err = nbtutil.ReadLookDegrees(tag, "Rotation"); err != nil {
		return
	}

	// TODO
	_ = tag.Lookup("Air").(*nbt.Short).Value
	_ = tag.Lookup("AttackTime").(*nbt.Short).Value
	_ = tag.Lookup("DeathTime").(*nbt.Short).Value
	_ = tag.Lookup("FallDistance").(*nbt.Float).Value
	_ = tag.Lookup("Fire").(*nbt.Short).Value
	_ = tag.Lookup("Health").(*nbt.Short).Value
	_ = tag.Lookup("HurtTime").(*nbt.Short).Value

	return nil
}