resource

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockState

type BlockState struct {
	// String is a list of properties that should be matched.
	// For example, `snowy=true` would match all variants of grass
	// that are snowy. An empty string matches everything.
	Variants map[string][]*BlockStateVariant `json:"variants"`
}

A blockstate in a resource pack. Example:

wall_torch.json
{
  "variants": {
    "facing=east":  [{"model": "block/wall_torch"}],
    "facing=south": [{"model": "block/wall_torch", "y": 90}],
    "facing=west":  [{"model": "block/wall_torch", "y": 180}],
    "facing=north": [{"model": "block/wall_torch", "y": 270}]
  }
}

type BlockStateVariant

type BlockStateVariant struct {
	// Path to the json model that should be used
	// for this variant
	Model string `json:"model"`

	// Rotation for the model. Only valid in 90 degree increments.
	X int `json:"x"`
	Y int `json:"y"`

	// If true, then the texture will not rotate with the model.
	UVLock bool `json:"uvlock"`

	// Probabilty that this model will be used. Defaults to 1 (100%).
	// If multiple models are specified, then the one that is
	// chosen will be based on this weight.
	Weight float32 `json:"weight"`
}

type Model

type Model struct {
	// Parent model to load.
	Parent string `json:"parent"`

	// Whether or not to enable ambient occlusion. Defaults to true.
	AmbientOcclusion bool `json:"ambientocclusion"`

	// List of models to use.
	Elements []struct {
		// Minimum position within the block. Coordinates are 0-16,
		// where 16 is one block.
		From []float32 `json:"from"`

		// Maximum position within the block. Coordinates are 0-16,
		// where 16 is one block.
		To []float32 `json:"to"`

		// Whether or not to shade this part of the model. Defaults to true.
		Shade bool `json:"shade"`

		// The way in which this element should be rotated.
		Rotation struct {
			// Origin point for rotation
			Origin []int `json:"origin"`

			// One of 'x', 'y', 'z'
			Axis string `json:"axis"`

			// Rotation angle. Can be from 45 to -45, in 22.5 degree increments.
			Angle float32 `json:"angle"`

			// Set to scale the face across the whole block.
			Rescale bool `json:"rescale"`
		}

		// List of faces to render on this model.
		Faces map[string]struct {
			// UV coordinates for this face
			UV []int `json:"uv"`

			// Texture name to use
			Texture string `json:"texture"`

			// Can be one of 'up', 'down', 'north', 'south', 'east', 'west'.
			// If there is a solid block in that direction, then this face will not
			// be rendered.
			Cullface string `json:"cullface"`

			// Rotates the texture in 90 degree increments.
			Rotation int `json:"rotation"`

			// Is unclear what this does. Only affects some blocks.
			TintIndex int `json:"tintindex"`
		} `json:"faces"`
	} `json:"elements"`

	// List of texture variables to texture paths.
	// Defining the variable 'particle' will set the particle
	// texture to use.
	Textures map[string]string
}

Json block/entity model. Used in resource packs. Example:

{
  "ambientocclusion": false,
  "textures": {
    "particle": "#torch"
  },
  "elements": [
    {
      "from": [ 7, 0, 7 ],
      "to": [ 9, 10, 9 ],
      "shade": false,
      "faces": {
        "down": { "uv": [ 7, 13, 9, 15 ], "texture": "#torch" },
        "up":   { "uv": [ 7,  6, 9,  8 ], "texture": "#torch" }
      }
    },
    {
      "from": [ 7, 0, 0 ],
      "to": [ 9, 16, 16 ],
      "shade": false,
      "faces": {
        "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#torch" },
        "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#torch" }
      }
    },
    {
      "from": [ 0, 0, 7 ],
      "to": [ 16, 16, 9 ],
      "shade": false,
      "faces": {
        "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#torch" },
        "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#torch" }
      }
    }
  ]
}

type Pack

type Pack struct {
	// contains filtered or unexported fields
}

func NewPack

func NewPack() *Pack

This creates an empty resource pack.

func (*Pack) AddBlockState

func (p *Pack) AddBlockState(name string, bs *BlockState)

This adds the given blockstate to the resource pack. When the resource pack is generated, it will be converted to json.

Name is just the name of the block. For example, if you want to set the blockstates of 'grass_block', name should be 'grass_block'. This will be expanded to the path 'assets/minecraft/blockstates/grass_block.json'.

func (*Pack) AddModel

func (p *Pack) AddModel(name string, model *Model)

This adds the given blockstate to the resource pack. When the resource pack is generated, it will be converted to json.

Name is just the name of the model. For example, if you want to set the model of grass_block, name should be 'block/grass_block'. This will be expanded to the path 'assets/minecraft/models/block/grass_block.json'.

func (*Pack) AddTexture

func (p *Pack) AddTexture(name, path string) error

This will load an image from path, and add it to the resource pack. The name is the path of the image in the resource pack, without the namespace. For example, the creeper texture is located here: 'assets/minecraft/textures/entity/creeper.png'. If you wanted to overwrite the creeper texture, you would pass in 'entity/creeper' for the name field.

func (*Pack) AddTextureImage

func (p *Pack) AddTextureImage(name string, texture image.Image)

This adds the image as an overwrite in the resource pack. The name is in the same format as AddTexture().

func (*Pack) Generate

func (p *Pack) Generate() ([]byte, error)

Generates a zip file, which is a minecraft resource pack. This filesystem is generated every time you call this function, so you will always get a unique pointer for each call. It is also very slow.

Jump to

Keyboard shortcuts

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