Search in sources :

Example 1 with EntityBridge

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

the class EntityMixin method arclight$entityDropItem.

@Inject(method = "entityDropItem(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/item/ItemEntity;", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
public void arclight$entityDropItem(ItemStack stack, float offsetY, CallbackInfoReturnable<ItemEntity> cir, ItemEntity itementity) {
    EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) ((EntityBridge) itementity).bridge$getBukkitEntity());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        cir.setReturnValue(null);
    }
}
Also used : EntityDropItemEvent(org.bukkit.event.entity.EntityDropItemEvent) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) 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 2 with EntityBridge

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

the class EntityMixin method addPassenger.

public boolean addPassenger(Entity entity) {
    if (entity.getRidingEntity() != (Object) this) {
        throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
    } else {
        // CraftBukkit start
        com.google.common.base.Preconditions.checkState(!((EntityBridge) entity).bridge$getPassengers().contains(this), "Circular entity riding! %s %s", this, entity);
        CraftEntity craft = (CraftEntity) ((EntityBridge) entity).bridge$getBukkitEntity().getVehicle();
        Entity orig = craft == null ? null : craft.getHandle();
        if (getBukkitEntity() instanceof Vehicle && ((EntityBridge) entity).bridge$getBukkitEntity() instanceof org.bukkit.entity.LivingEntity) {
            VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity());
            // Suppress during worldgen
            if (this.valid) {
                Bukkit.getPluginManager().callEvent(event);
            }
            CraftEntity craftn = (CraftEntity) ((EntityBridge) entity).bridge$getBukkitEntity().getVehicle();
            Entity n = craftn == null ? null : craftn.getHandle();
            if (event.isCancelled() || n != orig) {
                return false;
            }
        }
        // CraftBukkit end
        // Spigot start
        org.spigotmc.event.entity.EntityMountEvent event = new org.spigotmc.event.entity.EntityMountEvent(((EntityBridge) entity).bridge$getBukkitEntity(), this.getBukkitEntity());
        // Suppress during worldgen
        if (this.valid) {
            Bukkit.getPluginManager().callEvent(event);
        }
        if (event.isCancelled()) {
            return false;
        }
        // Spigot end
        if (!this.world.isRemote && entity instanceof PlayerEntity && !(this.getControllingPassenger() instanceof PlayerEntity)) {
            this.passengers.add(0, entity);
        } else {
            this.passengers.add(entity);
        }
    }
    // CraftBukkit
    return true;
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.item.ItemEntity) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vehicle(org.bukkit.entity.Vehicle) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge)

Example 3 with EntityBridge

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

the class PressurePlateBlockMixin method computeRedstoneStrength.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected int computeRedstoneStrength(World worldIn, BlockPos pos) {
    AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos);
    List<? extends Entity> list;
    switch(this.sensitivity) {
        case EVERYTHING:
            list = worldIn.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
            break;
        case MOBS:
            list = worldIn.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb);
            break;
        default:
            return 0;
    }
    if (!list.isEmpty()) {
        for (Entity entity : list) {
            if (this.getRedstoneStrength(worldIn.getBlockState(pos)) == 0) {
                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()) {
                    continue;
                }
            }
            if (!entity.doesEntityNotTriggerPressurePlate()) {
                return 15;
            }
        }
    }
    return 0;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) 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) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with EntityBridge

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

the class MobEntityMixin method arclight$attackCombust.

@Redirect(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V"))
public void arclight$attackCombust(Entity entity, int seconds) {
    EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds);
    org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
    if (!combustEvent.isCancelled()) {
        ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
    }
}
Also used : LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with EntityBridge

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

the class PhaseManagerMixin method setPhase.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void setPhase(PhaseType<?> phaseIn) {
    if (this.phase == null || phaseIn != this.phase.getType()) {
        if (this.phase != null) {
            this.phase.removeAreaEffect();
        }
        EnderDragonChangePhaseEvent event = new EnderDragonChangePhaseEvent((CraftEnderDragon) ((EntityBridge) this.dragon).bridge$getBukkitEntity(), (this.phase == null) ? null : CraftEnderDragon.getBukkitPhase(this.phase.getType()), CraftEnderDragon.getBukkitPhase(phaseIn));
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        phaseIn = CraftEnderDragon.getMinecraftPhase(event.getNewPhase());
        this.phase = this.getPhase(phaseIn);
        if (!this.dragon.world.isRemote) {
            this.dragon.getDataManager().set(EnderDragonEntity.PHASE, phaseIn.getId());
        }
        LOGGER.debug("Dragon is now in phase {} on the {}", phaseIn, this.dragon.world.isRemote ? "client" : "server");
        this.phase.initPhase();
    }
}
Also used : EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EnderDragonChangePhaseEvent(org.bukkit.event.entity.EnderDragonChangePhaseEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

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