Search in sources :

Example 6 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class ExplosiveInit method enderMissileCoordSet.

private static boolean enderMissileCoordSet(Entity entity, EntityPlayer player, EnumHand hand) {
    if (entity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null)) {
        final IExplosive provider = entity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
        final NBTTagCompound tag = provider.getCustomBlastData();
        if (tag != null) {
            final ItemStack heldItem = player.getHeldItem(hand);
            if (heldItem.getItem() instanceof IWorldPosItem) {
                final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
                final IWorldPosition link = posItem.getLocation(heldItem);
                if (link instanceof Location) {
                    ((Location) link).writeIntNBT(tag);
                    if (!entity.world.isRemote) {
                        // TODO translate
                        player.sendMessage(new TextComponentString("Coordinates encoded into entity"));
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 7 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class BlastEnderman method doExplode.

@Override
public boolean doExplode(int callCount) {
    if (this.world().isRemote) {
        int r = (int) (this.getBlastRadius() - ((double) this.callCount / (double) this.duration) * this.getBlastRadius());
        for (int x = -r; x < r; x++) {
            for (int z = -r; z < r; z++) {
                for (int y = -r; y < r; y++) {
                    // TODO replace with mutable blockpos
                    Location targetPosition = location.add(new Pos(x, y, z));
                    double distance = targetPosition.distance(location);
                    if (distance < r && distance > r - 1) {
                        if (!targetPosition.getBlock(world()).isAir(targetPosition.getBlockState(world()), world(), targetPosition.toBlockPos())) {
                            continue;
                        }
                        if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.01)) {
                            float velX = (float) ((targetPosition.x() - location.x()) * 0.6);
                            float velY = (float) ((targetPosition.y() - location.y()) * 0.6);
                            float velZ = (float) ((targetPosition.z() - location.z()) * 0.6);
                            world.spawnParticle(EnumParticleTypes.PORTAL, targetPosition.x(), targetPosition.y(), targetPosition.z(), velX, velY, velZ);
                        }
                    }
                }
            }
        }
    }
    int radius = (int) this.getBlastRadius();
    AxisAlignedBB bounds = new AxisAlignedBB(location.x() - radius, location.y() - radius, location.z() - radius, location.x() + radius, location.y() + radius, location.z() + radius);
    List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, bounds);
    boolean explosionCreated = false;
    for (Entity entity : allEntities) {
        if (entity != this.controller) {
            double xDifference = entity.posX - location.x();
            double yDifference = entity.posY - location.y();
            double zDifference = entity.posZ - location.z();
            int r = (int) this.getBlastRadius();
            if (xDifference < 0) {
                r = (int) -this.getBlastRadius();
            }
            entity.motionX -= (r - xDifference) * Math.abs(xDifference) * 0.0006;
            r = (int) this.getBlastRadius();
            if (entity.posY > location.y()) {
                r = (int) -this.getBlastRadius();
            }
            entity.motionY += (r - yDifference) * Math.abs(yDifference) * 0.0011;
            r = (int) this.getBlastRadius();
            if (zDifference < 0) {
                r = (int) -this.getBlastRadius();
            }
            entity.motionZ -= (r - zDifference) * Math.abs(zDifference) * 0.0006;
            if (new Pos(entity.posX, entity.posY, entity.posZ).distance(location) < 4) {
                if (!explosionCreated && callCount % 5 == 0) {
                    world().spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, entity.posX, entity.posY, entity.posZ, 0.0D, 0.0D, 0.0D);
                    explosionCreated = true;
                }
                try {
                    /**
                     * If a target doesn't exist, search for a random one within 100 block
                     * range.
                     */
                    if (this.teleportTarget == null) {
                        int checkY = (int) Math.floor(this.controller.posY);
                        int checkX = this.world().rand.nextInt(300) - 150 + (int) this.controller.posX;
                        int checkZ = this.world().rand.nextInt(300) - 150 + (int) this.controller.posZ;
                        // Look for space with air gap
                        BlockPos pos;
                        BlockPos pos2;
                        do {
                            pos = new BlockPos(checkX, checkY, checkZ);
                            pos2 = pos.up();
                            checkY++;
                        } while (this.world().isAirBlock(pos) && !this.world().isAirBlock(pos2) && checkY < 254);
                        this.teleportTarget = new Pos(checkX, checkY, checkZ);
                    }
                    this.world().playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1.0F, 1.0F);
                    if (entity instanceof EntityPlayerMP) {
                        ((EntityPlayerMP) entity).connection.setPlayerLocation(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5, entity.rotationYaw, entity.rotationPitch);
                    } else {
                        entity.setPosition(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5);
                    }
                } catch (Exception e) {
                    ICBMClassic.logger().error("Failed to teleport entity to the End.", e);
                }
            }
        }
    }
    this.world().playSound(null, this.location.x(), this.location.y(), this.location.z(), SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 2F, world().rand.nextFloat() * 0.4F + 0.8F);
    return this.callCount > this.duration;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Location(icbm.classic.lib.transform.vector.Location)

Example 8 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class BlastNuclear method setupBlast.

@Override
public boolean setupBlast() {
    super.setupBlast();
    if (this.world() != null) {
        if (this.spawnMoreParticles) {
            // Spawn nuclear cloud.
            for (int y = 0; y < 26; y++) {
                int r = 4;
                if (y < 8) {
                    r = Math.max(Math.min((8 - y) * 2, 10), 4);
                } else if (y > 15) {
                    r = Math.max(Math.min((y - 15) * 2, 15), 5);
                }
                for (int x = -r; x < r; x++) {
                    for (int z = -r; z < r; z++) {
                        double distance = MathHelper.sqrt(x * x + z * z);
                        if (r > distance && r - 3 < distance) {
                            Location spawnPosition = location.add(new Pos(x * 2, (y - 2) * 2, z * 2));
                            float xDiff = (float) (spawnPosition.x() - location.x());
                            float zDiff = (float) (spawnPosition.z() - location.z());
                            world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, spawnPosition.x(), spawnPosition.y(), spawnPosition.z(), xDiff * 0.3 * world().rand.nextFloat(), -world().rand.nextFloat(), // (float) (distance / this.getRadius()) * oldWorld().rand.nextFloat(), 0, //0, 8F, 1.2F);
                            zDiff * 0.3 * world().rand.nextFloat());
                        }
                    }
                }
            }
        }
        this.doDamageEntities(this.getBlastRadius(), this.energy * 1000);
        ICBMSounds.EXPLOSION.play(world, this.location.x(), this.location.y(), this.location.z(), 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F, true);
    }
    return true;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) Location(icbm.classic.lib.transform.vector.Location)

