-
Notifications
You must be signed in to change notification settings - Fork 139
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 bells #645
Open
JustTalDevelops
wants to merge
9
commits into
master
Choose a base branch
from
feature/bells
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implemented bells #645
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
834a164
server/block: Implemented bells.
JustTalDevelops b6683b1
block/bell.go: Projectile functionality.
JustTalDevelops 7b63838
Merge branch 'master' into feature/bells
JustTalDevelops af30496
block/bell.go: Item ejection.
JustTalDevelops fef1479
model: Implemented bell models.
JustTalDevelops 0eaaaa2
Merge branch 'master' into feature/bells
JustTalDevelops 42f3f67
Merge branch 'master' into feature/bells
JustTalDevelops 9fbd647
Merge branch 'master' into feature/bells
TwistedAsylumMC 9b2f966
block/bell.go: Update to work with latest dragonfly
TwistedAsylumMC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package block | ||
|
||
import ( | ||
"github.com/df-mc/dragonfly/server/block/cube" | ||
"github.com/df-mc/dragonfly/server/block/model" | ||
"github.com/df-mc/dragonfly/server/item" | ||
"github.com/df-mc/dragonfly/server/world" | ||
"github.com/df-mc/dragonfly/server/world/particle" | ||
"github.com/df-mc/dragonfly/server/world/sound" | ||
"github.com/go-gl/mathgl/mgl64" | ||
) | ||
|
||
// Bell is a transparent, animated block entity that produces a sound when used. Unlike most utility blocks, bells | ||
// cannot be crafted. | ||
type Bell struct { | ||
transparent | ||
|
||
// Attach represents the attachment type of the Bell. | ||
Attach BellAttachment | ||
// Facing represents the direction the Bell is facing. | ||
Facing cube.Direction | ||
} | ||
|
||
// Model ... | ||
func (b Bell) Model() world.BlockModel { | ||
return model.Bell{Attach: b.Attach.String(), Facing: b.Facing} | ||
} | ||
|
||
// BreakInfo ... | ||
func (b Bell) BreakInfo() BreakInfo { | ||
return newBreakInfo(1, pickaxeHarvestable, pickaxeEffective, oneOf(b)).withBlastResistance(15) | ||
} | ||
|
||
// UseOnBlock ... | ||
func (b Bell) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) { | ||
pos, face, used = firstReplaceable(w, pos, face, b) | ||
if !used { | ||
return false | ||
} | ||
b.Facing = user.Rotation().Direction().Opposite() | ||
if face == cube.FaceUp { | ||
if _, ok := w.Block(pos.Side(cube.FaceDown)).Model().(model.Solid); !ok { | ||
return false | ||
} | ||
} else if face == cube.FaceDown { | ||
if _, ok := w.Block(pos.Side(cube.FaceUp)).Model().(model.Solid); !ok { | ||
return false | ||
} | ||
b.Attach = HangingBellAttachment() | ||
} else { | ||
if _, ok := w.Block(pos.Side(face.Opposite())).Model().(model.Solid); !ok { | ||
return false | ||
} | ||
b.Facing = face.Direction() | ||
b.Attach = WallBellAttachment() | ||
if _, ok := w.Block(pos.Side(face)).Model().(model.Solid); ok { | ||
b.Attach = WallsBellAttachment() | ||
} | ||
} | ||
place(w, pos, b, user, ctx) | ||
return placed(ctx) | ||
} | ||
|
||
// NeighbourUpdateTick ... | ||
func (b Bell) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) { | ||
var supportFaces []cube.Face | ||
switch b.Attach { | ||
case HangingBellAttachment(): | ||
supportFaces = append(supportFaces, cube.FaceUp) | ||
case StandingBellAttachment(): | ||
supportFaces = append(supportFaces, cube.FaceDown) | ||
case WallBellAttachment(), WallsBellAttachment(): | ||
supportFaces = append(supportFaces, b.Facing.Face().Opposite()) | ||
if b.Attach == WallsBellAttachment() { | ||
supportFaces = append(supportFaces, b.Facing.Face()) | ||
} | ||
} | ||
for _, supportFace := range supportFaces { | ||
if _, ok := w.Block(pos.Side(supportFace)).Model().(model.Solid); !ok { | ||
w.SetBlock(pos, nil, nil) | ||
w.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: b}) | ||
dropItem(w, item.NewStack(b, 1), pos.Vec3Centre()) | ||
break | ||
} | ||
} | ||
} | ||
|
||
// Activate ... | ||
func (b Bell) Activate(pos cube.Pos, _ cube.Face, w *world.World, u item.User, _ *item.UseContext) bool { | ||
s, f := u.Rotation().Direction().Opposite().Face(), b.Facing.Face() | ||
switch b.Attach { | ||
case HangingBellAttachment(): | ||
b.Ring(pos, s, w) | ||
return true | ||
case StandingBellAttachment(): | ||
if s.Axis() == f.Axis() { | ||
b.Ring(pos, s, w) | ||
return true | ||
} | ||
case WallBellAttachment(), WallsBellAttachment(): | ||
if s == f.RotateLeft() || s == f.RotateRight() { | ||
b.Ring(pos, s, w) | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// EntityInside ... | ||
func (b Bell) EntityInside(pos cube.Pos, w *world.World, e world.Entity) { | ||
if ejector, ok := e.Type().(EntityEjector); ok { | ||
ejector.EntityEject(e, pos) | ||
|
||
// BDS always rings the bell on it's facing direction, even if the entity is ejected in a different direction. | ||
b.Ring(pos, b.Facing.Face(), w) | ||
} | ||
} | ||
|
||
// ProjectileHit ... | ||
func (b Bell) ProjectileHit(w *world.World, _ world.Entity, pos cube.Pos, face cube.Face) { | ||
b.Ring(pos, face, w) | ||
} | ||
|
||
// Ring rings the bell on the face passed. | ||
func (b Bell) Ring(pos cube.Pos, face cube.Face, w *world.World) { | ||
w.PlaySound(pos.Vec3Centre(), sound.BellRing{}) | ||
for _, v := range w.Viewers(pos.Vec3Centre()) { | ||
v.ViewBlockAction(pos, BellRing{Face: face}) | ||
} | ||
} | ||
|
||
// EncodeNBT encodes the Bell's block entity ID. There are other properties, but we can skip those. | ||
func (b Bell) EncodeNBT() map[string]any { | ||
return map[string]any{"id": "Bell"} | ||
} | ||
|
||
// DecodeNBT ... | ||
func (b Bell) DecodeNBT(map[string]any) any { | ||
return b | ||
} | ||
|
||
// EncodeItem ... | ||
func (b Bell) EncodeItem() (name string, meta int16) { | ||
return "minecraft:bell", 0 | ||
} | ||
|
||
// EncodeBlock ... | ||
func (b Bell) EncodeBlock() (string, map[string]any) { | ||
return "minecraft:bell", map[string]any{ | ||
"toggle_bit": uint8(0), // Useless property, updated on ring in vanilla. | ||
"attachment": b.Attach.String(), | ||
"direction": int32(horizontalDirection(b.Facing)), | ||
} | ||
} | ||
|
||
// allBells ... | ||
func allBells() (bells []world.Block) { | ||
for _, a := range BellAttachments() { | ||
for _, d := range cube.Directions() { | ||
bells = append(bells, Bell{Attach: a, Facing: d}) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package block | ||
|
||
// BellAttachment represents a type of attachment for a Bell. | ||
type BellAttachment struct { | ||
bellAttachment | ||
} | ||
|
||
// StandingBellAttachment is a type of attachment for a standing Bell. | ||
func StandingBellAttachment() BellAttachment { | ||
return BellAttachment{0} | ||
} | ||
|
||
// HangingBellAttachment is a type of attachment for a hanging Bell. | ||
func HangingBellAttachment() BellAttachment { | ||
return BellAttachment{1} | ||
} | ||
|
||
// WallBellAttachment is a type of attachment for a wall Bell. | ||
func WallBellAttachment() BellAttachment { | ||
return BellAttachment{2} | ||
} | ||
|
||
// WallsBellAttachment is a type of attachment for a two-wall Bell. | ||
func WallsBellAttachment() BellAttachment { | ||
return BellAttachment{3} | ||
} | ||
|
||
// BellAttachments returns all possible BellAttachments. | ||
func BellAttachments() []BellAttachment { | ||
return []BellAttachment{StandingBellAttachment(), HangingBellAttachment(), WallBellAttachment(), WallsBellAttachment()} | ||
} | ||
|
||
type bellAttachment uint8 | ||
|
||
// Uint8 returns the BellAttachment as a uint8. | ||
func (g bellAttachment) Uint8() uint8 { | ||
return uint8(g) | ||
} | ||
|
||
// String returns the BellAttachment as a string. | ||
func (g bellAttachment) String() string { | ||
switch g { | ||
case 0: | ||
return "standing" | ||
case 1: | ||
return "hanging" | ||
case 2: | ||
return "side" | ||
case 3: | ||
return "multiple" | ||
} | ||
panic("should never happen") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/df-mc/dragonfly/server/block/cube" | ||
"github.com/df-mc/dragonfly/server/world" | ||
"github.com/go-gl/mathgl/mgl64" | ||
) | ||
|
||
// Bell represents the block model of a bell. | ||
type Bell struct { | ||
// Attach represents the attachment type of the Bell. | ||
Attach string | ||
// Facing represents the direction the Bell is facing. | ||
Facing cube.Direction | ||
} | ||
|
||
// BBox ... | ||
func (b Bell) BBox(cube.Pos, *world.World) []cube.BBox { | ||
if b.Attach == "standing" { | ||
return []cube.BBox{full.Stretch(b.Facing.Face().Axis(), -0.25).ExtendTowards(cube.FaceUp, -0.1875)} | ||
} | ||
if b.Attach == "hanging" { | ||
return []cube.BBox{full.GrowVec3(mgl64.Vec3{-0.25, 0, -0.25}).ExtendTowards(cube.FaceDown, -0.25)} | ||
} | ||
|
||
box := full.Stretch(b.Facing.RotateLeft().Face().Axis(), -0.25). | ||
ExtendTowards(cube.FaceUp, -0.0625). | ||
ExtendTowards(cube.FaceDown, -0.25) | ||
if b.Attach == "side" { | ||
return []cube.BBox{box.ExtendTowards(b.Facing.Face(), -0.1875)} | ||
} | ||
return []cube.BBox{box} | ||
} | ||
|
||
// FaceSolid ... | ||
func (Bell) FaceSolid(cube.Pos, cube.Face, *world.World) bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem accurate as it's the item entity that's implementing this...