Search in sources :

Example 1 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity 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 2 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity in project Arclight by IzzelAliz.

the class EggEntityMixin method onImpact.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void onImpact(final RayTraceResult movingobjectposition) {
    if (movingobjectposition.getType() == RayTraceResult.Type.ENTITY) {
        ((EntityRayTraceResult) movingobjectposition).getEntity().attackEntityFrom(DamageSource.causeThrownDamage((EggEntity) (Object) this, this.getThrower()), 0.0f);
    }
    if (!this.world.isRemote) {
        boolean hatching = this.rand.nextInt(8) == 0;
        byte b0 = 1;
        if (this.rand.nextInt(32) == 0) {
            b0 = 4;
        }
        if (!hatching) {
            b0 = 0;
        }
        org.bukkit.entity.EntityType hatchingType = org.bukkit.entity.EntityType.CHICKEN;
        final Entity shooter = this.getThrower();
        if (shooter instanceof ServerPlayerEntity) {
            final PlayerEggThrowEvent event = new PlayerEggThrowEvent(((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity(), (Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
            Bukkit.getPluginManager().callEvent(event);
            b0 = event.getNumHatches();
            hatching = event.isHatching();
            hatchingType = event.getHatchingType();
        }
        if (hatching) {
            for (int i = 0; i < b0; ++i) {
                Entity entity = ((CraftEntity) ((WorldBridge) this.world).bridge$getWorld().spawnEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.posX, this.posY, this.posZ, this.rotationYaw, 0.0f), hatchingType)).getHandle();
                if (((EntityBridge) entity).bridge$getBukkitEntity() instanceof Ageable) {
                    ((Ageable) ((EntityBridge) entity).bridge$getBukkitEntity()).setBaby();
                }
                ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG);
                this.world.getWorld().addEntity(entity);
            }
        }
        this.world.setEntityState((EggEntity) (Object) this, (byte) 3);
        this.remove();
    }
}
Also used : Entity(net.minecraft.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Ageable(org.bukkit.entity.Ageable) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) PlayerEggThrowEvent(org.bukkit.event.player.PlayerEggThrowEvent) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity in project Arclight by IzzelAliz.

the class FollowOwnerGoalMixin_1_14 method arclight$teleport.

@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V"))
public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) {
    CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity();
    Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch);
    EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location);
    Bukkit.getPluginManager().callEvent(event);
    if (!(arclight$cancelled = event.isCancelled())) {
        tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity in project Arclight by IzzelAliz.

the class FollowOwnerGoalMixin_1_15 method arclight$teleport.

@Redirect(method = "tryToTeleportToLocation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V"))
public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) {
    CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity();
    Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch);
    EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location);
    Bukkit.getPluginManager().callEvent(event);
    if (!(arclight$cancelled = event.isCancelled())) {
        tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with CraftEntity

use of org.bukkit.craftbukkit.v.entity.CraftEntity in project Arclight by IzzelAliz.

the class EntityMixin method removePassenger.

public boolean removePassenger(Entity entity) {
    // CraftBukkit
    if (entity.getRidingEntity() == (Object) this) {
        throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
    } else {
        // CraftBukkit start
        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) {
            VehicleExitEvent event = new VehicleExitEvent((Vehicle) getBukkitEntity(), (org.bukkit.entity.LivingEntity) ((EntityBridge) entity).bridge$getBukkitEntity());
            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.EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(((EntityBridge) entity).bridge$getBukkitEntity(), this.getBukkitEntity());
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        // Spigot end
        this.passengers.remove(entity);
        ((EntityBridge) entity).bridge$setRideCooldown(60);
    }
    // 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) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) 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)

Aggregations

CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)6 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)5 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 Location (org.bukkit.Location)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 Entity (net.minecraft.entity.Entity)3 EntityTeleportEvent (org.bukkit.event.entity.EntityTeleportEvent)3 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)2 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)2 LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 TameableEntity (net.minecraft.entity.passive.TameableEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Vehicle (org.bukkit.entity.Vehicle)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 EndermanEntity (net.minecraft.entity.monster.EndermanEntity)1 EggEntity (net.minecraft.entity.projectile.EggEntity)1