Skip to content

Commit

Permalink
refactor: rename raw knockback to knockback in ActorKnockbackEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Sep 3, 2024
1 parent f440c2e commit 50b59ca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 28 deletions.
19 changes: 3 additions & 16 deletions include/endstone/event/actor/actor_knockback_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#pragma once

#include "endstone/event/actor/actor_event.h"
#include "endstone/actor/mob.h"
#include "endstone/event/actor/actor_event.h"

namespace endstone {

Expand All @@ -24,8 +24,8 @@ namespace endstone {
*/
class ActorKnockbackEvent : public ActorEvent {
public:
explicit ActorKnockbackEvent(Mob &mob, Actor *source, Vector<float> raw_knockback, Vector<float> knockback)
: ActorEvent(mob), mob_(mob), source_(source), raw_knockback_(raw_knockback), knockback_(knockback)
explicit ActorKnockbackEvent(Mob &mob, Actor *source, Vector<float> knockback)
: ActorEvent(mob), mob_(mob), source_(source), knockback_(knockback)
{
}
~ActorKnockbackEvent() override = default;
Expand Down Expand Up @@ -61,19 +61,6 @@ class ActorKnockbackEvent : public ActorEvent {
return source_;
}

/**
* @brief Gets the raw knockback that will be applied to the entity.
*
* <p>
* This value is read-only, changes made to it <b>will not</b> have any effect on the final knockback received.
*
* @return the raw knockback
*/
[[nodiscard]] Vector<float> getRawKnockback() const
{
return raw_knockback_;
}

/**
* Gets the knockback that will be applied to the entity.
*
Expand Down
5 changes: 0 additions & 5 deletions python/src/endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ class ActorKnockbackEvent(ActorEvent):
def knockback(self, arg1: Vector) -> None:
...
@property
def raw_knockback(self) -> Vector:
"""
Gets the raw knockback that will be applied to the entity.
"""
@property
def source(self) -> Actor:
"""
Get the source actor that has caused knockback to the defender, if exists.
Expand Down
2 changes: 0 additions & 2 deletions src/endstone_python/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ void init_event(py::module_ &m, py::class_<Event> &event, py::enum_<EventPriorit
"Returns the Mob involved in this event")
.def_property_readonly("source", &ActorKnockbackEvent::getSource, py::return_value_policy::reference,
"Get the source actor that has caused knockback to the defender, if exists.")
.def_property_readonly("raw_knockback", &ActorKnockbackEvent::getRawKnockback,
"Gets the raw knockback that will be applied to the entity.")
.def_property("knockback", &ActorKnockbackEvent::getKnockback, &ActorKnockbackEvent::setKnockback,
"Gets or sets the knockback that will be applied to the entity.");
py::class_<ActorRemoveEvent, ActorEvent>(m, "ActorRemoveEvent", "Called when an Actor is removed.");
Expand Down
8 changes: 3 additions & 5 deletions src/endstone_runtime/bedrock/world/actor/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ void Mob::knockback(Actor *source, int damage, float dx, float dz, float horizon
auto diff = after - before;

auto &server = entt::locator<EndstoneServer>::value();
endstone::ActorKnockbackEvent e{getEndstoneMob(),
source == nullptr ? nullptr : &source->getEndstoneActor(),
{diff.x, diff.y, diff.z},
{after.x, after.y, after.z}};
endstone::ActorKnockbackEvent e{
getEndstoneMob(), source == nullptr ? nullptr : &source->getEndstoneActor(), {diff.x, diff.y, diff.z}};
server.getPluginManager().callEvent(e);

auto knockback = e.getKnockback();
diff = e.isCancelled() ? Vec3::ZERO : (Vec3{knockback.getX(), knockback.getY(), knockback.getZ()} - before);
diff = e.isCancelled() ? Vec3::ZERO : Vec3{knockback.getX(), knockback.getY(), knockback.getZ()};
setPosDelta(before + diff);
}

Expand Down

0 comments on commit 50b59ca

Please sign in to comment.