Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 4 additions & 1 deletion server/block/bamboo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ func (b Bamboo) FlammabilityInfo() FlammabilityInfo {

// BreakInfo ...
func (b Bamboo) BreakInfo() BreakInfo {
return newBreakInfo(1, alwaysHarvestable, axeEffective, oneOf(b))
return newBreakInfo(1, alwaysHarvestable, anyEffective(item.TypeAxe, item.TypeSword), oneOf(b))
}

// SwordMiningSpeed is high enough for a sword to break bamboo in one tick.
func (Bamboo) SwordMiningSpeed() float64 { return 30 }

// EncodeBlock ...
func (b Bamboo) EncodeBlock() (string, map[string]any) {
thickness := "thin"
Expand Down
5 changes: 4 additions & 1 deletion server/block/bamboo_sapling.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ func (b BambooSapling) RandomTick(pos cube.Pos, tx *world.Tx, r *rand.Rand) {

// BreakInfo ...
func (b BambooSapling) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, axeEffective, oneOf(Bamboo{})).withBlastResistance(1)
return newBreakInfo(0, alwaysHarvestable, anyEffective(item.TypeAxe, item.TypeSword), oneOf(Bamboo{})).withBlastResistance(1)
}

// SwordMiningSpeed ...
func (BambooSapling) SwordMiningSpeed() float64 { return 30 }

// HasLiquidDrops ...
func (b BambooSapling) HasLiquidDrops() bool {
return true
Expand Down
8 changes: 8 additions & 0 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ var nothingEffective = func(item.Tool) bool {
return false
}

// anyEffective is a convenience function for blocks that are effectively mined with more than one type
// of tool.
func anyEffective(types ...item.ToolType) func(item.Tool) bool {
return func(t item.Tool) bool {
return slices.Contains(types, t.ToolType())
}
}

// alwaysHarvestable is a convenience function for blocks that are harvestable using any item.
var alwaysHarvestable = func(t item.Tool) bool {
return true
Expand Down
6 changes: 6 additions & 0 deletions server/block/cobweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type Cobweb struct {
// Cobweb is implemented because the item package needs to identify this block but cannot implement the block package.
func (Cobweb) Cobweb() {}

// SwordMiningSpeed ...
func (Cobweb) SwordMiningSpeed() float64 { return 15 }

// ShearsMiningSpeed ...
func (Cobweb) ShearsMiningSpeed() float64 { return 15 }

// EntityInside slows the entity's velocity and resets its fall distance while it is inside the cobweb.
func (Cobweb) EntityInside(_ cube.Pos, _ *world.Tx, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
Expand Down
5 changes: 4 additions & 1 deletion server/block/cocoa_bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ func (c CocoaBean) RandomTick(pos cube.Pos, tx *world.Tx, r *rand.Rand) {

// BreakInfo ...
func (c CocoaBean) BreakInfo() BreakInfo {
return newBreakInfo(0.2, alwaysHarvestable, axeEffective, func(item.Tool, []item.Enchantment) []item.Stack {
return newBreakInfo(0.2, alwaysHarvestable, anyEffective(item.TypeAxe, item.TypeSword), func(item.Tool, []item.Enchantment) []item.Stack {
if c.Age == 2 {
return []item.Stack{item.NewStack(c, rand.IntN(2)+2)}
}
return []item.Stack{item.NewStack(c, 1)}
}).withBlastResistance(3)
}

// SwordMiningSpeed ...
func (CocoaBean) SwordMiningSpeed() float64 { return 1.5 }

// CompostChance ...
func (CocoaBean) CompostChance() float64 {
return 0.65
Expand Down
10 changes: 7 additions & 3 deletions server/block/leaves.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,20 @@ func (l Leaves) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) {
}
}

// SwordMiningSpeed ...
func (Leaves) SwordMiningSpeed() float64 { return 1.5 }

// ShearsMiningSpeed ...
func (Leaves) ShearsMiningSpeed() float64 { return 15 }

// FlammabilityInfo ...
func (l Leaves) FlammabilityInfo() FlammabilityInfo {
return newFlammabilityInfo(30, 60, true)
}

// BreakInfo ...
func (l Leaves) BreakInfo() BreakInfo {
return newBreakInfo(0.2, alwaysHarvestable, func(t item.Tool) bool {
return t.ToolType() == item.TypeShears || t.ToolType() == item.TypeHoe
}, func(t item.Tool, enchantments []item.Enchantment) []item.Stack {
return newBreakInfo(0.2, alwaysHarvestable, anyEffective(item.TypeShears, item.TypeHoe, item.TypeSword), func(t item.Tool, enchantments []item.Enchantment) []item.Stack {
if t.ToolType() == item.TypeShears || hasSilkTouch(enchantments) {
return []item.Stack{item.NewStack(l, 1)}
}
Expand Down
5 changes: 4 additions & 1 deletion server/block/melon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ type Melon struct {

// BreakInfo ...
func (m Melon) BreakInfo() BreakInfo {
return newBreakInfo(1, alwaysHarvestable, axeEffective, discreteDrops(item.MelonSlice{}, m, 3, 7, 9))
return newBreakInfo(1, alwaysHarvestable, anyEffective(item.TypeAxe, item.TypeSword), discreteDrops(item.MelonSlice{}, m, 3, 7, 9))
}

// SwordMiningSpeed ...
func (Melon) SwordMiningSpeed() float64 { return 1.5 }

// CompostChance ...
func (Melon) CompostChance() float64 {
return 0.65
Expand Down
5 changes: 4 additions & 1 deletion server/block/moss_carpet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ func (m MossCarpet) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *w

// BreakInfo ...
func (m MossCarpet) BreakInfo() BreakInfo {
return newBreakInfo(0.1, alwaysHarvestable, nothingEffective, oneOf(m))
return newBreakInfo(0.1, alwaysHarvestable, swordEffective, oneOf(m))
}

// SwordMiningSpeed ...
func (MossCarpet) SwordMiningSpeed() float64 { return 1.5 }

// CompostChance ...
func (MossCarpet) CompostChance() float64 {
return 0.3
Expand Down
5 changes: 4 additions & 1 deletion server/block/pumpkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ func (p Pumpkin) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *worl

// BreakInfo ...
func (p Pumpkin) BreakInfo() BreakInfo {
return newBreakInfo(1, alwaysHarvestable, axeEffective, oneOf(p))
return newBreakInfo(1, alwaysHarvestable, anyEffective(item.TypeAxe, item.TypeSword), oneOf(p))
}

// SwordMiningSpeed ...
func (Pumpkin) SwordMiningSpeed() float64 { return 1.5 }

// CompostChance ...
func (Pumpkin) CompostChance() float64 {
return 0.65
Expand Down
8 changes: 7 additions & 1 deletion server/block/vine.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ func (Vines) FlammabilityInfo() FlammabilityInfo {
func (v Vines) BreakInfo() BreakInfo {
return newBreakInfo(0.2, func(t item.Tool) bool {
return t.ToolType() == item.TypeShears
}, axeEffective, oneOf(v))
}, anyEffective(item.TypeAxe, item.TypeSword, item.TypeShears), oneOf(v))
}

// SwordMiningSpeed ...
func (Vines) SwordMiningSpeed() float64 { return 1.5 }

// ShearsMiningSpeed ...
func (Vines) ShearsMiningSpeed() float64 { return 2 }

// EntityInside ...
func (Vines) EntityInside(_ cube.Pos, _ *world.Tx, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
Expand Down
3 changes: 3 additions & 0 deletions server/block/wool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (w Wool) BreakInfo() BreakInfo {
return newBreakInfo(0.8, alwaysHarvestable, shearsEffective, oneOf(w))
}

// ShearsMiningSpeed ...
func (Wool) ShearsMiningSpeed() float64 { return 5 }

// EncodeItem ...
func (w Wool) EncodeItem() (name string, meta int16) {
return "minecraft:" + w.Colour.String() + "_wool", 0
Expand Down
15 changes: 12 additions & 3 deletions server/item/shears.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,18 @@ func (s Shears) HarvestLevel() int {
return 1
}

// BaseMiningEfficiency ...
func (s Shears) BaseMiningEfficiency(world.Block) float64 {
return 1.5
// ShearsMineable is implemented by blocks that shears mine faster than a bare hand.
type ShearsMineable interface {
// ShearsMiningSpeed returns the speed shears mine the block at.
ShearsMiningSpeed() float64
}

// BaseMiningEfficiency returns the speed the block passed names for shears, or 1 if it names none.
func (s Shears) BaseMiningEfficiency(b world.Block) float64 {
if m, ok := b.(ShearsMineable); ok {
return m.ShearsMiningSpeed()
}
return 1
}

// DurabilityInfo ...
Expand Down
14 changes: 10 additions & 4 deletions server/item/sword.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ func (s Sword) EnchantmentValue() int {
return s.Tier.EnchantmentValue
}

// BaseMiningEfficiency always returns 1.5, unless the block passed is cobweb, in which case 15 is returned.
// SwordMineable is implemented by blocks that a sword mines faster than a bare hand.
type SwordMineable interface {
// SwordMiningSpeed returns the speed a sword mines the block at.
SwordMiningSpeed() float64
}

// BaseMiningEfficiency returns the speed the block passed names for a sword, or 1 if it names none.
func (s Sword) BaseMiningEfficiency(b world.Block) float64 {
if _, ok := b.(interface{ Cobweb() }); ok {
return 15
if m, ok := b.(SwordMineable); ok {
return m.SwordMiningSpeed()
}
return 1.5
return 1
}

// DurabilityInfo ...
Expand Down