53 lines
2.0 KiB
Java
53 lines
2.0 KiB
Java
package codes.som.hibiscus.mixins;
|
|
|
|
import codes.som.hibiscus.HibiscusMod;
|
|
import codes.som.hibiscus.events.MovePlayerEvent;
|
|
import codes.som.hibiscus.events.PlayerPreTickEvent;
|
|
import codes.som.hibiscus.events.PlayerTickEvent;
|
|
import codes.som.hibiscus.events.SendChatEvent;
|
|
import net.minecraft.client.network.ClientPlayerEntity;
|
|
import net.minecraft.entity.MovementType;
|
|
import net.minecraft.util.math.Vec3d;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Unique;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
@Mixin(ClientPlayerEntity.class)
|
|
public abstract class MixinClientPlayerEntity {
|
|
@Inject(method = "tick", at = @At("HEAD"))
|
|
private void onPreTick(CallbackInfo ci) {
|
|
HibiscusMod.bus().fire(PlayerPreTickEvent.INSTANCE);
|
|
}
|
|
|
|
@Inject(method = "tick", at = @At("RETURN"))
|
|
private void onPostTick(CallbackInfo ci) {
|
|
HibiscusMod.bus().fire(PlayerTickEvent.INSTANCE);
|
|
}
|
|
|
|
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
|
private void onChatMessage(String message, CallbackInfo ci) {
|
|
var event = new SendChatEvent(message);
|
|
HibiscusMod.bus().fire(event);
|
|
if (event.isCancelled())
|
|
ci.cancel();
|
|
}
|
|
|
|
@Unique
|
|
private MovementType movementType;
|
|
|
|
@Inject(method = "move", at = @At("HEAD"))
|
|
private void onMovePlayerWhatIsTheMovementType(MovementType type, Vec3d movement, CallbackInfo ci) {
|
|
this.movementType = type;
|
|
}
|
|
|
|
@ModifyVariable(method = "move", at = @At(value = "HEAD", shift = At.Shift.AFTER), argsOnly = true)
|
|
private Vec3d onMovePlayer(Vec3d movement) {
|
|
var event = new MovePlayerEvent(movement.x, movement.y, movement.z, this.movementType);
|
|
HibiscusMod.bus().fire(event);
|
|
return new Vec3d(event.getX(), event.getY(), event.getZ());
|
|
}
|
|
}
|