Search in sources :

Example 6 with EnderTeleportEvent

use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project EnderIO by SleepyTrousers.

the class RandomTeleportUtil method doTeleport.

private static boolean doTeleport(@Nonnull World world, @Nonnull EntityLivingBase entity, double targetX, double targetY, double targetZ) {
    float damage = 5f;
    if (entity.getMaxHealth() < 10f) {
        damage = 1f;
    }
    EnderTeleportEvent event = new EnderTeleportEvent(entity, targetX, targetY, targetZ, damage);
    if (!MinecraftForge.EVENT_BUS.post(event)) {
        if (rand.nextFloat() < 0.15F && world.getGameRules().getBoolean("doMobSpawning") && !(entity instanceof EntityEndermite)) {
            EntityEndermite entityendermite = new EntityEndermite(world);
            entityendermite.setSpawnedByPlayer(true);
            entityendermite.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
            world.spawnEntity(entityendermite);
        }
        if (entity.isRiding()) {
            entity.dismountRidingEntity();
        }
        if (entity.isBeingRidden()) {
            for (Entity passenger : entity.getPassengers()) {
                passenger.dismountRidingEntity();
            }
        }
        if (entity instanceof EntityPlayerMP) {
            ((EntityPlayerMP) entity).connection.setPlayerLocation(event.getTargetX(), event.getTargetY(), event.getTargetZ(), entity.rotationYaw, entity.rotationPitch);
        } else {
            entity.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ());
        }
        entity.fallDistance = 0.0F;
        entity.attackEntityFrom(DamageSource.FALL, event.getAttackDamage());
        return true;
    }
    return false;
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) Entity(net.minecraft.entity.Entity) EntityEndermite(net.minecraft.entity.monster.EntityEndermite) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 7 with EnderTeleportEvent

use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project BloodMagic by WayofTime.

the class RitualExpulsion method teleportTo.

public boolean teleportTo(EntityLivingBase entityLiving, double par1, double par3, double par5, double lastX, double lastY, double lastZ) {
    EnderTeleportEvent event = new EnderTeleportEvent(entityLiving, par1, par3, par5, 0);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        return false;
    }
    moveEntityViaTeleport(entityLiving, event.getTargetX(), event.getTargetY(), event.getTargetZ());
    boolean flag = false;
    int i = MathHelper.floor(entityLiving.posX);
    int j = MathHelper.floor(entityLiving.posY);
    int k = MathHelper.floor(entityLiving.posZ);
    int l;
    if (!entityLiving.getEntityWorld().isAirBlock(new BlockPos(i, j, k))) {
        boolean flag1 = false;
        while (!flag1 && j > 0) {
            IBlockState state = entityLiving.getEntityWorld().getBlockState(new BlockPos(i, j - 1, k));
            if (state.getMaterial().blocksMovement()) {
                flag1 = true;
            } else {
                --entityLiving.posY;
                --j;
            }
        }
        if (flag1) {
            moveEntityViaTeleport(entityLiving, entityLiving.posX, entityLiving.posY, entityLiving.posZ);
            if (!entityLiving.collided && !entityLiving.getEntityWorld().containsAnyLiquid(entityLiving.getEntityBoundingBox())) {
                flag = true;
            }
        }
    }
    if (!flag) {
        moveEntityViaTeleport(entityLiving, lastX, lastY, lastZ);
        return false;
    } else {
        for (l = 0; l < 128; ++l) {
            double lengthVal = (double) l / ((double) 128 - 1.0D);
            float randF1 = (entityLiving.getEntityWorld().rand.nextFloat() - 0.5F) * 0.2F;
            float randF2 = (entityLiving.getEntityWorld().rand.nextFloat() - 0.5F) * 0.2F;
            float randF3 = (entityLiving.getEntityWorld().rand.nextFloat() - 0.5F) * 0.2F;
            double lengthValX = lastX + (entityLiving.posX - lastX) * lengthVal + (entityLiving.getEntityWorld().rand.nextDouble() - 0.5D) * (double) entityLiving.width * 2.0D;
            double lengthValY = lastY + (entityLiving.posY - lastY) * lengthVal + entityLiving.getEntityWorld().rand.nextDouble() * (double) entityLiving.height;
            double lengthValZ = lastZ + (entityLiving.posZ - lastZ) * lengthVal + (entityLiving.getEntityWorld().rand.nextDouble() - 0.5D) * (double) entityLiving.width * 2.0D;
            entityLiving.getEntityWorld().spawnParticle(EnumParticleTypes.PORTAL, lengthValX, lengthValY, lengthValZ, (double) randF1, (double) randF2, (double) randF3);
        }
        return true;
    }
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 8 with EnderTeleportEvent

