-
Notifications
You must be signed in to change notification settings - Fork 183
feat: implement wind charges #1201
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
Open
HashimTheArab
wants to merge
5
commits into
df-mc:master
Choose a base branch
from
HashimTheArab:feature/wind-charge
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
| package entity | ||
|
|
||
| import ( | ||
| "github.com/df-mc/dragonfly/server/block" | ||
| "github.com/df-mc/dragonfly/server/block/cube" | ||
| "github.com/df-mc/dragonfly/server/block/cube/trace" | ||
| "github.com/df-mc/dragonfly/server/world" | ||
| "github.com/df-mc/dragonfly/server/world/particle" | ||
| "github.com/df-mc/dragonfly/server/world/sound" | ||
| ) | ||
|
|
||
| // windChargeBurstRadius is the maximum radius within which entities are | ||
| // knocked back by a wind charge burst. | ||
| const windChargeBurstRadius = 2.5 | ||
|
|
||
| // NewWindCharge creates a wind charge entity at a position with an owner | ||
| // entity. Wind charges fly in a straight line (no gravity) and create a burst | ||
| // of wind on impact that knocks back nearby entities and toggles certain | ||
| // interactive blocks. | ||
| func NewWindCharge(opts world.EntitySpawnOpts, owner world.Entity) *world.EntityHandle { | ||
| conf := windChargeConf | ||
| conf.Owner = owner.H() | ||
| return opts.New(WindChargeType, conf) | ||
| } | ||
|
|
||
| // TODO: Wind charges should have increased drag when travelling through water | ||
| // or lava, but per-medium drag is not yet supported by ProjectileBehaviour. | ||
| var windChargeConf = ProjectileBehaviourConfig{ | ||
| Gravity: 0, | ||
| Drag: 0, | ||
| Damage: -1, | ||
| Particle: particle.WindExplosion{}, | ||
| Sound: sound.WindChargeBurst{}, | ||
| Hit: windChargeBurst, | ||
| } | ||
|
HashimTheArab marked this conversation as resolved.
|
||
|
|
||
| // windChargeBurst is called when a wind charge hits a target. It deals 1 HP | ||
| // damage on a direct entity hit, knocks back all living entities within the | ||
| // burst radius, and toggles interactive blocks at the impact point. | ||
| func windChargeBurst(e *Ent, tx *world.Tx, target trace.Result) { | ||
| pos := target.Position() | ||
| owner, _ := e.Behaviour().(*ProjectileBehaviour).Owner().Entity(tx) | ||
|
|
||
| // Deal flat 1 HP damage to the directly-hit entity. | ||
| if er, ok := target.(trace.EntityResult); ok { | ||
| if l, ok := er.Entity().(Living); ok { | ||
| l.Hurt(1, ProjectileDamageSource{Projectile: e, Owner: owner}) | ||
| } | ||
| } | ||
|
|
||
| // Apply knockback to all living entities within the burst radius. Impact | ||
| // scales with distance (closer = stronger) and is split into horizontal | ||
| // and vertical components. | ||
| box := e.H().Type().BBox(e).Translate(pos).Grow(windChargeBurstRadius) | ||
| for other := range tx.EntitiesWithin(box) { | ||
| if other.H() == e.H() { | ||
| continue | ||
| } | ||
| l, ok := other.(Living) | ||
| if !ok { | ||
| continue | ||
| } | ||
| entityPos := other.Position() | ||
| dist := entityPos.Sub(pos).Len() | ||
| impact := 1.3 - dist/windChargeBurstRadius | ||
| if impact <= 0 { | ||
| continue | ||
| } | ||
|
|
||
| vel := l.Velocity() | ||
| // If the entity is directly above the impact, apply a flat upward | ||
| // boost. Otherwise split into horizontal and vertical components. | ||
| dx := entityPos[0] - pos[0] | ||
| dz := entityPos[2] - pos[2] | ||
| if dx*dx+dz*dz < 0.01 { | ||
| vel[1] += 1.1 | ||
| } else { | ||
| dir := entityPos.Sub(pos) | ||
| dir[1] = 0 | ||
| dir = dir.Normalize() | ||
| vel = vel.Add(dir.Mul(impact)) | ||
| vel[1] += impact * 0.4 | ||
| } | ||
| l.SetVelocity(vel) | ||
| } | ||
|
|
||
| // Toggle interactive blocks at the impact point. | ||
| if r, ok := target.(trace.BlockResult); ok { | ||
| pos := r.BlockPosition() | ||
| if b, ok := tx.Block(pos).(block.WindChargeAffected); ok { | ||
| b.Activate(pos, r.Face(), tx, nil, nil) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // WindChargeType is a world.EntityType implementation for WindCharge. | ||
| var WindChargeType windChargeType | ||
|
|
||
| type windChargeType struct{} | ||
|
|
||
| func (windChargeType) Open(tx *world.Tx, handle *world.EntityHandle, data *world.EntityData) world.Entity { | ||
| return &Ent{tx: tx, handle: handle, data: data} | ||
| } | ||
|
|
||
| func (windChargeType) EncodeEntity() string { return "minecraft:wind_charge_projectile" } | ||
| func (windChargeType) BBox(world.Entity) cube.BBox { | ||
| return cube.Box(-0.15625, 0, -0.15625, 0.15625, 0.3125, 0.15625) | ||
| } | ||
|
|
||
| func (windChargeType) DecodeNBT(_ map[string]any, data *world.EntityData) { | ||
| data.Data = windChargeConf.New() | ||
| } | ||
| func (windChargeType) EncodeNBT(*world.EntityData) map[string]any { return nil } | ||
This file contains hidden or 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 hidden or 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,33 @@ | ||
| package item | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/df-mc/dragonfly/server/world" | ||
| "github.com/df-mc/dragonfly/server/world/sound" | ||
| ) | ||
|
|
||
| // WindCharge is a throwable item that creates a burst of wind on impact, knocking back nearby entities and | ||
| // toggling certain blocks such as doors, trapdoors and fence gates. | ||
| type WindCharge struct{} | ||
|
|
||
| // Use ... | ||
| func (WindCharge) Use(tx *world.Tx, user User, ctx *UseContext) bool { | ||
| create := tx.World().EntityRegistry().Config().WindCharge | ||
| opts := world.EntitySpawnOpts{Position: eyePosition(user), Velocity: user.Rotation().Vec3().Mul(3.0)} | ||
|
HashimTheArab marked this conversation as resolved.
|
||
| tx.AddEntity(create(opts, user)) | ||
| tx.PlaySound(user.Position(), sound.ItemThrow{}) | ||
|
|
||
| ctx.SubtractFromCount(1) | ||
| return true | ||
| } | ||
|
|
||
| // Cooldown ... | ||
| func (WindCharge) Cooldown() time.Duration { | ||
| return time.Millisecond * 500 | ||
| } | ||
|
|
||
| // EncodeItem ... | ||
| func (WindCharge) EncodeItem() (name string, meta int16) { | ||
| return "minecraft:wind_charge", 0 | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.