Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions server/block/shulker_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ func (s ShulkerBox) BreakInfo() BreakInfo {
return newBreakInfo(2, alwaysHarvestable, pickaxeEffective, oneOf(s))
}

// CreativeDrops returns the drops produced when a creative player breaks the shulker box. Filled shulker boxes retain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be done with a break handler

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure it's to match bedrock natively in dragonfly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it bypassed HandleBlockBreak

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inside of BreakInfo instead of being its own thing.

because it bypassed HandleBlockBreak

Then we should also switch over all the container blocks that drop their content on break. So don't call this CreativeDrops, and make explosions drop those items too instead of what's happening under here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll keep this pr consistent with the existing behavior then and PR a separate fix for all the blocks

// their contents and drop themselves.
func (s ShulkerBox) CreativeDrops() []item.Stack {
s = s.initialised()
if s.inventory.Empty() {
return nil
}
return []item.Stack{item.NewStack(s, 1)}
}

func (s ShulkerBox) MaxCount() int {
return 1
}
Expand Down
14 changes: 12 additions & 2 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,18 +2182,28 @@ func (p *Player) BreakBlock(pos cube.Pos) {
}
}

type creativeDropper interface {
CreativeDrops() []item.Stack
}

// drops returns the drops that the player can get from the block passed using the item held.
func (p *Player) drops(held item.Stack, b world.Block) []item.Stack {
t, ok := held.Item().(item.Tool)
if !ok {
t = item.ToolNone{}
}
if p.GameMode().CreativeInventory() {
if b, ok := b.(creativeDropper); ok {
return b.CreativeDrops()
}
return nil
}
var drops []item.Stack
if breakable, ok := b.(block.Breakable); ok && !p.GameMode().CreativeInventory() {
if breakable, ok := b.(block.Breakable); ok {
if breakable.BreakInfo().Harvestable(t) {
drops = breakable.BreakInfo().Drops(t, held.Enchantments())
}
} else if it, ok := b.(world.Item); ok && !p.GameMode().CreativeInventory() {
} else if it, ok := b.(world.Item); ok {
drops = []item.Stack{item.NewStack(it, 1)}
}
return drops
Expand Down