Search in sources :

Example 16 with Pos

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

the class TileLauncherBase method update.

/**
 * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner
 * uses this to count ticks and creates a new spawn inside its implementation.
 */
@Override
public void update() {
    super.update();
    if (isServer()) {
        if (ticks % 3 == 0) {
            // Update seat position
            if (seat != null) {
                seat.setPosition(x() + 0.5, y() + 0.5, z() + 0.5);
            }
            // Create seat if missile
            if (// TODO add hook to disable riding some missiles
            !getMissileStack().isEmpty() && seat == null) {
                seat = new EntityPlayerSeat(world);
                seat.host = this;
                seat.rideOffset = new Pos(getRotation()).multiply(0.5, 1, 0.5);
                seat.setPosition(x() + 0.5, y() + 0.5, z() + 0.5);
                seat.setSize(0.5f, 2.5f);
                world.spawnEntity(seat);
            } else // Destroy seat if no missile
            if (getMissileStack().isEmpty() && seat != null) {
                if (seat.getRidingEntity() != null) {
                    seat.getRidingEntity().startRiding(null);
                }
                seat.setDead();
                seat = null;
            }
        }
    }
    // 1 second update
    if (ticks % 20 == 0) {
        // Only update if frame or screen is invalid
        if (this.supportFrame == null || launchScreen == null || launchScreen.isInvalid() || this.supportFrame.isInvalid()) {
            // Reset data
            if (this.supportFrame != null) {
                this.supportFrame.launcherBase = null;
            }
            this.supportFrame = null;
            this.launchScreen = null;
            // Check on all 4 sides
            for (EnumFacing rotation : EnumFacing.HORIZONTALS) {
                // Get tile entity on side
                Pos position = new Pos(getPos()).add(rotation);
                TileEntity tileEntity = this.world.getTileEntity(position.toBlockPos());
                // If frame update rotation
                if (tileEntity instanceof TileLauncherFrame) {
                    this.supportFrame = (TileLauncherFrame) tileEntity;
                    this.supportFrame.launcherBase = this;
                    if (isServer()) {
                        this.supportFrame.setRotation(getRotation());
                    }
                } else // If screen, tell the screen the base exists
                if (tileEntity instanceof TileLauncherScreen) {
                    this.launchScreen = (TileLauncherScreen) tileEntity;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayerSeat(icbm.classic.content.entity.EntityPlayerSeat) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) TileLauncherFrame(icbm.classic.content.blocks.launcher.frame.TileLauncherFrame) EnumFacing(net.minecraft.util.EnumFacing) TileLauncherScreen(icbm.classic.content.blocks.launcher.screen.TileLauncherScreen)

Example 17 with Pos

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

the class EntityMissile method getPredictedPosition.

public Pos getPredictedPosition(int t) {
    Pos position = new Pos((IPos3D) this);
    double tempMotionY = this.motionY;
    if (this.ticksInAir > 20) {
        for (int i = 0; i < t; i++) {
            if (this.missileType.movesDirectly) {
                position = position.add(this.motionVector);
            } else {
                position = position.add(motionX, tempMotionY - this.acceleration, motionZ);
            }
        }
    }
    return position;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos)

Example 18 with Pos

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

the class BlastGasBase method setEffectBoundsAndSpawnParticles.

private void setEffectBoundsAndSpawnParticles(int timePassed) {
    final int maxSize = (int) Math.ceil(this.getBlastRadius());
    // Get and validate radius
    final int radius = (int) Math.floor(maxSize * sizePercentageOverTime(timePassed));
    if (lastRadius == radius) {
        return;
    }
    lastRadius = radius;
    // Get radius sq for distance checks
    final int currentDistanceSQ = radius * radius;
    // Init path data
    if (affectedBlocks.isEmpty()) {
        affectedBlocks.add(getPos());
        edgeBlocks.add(getPos());
    }
    if (edgeBlocks.isEmpty()) {
        affectedBlocks.stream().filter((pos) -> Math.random() > 0.5).forEach(pos -> edgeBlocks.add(pos));
    }
    // Track blocks we pathed but didn't need
    final HashSet<BlockPos> hasPathed = new HashSet();
    // Track blocks we need to path next tick
    final Queue<BlockPos> nextSet = new LinkedList();
    // Loop edges from last tick
    while (edgeBlocks.peek() != null) {
        // Current edge block
        final BlockPos edge = edgeBlocks.poll();
        // Loop all 6 sides of the edge
        for (EnumFacing facing : EnumFacing.values()) {
            // Move our check pos to current target
            checkPos.setPos(edge);
            checkPos.move(facing);
            // Don't repath
            if (!hasPathed.contains(checkPos) && !affectedBlocks.contains(checkPos)) {
                // Check that it is in range
                if (isInRange(checkPos, currentDistanceSQ)) {
                    // Validate
                    if (isValidPath(checkPos)) {
                        final BlockPos pos = checkPos.toImmutable();
                        affectedBlocks.add(pos);
                        nextSet.add(pos);
                        spawnGasParticles(pos);
                    } else // Ignore if invalid
                    {
                        hasPathed.add(checkPos.toImmutable());
                    }
                }
            }
        }
    }
    // Add next set to follow up queue
    edgeBlocks.addAll(nextSet);
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBlastTickable(icbm.classic.api.explosion.IBlastTickable) CustomPotionEffect(icbm.classic.content.potion.CustomPotionEffect) NBTConstants(icbm.classic.lib.NBTConstants) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumFacing(net.minecraft.util.EnumFacing) ICBMSounds(icbm.classic.client.ICBMSounds) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) DamageSource(net.minecraft.util.DamageSource) HashSet(java.util.HashSet) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ICBMExplosives(icbm.classic.api.refs.ICBMExplosives) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ICBMClassic(icbm.classic.ICBMClassic) Queue(java.util.Queue) LinkedList(java.util.LinkedList) MobEffects(net.minecraft.init.MobEffects) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 19 with Pos

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

the class Cube method subtract.

public Cube subtract(double x, double y, double z) {
    if (isValid() && canEdit) {
        pointOne = new Pos(pointOne.x() - x, pointOne.y() - y, pointOne.z() - z);
        pointTwo = new Pos(pointTwo.x() - x, pointTwo.y() - y, pointTwo.z() - z);
        recalc();
    }
    return this;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 20 with Pos

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

the class Cube method cropToWorld.

/**
 * Limits the cube to the world bounds
 *
 * @return this
 */
public Cube cropToWorld() {
    Pos one = min();
    Pos two = max();
    if (min().y() < 0) {
        one = new Pos(min().x(), 0, min().y());
    }
    if (max().y() > ICBMClassic.MAP_HEIGHT) {
        two = new Pos(min().x(), ICBMClassic.MAP_HEIGHT, min().y());
    }
    set(one, two);
    return this;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) ChunkPos(net.minecraft.util.math.ChunkPos)

Aggregations

Pos (icbm.classic.lib.transform.vector.Pos)39 BlockPos (net.minecraft.util.math.BlockPos)22 TileEntity (net.minecraft.tileentity.TileEntity)8 Entity (net.minecraft.entity.Entity)6 ChunkPos (net.minecraft.util.math.ChunkPos)6 EnumFacing (net.minecraft.util.EnumFacing)5 TextComponentString (net.minecraft.util.text.TextComponentString)5 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)4 ItemStack (net.minecraft.item.ItemStack)4 Location (icbm.classic.lib.transform.vector.Location)3 Point (icbm.classic.lib.transform.vector.Point)3 FakeRadioSender (icbm.classic.prefab.FakeRadioSender)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 ICBMClassic (icbm.classic.ICBMClassic)2 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 IExplosiveData (icbm.classic.api.reg.IExplosiveData)2 ItemLaserDetonator (icbm.classic.content.items.ItemLaserDetonator)2 ItemRemoteDetonator (icbm.classic.content.items.ItemRemoteDetonator)2