player

package
v0.0.0-...-2a33acd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

func CanHarvest(tool_level int32, block_type string) bool

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

func GetBaseToolMultiplier(tool string) int32

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

func GetBlockHardness(block_type string) float32

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

func GetToolLevel(tool string) int32

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

func GetUUIDFromName(name string) *util.UUID

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

func ToolIsCorrectType(tool, block string) bool

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

func (p *Player) AxisFacing() block.Face

This will return a block face, which is one of north, south, east or west, depending on the player's yaw.

func (*Player) BlockX

func (p *Player) BlockX() int32

Will get X coordinate of the block they are standing in.

func (*Player) BlockY

func (p *Player) BlockY() int32

Will get Y coordinate of the block they are standing in. This is their feet position, not their eye position.

func (*Player) BlockZ

func (p *Player) BlockZ() int32

Will get Z coordinate of the block they are standing in.

func (*Player) ChunkX

func (p *Player) ChunkX() int32

Will get the X coordinate of the chunk they are in.

func (*Player) ChunkZ

func (p *Player) ChunkZ() int32

Will get the Z coordinate of the chunk they are in.

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

func (p *Player) DX() int16

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

func (p *Player) DY() int16

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

func (p *Player) DZ() int16

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

func (p *Player) Damage(amount float32)

Call this to damage the player. Amount is the number health (half hearts) to take away from their health.

func (*Player) Equipment

func (p *Player) Equipment() map[int]*item.Stack

Gets the equipment for the player (held items/armor. Things that are visible to other players)

func (*Player) Gamemode

func (p *Player) Gamemode() byte

Gets the player's gamemode.

0 -> survival
1 -> creative
2 -> adventure
3 -> spectator

func (*Player) HandleKeepAlive

func (p *Player) HandleKeepAlive(keep_alive_id int32)

Used whenever the client sends a keep alive packet. Should never be called.

func (*Player) Height

func (p *Player) Height() float64

func (*Player) Hit

func (p *Player) Hit(other entity.Entity)

Called when a player hits something

func (*Player) ImmuneToAttacks

func (p *Player) ImmuneToAttacks() bool

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) Name

func (p *Player) Name() string

Gets the player's username.

func (*Player) NeedsEquipmentChange

func (p *Player) NeedsEquipmentChange() bool

Used to check if an equipment change packet is needed

func (*Player) NeedsPositionSet

func (p *Player) NeedsPositionSet() bool

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

func (p *Player) NeedsRotUpdate() bool

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

func (p *Player) NeedsTeleport() bool

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) OnGround

func (p *Player) OnGround() bool

Gets whether or not the player is on the ground.

func (*Player) Pitch

func (p *Player) Pitch() float32

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

func (p *Player) PitchAngle() float64

Gets the player's pitch rotation in radians.

func (*Player) PitchByte

func (p *Player) PitchByte() byte

Gets the player's pitch rotation. This is how much they are rotated on the Y axis, from -64 to 64.

func (*Player) PrevBlockX

func (p *Player) PrevBlockX() int32

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

func (p *Player) PrevBlockY() int32

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

func (p *Player) PrevBlockZ() int32

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

func (p *Player) PrevChunkX() int32

Will get the X coordinate of the chunk they were in during the previous tick.

func (*Player) PrevChunkZ

func (p *Player) PrevChunkZ() int32

Will get the Z coordinate of the chunk they were in during the previous tick.

func (*Player) PrevX

func (p *Player) PrevX() float64

func (*Player) PrevY

func (p *Player) PrevY() float64

func (*Player) PrevZ

func (p *Player) PrevZ() float64

func (*Player) Respawn

func (p *Player) Respawn()

func (*Player) SendChat

func (p *Player) SendChat(chat *util.Chat)

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) SendTitle

func (p *Player) SendTitle(title, subtitle *util.Chat, fadein, stay, fadeout int)

func (*Player) SendToServer

func (p *Player) SendToServer(ip string)

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

func (p *Player) SetAbilities(value byte)

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) SetCanFly

func (p *Player) SetCanFly(value bool)

Sets whether or not the player can fly.

func (*Player) SetFlySpeed

func (p *Player) SetFlySpeed(value float32)

Sets the fly speed. This is a multiplier, not the actually value. So 1 is the base fly speed.

func (*Player) SetGamemode

func (p *Player) SetGamemode(value byte) error

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) SetHealth

func (p *Player) SetHealth(val float32)

func (*Player) SetIsFlying

func (p *Player) SetIsFlying(value bool)

Sets whether or not the player is flying. Used internally when the player sends a packet to start/stop flying.

func (*Player) SetOnGround

func (p *Player) SetOnGround(on_ground bool)

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

func (p *Player) SetRotation(yaw float32, pitch float32)

This updates the player's rotation. This is used internally when they send rotation update packets. Should never be called.

func (*Player) Sneak

func (p *Player) Sneak(sneak bool)

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

func (p *Player) SpawnParticleDust(x, y, z float64, r, g, b float32, scale float32)

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

func (p *Player) Teleport(x, y, z float64)

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

func (p *Player) Time() int

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

func (p *Player) TimeToBreakBlock(block_type string) int32

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

func (p *Player) Version() packet.Version

This is the protocol version that this player is using. Used when generating chunk packets.

func (*Player) Width

func (p *Player) Width() float64

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

func (p *Player) Yaw() float32

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

func (*Player) YawAngle

func (p *Player) YawAngle() float64

Gets the player's yaw rotation in radians.

func (*Player) YawByte

func (p *Player) YawByte() byte

Gets the player's yaw rotation. This is how much they are rotated on the X axis, from 0 to 256

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) Clear

func (s *Scoreboard) Clear()

This sets all lines to be blank.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL