Skip to content

Commit

Permalink
Merge branch 'master' into feature/dynamichashes
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Mar 14, 2024
2 parents 7969cf7 + fd85a55 commit d5b4b60
Show file tree
Hide file tree
Showing 34 changed files with 1,055 additions and 157 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.12
github.com/df-mc/worldupgrader v1.0.13
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.35.0
github.com/sandertv/gophertunnel v1.36.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.12 h1:Ry6XkcwclSMfRPdiwcfSFRWqTkVglu0u3oLd0X2CxZ4=
github.com/df-mc/worldupgrader v1.0.12/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/df-mc/worldupgrader v1.0.13 h1:97oSr83cHvU2j7iA7iPG6e+wWoGRCQ15c0H1U3q+bVM=
github.com/df-mc/worldupgrader v1.0.13/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.35.0 h1:1QQ/FSvSBQ4nqYus7Br4ihDDoI6g+L4/4MYNpPrIDKs=
github.com/sandertv/gophertunnel v1.35.0/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
github.com/sandertv/gophertunnel v1.36.0 h1:VF2znM3FFUkPqOVnOeH0KgM5iI167AzSB2oqLxrn2F4=
github.com/sandertv/gophertunnel v1.36.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
8 changes: 5 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,9 @@ func (c EnderChest) EncodeNBT() map[string]interface{} {

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

// 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
4 changes: 2 additions & 2 deletions server/block/grass.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (Grass) CompostChance() float64 {

// EncodeItem ...
func (Grass) EncodeItem() (name string, meta int16) {
return "minecraft:grass", 0
return "minecraft:grass_block", 0
}

// EncodeBlock ...
func (Grass) EncodeBlock() (string, map[string]any) {
return "minecraft:grass", nil
return "minecraft:grass_block", nil
}

// Till ...
Expand Down
18 changes: 2 additions & 16 deletions server/block/leaves.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,7 @@ func (Leaves) CompostChance() float64 {

// EncodeItem ...
func (l Leaves) EncodeItem() (name string, meta int16) {
switch l.Wood {
case OakWood(), SpruceWood(), BirchWood(), JungleWood():
return "minecraft:leaves", int16(l.Wood.Uint8())
case AcaciaWood(), DarkOakWood():
return "minecraft:leaves2", int16(l.Wood.Uint8() - 4)
default:
return "minecraft:" + l.Wood.String() + "_leaves", 0
}
return "minecraft:" + l.Wood.String() + "_leaves", 0
}

// LightDiffusionLevel ...
Expand All @@ -130,14 +123,7 @@ func (Leaves) SideClosed(cube.Pos, cube.Pos, *world.World) bool {

// EncodeBlock ...
func (l Leaves) EncodeBlock() (name string, properties map[string]any) {
switch l.Wood {
case OakWood(), SpruceWood(), BirchWood(), JungleWood():
return "minecraft:leaves", map[string]any{"old_leaf_type": l.Wood.String(), "persistent_bit": l.Persistent, "update_bit": l.ShouldUpdate}
case AcaciaWood(), DarkOakWood():
return "minecraft:leaves2", map[string]any{"new_leaf_type": l.Wood.String(), "persistent_bit": l.Persistent, "update_bit": l.ShouldUpdate}
default:
return "minecraft:" + l.Wood.String() + "_leaves", map[string]any{"persistent_bit": l.Persistent, "update_bit": l.ShouldUpdate}
}
return "minecraft:" + l.Wood.String() + "_leaves", map[string]any{"persistent_bit": l.Persistent, "update_bit": l.ShouldUpdate}
}

// allLogs returns a list of all possible leaves states.
Expand Down
7 changes: 1 addition & 6 deletions server/block/slab_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ func encodeSlabBlock(block world.Block) (id, slabType string, meta int16) {
}
return "red_nether_brick", "stone_slab_type_2", 7
case Planks:
switch block.Wood {
case OakWood(), SpruceWood(), BirchWood(), JungleWood(), AcaciaWood(), DarkOakWood():
return block.Wood.String(), "wood_type", int16(block.Wood.Uint8())
default:
return block.Wood.String(), "", 0
}
return block.Wood.String(), "", 0
case PolishedBlackstoneBrick:
if !block.Cracked {
return "polished_blackstone_brick", "", 0
Expand Down
20 changes: 14 additions & 6 deletions server/block/tnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,36 @@ 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.
// It is nil if ignited by a world source like fire.
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 +67,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))
}
10 changes: 4 additions & 6 deletions server/block/wood.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func (w Wood) Strip() (world.Block, bool) {
// EncodeItem ...
func (w Wood) EncodeItem() (name string, meta int16) {
switch w.Wood {
case OakWood(), SpruceWood(), BirchWood(), JungleWood(), AcaciaWood(), DarkOakWood():
if w.Stripped {
return "minecraft:wood", int16(8 + w.Wood.Uint8())
}
return "minecraft:wood", int16(w.Wood.Uint8())
case CrimsonWood(), WarpedWood():
if w.Stripped {
return "minecraft:stripped_" + w.Wood.String() + "_hyphae", 0
Expand All @@ -92,7 +87,10 @@ func (w Wood) EncodeItem() (name string, meta int16) {
func (w Wood) EncodeBlock() (name string, properties map[string]any) {
switch w.Wood {
case OakWood(), SpruceWood(), BirchWood(), JungleWood(), AcaciaWood(), DarkOakWood():
return "minecraft:wood", map[string]any{"wood_type": w.Wood.String(), "pillar_axis": w.Axis.String(), "stripped_bit": boolByte(w.Stripped)}
if w.Stripped {
return "minecraft:stripped_" + w.Wood.String() + "_wood", map[string]any{"pillar_axis": w.Axis.String()}
}
return "minecraft:" + w.Wood.String() + "_wood", map[string]any{"pillar_axis": w.Axis.String()}
case CrimsonWood(), WarpedWood():
if w.Stripped {
return "minecraft:stripped_" + w.Wood.String() + "_hyphae", map[string]any{"pillar_axis": w.Axis.String()}
Expand Down
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
16 changes: 11 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,22 @@ func explodeTNT(e *Ent) {
}

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

// Igniter returns the entity that ignited the TNT.
// It is nil if ignited by a world source like fire.
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
Binary file modified server/item/creative/creative_items.nbt
Binary file not shown.
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
Binary file modified server/item/recipe/crafting_data.nbt
Binary file not shown.
44 changes: 30 additions & 14 deletions server/item/recipe/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"math"
)

// Item represents an item that can be used as either the input or output of an item. These do not
// necessarily resolve to an actual item, but can be just as simple as a tag etc.
type Item interface {
// Count returns the amount of items that is present on the stack. The count is guaranteed never to be
// negative.
Count() int
// Empty checks if the stack is empty (has a count of 0).
Empty() bool
}

// inputItems is a type representing a list of input items, with helper functions to convert them to
type inputItems []struct {
// Name is the name of the item being inputted.
Expand All @@ -20,26 +30,32 @@ type inputItems []struct {
Properties map[string]interface{} `nbt:"states"`
Version int32 `nbt:"version"`
} `nbt:"block"`
// Tag is included if the input item is defined by a tag instead of a specific item.
Tag string `nbt:"tag"`
}

// Stacks converts input items to item stacks.
func (d inputItems) Stacks() ([]item.Stack, bool) {
s := make([]item.Stack, 0, len(d))
// Items converts input items to recipe items.
func (d inputItems) Items() ([]Item, bool) {
s := make([]Item, 0, len(d))
for _, i := range d {
it, ok := world.ItemByName(i.Name, int16(i.Meta))
if !ok {
return nil, false
}
if b, ok := world.BlockByName(i.State.Name, i.State.Properties); ok {
if it, ok = b.(world.Item); !ok {
if i.Tag != "" {
s = append(s, NewItemTag(i.Tag, int(i.Count)))
} else {
it, ok := world.ItemByName(i.Name, int16(i.Meta))
if !ok {
return nil, false
}
if b, ok := world.BlockByName(i.State.Name, i.State.Properties); ok {
if it, ok = b.(world.Item); !ok {
return nil, false
}
}
st := item.NewStack(it, int(i.Count))
if i.Meta == math.MaxInt16 {
st = st.WithValue("variants", true)
}
s = append(s, st)
}
st := item.NewStack(it, int(i.Count))
if i.Meta == math.MaxInt16 {
st = st.WithValue("variants", true)
}
s = append(s, st)
}
return s, true
}
Expand Down
Loading

0 comments on commit d5b4b60

Please sign in to comment.