Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Operator Functions

EmosewaPixel edited this page Nov 9, 2019 · 2 revisions

Overview

For writing shorter code, PixelLib adds a couple of operator extensions functions to commonly-used class. Since destructuring components are also counted as operator functions, they're listed here as well.

Vectors

PixelLib adds operator functions to Vec3i, Vector3f, Vector4f and Vec3d, as well as an infix function for cross products for all but Vector4f.

val vec1 = Vec3d(1.5, 2.7, -1.9)
val vec2 = Vec3d(16.1, -29.4, 9.2)

val sum = vec1 + vec2
val diff = vec1 - vec2
val product = vec1 * vec2
val q = vec1 / vec2
val cross = vec1 x vec2
val neg1 = -vec1

for ((x, _, z) in listOf(vec1, vec2)) {
    ...        
}

Stacks

PixelLib lets you easily create Item and Fluid Stacks adds destructure them.

val itemStack1 = Items.COAL * 5
val fluidStack1 = Fluids.LAVA * 420

val (item, countI) = itemStack1
val (fluid, countF) = fluidStack1

Resource Locations

PixelLib adds destructuring to Resource Locations and a plus operator for adding to the path. It also lets you easily convert a string into a Resource Location.

val (namespace, path) = "test:block/machine".toResLoc() + "/crusher"

Clone this wiki locally