Add on_move Entity Event for Scarpet (#1096)

* Add ON_MOVE Entity Event for Scarpet

* Update src/main/java/carpet/script/EntityEventsGroup.java

* Add on_move to Entities.md

* Switch to ValueConversions

* Update docs/scarpet/api/Entities.md

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>

* Fix #1126

* undo last commit cause it was on the wrong branch

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
intricateandgnembon authored and GitHub committed 2022-01-19 21:36:16 +01:00
1 parent ec47dea267
commit 0ac214963f
3 files changed
+33

No files matched your search

@@ -3,6 +3,7 @@ package carpet.mixins;
import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -19,10 +20,14 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
@Shadow public abstract boolean isRemoved();
@Shadow private Vec3d pos, velocity;
private boolean permanentVehicle;
private final EntityEventsGroup events = new EntityEventsGroup((Entity) (Object)this);
private Vec3d pos1, motion;
@Override
public EntityEventsGroup getEventContainer()
{
@@ -79,4 +84,16 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
}
@Inject(method = "setPos", at = @At("HEAD"))
private void firstPos(CallbackInfo ci)
{
pos1 = this.pos;
motion = this.velocity;
}
@Inject(method = "setPos", at = @At("TAIL"))
private void secondPos(CallbackInfo ci)
{
events.onEvent(EntityEventsGroup.Event.ON_MOVE, motion, pos1, this.pos);
}
}