Categorygithub.com/df-mc/npc
modulepackage
1.0.4
Repository: https://github.com/df-mc/npc.git
Documentation: pkg.go.dev

# README

npc

NPC library for Dragonfly.

Getting started

The NPC library may be imported using go get:

go get github.com/df-mc/npc

Usage

Go Reference

Usage of the NPC library is simple. It relies on the Create method:

// var w *world.World

settings := npc.Settings{
    Name: "Example NPC",
    Scale: 2,
    Position: mgl64.Vec3{1, 2, 3},
    Skin   ...,
}
p := npc.Create(settings, w, nil)
p.SwingArm()

Instead of nil, an npc.HandlerFunc may be passed to handle the NPC being hit by other players.

Note that the npc.Settings passed initially may be overwritten by calling methods on the *player.Player returned by npc.Create().

The NPC library also contains convenience functions for reading/parsing skin data from files. The npc.Skin(), npc.*Model() and npc.*Texture() functions may be used to do so.

# Functions

Create creates a new NPC with the Settings passed.
MustParseModel parses a Model from a JSON file at a specific path.
MustParseTexture parses a Texture from an image file at a specific path.
MustSkin creates a new skin.Skin using the Texture and Model passed.
ParseModel parses a Model from a JSON file at a specific path.
ParseTexture parses a Texture from an image file at a specific path.
ReadModel parses a JSON model from a file at a path passed and returns a Model.
ReadTexture parses a skin texture from the path passed and returns a Texture struct with data, where each pixel is represented by 4 bytes.
Skin creates a new skin.Skin using the Texture and Model passed.

# Variables

DefaultModel is a Model for a default custom skin.

# Structs

Model is the model of a skin.Skin parsed with ParseModel or ReadModel.
Settings holds different NPC settings such as the NPC's name, skin, position, etc.
Texture is the texture of a skin.Skin parsed with ParseTexture or ReadTexture.

# Type aliases

HandlerFunc may be passed to Create to handle a *player.Player attacking an NPC.