Skip to content

Commit

Permalink
dragonfly: Finish custom block implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Nov 3, 2023
1 parent cbdfa9b commit 273b125
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 530 deletions.
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package main
import (
"fmt"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/block"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/item/creative"
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/dragonfly/server/player/chat"
"github.com/df-mc/dragonfly/server/world"
"github.com/pelletier/go-toml"
"github.com/sirupsen/logrus"
"os"
Expand All @@ -21,11 +27,19 @@ func main() {
log.Fatalln(err)
}

for _, direction := range cube.Directions() {
world.RegisterBlock(block.Pig{Facing: direction})
}
world.RegisterItem(block.Pig{})
creative.RegisterItem(item.NewStack(block.Pig{}, 1))

srv := conf.New()
srv.CloseOnProgramEnd()

srv.Listen()
for srv.Accept(nil) {
for srv.Accept(func(p *player.Player) {
p.Inventory().AddItem(item.NewStack(block.Pig{}, 64))
}) {
}
}

Expand Down
41 changes: 4 additions & 37 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/block/customblock"
"github.com/df-mc/dragonfly/server/block/model"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
Expand Down Expand Up @@ -42,13 +43,6 @@ type LightEmitter interface {
LightEmissionLevel() uint8
}

// PermutableLightEmitter represents a permutable custom block that emits light when placed.
type PermutableLightEmitter interface {
// LightEmissionLevel returns the light emission level of the block, a number from 0-15 where 15 is the
// brightest and 0 means it doesn't emit light at all.
LightEmissionLevel() (uint8, bool, map[string]uint8)
}

// LightDiffuser represents a block that diffuses light. This means that a specific amount of light levels
// will be subtracted when light passes through the block.
// Blocks that do not implement LightDiffuser will be assumed to be solid: Light will not be able to pass
Expand All @@ -60,14 +54,6 @@ type LightDiffuser interface {
LightDiffusionLevel() uint8
}

// PermutableLightDiffuser represents a permutable custom block that diffuses light.
type PermutableLightDiffuser interface {
// LightDiffusionLevel returns the amount of light levels that is subtracted when light passes through
// this block. Some blocks, such as leaves, have this behaviour. A diffusion level of 15 means that all
// light will be completely blocked when it passes through the block.
LightDiffusionLevel() (uint8, bool, map[string]uint8)
}

// Replaceable represents a block that may be replaced by another block automatically. An example is grass,
// which may be replaced by clicking it with another block.
type Replaceable interface {
Expand Down Expand Up @@ -95,22 +81,9 @@ type Frictional interface {
Friction() float64
}

// PermutableFrictional represents a permutable custom block that may have a custom friction value.
type PermutableFrictional interface {
// Friction returns the block's friction value.
Friction() (float64, bool, map[string]float64)
}

// Rotatable represents a custom block that may be rotated.
type Rotatable interface {
// Rotation returns the rotation of the block as an mgl64.Vec3.
Rotation() mgl64.Vec3
}

// PermutableRotatable represents a permutable custom block that may be rotated.
type PermutableRotatable interface {
// Rotation returns the rotation of the block as an mgl64.Vec3.
Rotation() (mgl64.Vec3, bool, map[string]mgl64.Vec3)
type Permutable interface {
States() map[string][]any
Permutations() []customblock.Permutation
}

func calculateFace(user item.User, placePos cube.Pos) cube.Face {
Expand Down Expand Up @@ -247,12 +220,6 @@ type Flammable interface {
FlammabilityInfo() FlammabilityInfo
}

// PermutableFlammable is an interface for permutable custom blocks that can catch on fire.
type PermutableFlammable interface {
// FlammabilityInfo returns information about a block's behavior involving fire.
FlammabilityInfo() (FlammabilityInfo, bool, map[string]FlammabilityInfo)
}

// FlammabilityInfo contains values related to block behaviors involving fire.
type FlammabilityInfo struct {
// Encouragement is the chance a block will catch on fire during attempted fire spread.
Expand Down
6 changes: 0 additions & 6 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ type Breakable interface {
BreakInfo() BreakInfo
}

// PermutableBreakable represents a permutable custom block that may be broken by a player in survival mode.
type PermutableBreakable interface {
// BreakInfo returns information of the block related to the breaking of it.
BreakInfo() (BreakInfo, bool, map[string]BreakInfo)
}

// BreakDuration returns the base duration that breaking the block passed takes when being broken using the
// item passed.
func BreakDuration(b world.Block, i item.Stack) time.Duration {
Expand Down
95 changes: 0 additions & 95 deletions server/block/customblock/geometry.go

This file was deleted.

14 changes: 3 additions & 11 deletions server/block/customblock/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type Material struct {
// occlusion based on the render method given.
func NewMaterial(texture string, method Method) Material {
return Material{
faceDimming: true,
texture: texture,
renderMethod: method,
faceDimming: true,
ambientOcclusion: method.AmbientOcclusion(),
}
}
Expand Down Expand Up @@ -52,15 +52,7 @@ func (m Material) Encode() map[string]any {
return map[string]any{
"texture": m.texture,
"render_method": m.renderMethod.String(),
"face_dimming": boolByte(m.faceDimming),
"ambient_occlusion": boolByte(m.ambientOcclusion),
}
}

// boolByte returns 1 if the bool passed is true, or 0 if it is false.
func boolByte(b bool) uint8 {
if b {
return 1
"face_dimming": m.faceDimming,
"ambient_occlusion": m.ambientOcclusion,
}
return 0
}
51 changes: 0 additions & 51 deletions server/block/customblock/model.go

This file was deleted.

23 changes: 23 additions & 0 deletions server/block/customblock/permutations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package customblock

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/go-gl/mathgl/mgl64"
)

type Properties struct {
CollisionBox cube.BBox
Cube bool
Geometry string
MapColour string
Rotation cube.Pos
Scale mgl64.Vec3
SelectionBox cube.BBox
Textures map[string]Material
Translation mgl64.Vec3
}

type Permutation struct {
Properties
Condition string
}
Loading

0 comments on commit 273b125

Please sign in to comment.