Documentation ¶
Index ¶
- Constants
- func CanHarvest(tool_level int32, block_type string) bool
- func GetBaseToolMultiplier(tool string) int32
- func GetBlockHardness(block_type string) float32
- func GetToolLevel(tool string) int32
- func GetUUIDFromName(name string) *util.UUID
- func SetupBlockTypes()
- func SetupToolTypes()
- func ToolIsCorrectType(tool, block string) bool
- type Player
- func (p *Player) AxisFacing() block.Face
- func (p *Player) BlockX() int32
- func (p *Player) BlockY() int32
- func (p *Player) BlockZ() int32
- func (p *Player) ChunkX() int32
- func (p *Player) ChunkZ() int32
- func (p *Player) ClearEquipmentChange()
- func (p *Player) ClearFlags()
- func (p *Player) Collide(info *entity.CollisionInfo)
- func (p *Player) DX() int16
- func (p *Player) DY() int16
- func (p *Player) DZ() int16
- func (p *Player) Damage(amount float32)
- func (p *Player) Equipment() map[int]*item.Stack
- func (p *Player) Gamemode() byte
- func (p *Player) HandleKeepAlive(keep_alive_id int32)
- func (p *Player) Height() float64
- func (p *Player) Hit(other entity.Entity)
- func (p *Player) ImmuneToAttacks() bool
- func (p *Player) Inventory() item.PlayerInventory
- func (p *Player) Name() string
- func (p *Player) NeedsEquipmentChange() bool
- func (p *Player) NeedsPositionSet() bool
- func (p *Player) NeedsRotUpdate() bool
- func (p *Player) NeedsTeleport() bool
- func (p *Player) OnGround() bool
- func (p *Player) Pitch() float32
- func (p *Player) PitchAngle() float64
- func (p *Player) PitchByte() byte
- func (p *Player) PrevBlockX() int32
- func (p *Player) PrevBlockY() int32
- func (p *Player) PrevBlockZ() int32
- func (p *Player) PrevChunkX() int32
- func (p *Player) PrevChunkZ() int32
- func (p *Player) PrevX() float64
- func (p *Player) PrevY() float64
- func (p *Player) PrevZ() float64
- func (p *Player) Respawn()
- func (p *Player) SendChat(chat *util.Chat)
- func (p *Player) SendTitle(title, subtitle *util.Chat, fadein, stay, fadeout int)
- func (p *Player) SendToServer(ip string)
- func (p *Player) SetAbilities(value byte)
- func (p *Player) SetCanFly(value bool)
- func (p *Player) SetFlySpeed(value float32)
- func (p *Player) SetGamemode(value byte) error
- func (p *Player) SetHealth(val float32)
- func (p *Player) SetIsFlying(value bool)
- func (p *Player) SetOnGround(on_ground bool)
- func (p *Player) SetPrevPosition()
- func (p *Player) SetRotation(yaw float32, pitch float32)
- func (p *Player) Sneak(sneak bool)
- func (p *Player) SpawnParticleDust(x, y, z float64, r, g, b float32, scale float32)
- func (p *Player) Teleport(x, y, z float64)
- func (p *Player) Tick()
- func (p *Player) Time() int
- func (p *Player) TimeToBreakBlock(block_type string) int32
- func (p *Player) UpdateAbilities()
- func (p *Player) Version() packet.Version
- func (p *Player) Width() float64
- func (p *Player) Yaw() float32
- func (p *Player) YawAngle() float64
- func (p *Player) YawByte() byte
- type Scoreboard
Constants ¶
const ( NormalMultiplier = 1 WoodMultiplier = 2 StoneMultiplier = 4 IronMultiplier = 6 DiamondMultiplier = 8 NethertiteMultiplier = 9 GoldMultiplier = 16 )
Speed multipliers for all tools.
Variables ¶
This section is empty.
Functions ¶
func CanHarvest ¶
This checks if a tool's level >= the min level of the block that they are trying to harvest.
Used in the TimeToBreakBlock function.
func GetBaseToolMultiplier ¶
This can take any item name, and will give you the speed multiplier of that item. This will return 1 for anything that is not a tool.
Used in the TimeToBreakBlock function.
func GetBlockHardness ¶
Gets the block's "hardness" value. This is all hardcoded, copied from a table on the minecraft wiki. This will return 0 if the block passed in is not a valid block.
Used in the TimeToBreakBlock function.
func GetToolLevel ¶
This is the mining level of the tool. Used for checking if a block is harvestable by the given tool. This will return 0 if you pass in an item that is not a tool.
Used in the TimeToBreakBlock function.
func GetUUIDFromName ¶
This is an old function, that is never used. It gets the player's UUID based on their username. However, now that the proxy does mojang authentication for you, this is no longer needed. I am leaving this here, as it might be useful to get the UUID of someone who is offline.
func SetupBlockTypes ¶
func SetupBlockTypes()
This creates a map that is a list of all blocks in the game, and what tools/mining level/hardness they are.
This is called automatically when you call mc.Load(). Should not be called manually.
Note: This was created manually. It is ~200 lines of assignments into a map. It took forever. Feel free to copy it.
func SetupToolTypes ¶
func SetupToolTypes()
This creates a map of all tools, and what multipliers they have. This is automatically called on mc.Load().
func ToolIsCorrectType ¶
This checks if they are using the correct tool type for the given block. This will return true if they are using an axe on wood, for example.
Used in the TimeToBreakBlock function.
Types ¶
type Player ¶
type Player struct { entity.LivingBase UUID util.UUID PacketStream *packet.ConnectionWithChan Scoreboard *Scoreboard // contains filtered or unexported fields }
This is the player struct. There is one created per player, and it should be passed around by pointer. Each player has a UUID. This is their mojang account UUID. This will always be the same for the same account. If you need to track someone who logs off, then logs back in, you should use the UUID. Do not change the UUID on the player. That will break things.
If you need to send the player a packet, use the PacketStream. To modify the scoreboard (this will be displayed on the sidebar) use the Scoreboard. To modify their inventory, and show them windows (chest GUIS, etc) use Inventory.
func New ¶
func New(name string, uuid util.UUID, conn *packet.ConnectionWithChan, eid uint32, version packet.Version) *Player
Used internally when a player joins. Should never by called.
func (*Player) AxisFacing ¶
This will return a block face, which is one of north, south, east or west, depending on the player's yaw.
func (*Player) BlockY ¶
Will get Y coordinate of the block they are standing in. This is their feet position, not their eye position.
func (*Player) ClearEquipmentChange ¶
func (p *Player) ClearEquipmentChange()
Sets the needs equipment change field to false
func (*Player) ClearFlags ¶
func (p *Player) ClearFlags()
Called once all packets have been sent to the other client. This will clear things like needs_position_set, and needs_rot_update. Should never be called.
func (*Player) Collide ¶
func (p *Player) Collide(info *entity.CollisionInfo)
This is called whenever the player is inside a block. It will update the position of the player, such that they are now outside the block. It will also set the needs_position_set flag, which will cause them to rubberband next tick.
func (*Player) DX ¶
Get's their delta X, since the last time Tick() was called. Is used internally by the world update loop. There is not harm in calling it.
func (*Player) DY ¶
Get's their delta Y, since the last time Tick() was called. Is used internally by the world update loop. There is not harm in calling it.
func (*Player) DZ ¶
Get's their delta Z, since the last time Tick() was called. Is used internally by the world update loop. There is not harm in calling it.
func (*Player) Damage ¶
Call this to damage the player. Amount is the number health (half hearts) to take away from their health.
func (*Player) Equipment ¶
Gets the equipment for the player (held items/armor. Things that are visible to other players)
func (*Player) Gamemode ¶
Gets the player's gamemode.
0 -> survival 1 -> creative 2 -> adventure 3 -> spectator
func (*Player) HandleKeepAlive ¶
Used whenever the client sends a keep alive packet. Should never be called.
func (*Player) ImmuneToAttacks ¶
Needs to be overridden, as player.Tick() was overridden.
func (*Player) Inventory ¶
func (p *Player) Inventory() item.PlayerInventory
Gets the player's current inventory
func (*Player) NeedsEquipmentChange ¶
Used to check if an equipment change packet is needed
func (*Player) NeedsPositionSet ¶
Used to check if the player has moved incorrectly. This is called in the world update loop, and if it returns true, then the player will be rubberbanded.
func (*Player) NeedsRotUpdate ¶
Checks if the player has sent a rotation packet since the last time Tick() was called. Used internally to know if it needs to send rotation packets to all the other nearby clients. There is no harm in calling it.
func (*Player) NeedsTeleport ¶
This checks if the player's delta position is greater than 8 blocks in any direction. This is because the DX, DY and DZ values are int16s, and will overflow if the delta is greater than 8 blocks. This is used internally to check if it needs to send a PlayerTeleport packet to everyone, or if it can just send position deltas. There is no harm in calling it.
func (*Player) Pitch ¶
Gets the player's pitch rotation. This is how much they are rotated on the Y axis, from -90 to 90 degrees.
func (*Player) PitchAngle ¶
Gets the player's pitch rotation in radians.
func (*Player) PitchByte ¶
Gets the player's pitch rotation. This is how much they are rotated on the Y axis, from -64 to 64.
func (*Player) PrevBlockX ¶
Will get the X coordinate of the block they were in before the current tick. This is only updated when Tick() is called. This is used to see if the players have travelled across chunk borders.
func (*Player) PrevBlockY ¶
Will get the Y coordinate of the block they were in before the current tick. This is only updated when Tick() is called. This is used to see if the players have travelled across chunk borders.
func (*Player) PrevBlockZ ¶
Will get the Z coordinate of the block they were in before the current tick. This is only updated when Tick() is called. This is used to see if the players have travelled across chunk borders.
func (*Player) PrevChunkX ¶
Will get the X coordinate of the chunk they were in during the previous tick.
func (*Player) PrevChunkZ ¶
Will get the Z coordinate of the chunk they were in during the previous tick.
func (*Player) SendChat ¶
This will send the player a chat message. This is not prefixed by a player's username or anything, it just sends them a chat message with the exact text as defined in the Chat. This works with all formatting options of packet.Chat.
func (*Player) SendToServer ¶
This will send the player to a server, at the given ip. It will not reserve slots on that server, it will only send the packet to the proxy, which will redirect them.
func (*Player) SetAbilities ¶
Sets the abilities byte. You shouldn't need to call this, as wrapper functions like SetCanFly will do this for you. This is used internally when the client sends an ability update packet.
func (*Player) SetFlySpeed ¶
Sets the fly speed. This is a multiplier, not the actually value. So 1 is the base fly speed.
func (*Player) SetGamemode ¶
Sets the player's gamemode. If the value is > 3, this will return an error. This also checks if they are being set to/from creative, and updates their abilities as such.
func (*Player) SetIsFlying ¶
Sets whether or not the player is flying. Used internally when the player sends a packet to start/stop flying.
func (*Player) SetOnGround ¶
This updates the player's on_ground status. Fall damage is applied when this happens. This is used internally when they send on_ground change packets. Should never be called.
func (*Player) SetPrevPosition ¶
func (p *Player) SetPrevPosition()
Updates the prev position. Should never be called.
func (*Player) SetRotation ¶
This updates the player's rotation. This is used internally when they send rotation update packets. Should never be called.
func (*Player) Sneak ¶
Updates the player's entity metadata to reflect if they are sneaking. This will be sent to all players in view distance on the next player tick.
func (*Player) SpawnParticleDust ¶
This will spawn a redstone dust particle at the given location, with the given color. It should not be used, as a proper particle api will be introduced later. It is used by the worldedit server to display a bounding box around your selection.
func (*Player) Teleport ¶
This will teleport the player to a set location, facing 0,0. Use this when you want to move players around, instead of SetPosition. A TeleportFacing function will be added in the future, which will let you set the direction they are facing.
func (*Player) Tick ¶
func (p *Player) Tick()
This is an update function for the player. It is called once per tick by the world update loop. Should never be called.
func (*Player) Time ¶
Is the same as the entity.Time function, but it needs to be overridden here, as the Tick() function is also overridden.
func (*Player) TimeToBreakBlock ¶
This calculates the amount of time it will take the player to break a block of the given type. This does not account for the player changing on_ground in the middle of the break, but otherwise it takes all implemented features into account. Exceptions:
It does not use the haste level yet, as status effects have not been added.
It does not check if the player is in water, as that has not been implemented.
Returns a value in ticks
func (*Player) UpdateAbilities ¶
func (p *Player) UpdateAbilities()
Sends the player a packet about their current abilities. Is called automatically whenever you call SetCanFly, SetAbilities, etc.
func (*Player) Version ¶
This is the protocol version that this player is using. Used when generating chunk packets.
func (*Player) Width ¶
We shrink the player's hitbox, to make sure they don't get rubber-banded all the time. The newer client sends the player's position as an average between physics updates, which can make the player appear inside a block. 0.6 and 1.8 are is the real size of the player, but that caused to many issues on corners of blocks. func (p *Player) Width() float64 { return 0.6 } func (p *Player) Height() float64 { return 1.8 }
func (*Player) Yaw ¶
Gets the player's yaw rotation. This is how much they are rotated on the X axis, in degrees. This is a weird measurement, and is essentially an inverted y axis unit circle. Refer to AxisAngle() to get a north-south-east-west value for the player yaw. This will always return a value from 0 - 360
type Scoreboard ¶
type Scoreboard struct {
// contains filtered or unexported fields
}
This is a wrapper class for the sidebar scoreboard. One is automatically created whenever a player joins, but it is not displayed. You can call Show() to show the scoreboard to the player.
In the future, it will be able to also do tab list scores, and above name things. But right now, it can only do sidebar information.
func (*Scoreboard) SetLine ¶
func (s *Scoreboard) SetLine(line int32, text_chat *util.Chat)
Will set the given line to the text passed in. Will panic if
line < 1 || line > 15
func (*Scoreboard) SetTitle ¶
func (s *Scoreboard) SetTitle(new_title *util.Chat)
Sets the title above the scoreboard.
func (*Scoreboard) Show ¶
func (s *Scoreboard) Show()
Will start displaying the scoreboard to the player.