Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented functional anvils #521

Merged
merged 65 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
2bf1ce8
dragonfly: Started implementing anvils.
JustTalDevelops May 15, 2022
0c68672
Merge remote-tracking branch 'origin/master' into feature/anvils
T14Raptor May 16, 2022
a4c6aee
Anvil progress
T14Raptor May 18, 2022
a6c896c
Progress.
T14Raptor May 31, 2022
780c119
session/handler_item_stack_request.go: Set enchantments.
T14Raptor May 31, 2022
6d1b6df
Merge branch 'master' into feature/anvils
JustTalDevelops Jul 4, 2022
acfcc6d
item/item.go: Added a DisplayName function.
JustTalDevelops Jul 6, 2022
8f36c70
session/handler_item_stack_request.go: Renaming.
JustTalDevelops Jul 6, 2022
9dccb44
session/handler_item_stack_request.go: Fix damaging.
JustTalDevelops Jul 6, 2022
775bb73
enchantment/sharpness.go: Correct MaxLevel.
JustTalDevelops Jul 6, 2022
8041cb4
Repairing stuff
T14Raptor Jul 7, 2022
69fd08f
block/anvil.go: Proper falling block mechanics.
JustTalDevelops Jul 7, 2022
45483c3
Merge remote-tracking branch 'origin/feature/anvils' into feature/anvils
JustTalDevelops Jul 7, 2022
516eed3
entity/falling_block.go: Move damage information to damageables.
JustTalDevelops Jul 7, 2022
ebfc7fc
item/tool.go: ToolTierGold is repairable.
JustTalDevelops Jul 7, 2022
a8ee312
cube/direction.go: Replaced (Direction).Horizontal() with an unexport…
JustTalDevelops Jul 7, 2022
9137fed
enchantment/efficiency.go: Fix CompatibleWithItem not accounting for …
JustTalDevelops Jul 7, 2022
10a337f
enchantment/efficiency.go: Fix CompatibleWithItem not accounting for …
JustTalDevelops Jul 7, 2022
146b798
enchantment/efficiency.go: Account for shears and hoes.
JustTalDevelops Jul 7, 2022
b0d6f29
repair cost
T14Raptor Jul 7, 2022
bbecd9a
Merge remote-tracking branch 'origin/feature/anvils' into feature/anvils
T14Raptor Jul 7, 2022
b004c58
session/handler_item_stack_request.go: Only cancel if there are no co…
JustTalDevelops Jul 7, 2022
3b0eba5
Merge remote-tracking branch 'origin/feature/anvils' into feature/anvils
JustTalDevelops Jul 7, 2022
9a5ebe2
session/handler_item_stack_request.go: Remove useless resultEnchantme…
JustTalDevelops Jul 7, 2022
c881565
main.go: Removed debugging code.
JustTalDevelops Jul 7, 2022
f7e2e8a
nbtconv: Always read/write RepairCost as an int32.
JustTalDevelops Jul 7, 2022
a7b79b9
session/handler_item_stack_request.go: Update result with repair cost.
JustTalDevelops Jul 7, 2022
8c662b5
session/handler_item_stack_request.go: Split up anvils, crafting, and…
JustTalDevelops Jul 7, 2022
5228bfc
session/handler_anvil.go: Document handleCraftRecipeOptional.
JustTalDevelops Jul 7, 2022
f6d50b2
session/handler_anvil.go: Error on impossible circumstances.
JustTalDevelops Jul 7, 2022
a971850
session/handler_anvil.go: Various improvements.
JustTalDevelops Jul 7, 2022
1ce0bf7
session/handler_anvil.go: Various improvements.
JustTalDevelops Jul 7, 2022
12c836c
session/handler_anvil.go: Error on not enough experience.
JustTalDevelops Jul 7, 2022
61e28c9
session/handler_anvil.go: Allow combining two items with incompatible…
JustTalDevelops Jul 7, 2022
6e356ed
block/anvil.go: Use the Anvil model.
JustTalDevelops Jul 7, 2022
b5b0668
main.go: Remove debug.
JustTalDevelops Jul 7, 2022
f7aa631
model/anvil.go: Fix staticcheck issues.
JustTalDevelops Jul 7, 2022
d443e7a
Update server/block/cobblestone.go
JustTalDevelops Jul 7, 2022
021339c
damage/source.go: Renamed SourceDamagingBlock to SourceBlock.
JustTalDevelops Jul 7, 2022
7237375
Merge remote-tracking branch 'origin/feature/anvils' into feature/anvils
JustTalDevelops Jul 7, 2022
7323758
lang/lang.go: Lazily load locales.
T14Raptor Jul 7, 2022
0a75332
lang: Minify locale files and default to english in DisplayName if we…
T14Raptor Jul 7, 2022
b9b273c
british english
T14Raptor Jul 7, 2022
ef81884
inline
T14Raptor Jul 7, 2022
a050c8a
lang/lang.go: Return a bool from load.
JustTalDevelops Jul 7, 2022
46308a0
nbtconv/write.go: Only write RepairCost if > 0.
JustTalDevelops Jul 7, 2022
a612044
dragonfly: Various improvements to anvils.
JustTalDevelops Jul 10, 2022
76f8cd2
session/handler_anvil.go: Added documentation.
JustTalDevelops Jul 10, 2022
3c3cd67
Merge branch 'master' into feature/anvils
JustTalDevelops Jul 10, 2022
3289909
Merge remote-tracking branch 'origin/master' into feature/anvils
JustTalDevelops Jul 10, 2022
25790ec
item/enchantment_rarity.go: Made EnchantmentRarity an interface.
JustTalDevelops Jul 10, 2022
0c47c53
session/handler_anvil.go: Split up code into different functions.
JustTalDevelops Jul 10, 2022
988fd47
Merge branch 'master' into feature/anvils
JustTalDevelops Jul 11, 2022
4f84bac
enchantment: Various fixes.
JustTalDevelops Jul 11, 2022
82de40a
main.go: Remove debugging code.
JustTalDevelops Jul 11, 2022
d38ba17
enchantment/soul_speed.go: Implement Undiscoverable.
JustTalDevelops Jul 11, 2022
fa79386
Update server/session/handler_anvil.go
JustTalDevelops Jul 11, 2022
0e10582
Update server/session/handler_anvil.go
JustTalDevelops Jul 11, 2022
954ceb5
block/fire.go: corrected damage taken while inside of soul fire
DaPigGuy Jul 11, 2022
86f67bd
session/handler_anvil.go: vanilla parity changes for enchantment merging
DaPigGuy Jul 11, 2022
5e1d7ac
Revert "enchantment/soul_speed.go: Implement Undiscoverable."
DaPigGuy Jul 11, 2022
2b97207
anvil: fixed client & server not agreeing on xp cost, primarily with …
DaPigGuy Jul 11, 2022
66596f7
session/handler_anvil.go: Various improvements.
JustTalDevelops Jul 11, 2022
350964b
main.go: Remove debugging code.
JustTalDevelops Jul 11, 2022
82fe9bd
session/handler_anvil.go: Consistency!
JustTalDevelops Jul 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".Uint8())", 4
case "CoralType":
return "uint64(" + s + ".Uint8())", 3
case "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType":
case "AnvilType", "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType":
return "uint64(" + s + ".Uint8())", 2
case "OreType", "FireType", "GrassType":
return "uint64(" + s + ".Uint8())", 1
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.20.0
github.com/sandertv/gophertunnel v1.21.2
github.com/sirupsen/logrus v1.8.1
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb
golang.org/x/text v0.3.7
Expand Down
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,8 @@ github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhg
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sandertv/go-raknet v1.10.9 h1:1a8ntIenpDBue3IsUdhJhxTznGt8Qeaan7HtQKi0hBs=
github.com/sandertv/go-raknet v1.10.9/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.19.11-0.20220528215528-9a29e457b568 h1:gJj5u6lizaLUd6USTP/f4xFPXYaaMcMtzOy82l5p/V0=
github.com/sandertv/gophertunnel v1.19.11-0.20220528215528-9a29e457b568/go.mod h1:KWY6jLxX/2P7e9n5oVFjVnPL3U1YsWuFgCrgtRazuhw=
github.com/sandertv/gophertunnel v1.19.11-0.20220528222242-c50246c32560 h1:+coYbeRFnYXGFheqIa3u5Bt5OhKeFDrdhFBn25cokNY=
github.com/sandertv/gophertunnel v1.19.11-0.20220528222242-c50246c32560/go.mod h1:KWY6jLxX/2P7e9n5oVFjVnPL3U1YsWuFgCrgtRazuhw=
github.com/sandertv/gophertunnel v1.19.11-0.20220601231535-4fdf3713c504 h1:F5wOiMpqxX/P+My9RVRvApjeQBRUi25FFZu5XbqJPqI=
github.com/sandertv/gophertunnel v1.19.11-0.20220601231535-4fdf3713c504/go.mod h1:KWY6jLxX/2P7e9n5oVFjVnPL3U1YsWuFgCrgtRazuhw=
github.com/sandertv/gophertunnel v1.19.13 h1:agU7PpriACYVnlxiG0nhjOFXBjagGOQXO9sfyCulKjU=
github.com/sandertv/gophertunnel v1.19.13/go.mod h1:MM2eeBapijrPCK45QL0EaTEheEBHWJshdZpr6ZBsaXc=
github.com/sandertv/gophertunnel v1.20.0 h1:DZHlUZvQvENyddgDrrtQ6oEt5J3B3sjR7l/4yHnHYww=
github.com/sandertv/gophertunnel v1.20.0/go.mod h1:MM2eeBapijrPCK45QL0EaTEheEBHWJshdZpr6ZBsaXc=
github.com/sandertv/gophertunnel v1.21.2 h1:+fTgLsGY4qqO+A27u3Z2IveIcvuz25nRJZRYzVeHyjI=
github.com/sandertv/gophertunnel v1.21.2/go.mod h1:MM2eeBapijrPCK45QL0EaTEheEBHWJshdZpr6ZBsaXc=
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=
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package main
import (
"fmt"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/entity"
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/dragonfly/server/player/chat"
"github.com/pelletier/go-toml"
"github.com/sirupsen/logrus"
"io/ioutil"
"os"
"time"
)

