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

56 lines
2.2 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.entity.*;
import com.minelittlepony.unicopia.entity.duck.RotatedView;
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
2021-02-22 22:12:08 +01:00
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack;
2021-02-22 22:12:08 +01:00
import net.minecraft.world.World;
@Mixin(MobEntity.class)
abstract class MixinMobEntity extends LivingEntity implements Equine.Container<Creature> {
private MixinMobEntity() { super(null, null); }
@Shadow
protected @Final GoalSelector goalSelector;
@Shadow
protected @Final GoalSelector targetSelector;
2021-02-22 22:12:08 +01:00
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
private void init(EntityType<? extends MobEntity> entityType, World world, CallbackInfo info) {
get().initAi(goalSelector, targetSelector);
}
@Inject(method = "tickNewAi", at = @At("HEAD"))
public void beforeTickAi(CallbackInfo into) {
if (get().getPhysics().isGravityNegative()) {
2023-06-03 13:40:54 +02:00
((RotatedView)getWorld()).pushRotation((int)getY());
}
}
@Inject(method = "tickNewAi", at = @At("RETURN"))
public void afterTickAi(CallbackInfo into) {
2023-06-03 13:40:54 +02:00
((RotatedView)getWorld()).popRotation();
}
@Inject(method = "prefersNewEquipment(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z",
at = @At("HEAD"), cancellable = true)
private void onPrefersNewEquipment(ItemStack newStack, ItemStack oldStack, CallbackInfoReturnable<Boolean> info) {
if (WantItNeedItEnchantment.prefersEquipment(newStack, oldStack)) {
info.setReturnValue(true);
}
}
}