Search in sources :

Example 21 with Pos

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

the class Cube method expand.

public Cube expand(int range) {
    Pos start = min().sub(range);
    Pos end = max().add(range);
    set(start, end);
    return this;
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 22 with Pos

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

the class EntityProjectile method readEntityFromNBT.

@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
    if (nbt.hasKey(NBTConstants.X_TILE)) {
        // Legacy
        tilePos = new BlockPos(nbt.getShort(NBTConstants.X_TILE), nbt.getShort(NBTConstants.Y_TILE), nbt.getShort(NBTConstants.Z_TILE));
    } else if (nbt.hasKey(NBTConstants.X_TILE_POS)) {
        tilePos = new BlockPos(nbt.getInteger(NBTConstants.X_TILE_POS), nbt.getInteger(NBTConstants.Y_TILE_POS), nbt.getInteger(NBTConstants.Z_TILE_POS));
    }
    if (nbt.hasKey(NBTConstants.SIDE_TILE)) {
        // Legacy
        this.sideTile = EnumFacing.byIndex(nbt.getShort(NBTConstants.SIDE_TILE));
    } else {
        this.sideTile = EnumFacing.byIndex(nbt.getByte(NBTConstants.SIDE_TILE_POS));
    }
    this.ticksInGround = nbt.getShort(NBTConstants.LIFE);
    if (nbt.hasKey(NBTConstants.IN_TILE)) {
        // Legacy
        Block block = Block.getBlockById(nbt.getByte(NBTConstants.IN_TILE));
        if (block != null) {
            int meta = nbt.getByte(NBTConstants.IN_DATA);
            this.blockInside = block.getStateFromMeta(meta);
        }
    } else if (nbt.hasKey(NBTConstants.IN_TILE_STATE)) {
        this.blockInside = Block.getStateById(nbt.getInteger(NBTConstants.IN_TILE_STATE));
    }
    this.inGround = nbt.getByte(NBTConstants.IN_GROUND) == 1;
    if (nbt.hasKey(NBTConstants.SOURCE_POS)) {
        sourceOfProjectile = new Pos(nbt.getCompoundTag(NBTConstants.SOURCE_POS));
    }
    if (nbt.hasKey(NBTConstants.SHOOTER_UUID)) {
        shootingEntityUUID = UUID.fromString(nbt.getString(NBTConstants.SHOOTER_UUID));
    }
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 23 with Pos

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

the class ExplosiveHandler method removeNear.

/**
 * Called to remove blasts near the location
 *
 * @param world = position
 * @param x     - position
 * @param y     - position
 * @param z     - position
 * @param range - distance from position, less than zero will turn into global
 * @return number of blasts removed
 */
public static int removeNear(World world, double x, double y, double z, double range) {
    final Pos pos = new Pos(x, y, z);
    // Collect blasts marked for removal
    final List<IBlast> toRemove = ExplosiveHandler.activeBlasts.stream().filter(blast -> blast.world() == world).filter(blast -> range < 0 || range > 0 && range > pos.distance(blast)).collect(Collectors.toList());
    // Do removals
    activeBlasts.removeAll(toRemove);
    toRemove.forEach(IBlast::clearBlast);
    return toRemove.size();
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Blast(icbm.classic.content.blast.Blast) Entity(net.minecraft.entity.Entity) WorldEvent(net.minecraftforge.event.world.WorldEvent) World(net.minecraft.world.World) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ICBMClassicAPI(icbm.classic.api.ICBMClassicAPI) IExplosiveData(icbm.classic.api.reg.IExplosiveData) List(java.util.List) BlastState(icbm.classic.api.explosion.BlastState) IBlastInit(icbm.classic.api.explosion.IBlastInit) IBlast(icbm.classic.api.explosion.IBlast) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) IExplosive(icbm.classic.api.caps.IExplosive) Mod(net.minecraftforge.fml.common.Mod) ICBMClassic(icbm.classic.ICBMClassic) ICBMConstants(icbm.classic.ICBMConstants) Pos(icbm.classic.lib.transform.vector.Pos) IBlast(icbm.classic.api.explosion.IBlast)

Example 24 with Pos

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

the class PosDistanceSorter method compare.

@Override
public int compare(BlockPos o1, BlockPos o2) {
    if (!sortY || o1.getY() == o2.getY()) {
        double d = new Pos(o1).distance(center);
        double d2 = new Pos(o2).distance(center);
        return d > d2 ? 1 : d == d2 ? 0 : -1;
    }
    return Integer.compare(o1.getY(), o2.getY());
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos)

Example 25 with Pos

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

the class EntityMissile method launch.

/**
 * Used {@link #capabilityMissile} {@link CapabilityMissile#launch(double, double, double, double)}
 *
 * @param target
 */
protected void launch(Pos target) {
    // Start motion
    if (ticksInAir <= 0) {
        this.ticksInAir = 2;
    }
    // Update data
    // TODO get source of launch
    this.sourceOfProjectile = new Pos((IPos3D) this);
    this.targetPos = target;
    this.targetHeight = this.targetPos != null ? this.targetPos.yi() : -1;
    // Trigger events
    // TODO add generic event
    ICBMClassicAPI.EX_MISSILE_REGISTRY.triggerLaunch(capabilityMissile);
    // Trigger code
    this.recalculatePath();
    this.updateMotion();
    // Play audio
    ICBMSounds.MISSILE_LAUNCH.play(world, posX, posY, posZ, 1F, (1.0F + CalculationHelpers.randFloatRange(this.world.rand, 0.2F)) * 0.7F, true);
    // Trigger events
    // TODO add an event system here
    RadarRegistry.add(this);
    if (ConfigDebug.DEBUG_MISSILE_LAUNCHES) {
        if (target != null) {
            ICBMClassic.logger().info("Launching " + this.getEntityName() + " (" + this.getEntityId() + ") from " + sourceOfProjectile.xi() + ", " + sourceOfProjectile.yi() + ", " + sourceOfProjectile.zi() + " to " + targetPos.xi() + ", " + targetPos.yi() + ", " + targetPos.zi());
        } else {
            ICBMClassic.logger().info("Launching " + this.getEntityName() + " (" + this.getEntityId() + ") from " + sourceOfProjectile.xi() + ", " + sourceOfProjectile.yi() + ", " + sourceOfProjectile.zi());
        }
    }
}
Also used : IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos)

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