func main() {
Expand All @@ -28,7 +31,14 @@ func main() {
log.Fatalln(err)
}

for srv.Accept(nil) {
for srv.Accept(func(p *player.Player) {
go func() {
for {
p.SendTip(entity.Facing(p))
time.Sleep(200 * time.Millisecond)
}
}()
}) {
JustTalDevelops marked this conversation as resolved.
Show resolved Hide resolved
}
}

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

import (
"github.com/df-mc/dragonfly/server/block/cube"
"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
solid
JustTalDevelops marked this conversation as resolved.
Show resolved Hide resolved
transparent

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

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

// Activate ...
func (a 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 (a 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 (a 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")
}
20 changes: 17 additions & 3 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ func place(w *world.World, pos cube.Pos, b world.Block, user item.User, ctx *ite
w.PlaySound(pos.Vec3(), sound.BlockPlace{Block: b})
}

// horizontalDirection returns the horizontal direction of the given direction. This is a legacy type still used in
// various blocks.
func horizontalDirection(d cube.Direction) cube.Direction {
switch d {
case cube.South:
return cube.North
case cube.West:
return cube.South
case cube.North:
return cube.West
case cube.East:
return cube.East
}
panic("invalid direction")
}

// placed checks if an item was placed with the use context passed.
func placed(ctx *item.UseContext) bool {
return ctx.CountSub > 0
Expand Down Expand Up @@ -185,9 +201,7 @@ func (g gravityAffected) fall(b world.Block, pos cube.Pos, w *world.World) {
_, liquid := w.Liquid(pos.Side(cube.FaceDown))
if air || liquid {
w.SetBlock(pos, nil, nil)

e := entity.NewFallingBlock(b, pos.Vec3Middle())
w.AddEntity(e)
w.AddEntity(entity.NewFallingBlock(b, pos.Vec3Middle()))
}
}

Expand Down
8 changes: 1 addition & 7 deletions server/block/coal_block.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package block

import (
"github.com/df-mc/dragonfly/server/item"
)

// CoalBlock is a precious mineral block made from 9 coal.
type CoalBlock struct {
solid
Expand All @@ -17,9 +13,7 @@ func (c CoalBlock) FlammabilityInfo() FlammabilityInfo {

// BreakInfo ...
func (c CoalBlock) BreakInfo() BreakInfo {
return newBreakInfo(5, func(t item.Tool) bool {
return t.ToolType() == item.TypePickaxe && t.HarvestLevel() >= item.ToolTierWood.HarvestLevel
}, pickaxeEffective, oneOf(c))
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c))
}

// EncodeItem ...
Expand Down
5 changes: 5 additions & 0 deletions server/block/cobblestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (c Cobblestone) BreakInfo() BreakInfo {
return newBreakInfo(2, pickaxeHarvestable, pickaxeEffective, oneOf(c))
}

// Cobblestone ...
func (c Cobblestone) Cobblestone() bool {
return true
JustTalDevelops marked this conversation as resolved.
Show resolved Hide resolved
}

// EncodeItem ...
func (c Cobblestone) EncodeItem() (name string, meta int16) {
if c.Mossy {
Expand Down
12 changes: 1 addition & 11 deletions server/block/cocoa_bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,7 @@ func (c CocoaBean) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (c CocoaBean) EncodeBlock() (name string, properties map[string]any) {
direction := 2
switch c.Facing {
case cube.South:
direction = 0
case cube.West:
direction = 1
case cube.East:
direction = 3
}

return "minecraft:cocoa", map[string]any{"age": int32(c.Age), "direction": int32(direction)}
return "minecraft:cocoa", map[string]any{"age": int32(c.Age), "direction": int32(horizontalDirection(c.Facing))}
}

// Model ...
Expand Down
10 changes: 5 additions & 5 deletions server/block/cube/direction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const (
East
)

// Face converts the direction to a Face and returns it.
func (d Direction) Face() Face {
return Face(d + 2)
}

// Opposite returns Direction opposite to the current one.
func (d Direction) Opposite() Direction {
switch d {
Expand All @@ -29,11 +34,6 @@ func (d Direction) Opposite() Direction {
panic("invalid direction")
}

// Face converts the direction to a Face and returns it.
func (d Direction) Face() Face {
return Face(d + 2)
}

// RotateRight rotates the direction 90 degrees to the right horizontally and returns the new direction.
func (d Direction) RotateRight() Direction {
switch d {
Expand Down
5 changes: 5 additions & 0 deletions server/block/hash.go

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

5 changes: 5 additions & 0 deletions server/block/planks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (p Planks) BreakInfo() BreakInfo {
return newBreakInfo(2, alwaysHarvestable, axeEffective, oneOf(p))
}

// Planks ...
func (p Planks) Planks() bool {
return true
}

// EncodeItem ...
func (p Planks) EncodeItem() (name string, meta int16) {
switch p.Wood {
Expand Down
14 changes: 2 additions & 12 deletions server/block/pumpkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,10 @@ func (p Pumpkin) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (p Pumpkin) EncodeBlock() (name string, properties map[string]any) {
direction := 2
switch p.Facing {
case cube.South:
direction = 0
case cube.West:
direction = 1
case cube.East:
direction = 3
}

if p.Carved {
return "minecraft:carved_pumpkin", map[string]any{"direction": int32(direction)}
return "minecraft:carved_pumpkin", map[string]any{"direction": int32(horizontalDirection(p.Facing))}
}
return "minecraft:pumpkin", map[string]any{"direction": int32(direction)}
return "minecraft:pumpkin", map[string]any{"direction": int32(horizontalDirection(p.Facing))}
}

func allPumpkins() (pumpkins []world.Block) {
Expand Down
4 changes: 4 additions & 0 deletions server/block/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func init() {
world.RegisterBlock(ReinforcedDeepslate{})
world.RegisterBlock(MuddyMangroveRoots{})

registerAll(allAnvils())
registerAll(allBarrels())
registerAll(allBasalt())
registerAll(allBeetroot())
Expand Down Expand Up @@ -306,6 +307,9 @@ func init() {
for _, s := range allStoneBricks() {
world.RegisterItem(s.(world.Item))
}
for _, t := range AnvilTypes() {
world.RegisterItem(Anvil{Type: t})
}
for _, c := range item.Colours() {
world.RegisterItem(Concrete{Colour: c})
world.RegisterItem(ConcretePowder{Colour: c})
Expand Down
Loading