Search in sources :

Example 11 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class LeadItemMixin_1_14 method attachToFence.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public static boolean attachToFence(PlayerEntity player, World worldIn, BlockPos fence) {
    LeashKnotEntity leashknotentity = null;
    boolean flag = false;
    double d0 = 7.0D;
    int i = fence.getX();
    int j = fence.getY();
    int k = fence.getZ();
    for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
        if (mobentity.getLeashHolder() == player) {
            if (leashknotentity == null) {
                leashknotentity = LeashKnotEntity.create(worldIn, fence);
                HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    leashknotentity.remove();
                    return false;
                }
            }
            if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
                continue;
            }
            mobentity.setLeashHolder(leashknotentity, true);
            flag = true;
        }
    }
    return flag;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 12 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class ZombiePigmanEntityMixin_1_14 method arclight$anger.

@Inject(method = "becomeAngryAt", cancellable = true, at = @At("HEAD"))
private void arclight$anger(Entity entity, CallbackInfoReturnable<Boolean> cir) {
    PigZombieAngerEvent event = new PigZombieAngerEvent((PigZombie) this.bridge$getBukkitEntity(), (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), this.func_223336_ef());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        cir.setReturnValue(false);
    } else {
        arclight$capture = event.getNewAnger();
    }
}
Also used : PigZombieAngerEvent(org.bukkit.event.entity.PigZombieAngerEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 13 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class CraftEventFactoryMixin method arclight$unhandledDamage.

@Inject(method = "handleEntityDamageEvent(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", cancellable = true, at = @At(value = "NEW", target = "java/lang/IllegalStateException"))
private static void arclight$unhandledDamage(Entity entity, DamageSource source, Map<EntityDamageEvent.DamageModifier, Double> modifiers, Map<EntityDamageEvent.DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled, CallbackInfoReturnable<EntityDamageEvent> cir) {
    // todo blockDamage is lost
    EntityDamageEvent event;
    if (source.getTrueSource() != null) {
        ArclightMod.LOGGER.debug("Unhandled damage of {} by {} from {}", entity, source.getTrueSource(), source.damageType);
        event = new EntityDamageByEntityEvent(((EntityBridge) source.getTrueSource()).bridge$getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions);
    } else {
        ArclightMod.LOGGER.debug("Unhandled damage of {} from {}", entity, source.damageType);
        event = new EntityDamageEvent(((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions);
    }
    event.setCancelled(cancelled);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        ((EntityBridge) entity).bridge$getBukkitEntity().setLastDamageCause(event);
    }
    cir.setReturnValue(event);
}
Also used : EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 14 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class ServerWorldMixin method arclight$lightningEvent.

@Inject(method = "addLightningBolt", cancellable = true, at = @At("HEAD"))
public void arclight$lightningEvent(LightningBoltEntity entityIn, CallbackInfo ci) {
    LightningStrikeEvent event = new LightningStrikeEvent(this.getWorld(), (LightningStrike) ((EntityBridge) entityIn).bridge$getBukkitEntity(), arclight$cause);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        ci.cancel();
    }
    arclight$cause = null;
}
Also used : LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with EntityBridge

use of io.izzel.arclight.common.bridge.entity.EntityBridge in project Arclight by IzzelAliz.

the class CauldronBlockMixin_1_15 method changeLevel.

private boolean changeLevel(World world, BlockPos pos, BlockState state, int i, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) {
    int newLevel = MathHelper.clamp(i, 0, 3);
    CauldronLevelChangeEvent event = new CauldronLevelChangeEvent(CraftBlock.at(world, pos), (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), reason, state.get(CauldronBlock.LEVEL), newLevel);
    Bukkit.getPluginManager().callEvent(event);
    return !event.isCancelled();
}
Also used : CauldronLevelChangeEvent(org.bukkit.event.block.CauldronLevelChangeEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge)

Aggregations

EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)39 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)15 Overwrite (org.spongepowered.asm.mixin.Overwrite)15 Entity (net.minecraft.entity.Entity)13 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Inject (org.spongepowered.asm.mixin.injection.Inject)10 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)9 LivingEntity (net.minecraft.entity.LivingEntity)9 MobEntity (net.minecraft.entity.MobEntity)9 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)9 BlockPos (net.minecraft.util.math.BlockPos)8 Redirect (org.spongepowered.asm.mixin.injection.Redirect)8 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)7 Location (org.bukkit.Location)7 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)6 Vec3d (net.minecraft.util.math.Vec3d)6 EntityCombustByEntityEvent (org.bukkit.event.entity.EntityCombustByEntityEvent)6 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)5 CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)5 Player (org.bukkit.entity.Player)5