Skip to content

Commit

Permalink
Revert "Revert "Merge branch 'master' of ssh://github.com/RestartFU/d…
Browse files Browse the repository at this point in the history
…ragonfly""

This reverts commit 9c7fe4f.
  • Loading branch information
RestartFU committed Mar 6, 2024
1 parent 9c7fe4f commit d3fb958
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 37 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/df-mc/atomic v1.10.0
github.com/df-mc/goleveldb v1.1.9
github.com/df-mc/worldupgrader v1.0.11
github.com/df-mc/worldupgrader v1.0.12
github.com/go-gl/mathgl v1.1.0
github.com/google/uuid v1.4.0
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.11.0
github.com/sandertv/gophertunnel v1.34.1
github.com/sandertv/gophertunnel v1.35.0
github.com/segmentio/fasthash v1.0.3
github.com/sirupsen/logrus v1.9.3
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/df-mc/atomic v1.10.0 h1:0ZuxBKwR/hxcFGorKiHIp+hY7hgY+XBTzhCYD2NqSEg=
github.com/df-mc/atomic v1.10.0/go.mod h1:Gw9rf+rPIbydMjA329Jn4yjd/O2c/qusw3iNp4tFGSc=
github.com/df-mc/goleveldb v1.1.9 h1:ihdosZyy5jkQKrxucTQmN90jq/2lUwQnJZjIYIC/9YU=
github.com/df-mc/goleveldb v1.1.9/go.mod h1:+NHCup03Sci5q84APIA21z3iPZCuk6m6ABtg4nANCSk=
github.com/df-mc/worldupgrader v1.0.11 h1:7dlebxDXY8QND3MnDPnty7qeAqtxJE8kVqvs6VDs1YI=
github.com/df-mc/worldupgrader v1.0.11/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/df-mc/worldupgrader v1.0.12 h1:Ry6XkcwclSMfRPdiwcfSFRWqTkVglu0u3oLd0X2CxZ4=
github.com/df-mc/worldupgrader v1.0.12/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA=
github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
Expand Down Expand Up @@ -50,8 +50,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.34.1 h1:gRU9KVT8GewlSPRCn3sQNw6RbTGyd02yyXZOXyIjz+o=
github.com/sandertv/gophertunnel v1.34.1/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
github.com/sandertv/gophertunnel v1.35.0 h1:1QQ/FSvSBQ4nqYus7Br4ihDDoI6g+L4/4MYNpPrIDKs=
github.com/sandertv/gophertunnel v1.35.0/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
2 changes: 1 addition & 1 deletion server/block/decorated_pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (p DecoratedPot) BreakInfo() BreakInfo {

// MaxCount ...
func (DecoratedPot) MaxCount() int {
return 1
return 64
}

// EncodeItem ...
Expand Down
6 changes: 3 additions & 3 deletions server/block/ender_chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func (c EnderChest) open(w *world.World, pos cube.Pos) {
for _, v := range w.Viewers(pos.Vec3()) {
v.ViewBlockAction(pos, OpenAction{})
}
w.PlaySound(pos.Vec3Centre(), sound.ChestOpen{})
w.PlaySound(pos.Vec3Centre(), sound.EnderChestOpen{})
}

// close closes the ender chest, displaying the animation and playing a sound.
func (c EnderChest) close(w *world.World, pos cube.Pos) {
for _, v := range w.Viewers(pos.Vec3()) {
v.ViewBlockAction(pos, CloseAction{})
}
w.PlaySound(pos.Vec3Centre(), sound.ChestClose{})
w.PlaySound(pos.Vec3Centre(), sound.EnderChestClose{})
}

// EncodeNBT ...
Expand All @@ -113,7 +113,7 @@ func (c EnderChest) EncodeNBT() map[string]interface{} {

// DecodeNBT ...
func (c EnderChest) DecodeNBT(map[string]interface{}) interface{} {
return NewEnderChest()
return c
}

// EncodeItem ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/fire.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (f Fire) burn(from, to cube.Pos, w *world.World, r *rand.Rand, chanceBound
return
}
if t, ok := flammable.(TNT); ok {
t.Ignite(to, w)
t.Ignite(to, w, nil)
return
}
w.SetBlock(to, nil, nil)
Expand Down
19 changes: 13 additions & 6 deletions server/block/tnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@ import (
// TNT is an explosive block that can be primed to generate an explosion.
type TNT struct {
solid
igniter world.Entity
}

// Activate ...
func (t TNT) Activate(pos cube.Pos, _ cube.Face, w *world.World, u item.User, ctx *item.UseContext) bool {
held, _ := u.HeldItems()
if _, ok := held.Enchantment(enchantment.FireAspect{}); ok {
t.Ignite(pos, w)
t.Ignite(pos, w, u)
ctx.DamageItem(1)
return true
}
return false
}

// Ignite ...
func (t TNT) Ignite(pos cube.Pos, w *world.World) bool {
spawnTnt(pos, w, time.Second*4)
func (t TNT) Ignite(pos cube.Pos, w *world.World, igniter world.Entity) bool {
t.igniter = igniter
spawnTnt(pos, w, time.Second*4, t.igniter)
return true
}

// Igniter returns the entity that ignited the TNT.
func (t TNT) Igniter() world.Entity {
return t.igniter
}

// Explode ...
func (t TNT) Explode(_ mgl64.Vec3, pos cube.Pos, w *world.World, _ ExplosionConfig) {
spawnTnt(pos, w, time.Second/2+time.Duration(rand.Intn(int(time.Second+time.Second/2))))
spawnTnt(pos, w, time.Second/2+time.Duration(rand.Intn(int(time.Second+time.Second/2))), t.igniter)
}

// BreakInfo ...
Expand All @@ -59,8 +66,8 @@ func (t TNT) EncodeBlock() (name string, properties map[string]interface{}) {
}

// spawnTnt creates a new TNT entity at the given position with the given fuse duration.
func spawnTnt(pos cube.Pos, w *world.World, fuse time.Duration) {
func spawnTnt(pos cube.Pos, w *world.World, fuse time.Duration, igniter world.Entity) {
w.PlaySound(pos.Vec3Centre(), sound.TNT{})
w.SetBlock(pos, nil, nil)
w.AddEntity(w.EntityRegistry().Config().TNT(pos.Vec3Centre(), fuse))
w.AddEntity(w.EntityRegistry().Config().TNT(pos.Vec3Centre(), fuse, igniter))
}
2 changes: 1 addition & 1 deletion server/entity/projectile.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (lt *ProjectileBehaviour) Tick(e *Ent) *Movement {
case trace.BlockResult:
bpos := r.BlockPosition()
if t, ok := w.Block(bpos).(block.TNT); ok && e.OnFireDuration() > 0 {
t.Ignite(bpos, w)
t.Ignite(bpos, w, e)
}
if lt.conf.SurviveBlockCollision {
lt.hitBlockSurviving(e, r, m)
Expand Down
4 changes: 2 additions & 2 deletions server/entity/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var conf = world.EntityRegistryConfig{
FallingBlock: func(bl world.Block, pos mgl64.Vec3) world.Entity {
return NewFallingBlock(bl, pos)
},
TNT: func(pos mgl64.Vec3, fuse time.Duration) world.Entity {
return NewTNT(pos, fuse)
TNT: func(pos mgl64.Vec3, fuse time.Duration, igniter world.Entity) world.Entity {
return NewTNT(pos, fuse, igniter)
},
BottleOfEnchanting: func(pos, vel mgl64.Vec3, owner world.Entity) world.Entity {
b := NewBottleOfEnchanting(pos, owner)
Expand Down
14 changes: 9 additions & 5 deletions server/entity/tnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

// NewTNT creates a new primed TNT entity.
func NewTNT(pos mgl64.Vec3, fuse time.Duration) *Ent {
func NewTNT(pos mgl64.Vec3, fuse time.Duration, igniter world.Entity) *Ent {
config := tntConf
config.ExistenceDuration = fuse
ent := Config{Behaviour: config.New()}.New(TNTType{}, pos)
ent := Config{Behaviour: config.New()}.New(TNTType{igniter: igniter}, pos)

angle := rand.Float64() * math.Pi * 2
ent.vel = mgl64.Vec3{-math.Sin(angle) * 0.02, 0.1, -math.Cos(angle) * 0.02}
Expand All @@ -35,16 +35,20 @@ func explodeTNT(e *Ent) {
}

// TNTType is a world.EntityType implementation for TNT.
type TNTType struct{}
type TNTType struct {
igniter world.Entity
}

func (t TNTType) Igniter() world.Entity { return t.igniter }

func (TNTType) EncodeEntity() string { return "minecraft:tnt" }
func (TNTType) NetworkOffset() float64 { return 0.49 }
func (TNTType) BBox(world.Entity) cube.BBox {
return cube.Box(-0.49, 0, -0.49, 0.49, 0.98, 0.49)
}

func (TNTType) DecodeNBT(m map[string]any) world.Entity {
tnt := NewTNT(nbtconv.Vec3(m, "Pos"), nbtconv.TickDuration[uint8](m, "Fuse"))
func (t TNTType) DecodeNBT(m map[string]any) world.Entity {
tnt := NewTNT(nbtconv.Vec3(m, "Pos"), nbtconv.TickDuration[uint8](m, "Fuse"), t.igniter)
tnt.vel = nbtconv.Vec3(m, "Motion")
return tnt
}
Expand Down
7 changes: 6 additions & 1 deletion server/internal/blockinternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ type ComponentBuilder struct {
permutations map[string]map[string]any
properties []map[string]any
components map[string]any
blockID int32

identifier string
menuCategory category.Category
}

// NewComponentBuilder returns a new component builder with the provided block data, using the provided components map
// as a base.
func NewComponentBuilder(identifier string, components map[string]any) *ComponentBuilder {
func NewComponentBuilder(identifier string, components map[string]any, blockID int32) *ComponentBuilder {
if components == nil {
components = map[string]any{}
}
return &ComponentBuilder{
permutations: make(map[string]map[string]any),
components: components,
blockID: blockID,

identifier: identifier,
menuCategory: category.Construction(),
Expand Down Expand Up @@ -79,6 +81,9 @@ func (builder *ComponentBuilder) Construct() map[string]any {
"category": builder.menuCategory.String(),
"group": builder.menuCategory.Group(),
},
"vanilla_block_data": map[string]any{
"block_id": builder.blockID,
},
}
if len(properties) > 0 {
result["properties"] = properties
Expand Down
4 changes: 2 additions & 2 deletions server/internal/blockinternal/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

// Components returns all the components for the custom block, including permutations and properties.
func Components(identifier string, b world.CustomBlock) map[string]any {
func Components(identifier string, b world.CustomBlock, blockID int32) map[string]any {
components := componentsFromProperties(b.Properties())
builder := NewComponentBuilder(identifier, components)
builder := NewComponentBuilder(identifier, components, blockID)
if emitter, ok := b.(block.LightEmitter); ok {
builder.AddComponent("minecraft:block_light_emission", map[string]any{
"emission": float32(emitter.LightEmissionLevel() / 15),
Expand Down
4 changes: 3 additions & 1 deletion server/internal/iteminternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func (builder *ComponentBuilder) Construct() map[string]any {
// not modify the builder's properties map directly otherwise Empty() will return false in future use of the builder.
func (builder *ComponentBuilder) applyDefaultProperties(x map[string]any) {
x["minecraft:icon"] = map[string]any{
"texture": strings.Split(builder.identifier, ":")[1],
"textures": map[string]any{
"default": strings.Split(builder.identifier, ":")[1],
},
}
x["creative_group"] = builder.category.Group()
x["creative_category"] = int32(builder.category.Uint8())
Expand Down
4 changes: 2 additions & 2 deletions server/item/fire_charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (f FireCharge) EncodeItem() (name string, meta int16) {
}

// UseOnBlock ...
func (f FireCharge) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
if l, ok := w.Block(pos).(ignitable); ok && l.Ignite(pos, w) {
func (f FireCharge) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, u User, ctx *UseContext) bool {
if l, ok := w.Block(pos).(ignitable); ok && l.Ignite(pos, w, u) {
ctx.SubtractFromCount(1)
w.PlaySound(pos.Vec3Centre(), sound.FireCharge{})
return true
Expand Down
6 changes: 3 additions & 3 deletions server/item/flint_and_steel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func (f FlintAndSteel) DurabilityInfo() DurabilityInfo {
// ignitable represents a block that can be lit by a fire emitter, such as flint and steel.
type ignitable interface {
// Ignite is called when the block is lit by flint and steel.
Ignite(pos cube.Pos, w *world.World) bool
Ignite(pos cube.Pos, w *world.World, igniter world.Entity) bool
}

// UseOnBlock ...
func (f FlintAndSteel) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
func (f FlintAndSteel) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, u User, ctx *UseContext) bool {
ctx.DamageItem(1)
if l, ok := w.Block(pos).(ignitable); ok && l.Ignite(pos, w) {
if l, ok := w.Block(pos).(ignitable); ok && l.Ignite(pos, w, u) {
return true
} else if s := pos.Side(face); w.Block(s) == air() {
w.PlaySound(s.Vec3Centre(), sound.Ignite{})
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (srv *Server) makeBlockEntries() {
name, _ := b.EncodeBlock()
srv.customBlocks[i] = protocol.BlockEntry{
Name: name,
Properties: blockinternal.Components(name, b),
Properties: blockinternal.Components(name, b, 10000+int32(i)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/session/enchantment_texts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/session/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ func (s *Session) playSound(pos mgl64.Vec3, t world.Sound, disableRelative bool)
pk.SoundType = packet.SoundEventChestClosed
case sound.ChestOpen:
pk.SoundType = packet.SoundEventChestOpen
case sound.EnderChestClose:
pk.SoundType = packet.SoundEventEnderChestClosed
case sound.EnderChestOpen:
pk.SoundType = packet.SoundEventEnderChestOpen
case sound.BarrelClose:
pk.SoundType = packet.SoundEventBarrelClose
case sound.BarrelOpen:
Expand Down
Binary file modified server/world/block_states.nbt
Binary file not shown.
2 changes: 1 addition & 1 deletion server/world/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type EntityRegistry struct {
type EntityRegistryConfig struct {
Item func(it any, pos, vel mgl64.Vec3) Entity
FallingBlock func(bl Block, pos mgl64.Vec3) Entity
TNT func(pos mgl64.Vec3, fuse time.Duration) Entity
TNT func(pos mgl64.Vec3, fuse time.Duration, igniter Entity) Entity
BottleOfEnchanting func(pos, vel mgl64.Vec3, owner Entity) Entity
Arrow func(pos, vel mgl64.Vec3, rot cube.Rotation, damage float64, owner Entity, critical, disallowPickup, obtainArrowOnPickup bool, punchLevel int, tip any) Entity
Egg func(pos, vel mgl64.Vec3, owner Entity) Entity
Expand Down
6 changes: 6 additions & 0 deletions server/world/sound/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type ChestOpen struct{ sound }
// ChestClose is played when a chest is closed.
type ChestClose struct{ sound }

// EnderChestOpen is played when a ender chest is opened.
type EnderChestOpen struct{ sound }

// EnderChestClose is played when a ender chest is closed.
type EnderChestClose struct{ sound }

// BarrelOpen is played when a barrel is opened.
type BarrelOpen struct{ sound }

Expand Down

0 comments on commit d3fb958

Please sign in to comment.