Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into map-item
Browse files Browse the repository at this point in the history
  • Loading branch information
Endermanbugzjfc committed Jul 20, 2022
2 parents 84d3f57 + a038de7 commit 9d329b2
Show file tree
Hide file tree
Showing 349 changed files with 10,872 additions and 3,757 deletions.
5 changes: 5 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ opening a pull request:
* Where possible, try to expose as few exported symbols (functions, types) as possible, unless
strictly necessary. This makes it easier for us to change code in the future and ensures that
users cannot use functions not suitable for the API.
* In big functions it can become difficult to track the execution flow. Try to `return` as quickly
possible in functions so that the main code flow is minimally indented and therefore easy to
track and understand.
* In places where there are three or more sequential variable declarations, these should be grouped
into a single `var ( )` block.
* Try to be conservative with the usage of generics. While these are often useful, they can quickly
pollute code if used in excess. Consider carefully if generics are needed, particularly for
exported types and functions. Don't hesitate on using them if they are able to clean up the code
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,18 @@ jobs:
HOST: ${{ secrets.VPS_HOST }}
run: |
ssh -i ~/.ssh/id_rsa $HOST "screen -d -R -S dragonfly -X stuff '/home/dragonfly_exe\n'"
update_contributors:
name: Update Contributors
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Contributors
run: >
echo -e "// Code generated by .github/workflows/push.yml; DO NOT EDIT\n\npackage session\n\n// enchantNames are names translated to the 'Standard Galactic Alphabet' client-side. The names generally have no meaning\n// on the vanilla server implementation, so we can sneak some easter eggs in here without anyone noticing.\nvar enchantNames = []string{"$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/df-mc/dragonfly/contributors | jq .[].login | sort | sed -z "s/\n/,/g" | sed -r -e "s/([^A-Z\"])([A-Z])/\1 \2/g" | sed "s/./\L&/g")"}" > server/session/enchantment_texts.go
- run: gofmt -w server/session/enchantment_texts.go
- name: Push Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "updated contributor list"
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ Running Dragonfly requires at least **Go 1.18**. After starting the server throu
more detailed info.

#### Installation as library
```
go mod init github.com/<user>/<module name>
```shell
go mod init github.com/user/module
go get github.com/df-mc/dragonfly
```

![SetupLibrary](https://user-images.githubusercontent.com/16114089/121804512-0f843900-cc47-11eb-9320-d195393b5a1f.gif)

#### Installation of the latest commit
```
```shell
git clone https://github.com/df-mc/dragonfly
cd dragonfly
go run main.go
```

![SetupClone](https://user-images.githubusercontent.com/16114089/121804495-ff6c5980-cc46-11eb-8e31-df4d94782e5b.gif)


## Developer info
[![Go Reference](https://pkg.go.dev/badge/github.com/df-mc/dragonfly/server.svg)](https://pkg.go.dev/github.com/df-mc/dragonfly/server)

Expand Down
6 changes: 3 additions & 3 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".FaceUint8())", 3
}
return "uint64(" + s + ".Uint8())", 5
case "FlowerType", "DoubleFlowerType", "Colour":
case "WoodType", "FlowerType", "DoubleFlowerType", "Colour":
// Assuming these were all based on metadata, it should be safe to assume a bit size of 4 for this.
return "uint64(" + s + ".Uint8())", 4
case "WoodType", "CoralType":
case "CoralType":
return "uint64(" + s + ".Uint8())", 3
case "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType":
case "AnvilType", "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType":
return "uint64(" + s + ".Uint8())", 2
case "OreType", "FireType", "GrassType":
return "uint64(" + s + ".Uint8())", 1
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ require (
github.com/google/uuid v1.3.0
github.com/pelletier/go-toml v1.9.4
github.com/rogpeppe/go-internal v1.3.0
github.com/sandertv/gophertunnel v1.19.9
github.com/sandertv/gophertunnel v1.22.3
github.com/sirupsen/logrus v1.8.1
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb
go.uber.org/atomic v1.9.0
golang.org/x/exp v0.0.0-20220713135740-79cabaa25d75
golang.org/x/text v0.3.7
)

Expand All @@ -22,8 +23,8 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
github.com/sandertv/go-raknet v1.10.6 // indirect
go.uber.org/atomic v1.9.0 // indirect
github.com/sandertv/go-raknet v1.11.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/image v0.0.0-20220321031419-a8550c1d254a // indirect
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2 // indirect
Expand All @@ -33,4 +34,5 @@ require (
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
21 changes: 12 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down Expand Up @@ -145,19 +145,20 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sandertv/go-raknet v1.10.6 h1:SGGP+D9iEt8OOM2SoGM5SvYKYJMlIb6U/uw/7lpRElU=
github.com/sandertv/go-raknet v1.10.6/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.19.9 h1:RHLB4OxULdzB+DeShuRvt1rjFSeQ5jhC3iLbLhCBqFs=
github.com/sandertv/gophertunnel v1.19.9/go.mod h1:KWY6jLxX/2P7e9n5oVFjVnPL3U1YsWuFgCrgtRazuhw=
github.com/sandertv/go-raknet v1.11.1 h1:0auvhHoZNyC/Z1l5xqniE3JE+w3MGO3n3JXEGHzdlRE=
github.com/sandertv/go-raknet v1.11.1/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.22.3 h1:xVTC348fU0gr62tbWnr8iuvZggOBgsKEm98sotZYhb8=
github.com/sandertv/gophertunnel v1.22.3/go.mod h1:dMOw79FHxr2azEqiGH20AwdljisAN1kqwu5SjPBnZ5k=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -185,8 +186,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/exp v0.0.0-20220713135740-79cabaa25d75 h1:x03zeu7B2B11ySp+daztnwM5oBJ/8wGUSqrwcw9L0RA=
golang.org/x/exp v0.0.0-20220713135740-79cabaa25d75/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down Expand Up @@ -341,7 +342,6 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand Down Expand Up @@ -435,6 +435,9 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func main() {
log.Fatalln(err)
}

for {
if _, err := srv.Accept(); err != nil {
return
}
for srv.Accept(nil) {
}
}

Expand Down
21 changes: 21 additions & 0 deletions server/block/amethyst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package block

// Amethyst is a decorative block crafted from four amethyst shards.
type Amethyst struct {
solid
}

// BreakInfo ...
func (a Amethyst) BreakInfo() BreakInfo {
return newBreakInfo(1.5, pickaxeHarvestable, pickaxeHarvestable, oneOf(a))
}

// EncodeItem ...
func (Amethyst) EncodeItem() (name string, meta int16) {
return "minecraft:amethyst_block", 0
}

// EncodeBlock ...
func (Amethyst) EncodeBlock() (string, map[string]any) {
return "minecraft:amethyst_block", nil
}
21 changes: 0 additions & 21 deletions server/block/amethyst_block.go

This file was deleted.

5 changes: 5 additions & 0 deletions server/block/ancient_debris.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (a AncientDebris) BreakInfo() BreakInfo {
}, pickaxeEffective, oneOf(a))
}

// SmeltInfo ...
func (AncientDebris) SmeltInfo() item.SmeltInfo {
return newOreSmeltInfo(item.NewStack(item.NetheriteScrap{}, 1), 2)
}

// EncodeItem ...
func (AncientDebris) EncodeItem() (name string, meta int16) {
return "minecraft:ancient_debris", 0
Expand Down
103 changes: 103 additions & 0 deletions server/block/anvil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package block

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

// Anvil is a block that allows players to repair items, rename items, and combine enchantments.
type Anvil struct {
gravityAffected
transparent

// Type is the type of anvil.
Type AnvilType
// Facing is the direction that the anvil is facing.
Facing cube.Direction
}

// Model ...
func (a Anvil) Model() world.BlockModel {
return model.Anvil{Facing: a.Facing}
}

// BreakInfo ...
func (a Anvil) BreakInfo() BreakInfo {
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(a))
}

// Activate ...
func (Anvil) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User) bool {
if opener, ok := u.(ContainerOpener); ok {
opener.OpenBlockContainer(pos)
return true
}
return false
}

