Unicopia/src/main/java/com/minelittlepony/unicopia/mixin/MixinBrain.java

33 lines
1.1 KiB
Java
Raw Normal View History

2021-02-23 22:49:14 +01:00
package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2021-02-23 22:49:14 +01:00
import com.minelittlepony.unicopia.entity.Equine;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.duck.RotatedView;
2021-02-23 22:49:14 +01:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.Brain;
import net.minecraft.server.world.ServerWorld;
@Mixin(Brain.class)
abstract class MixinBrain<E extends LivingEntity> {
@Inject(method = "tick", at = @At("HEAD"))
public void beforeTickAi(ServerWorld world, E entity, CallbackInfo into) {
2021-03-06 22:11:17 +01:00
Equine<?> eq = Equine.of(entity).orElse(null);
2021-02-23 22:49:14 +01:00
if (eq instanceof Living<?> && eq.getPhysics().isGravityNegative()) {
((RotatedView)world).pushRotation((int)entity.getY());
}
}
@Inject(method = "tick", at = @At("RETURN"))
public void afterTickAi(ServerWorld world, E entity, CallbackInfo into) {
((RotatedView)world).popRotation();
}
}