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:
1 parent
ec47dea267
commit
0ac214963f
3 files changed
+33
No files matched your search
@@ -858,6 +858,7 @@ defining the callback with `entity_event`.
|
||||
The following events can be handled by entities:
|
||||
|
||||
* `'on_tick'`: executes every tick right before the entity is ticked in the game. Required arguments: `entity`
|
||||
* `'on_move'`: executes every time an entity changes position, invoked just after it has been moved to the new position. Required arguments: `entity, velocity, pos1, pos2`
|
||||
* `'on_death'`: executes once when a living entity dies. Required arguments: `entity, reason`
|
||||
* `'on_removed'`: execute once when an entity is removed. Required arguments: `entity`
|
||||
* `'on_damaged'`: executed every time a living entity is about to receive damage.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,10 @@ import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -108,6 +110,19 @@ public class EntityEventsGroup
|
||||
);
|
||||
}
|
||||
};
|
||||
public static final Event ON_MOVE = new Event("on_move", 3)
|
||||
{
|
||||
@Override
|
||||
public List<Value> makeArgs(Entity entity, Object... providedArgs)
|
||||
{
|
||||
return Arrays.asList(
|
||||
new EntityValue(entity),
|
||||
ValueConversions.of((Vec3d) providedArgs[0]),
|
||||
ValueConversions.of((Vec3d) providedArgs[1]),
|
||||
ValueConversions.of((Vec3d) providedArgs[2])
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
public final int argcount;
|
||||
public final String id;
|
||||
|
||||
Reference in new issue
Block a user