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

Add cobwebs, strings, and placeable tripwires (no function) #437

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ var axeEffective = func(t item.Tool) bool {
return t.ToolType() == item.TypeAxe
}

// swordEffective is a convenience function for blocks that are effectively mined with a sword.
var swordEffective = func(t item.Tool) bool {
return t.ToolType() == item.TypeSword
}

// shearsEffective is a convenience function for blocks that are effectively mined with shears.
var shearsEffective = func(t item.Tool) bool {
return t.ToolType() == item.TypeShears
Expand Down
46 changes: 46 additions & 0 deletions server/block/cobweb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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"
)

// Cobweb is a block that can slow down entity movement and negate fall damage.
HashimTheArab marked this conversation as resolved.
Show resolved Hide resolved
type Cobweb struct {
empty
}

// BreakInfo ...
func (c Cobweb) BreakInfo() BreakInfo {
return newBreakInfo(
4,
alwaysHarvestable,
func(t item.Tool) bool {
return swordEffective(t) || shearsEffective(t)
},
func(t item.Tool, e []item.Enchantment) []item.Stack {
if t.ToolType() == item.TypeShears || (t.ToolType() == item.TypeSword && hasSilkTouch(e)) {
return oneOf(c)(t, e)
}
return oneOf(String{})(t, e)
},
)
}

// EntityInside ...
func (Cobweb) EntityInside(_ cube.Pos, _ *world.World, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
fallEntity.ResetFallDistance()
}
}

// EncodeItem ...
func (c Cobweb) EncodeItem() (name string, meta int16) {
return "minecraft:web", 0
}

// EncodeBlock ...
func (c Cobweb) EncodeBlock() (string, map[string]interface{}) {
return "minecraft:web", nil
}
10 changes: 10 additions & 0 deletions server/block/hash.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/block/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
world.RegisterBlock(Coal{})
world.RegisterBlock(Cobblestone{Mossy: true})
world.RegisterBlock(Cobblestone{})
world.RegisterBlock(Cobweb{})
world.RegisterBlock(CraftingTable{})
world.RegisterBlock(DeadBush{})
world.RegisterBlock(DeepslateBricks{Cracked: true})
Expand Down Expand Up @@ -98,6 +99,7 @@ func init() {
world.RegisterBlock(SporeBlossom{})
world.RegisterBlock(Stone{Smooth: true})
world.RegisterBlock(Stone{})
world.RegisterBlock(String{})
world.RegisterBlock(TNT{})
world.RegisterBlock(Terracotta{})
world.RegisterBlock(Tuff{})
Expand Down Expand Up @@ -218,6 +220,7 @@ func init() {
world.RegisterItem(Coal{})
world.RegisterItem(Cobblestone{Mossy: true})
world.RegisterItem(Cobblestone{})
world.RegisterItem(Cobweb{})
world.RegisterItem(CocoaBean{})
world.RegisterItem(CraftingTable{})
world.RegisterItem(DeadBush{})
Expand Down Expand Up @@ -315,6 +318,7 @@ func init() {
world.RegisterItem(Stonecutter{})
world.RegisterItem(Stone{Smooth: true})
world.RegisterItem(Stone{})
world.RegisterItem(String{})
world.RegisterItem(SugarCane{})
world.RegisterItem(TNT{})
world.RegisterItem(Terracotta{})
Expand Down
40 changes: 40 additions & 0 deletions server/block/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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/go-gl/mathgl/mgl64"
)

// String is an item dropped by spiders and cobwebs. When placed, it turns into a tripwire.
type String struct {
empty
transparent
}

// UseOnBlock ...
func (s String) 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, s)
if !used {
return
}

place(w, pos, s, user, ctx)
return placed(ctx)
}

// BreakInfo ...
func (s String) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(String{}))
}

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

// EncodeBlock ...
func (s String) EncodeBlock() (string, map[string]interface{}) {
return "minecraft:tripWire", map[string]interface{}{"attached_bit": uint8(0), "disarmed_bit": uint8(0), "powered_bit": uint8(0), "suspended_bit": uint8(1)}
}