Example 9 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class BlastNuclear method doExplode.

@Override
public boolean doExplode(int callCount) {
    super.doExplode(callCount);
    int r = this.callCount;
    if (this.world().isRemote) {
        for (int x = -r; x < r; x++) {
            for (int z = -r; z < r; z++) {
                double distance = MathHelper.sqrt(x * x + z * z);
                if (distance < r && distance > r - 1) {
                    Location targetPosition = this.location.add(new Pos(x, 0, z));
                    if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.05)) {
                        // 5F, 1F);
                        world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, targetPosition.x(), targetPosition.y(), targetPosition.z(), 0, 0, 0);
                    }
                }
            }
        }
    }
    return false;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) Location(icbm.classic.lib.transform.vector.Location)

Example 10 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class Blast method setPosition.

/**
 * Called to set the position of the blast. Only call this for initialization, anything
 * that happens during world tick should call {@link #onPositionUpdate(double, double, double)}
 *
 * @param posX
 * @param posY
 * @param posZ
 */
public Blast setPosition(double posX, double posY, double posZ) {
    this.x = posX;
    this.y = posY;
    this.z = posZ;
    location = new Location(world, posX, posY, posZ);
    // TODO super contains a vec3 also called position, we need to set that value instead of overriding the return
    return this;
}
Also used : Location(icbm.classic.lib.transform.vector.Location)

Aggregations

Location (icbm.classic.lib.transform.vector.Location)11 ItemStack (net.minecraft.item.ItemStack)4 Pos (icbm.classic.lib.transform.vector.Pos)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 IExplosive (icbm.classic.api.caps.IExplosive)2 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 Entity (net.minecraft.entity.Entity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 IMissile (icbm.classic.api.caps.IMissile)1 IMissileLauncher (icbm.classic.api.caps.IMissileLauncher)1 RadarGunTraceEvent (icbm.classic.api.events.RadarGunTraceEvent)1 IMultiTile (icbm.classic.api.tile.multiblock.IMultiTile)1 IMultiTileHost (icbm.classic.api.tile.multiblock.IMultiTileHost)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 IPacketIDReceiver (icbm.classic.lib.network.IPacketIDReceiver)1