Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feature/dynamichashes
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/block/hash.go
  • Loading branch information
TwistedAsylumMC committed Aug 28, 2024
2 parents 2e27606 + 29a214b commit 7dc96a7
Show file tree
Hide file tree
Showing 64 changed files with 1,132 additions and 307 deletions.
29 changes: 14 additions & 15 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"flag"
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/go/packages"
"io"
"log"
"os"
Expand All @@ -22,24 +21,25 @@ func main() {
if len(flag.Args()) != 1 {
log.Fatalln("Must pass one package to produce block hashes for.")
}
fs := token.NewFileSet()
packages, err := parser.ParseDir(fs, flag.Args()[0], nil, parser.ParseComments)
cfg := &packages.Config{
Mode: packages.NeedName | packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedFiles,
}
pkgs, err := packages.Load(cfg, flag.Args()[0])
if err != nil {
log.Fatalln(err)
}
f, err := os.OpenFile(*out, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatalln(err)
}
for _, pkg := range packages {
procPackage(pkg, fs, f)
for _, pkg := range pkgs {
procPackage(pkg, f)
}
_ = f.Close()
}

func procPackage(pkg *ast.Package, fs *token.FileSet, w io.Writer) {
func procPackage(pkg *packages.Package, w io.Writer) {
b := &hashBuilder{
fs: fs,
pkg: pkg,
fields: make(map[string][]*ast.Field),
aliases: make(map[string]string),
Expand All @@ -66,8 +66,7 @@ var (
)

type hashBuilder struct {
fs *token.FileSet
pkg *ast.Package
pkg *packages.Package
fields map[string][]*ast.Field
funcs map[string]*ast.FuncDecl
aliases map[string]string
Expand Down Expand Up @@ -151,7 +150,7 @@ func (b *hashBuilder) writeMethods(w io.Writer) {
for _, n := range fun.Recv.List[0].Names {
recvName = n.Name
}
pos := b.fs.Position(fun.Body.Pos())
pos := b.pkg.Fset.Position(fun.Body.Pos())
f, err := os.Open(pos.Filename)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -277,8 +276,8 @@ func (b *hashBuilder) resolveBlocks() {
}
}

func (b *hashBuilder) readFuncs(pkg *ast.Package) {
for _, f := range pkg.Files {
func (b *hashBuilder) readFuncs(pkg *packages.Package) {
for _, f := range pkg.Syntax {
ast.Inspect(f, b.readFuncDecls)
}
}
Expand All @@ -294,8 +293,8 @@ func (b *hashBuilder) readFuncDecls(node ast.Node) bool {
return true
}

func (b *hashBuilder) readStructFields(pkg *ast.Package) {
for _, f := range pkg.Files {
func (b *hashBuilder) readStructFields(pkg *packages.Package) {
for _, f := range pkg.Syntax {
ast.Inspect(f, b.readStructs)
}
b.resolveEmbedded()
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ 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.15
github.com/df-mc/worldupgrader v1.0.16
github.com/go-gl/mathgl v1.1.0
github.com/google/uuid v1.6.0
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.11.0
github.com/sandertv/gophertunnel v1.39.0
github.com/sandertv/gophertunnel v1.40.1
github.com/segmentio/fasthash v1.0.3
github.com/sirupsen/logrus v1.9.3
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/text v0.16.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
)

require (
Expand All @@ -29,8 +30,10 @@ require (
github.com/sandertv/go-raknet v1.14.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/image v0.17.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
17 changes: 12 additions & 5 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.15 h1:kR/nYWQbFvmR5LqPncpBXtXKGyiRBPc9NPkBKlLSAIk=
github.com/df-mc/worldupgrader v1.0.15/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/df-mc/worldupgrader v1.0.16 h1:3n9yvLFNCe8IDJnUEliTGbhDvV1frjtPX/y5zl3Q5EE=
github.com/df-mc/worldupgrader v1.0.16/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 All @@ -20,8 +20,9 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand All @@ -44,8 +45,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.14.1 h1:V2Gslo+0x4jfj+p0PM48mWxmMbYkxSlgeKy//y3ZrzI=
github.com/sandertv/go-raknet v1.14.1/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU=
github.com/sandertv/gophertunnel v1.39.0 h1:Am2NhSQjxscAVihRG/Qz7cfyJJp91RIl/5DpSLbwXp0=
github.com/sandertv/gophertunnel v1.39.0/go.mod h1:uSaX7RbVaCcxsGAx2vyZnkT0M6kZFGCdAqLn0+wuKyY=
github.com/sandertv/gophertunnel v1.40.1 h1:foWxpIEXm/pCqik8r8TmcIlQyG8Vpe98JJwFKurdb/4=
github.com/sandertv/gophertunnel v1.40.1/go.mod h1:uSaX7RbVaCcxsGAx2vyZnkT0M6kZFGCdAqLn0+wuKyY=
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 All @@ -69,6 +70,8 @@ golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco=
golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand All @@ -83,6 +86,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -112,6 +117,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
Expand Down
5 changes: 2 additions & 3 deletions server/block/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ func (Anvil) Landed(w *world.World, pos cube.Pos) {

// EncodeItem ...
func (a Anvil) EncodeItem() (name string, meta int16) {
return "minecraft:anvil", int16(a.Type.Uint8() * 4)
return "minecraft:" + a.Type.String(), 0
}

// EncodeBlock ...
func (a Anvil) EncodeBlock() (string, map[string]any) {
return "minecraft:anvil", map[string]any{
"damage": a.Type.String(),
return "minecraft:" + a.Type.String(), map[string]any{
"minecraft:cardinal_direction": a.Facing.String(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions server/block/anvil_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (a anvil) Uint8() uint8 {
func (a anvil) String() string {
switch a {
case 0:
return "undamaged"
return "anvil"
case 1:
return "slightly_damaged"
return "chipped_anvil"
case 2:
return "very_damaged"
return "damaged_anvil"
}
panic("should never happen")
}
8 changes: 6 additions & 2 deletions server/block/barrel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewBarrel() Barrel {
}

// Inventory returns the inventory of the barrel. The size of the inventory will be 27.
func (b Barrel) Inventory() *inventory.Inventory {
func (b Barrel) Inventory(*world.World, cube.Pos) *inventory.Inventory {
return b.inventory
}

Expand Down Expand Up @@ -124,7 +124,11 @@ func (b Barrel) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.

// BreakInfo ...
func (b Barrel) BreakInfo() BreakInfo {
return newBreakInfo(2.5, alwaysHarvestable, axeEffective, oneOf(b))
return newBreakInfo(2.5, alwaysHarvestable, axeEffective, oneOf(b)).withBreakHandler(func(pos cube.Pos, w *world.World, u item.User) {
for _, i := range b.Inventory(w, pos).Clear() {
dropItem(w, i, pos.Vec3())
}
})
}

// FlammabilityInfo ...
Expand Down
10 changes: 7 additions & 3 deletions server/block/blast_furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func (b BlastFurnace) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *
// BreakInfo ...
func (b BlastFurnace) BreakInfo() BreakInfo {
xp := b.Experience()
return newBreakInfo(3.5, alwaysHarvestable, pickaxeEffective, oneOf(b)).withXPDropRange(xp, xp)
return newBreakInfo(3.5, alwaysHarvestable, pickaxeEffective, oneOf(b)).withXPDropRange(xp, xp).withBreakHandler(func(pos cube.Pos, w *world.World, u item.User) {
for _, i := range b.Inventory(w, pos).Clear() {
dropItem(w, i, pos.Vec3())
}
})
}

// Activate ...
Expand All @@ -97,7 +101,7 @@ func (b BlastFurnace) EncodeNBT() map[string]interface{} {
"CookTime": int16(cook.Milliseconds() / 50),
"BurnDuration": int16(maximum.Milliseconds() / 50),
"StoredXPInt": int16(b.Experience()),
"Items": nbtconv.InvToNBT(b.Inventory()),
"Items": nbtconv.InvToNBT(b.inventory),
"id": "BlastFurnace",
}
}
Expand All @@ -116,7 +120,7 @@ func (b BlastFurnace) DecodeNBT(data map[string]interface{}) interface{} {
b.Lit = lit
b.setExperience(xp)
b.setDurations(remaining, maximum, cook)
nbtconv.InvFromNBT(b.Inventory(), nbtconv.Slice(data, "Items"))
nbtconv.InvFromNBT(b.inventory, nbtconv.Slice(data, "Items"))
return b
}

Expand Down
Loading

0 comments on commit 7dc96a7

Please sign in to comment.