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

30 lines
1.1 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.mixin;
2020-01-16 12:35:46 +01:00
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;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.ducks.PonyContainer;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.Projectile;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.util.hit.EntityHitResult;
@Mixin(ProjectileEntity.class)
abstract class MixinProjectileEntity extends Entity implements Projectile {
private MixinProjectileEntity() { super(null, null); }
2020-01-16 12:35:46 +01:00
@Inject(method = "onEntityHit(Lnet/minecraft/util/hit/EntityHitResult;)V",
at = @At("HEAD"),
cancellable = true)
private void onOnEntityHit(EntityHitResult hit, CallbackInfo info) {
2020-04-15 18:12:00 +02:00
PonyContainer.of(hit.getEntity()).ifPresent(container -> {
if (container.get().onProjectileImpact((ProjectileEntity)(Object)this)) {
2020-01-16 12:35:46 +01:00
info.cancel();
}
});
}
}