本文整理汇总了Golang中github.com/huin/chunkymonkey/gamerules.IPlayerClient类的典型用法代码示例。如果您正苦于以下问题:Golang IPlayerClient类的具体用法?Golang IPlayerClient怎么用?Golang IPlayerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPlayerClient类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: reqInteractBlock
func (chunk *Chunk) reqInteractBlock(player gamerules.IPlayerClient, held gamerules.Slot, target *BlockXyz, againstFace Face) {
// TODO use held item to better check of if the player is trying to place a
// block vs. perform some other interaction (e.g hoeing dirt). This is
// perhaps best solved by sending held item type and the face to
// blockType.Aspect.Interact()
blockInstance, blockType, ok := chunk.blockInstanceAndType(target)
if !ok {
return
}
if _, isBlockHeld := held.ItemTypeId.ToBlockId(); isBlockHeld && blockType.Attachable {
// The player is interacting with a block that can be attached to.
// Work out the position to put the block at.
dx, dy, dz := againstFace.Dxyz()
destLoc := target.AddXyz(dx, dy, dz)
if destLoc == nil {
// there is overflow with the translation, so do nothing
return
}
player.PlaceHeldItem(*destLoc, held)
} else {
// Player is otherwise interacting with the block.
blockType.Aspect.Interact(blockInstance, player)
}
return
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:30,代码来源:chunk.go
示例2: cmdSay
func cmdSay(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
args := strings.Split(message, " ")
if len(args) < 2 {
player.EchoMessage(sayUsage)
return
}
msg := strings.Join(args[1:], " ")
cmdHandler.BroadcastMessage("§d" + msg)
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:9,代码来源:commands.go
示例3: cmdTell
func cmdTell(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
args := strings.Split(message, " ")
if len(args) < 3 {
player.EchoMessage(tellUsage)
return
}
/* TODO Get player to send message, too
player := args[1]
message := strings.Join(args[2:], " ")
*/
player.EchoMessage(msgNotImplemented)
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:12,代码来源:commands.go
示例4: reqTakeItem
func (chunk *Chunk) reqTakeItem(player gamerules.IPlayerClient, entityId EntityId) {
if entity, ok := chunk.entities[entityId]; ok {
if item, ok := entity.(*gamerules.Item); ok {
player.GiveItemAtPosition(*item.Position(), *item.GetSlot())
// Tell all subscribers to animate the item flying at the
// player.
buf := new(bytes.Buffer)
proto.WriteItemCollect(buf, entityId, player.GetEntityId())
chunk.reqMulticastPlayers(-1, buf.Bytes())
chunk.removeEntity(item)
}
}
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:14,代码来源:chunk.go
示例5: cmdTp
func cmdTp(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
args := strings.Split(message, " ")
if len(args) < 3 {
player.EchoMessage(tpUsage)
return
}
teleportee := cmdHandler.PlayerByName(args[1])
destination := cmdHandler.PlayerByName(args[2])
if teleportee == nil {
msg := fmt.Sprintf("'%s' is not logged in", args[1])
player.EchoMessage(msg)
return
}
if destination == nil {
msg := fmt.Sprintf("'%s' is not logged in", args[2])
player.EchoMessage(msg)
return
}
pos, look := destination.PositionLook()
// TODO: Remove this hack or figure out what needs to happen instead
pos.Y += 1.63
teleportee.EchoMessage(fmt.Sprintf("Hold still! You are being teleported to %s", args[2]))
msg := fmt.Sprintf("Teleporting %s to %s at (%.2f, %.2f, %.2f)", args[1], args[2], pos.X, pos.Y, pos.Z)
log.Printf("Message: %s", msg)
player.EchoMessage(msg)
teleportee.SetPositionLook(pos, look)
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:32,代码来源:commands.go
示例6: reqSubscribeChunk
func (chunk *Chunk) reqSubscribeChunk(entityId EntityId, player gamerules.IPlayerClient, notify bool) {
if _, ok := chunk.subscribers[entityId]; ok {
// Already subscribed.
return
}
chunk.subscribers[entityId] = player
buf := new(bytes.Buffer)
proto.WritePreChunk(buf, &chunk.loc, ChunkInit)
player.TransmitPacket(buf.Bytes())
player.TransmitPacket(chunk.chunkPacket())
if notify {
player.NotifyChunkLoad()
}
// Send spawns packets for all entities in the chunk.
if len(chunk.entities) > 0 {
buf := new(bytes.Buffer)
for _, e := range chunk.entities {
e.SendSpawn(buf)
}
player.TransmitPacket(buf.Bytes())
}
// Spawn existing players for new player.
if len(chunk.playersData) > 0 {
playersPacket := new(bytes.Buffer)
for _, existing := range chunk.playersData {
if existing.entityId != entityId {
existing.sendSpawn(playersPacket)
}
}
player.TransmitPacket(playersPacket.Bytes())
}
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:37,代码来源:chunk.go
示例7: cmdKill
func cmdKill(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
// TODO inflict damage to player
player.EchoMessage(msgNotImplemented)
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:4,代码来源:commands.go
示例8: cmdGive
func cmdGive(player gamerules.IPlayerClient, message string, cmdHandler gamerules.IGame) {
args := strings.Split(message, " ")
if len(args) < 3 || len(args) > 5 {
player.EchoMessage(giveUsage)
return
}
args = args[1:]
// Check to make sure this is a valid player name (at the moment command
// is being run, the player may log off before command completes).
target := cmdHandler.PlayerByName(args[0])
if target == nil {
msg := fmt.Sprintf("'%s' is not logged in", args[0])
player.EchoMessage(msg)
return
}
itemNum, err := strconv.Atoi(args[1])
itemType, ok := cmdHandler.ItemTypeById(itemNum)
if err != nil || !ok {
msg := fmt.Sprintf("'%s' is not a valid item id", args[1])
player.EchoMessage(msg)
return
}
quantity := 1
if len(args) >= 3 {
quantity, err = strconv.Atoi(args[2])
if err != nil {
player.EchoMessage(giveUsage)
return
}
if quantity > 512 {
msg := "Cannot give more than 512 items at once"
player.EchoMessage(msg)
return
}
}
data := 0
if len(args) >= 4 {
data, err = strconv.Atoi(args[2])
if err != nil {
player.EchoMessage(giveUsage)
return
}
}
// Perform the actual give
msg := fmt.Sprintf("Giving %d of '%s' to %s", quantity, itemType.Name, args[0])
player.EchoMessage(msg)
maxStack := int(itemType.MaxStack)
for quantity > 0 {
count := quantity
if count > maxStack {
count = maxStack
}
item := gamerules.Slot{
ItemTypeId: itemType.Id,
Count: ItemCount(count),
Data: ItemData(data),
}
target.GiveItem(item)
quantity -= count
}
if player != target {
msg = fmt.Sprintf("%s gave you %d of '%s'", player, quantity, itemType.Name)
target.EchoMessage(msg)
}
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:76,代码来源:commands.go
示例9: cmdHelp
func cmdHelp(player gamerules.IPlayerClient, message string, cmdFramework *CommandFramework, cmdHandler gamerules.IGame) {
args := strings.Split(message, " ")
if len(args) > 2 {
player.EchoMessage(helpUsage)
return
}
cmds := cmdFramework.Commands()
if len(args) == 2 {
cmd := args[1]
if command, ok := cmds[cmd]; ok {
player.EchoMessage("Command: " + cmdFramework.Prefix() + command.Trigger)
player.EchoMessage("Usage: " + command.Usage)
player.EchoMessage("Description: " + command.Description)
return
}
player.EchoMessage(msgUnknownCommand)
return
}
var resp string
if len(cmds) == 0 {
resp = "No commands available."
} else {
resp = "Commands:"
for trigger, _ := range cmds {
resp += " " + trigger + ","
}
resp = resp[:len(resp)-1]
}
player.EchoMessage(resp)
}
开发者ID:huin,项目名称:chunkymonkey,代码行数:30,代码来源:commands.go
注:本文中的github.com/huin/chunkymonkey/gamerules.IPlayerClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论