<commit_before>package gamerules

import (
	"os"

	"chunkymonkey/nbtutil"
	. "chunkymonkey/types"
	"nbt"
)

// blockInventory is the data stored in Chunk.SetTileEntity by some block
// aspects that contain inventories. It also implements IInventorySubscriber to
// relay events to player(s) subscribed to the inventories.
type blockInventory struct {
	chunk              IChunkBlock
	inv                IInventory
	subscribers        map[EntityId]IPlayerClient
	ejectOnUnsubscribe bool
	invTypeId          InvTypeId
	blockLoc           BlockXyz
}

// newBlockInventory creates a new blockInventory.
func newBlockInventory(instance *BlockInstance, inv IInventory, ejectOnUnsubscribe bool, invTypeId InvTypeId) *blockInventory {
	blkInv := &blockInventory{
		inv:                inv,
		subscribers:        make(map[EntityId]IPlayerClient),
		ejectOnUnsubscribe: ejectOnUnsubscribe,
		invTypeId:          invTypeId,
	}

	if instance != nil {
		blkInv.chunk = instance.Chunk
		blkInv.blockLoc = instance.BlockLoc
	}

	blkInv.inv.SetSubscriber(blkInv)

	return blkInv
}

func (blkInv *blockInventory) ReadNbt(tag nbt.ITag) (err os.Error) {
	if err = blkInv.inv.ReadNbt(tag); err != nil {
		return
	}

	if blkInv.blockLoc, err = nbtutil.ReadBlockXyzCompound(tag); err != nil {
		return
	}

	return nil
}

func (blkInv *blockInventory) WriteNbt() nbt.ITag {
	// TODO
	return nil
}

func (blkInv *blockInventory) SetChunk(chunk IChunkBlock) {
	blkInv.chunk = chunk
}

func (blkInv *blockInventory) Block() BlockXyz {
	return blkInv.blockLoc
}

func (blkInv *blockInventory) Click(player IPlayerClient, click *Click) {
	txState := blkInv.inv.Click(click)

	player.InventoryCursorUpdate(blkInv.blockLoc, click.Cursor)<commit_msg>Factored out tileEntity type from blockInventory.<commit_after>package gamerules

import (
	"os"

	. "chunkymonkey/types"
	"nbt"
)

// blockInventory is the data stored in Chunk.SetTileEntity by some block
// aspects that contain inventories. It also implements IInventorySubscriber to
// relay events to player(s) subscribed to the inventories.
type blockInventory struct {
	tileEntity
	inv                IInventory
	subscribers        map[EntityId]IPlayerClient
	ejectOnUnsubscribe bool
	invTypeId          InvTypeId
}

// newBlockInventory creates a new blockInventory.
func newBlockInventory(instance *BlockInstance, inv IInventory, ejectOnUnsubscribe bool, invTypeId InvTypeId) *blockInventory {
	blkInv := &blockInventory{
		inv:                inv,
		subscribers:        make(map[EntityId]IPlayerClient),
		ejectOnUnsubscribe: ejectOnUnsubscribe,
		invTypeId:          invTypeId,
	}

	if instance != nil {
		blkInv.chunk = instance.Chunk
		blkInv.blockLoc = instance.BlockLoc
	}

	blkInv.inv.SetSubscriber(blkInv)

	return blkInv
}

func (blkInv *blockInventory) ReadNbt(tag nbt.ITag) (err os.Error) {
	if err = blkInv.tileEntity.ReadNbt(tag); err != nil {
		return
	}

	if err = blkInv.inv.ReadNbt(tag); err != nil {
		return
	}

	return nil
}

func (blkInv *blockInventory) WriteNbt() nbt.ITag {
	// TODO
	return nil
}

func (blkInv *blockInventory) Block() BlockXyz {
	return blkInv.blockLoc
}

func (blkInv *blockInventory) Click(player IPlayerClient, click *Click) {
	txState := blkInv.inv.Click(click)

	player.InventoryCursorUpdate(blkInv.blockLoc, click.Cursor)
{'fraction_non_alphanumeric': 0.0891990291262136, 'fraction_numerical': 0.0, 'mean_word_length': 3.8844444444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6262478', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1106, 'n_words': 270}