Ejemplo n.º 1
0
func (cm *ChunkManager) queue(w *game.World, cc coords.Chunk, priority int) {
	status := cm.chunks[cc]
	status.priority = priority
	if status.sent == false && status.data == nil {
		status.data = w.Chunk(cc)
	}
	cm.chunks[cc] = status
}
Ejemplo n.º 2
0
func (c *Client) handleBlock(g *Game, w *game.World, m *proto.MsgBlock) {
	// Eventually we should simulate block placement/removal entirely
	// on the server side, but for now, this works fairly well.
	inv := c.player.Inventory()
	curBlock := w.Block(m.Pos)

	if curBlock == mapgen.BLOCK_AIR {
		// If we are changing AIR to AIR (caused by a race condition) ignore it.
		if m.Type == mapgen.BLOCK_AIR {
			return
		}
		// Placing a block
		item := game.ItemFromBlock(m.Type)
		if inv.RemoveItem(item) {
			w.ChangeBlock(m.Pos, m.Type)
		} else {
			log.Println("Rejecting attempt to place block that is not in inventory!")
			c.sendBlockChanged(m.Pos, curBlock)
		}
	} else {
		if !curBlock.Mineable() {
			log.Println("Attempt to mine unmineable block rejected!")
			c.sendBlockChanged(m.Pos, curBlock)
			return
		}
		// Removing a block
		item := game.ItemFromBlock(curBlock)
		w.AddEntity(game.NewWorldItem(item, m.Pos.Center()))
		w.ChangeBlock(m.Pos, mapgen.BLOCK_AIR)
	}

	c.Send(&proto.MsgInventoryState{
		Items: c.player.Inventory().ItemsToByteArray(),
	})
}
Ejemplo n.º 3
0
func (c *Client) Disconnected(g *Game, w *game.World) {
	w.RemoveEntity(c.player)
	w.RemoveBlockListener(c)
	w.RemoveBioticListener(c)
	w.RemoveWorldItemListener(c)
	c.conn.Close()
}
Ejemplo n.º 4
0
func (p *persister) ListenForChanges(w *game.World) {
	w.AddChunkListener(p)
	w.AddBlockListener(p)
}
Ejemplo n.º 5
0
func (c *Client) Connected(g *Game, w *game.World) {
	p := game.NewPlayer(w, c.name)

	for id, b := range w.Biotics() {
		c.BioticCreated(id, b)
		c.Send(&proto.MsgScoreboardAdd{
			Name:  string(id),
			Score: g.scores[string(id)],
		})
	}

	for id, wi := range w.WorldItems() {
		c.WorldItemAdded(id, wi)
	}

	w.AddEntity(p)

	w.AddBlockListener(c)
	w.AddBioticListener(c)
	w.AddWorldItemListener(c)

	c.player = p
	c.Send(&proto.MsgInventoryState{
		Items: c.player.Inventory().ItemsToByteArray(),
	})
}