use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project takumicraft by TNTModders.

the class EntityDarkCreeper method teleportTo.

protected boolean teleportTo(EntityLivingBase entity) {
    Random rand = new Random();
    int distance = 128;
    double x = entity.posX + (rand.nextDouble() - 0.5D) * distance;
    double y = entity.posY + rand.nextInt(distance + 1) - distance / 2;
    double z = entity.posZ + (rand.nextDouble() - 0.5D) * distance;
    EnderTeleportEvent event = new EnderTeleportEvent(entity, x, y, z, 0);
    double d3 = entity.posX;
    double d4 = entity.posY;
    double d5 = entity.posZ;
    entity.posX = event.getTargetX();
    entity.posY = event.getTargetY();
    entity.posZ = event.getTargetZ();
    int xInt = MathHelper.floor(entity.posX);
    int yInt = MathHelper.floor(entity.posY);
    int zInt = MathHelper.floor(entity.posZ);
    boolean flag = false;
    if (entity.world.isAirBlock(new BlockPos(xInt, yInt, zInt))) {
        boolean foundGround = false;
        while (!foundGround && yInt > 0) {
            IBlockState block = entity.world.getBlockState(new BlockPos(xInt, yInt - 1, zInt));
            if (block.getMaterial().blocksMovement()) {
                foundGround = true;
            } else {
                --entity.posY;
                --yInt;
            }
        }
        if (foundGround) {
            entity.setPosition(entity.posX, entity.posY, entity.posZ);
            if (entity.world.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty() && !entity.world.containsAnyLiquid(entity.getEntityBoundingBox())) {
                flag = true;
            }
        }
    }
    if (!flag) {
        entity.setPosition(d3, d4, d5);
        return false;
    }
    entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
    short short1 = 128;
    for (int l = 0; l < short1; ++l) {
        double d6 = l / (short1 - 1.0D);
        float f = (rand.nextFloat() - 0.5F) * 0.2F;
        float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
        float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
        double d7 = d3 + (entity.posX - d3) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
        double d8 = d4 + (entity.posY - d4) * d6 + rand.nextDouble() * entity.height;
        double d9 = d5 + (entity.posZ - d5) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
        entity.world.spawnParticle(EnumParticleTypes.PORTAL, d7, d8, d9, f, f1, f2);
    }
    entity.world.playSound(null, entity.prevPosX, entity.prevPosY, entity.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, entity.getSoundCategory(), 1.0F, 1.0F);
    entity.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
    return true;
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with EnderTeleportEvent

use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project takumicraft by TNTModders.

the class EntityEndermiteCreeper method teleportTo.

protected boolean teleportTo(EntityLivingBase entity) {
    Random rand = new Random();
    int distance = 128;
    double x = entity.posX + (rand.nextDouble() - 0.5D) * distance;
    double y = entity.posY + rand.nextInt(distance + 1) - distance / 2;
    double z = entity.posZ + (rand.nextDouble() - 0.5D) * distance;
    EnderTeleportEvent event = new EnderTeleportEvent(entity, x, y, z, 0);
    double d3 = entity.posX;
    double d4 = entity.posY;
    double d5 = entity.posZ;
    entity.posX = event.getTargetX();
    entity.posY = event.getTargetY();
    entity.posZ = event.getTargetZ();
    int xInt = MathHelper.floor(entity.posX);
    int yInt = MathHelper.floor(entity.posY);
    int zInt = MathHelper.floor(entity.posZ);
    boolean flag = false;
    if (entity.world.isAirBlock(new BlockPos(xInt, yInt, zInt))) {
        boolean foundGround = false;
        while (!foundGround && yInt > 0) {
            BlockPos pos = new BlockPos(xInt, yInt - 1, zInt);
            IBlockState block = entity.world.getBlockState(pos);
            if (block.getMaterial().blocksMovement() && entity.world.isAirBlock(pos.up(20)) && entity.world.isAirBlock(pos.up(21))) {
                foundGround = true;
            } else {
                --entity.posY;
                --yInt;
            }
        }
        boolean flg = true;
        try {
            Method method = EntityLivingBase.class.getDeclaredMethod("isMovementBlocked");
            method.setAccessible(true);
            flg = !(Boolean) method.invoke(entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (foundGround && flg) {
            entity.setPosition(entity.posX, entity.posY + 20, entity.posZ);
            if (entity.world.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty() && !entity.world.containsAnyLiquid(entity.getEntityBoundingBox())) {
                flag = true;
            }
        }
    }
    if (!flag) {
        entity.setPosition(d3, d4, d5);
        return false;
    }
    entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
    short short1 = 128;
    for (int l = 0; l < short1; ++l) {
        double d6 = l / (short1 - 1.0D);
        float f = (rand.nextFloat() - 0.5F) * 0.2F;
        float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
        float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
        double d7 = d3 + (entity.posX - d3) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
        double d8 = d4 + (entity.posY - d4) * d6 + rand.nextDouble() * entity.height;
        double d9 = d5 + (entity.posZ - d5) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
        entity.world.spawnParticle(EnumParticleTypes.PORTAL, d7, d8, d9, f, f1, f2);
    }
    entity.world.playSound(null, entity.prevPosX, entity.prevPosY, entity.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, entity.getSoundCategory(), 1.0F, 1.0F);
    entity.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
    return true;
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) Method(java.lang.reflect.Method)

Example 10 with EnderTeleportEvent

use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project ArsMagica2 by Mithion.

the class RandomTeleport method teleportTo.

protected boolean teleportTo(double par1, double par3, double par5, Entity target) {
    if (target instanceof EntityLivingBase) {
        EnderTeleportEvent event = new EnderTeleportEvent((EntityLivingBase) target, par1, par3, par5, 0);
        if (MinecraftForge.EVENT_BUS.post(event)) {
            return false;
        }
        par1 = event.targetX;
        par3 = event.targetY;
        par5 = event.targetZ;
    }
    double d3 = target.posX;
    double d4 = target.posY;
    double d5 = target.posZ;
    target.posX = par1;
    target.posY = par3;
    target.posZ = par5;
    boolean locationValid = false;
    int i = MathHelper.floor_double(target.posX);
    int j = MathHelper.floor_double(target.posY);
    int k = MathHelper.floor_double(target.posZ);
    Block l;
    if (target.worldObj.blockExists(i, j, k)) {
        boolean targetBlockIsSolid = false;
        while (!targetBlockIsSolid && j > 0) {
            l = target.worldObj.getBlock(i, j - 1, k);
            if (l != Blocks.air && l.getMaterial().blocksMovement()) {
                targetBlockIsSolid = true;
            } else {
                --target.posY;
                --j;
            }
        }
        if (targetBlockIsSolid) {
            target.setPosition(target.posX, target.posY, target.posZ);
            if (target.worldObj.getCollidingBoundingBoxes(target, target.boundingBox).isEmpty()) {
                locationValid = true;
            }
        }
    }
    if (!locationValid) {
        target.setPosition(d3, d4, d5);
        return false;
    } else {
        return true;
    }
}
Also used : EnderTeleportEvent(net.minecraftforge.event.entity.living.EnderTeleportEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block)

Aggregations

EnderTeleportEvent (net.minecraftforge.event.entity.living.EnderTeleportEvent)10 BlockPos (net.minecraft.util.math.BlockPos)6 IBlockState (net.minecraft.block.state.IBlockState)4 Random (java.util.Random)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 Method (java.lang.reflect.Method)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityEndermite (net.minecraft.entity.monster.EntityEndermite)2 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityEndGateway (net.minecraft.tileentity.TileEntityEndGateway)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1