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 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c29e4fd
add cobwebs, strings, tripwires
HashimTheArab Mar 3, 2022
7756311
embed empty for strings instead of returning in Model()
HashimTheArab Mar 3, 2022
d7bd260
reset fall distance when in a cobweb
HashimTheArab Mar 7, 2022
4ee60e2
order / docs
HashimTheArab Mar 7, 2022
fc8942c
e
HashimTheArab Jul 4, 2022
5db9322
e 2
HashimTheArab Jul 4, 2022
794e5b9
Merge branch 'df-mc:master' into master
HashimTheArab Jul 7, 2022
6e8538a
Merge branch 'df-mc:master' into master
HashimTheArab Jul 8, 2022
b58bd50
Merge https://github.com/df-mc/dragonfly
HashimTheArab Jul 11, 2022
6c57b86
Merge branch 'df-mc:master' into master
HashimTheArab Jul 11, 2022
91f302d
Merge branch 'df-mc:master' into master
HashimTheArab Jul 14, 2022
99353e8
Merge branch 'df-mc:master' into master
HashimTheArab Jul 15, 2022
ff7fe76
Merge branch 'master' of https://github.com/grapedevs/dragonfly
HashimTheArab Jul 15, 2022
7308c06
Merge branch 'df-mc:master' into master
HashimTheArab Jul 18, 2022
b710735
Merge branch 'master' of https://github.com/grapedevs/dragonfly
HashimTheArab Jul 18, 2022
dfd4d8f
Merge branch 'df-mc:master' into master
HashimTheArab Jul 20, 2022
362ede1
Merge branch 'df-mc:master' into master
HashimTheArab Aug 11, 2022
e1519be
Merge branch 'df-mc:master' into master
HashimTheArab Aug 12, 2022
14848c1
Merge branch 'df-mc:master' into master
HashimTheArab Aug 15, 2022
2442349
Merge branch 'master' of https://github.com/grapedevs/dragonfly into …
HashimTheArab Aug 15, 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
5 changes: 5 additions & 0 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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 @@ -25,6 +25,7 @@ func init() {
world.RegisterBlock(Dirt{Coarse: true})
world.RegisterBlock(Cobblestone{})
world.RegisterBlock(Cobblestone{Mossy: true})
world.RegisterBlock(Cobweb{})
world.RegisterBlock(Bedrock{})
world.RegisterBlock(Bedrock{InfiniteBurning: true})
world.RegisterBlock(Obsidian{})
Expand Down Expand Up @@ -93,6 +94,7 @@ func init() {
world.RegisterBlock(PackedIce{})
world.RegisterBlock(DeadBush{})
world.RegisterBlock(Snow{})
world.RegisterBlock(String{})
world.RegisterBlock(Bookshelf{})

registerAll(allBarrels())
Expand Down Expand Up @@ -171,6 +173,7 @@ func init() {
world.RegisterItem(Dirt{})
world.RegisterItem(Dirt{Coarse: true})
world.RegisterItem(Cobblestone{})
world.RegisterItem(Cobweb{})
world.RegisterItem(Bedrock{})
world.RegisterItem(Kelp{})
world.RegisterItem(Chest{})
Expand Down Expand Up @@ -260,6 +263,7 @@ func init() {
world.RegisterItem(Snow{})
world.RegisterItem(Bookshelf{})
world.RegisterItem(Chain{})
world.RegisterItem(String{})
world.RegisterItem(SandstoneStairs{})
world.RegisterItem(SandstoneStairs{Red: true})
world.RegisterItem(SandstoneStairs{Smooth: true})
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)}
}