Search in sources :

Example 1 with ItemWaystone

use of com.bewitchment.common.item.ItemWaystone in project Bewitchment by Um-Mitternacht.

the class RitualTeleport method onFinished.

@Override
public void onFinished(World world, BlockPos altarPos, BlockPos effectivePos, EntityPlayer caster, ItemStackHandler inventory) {
    world.playSound(null, effectivePos, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.BLOCKS, 0.7f, 0.7f);
    BlockPos pos0 = null;
    int dimension = 0;
    if (world.getTileEntity(effectivePos) instanceof TileEntityGlyph) {
        for (int i = 0; i < inventory.getSlots(); i++) {
            ItemStack stack = inventory.getStackInSlot(i);
            if (stack.getItem() instanceof ItemWaystone) {
                pos0 = BlockPos.fromLong(stack.getTagCompound().getLong("location"));
                dimension = stack.getTagCompound().getInteger("dimension");
                stack.damageItem(1, caster);
                break;
            }
            if (stack.getItem() instanceof ItemTaglock) {
                for (Entity entity : world.loadedEntityList) {
                    if (entity.getPersistentID().equals(UUID.fromString(stack.getTagCompound().getString("boundId")))) {
                        pos0 = entity.getPosition();
                        dimension = entity.dimension;
                        stack.shrink(1);
                        break;
                    }
                }
            }
        }
    }
    if (pos0 == null || dimension != world.provider.getDimension())
        return;
    for (Entity entity : world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(effectivePos).grow(3))) {
        world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
        if (entity instanceof EntityPlayer)
            Util.teleportPlayer((EntityPlayer) entity, pos0.getX() + 0.5, pos0.getY(), pos0.getZ() + 0.5);
        else
            entity.setPositionAndUpdate(pos0.getX() + 0.5, pos0.getY(), pos0.getZ() + 0.5);
        world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntityGlyph(com.bewitchment.common.block.tile.entity.TileEntityGlyph) ItemWaystone(com.bewitchment.common.item.ItemWaystone) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemTaglock(com.bewitchment.common.item.ItemTaglock)

Aggregations

TileEntityGlyph (com.bewitchment.common.block.tile.entity.TileEntityGlyph)1 ItemTaglock (com.bewitchment.common.item.ItemTaglock)1 ItemWaystone (com.bewitchment.common.item.ItemWaystone)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1