// UseOnBlock ...
func (a Anvil) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, _, used = firstReplaceable(w, pos, face, a)
if !used {
return
}
a.Facing = user.Facing().RotateRight()
place(w, pos, a, user, ctx)
return placed(ctx)
}

// NeighbourUpdateTick ...
func (a Anvil) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
a.fall(a, pos, w)
}

// Damage returns the damage per block fallen of the anvil and the maximum damage the anvil can deal.
func (Anvil) Damage() (damagePerBlock, maxDamage float64) {
return 2, 40
}

// Break breaks the anvil and moves it to the next damage stage. If the anvil is at the last damage stage, it will be
// destroyed.
func (a Anvil) Break() world.Block {
switch a.Type {
case UndamagedAnvil():
a.Type = SlightlyDamagedAnvil()
case SlightlyDamagedAnvil():
a.Type = VeryDamagedAnvil()
case VeryDamagedAnvil():
return Air{}
}
return a
}

// Landed is called when a falling anvil hits the ground, used to, for example, play a sound.
func (Anvil) Landed(w *world.World, pos cube.Pos) {
w.PlaySound(pos.Vec3Centre(), sound.AnvilLand{})
}

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

// EncodeBlock ...
func (a Anvil) EncodeBlock() (string, map[string]any) {
return "minecraft:anvil", map[string]any{
"damage": a.Type.String(),
"direction": int32(horizontalDirection(a.Facing)),
}
}

// allAnvils ...
func allAnvils() (anvils []world.Block) {
for _, t := range AnvilTypes() {
for _, d := range cube.Directions() {
anvils = append(anvils, Anvil{Type: t, Facing: d})
}
}
return
}
46 changes: 46 additions & 0 deletions server/block/anvil_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package block

// AnvilType represents a type of anvil, such as undamaged, slightly damaged, or very damaged.
type AnvilType struct {
anvil
}

// UndamagedAnvil returns the undamaged anvil type.
func UndamagedAnvil() AnvilType {
return AnvilType{0}
}

// SlightlyDamagedAnvil returns the slightly damaged anvil type.
func SlightlyDamagedAnvil() AnvilType {
return AnvilType{1}
}

// VeryDamagedAnvil returns the very damaged anvil type.
func VeryDamagedAnvil() AnvilType {
return AnvilType{2}
}

// AnvilTypes returns all anvil types.
func AnvilTypes() []AnvilType {
return []AnvilType{UndamagedAnvil(), SlightlyDamagedAnvil(), VeryDamagedAnvil()}
}

type anvil uint8

// Uint8 returns the anvil type as a uint8.
func (a anvil) Uint8() uint8 {
return uint8(a)
}

// String returns the anvil type as a string.
func (a anvil) String() string {
switch a {
case 0:
return "undamaged"
case 1:
return "slightly_damaged"
case 2:
return "very_damaged"
}
panic("should never happen")
}
Loading

0 comments on commit 9d329b2

Please sign in to comment.