當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IPlayerClient.PlaceHeldItem方法代碼示例

本文整理匯總了Golang中chunkymonkey/gamerules.IPlayerClient.PlaceHeldItem方法的典型用法代碼示例。如果您正苦於以下問題:Golang IPlayerClient.PlaceHeldItem方法的具體用法?Golang IPlayerClient.PlaceHeldItem怎麽用?Golang IPlayerClient.PlaceHeldItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chunkymonkey/gamerules.IPlayerClient的用法示例。


在下文中一共展示了IPlayerClient.PlaceHeldItem方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:nictuku,項目名稱:chunkymonkey,代碼行數:30,代碼來源:chunk.go


注:本文中的chunkymonkey/gamerules.IPlayerClient.PlaceHeldItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。