glowstone

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 12 Imported by: 0

README

Glowstone

Glowstone

Glowstone is a Golang library for reading and writing Minecraft Bedrock Edition addon.

Setup

Make sure you have installed Go with minimum version of 1.19.

To enable multiple workspace of go, you need to create a file go.work in your workspace.

$ go work init

Let's say you want to create go workspace at ./scripts/dummy_entity

$ mkdir ./scripts/dummy_entity
$ cd ./scripts/dummy_entity
$ go mod init dummy_entity
$ go get github.com/respectZ/glowstone

Create main.go in the ./scripts/dummy_entity directory with the following contents:

package main

import (
  "github.com/respectZ/glowstone"
)

func main() {
  project := glowstone.NewProject()

  // Set your RP and BP path.
  // Below is the default value.
  project.BP.Path = filepath.Join("packs", "BP")
  project.RP.Path = filepath.Join("packs", "RP")

  // Do something here before saving

  project.Save()
}

Add the project into go.work

<!-- Back to your workspace -->
$ cd ../../
$ go work use ./scripts/dummy_entity

To execute your scripts from workspace:

$ go run ./scripts/dummy_entity/

Example

package main

import (
  "path/filepath"
  "github.com/respectZ/glowstone"
  component "github.com/respectZ/glowstone/bp/entity/component"
)

func main() {
  // Create a project workspace.
  project := glowstone.NewProject()

  // Set your RP and BP path.
  // Below is the default value.
  project.BP.Path = filepath.Join("packs", "BP")
  project.RP.Path = filepath.Join("packs", "RP")

  // Preload BP and RP packs from the path.
  // Warning: this is unstable and may cause some errors for some compabilities.
  // This isn't necessary if you didn't need any read operation.
  project.Preload()

  NewEntity(project, "glowstone:chair")

  project.Save()
}

func NewEntity(project *glowstone.Project, identifier string) {
  bpFile, rpFile := project.NewEntity(identifier)
  bp := bpFile.Data
  rp := rpFile.Data

  rp.Entity.Description.Textures.Add("default", "textures/items/blaze_rod")

  bp.Entity.Description.IsSpawnable = false
    bp.Entity.ComponentGroups.Add("despawn", &component.InstantDespawn{})

  ev := bp.Entity.Events.New("glowstone:despawn")
    ev.Add.ComponentGroups.Add("despawn")
}

Todo

  • BP

    • Animation
    • Animation Controller
    • Block
    • Entity
    • Item
    • Loot Table
    • Recipe
    • Spawn Rule
    • Structure
  • RP

    • Animation Controller
    • Animation
    • Attachable
    • Entity
    • Fog
    • Material
    • Model
    • Particle
    • Render Controller
    • Item Texture
    • sounds.json
    • sound_definitions.json
    • blocks.json
    • terrain_textures.json
  • Misc

    • Make a field for saving filename, since it will duplicate if thee filename doesn't match with the identifier.
    • Rework project fields, glowstone.NewBPAnimationController -> glowstone.BP.AnimationController.New("asdf")
    • Remove unnecessary pointer
    • Add project setting to minify JSON
    • Add format version setting, especially for item, block, and entity
  • Util

    • BBModel Parser
  • Documentation

  • Format Version

    • Item
    • Block
    • Entity (RP)
    • Blocks (RP)
    • Attachable (RP)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZeroValue = values{false, 0, 0.0}

Functions

This section is empty.

Types

type IMiddlewares added in v0.0.11

type IMiddlewares interface {
	Apply(*Project) error
	All() []Middleware
	Add(Middleware)
}

type Middleware added in v0.0.11

type Middleware func(*Project) error

type Middlewares added in v0.0.11

type Middlewares []Middleware

func (*Middlewares) Add added in v0.0.11

func (m *Middlewares) Add(f Middleware)

func (Middlewares) All added in v0.0.11

func (m Middlewares) All() []Middleware

func (Middlewares) Apply added in v0.0.11

func (m Middlewares) Apply(g *Project) error

type Project added in v0.0.11

type Project struct {
	// Logger
	Logger *logger

	// Contains Behavior Pack data.
	BP *bp.GlowstoneBP

	// Contains Resource Pack data.
	RP *rp.GlowstoneRP

	// Middlewares
	//
	// Contains functions that will be executed before saving the project.
	//
	// Example:
	//
	//	g := glowstone.NewProjectV2()
	//	func entity_WriteLang(g *Project) error {
	// 		// code
	//		return nil
	//	}
	//	g.Middlewares.Add(entity_WriteLang)
	Middlewares IMiddlewares
}

func NewProject

func NewProject() *Project

func (*Project) NewEntity added in v0.0.11

func (g *Project) NewEntity(identifier string) (*bp.EntityFile, *rp.EntityFile)

Create a new entity (BP and RP).

Returns BPFile and RPFile of the entity, which contain additional fields along with the entity.

Example:

bp, rp := g.NewEntity("glostone:diamond_sword")

func (*Project) Preload added in v0.0.11

func (g *Project) Preload()

Preload loads all files from the project.

func (*Project) Save added in v0.0.11

func (g *Project) Save()

type Settings added in v0.0.8

type Settings struct {
	MinifyJSON    bool
	FormatVersion *SettingsFormatVersion
}

type SettingsFormatVersion added in v0.0.8

type SettingsFormatVersion struct {
	BlockBP  string
	ItemBP   string
	EntityBP string

	EntityRP     string
	BlocksRP     [3]int
	AttachableRP string
}

Jump to

Keyboard shortcuts

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