Search in sources :

Example 36 with EntityBridge

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

the class WeightedPressurePlateBlockMixin method arclight$entityInteract.

@Redirect(method = "computeRedstoneStrength", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/List;size()I"))
public int arclight$entityInteract(List<Entity> list, World worldIn, BlockPos pos) {
    int i = 0;
    for (Entity entity : list) {
        Cancellable cancellable;
        if (entity instanceof PlayerEntity) {
            cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, pos, null, null, null);
        } else {
            cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos));
            Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable);
        }
        // We only want to block turning the plate on if all events are cancelled
        if (!cancellable.isCancelled()) {
            i++;
        }
    }
    return i;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Cancellable(org.bukkit.event.Cancellable) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 37 with EntityBridge

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

the class LeadItemMixin_1_15 method bindPlayerMobs.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public static ActionResultType bindPlayerMobs(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 ActionResultType.PASS;
                }
            }
            if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
                continue;
            }
            mobentity.setLeashHolder(leashknotentity, true);
            flag = true;
        }
    }
    return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
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 38 with EntityBridge

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

the class EntityTeleportEventDispatcher method onTeleport.

@SubscribeEvent(receiveCanceled = true)
public void onTeleport(EnderTeleportEvent event) {
    if (!(event.getEntity() instanceof EndermanEntity)) {
        if (event.getEntity() instanceof ServerPlayerEntity) {
            CraftPlayer player = ((ServerPlayerEntityBridge) event.getEntity()).bridge$getBukkitEntity();
            PlayerTeleportEvent bukkitEvent = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()), PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        } else {
            CraftEntity entity = ((EntityBridge) event.getEntity()).bridge$getBukkitEntity();
            EntityTeleportEvent bukkitEvent = new EntityTeleportEvent(entity, entity.getLocation(), new Location(entity.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()));
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        }
    }
}
Also used : EndermanEntity(net.minecraft.entity.monster.EndermanEntity) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Location(org.bukkit.Location) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 39 with EntityBridge

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

the class BlockBreakEventDispatcher method onFarmlandBreak.

@SubscribeEvent
public void onFarmlandBreak(BlockEvent.FarmlandTrampleEvent event) {
    Entity entity = event.getEntity();
    Cancellable cancellable;
    if (entity instanceof PlayerEntity) {
        cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, event.getPos(), null, null, null);
    } else {
        cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(event.getWorld(), event.getPos()));
        Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable);
    }
    if (cancellable.isCancelled()) {
        event.setCanceled(true);
        return;
    }
    if (CraftEventFactory.callEntityChangeBlockEvent(entity, event.getPos(), Blocks.DIRT.getDefaultState()).isCancelled()) {
        event.setCanceled(true);
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Cancellable(org.bukkit.event.Cancellable) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

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