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

31 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)
public abstract class MixinProjectileEntity extends Entity implements Projectile {
public MixinProjectileEntity() { super(null, null); }
@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();
}
});
}
}