Search in sources :

Example 1 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.

the class TestAbstractLocation method testInit.

/**
     * Tests constructors
     */
public void testInit() {
    List<TLocation> locations = new ArrayList();
    //Test main method
    locations.add(new TLocation(world, 10, 11, 12));
    //Test entity method
    Entity entity = new EntitySheep(world);
    entity.setPosition(10, 11, 12);
    locations.add(new TLocation(entity));
    //Test tile
    TileEntity tile = new TileEntity();
    tile.setWorldObj(world);
    tile.xCoord = 10;
    tile.yCoord = 11;
    tile.zCoord = 12;
    locations.add(new TLocation(tile));
    //Test NBT method
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("dimension", world.provider.dimensionId);
    tag.setDouble("x", 10);
    tag.setDouble("y", 11);
    tag.setDouble("z", 12);
    locations.add(new TLocation(tag));
    //Test byte buf method
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(world.provider.dimensionId);
    buf.writeDouble(10);
    buf.writeDouble(11);
    buf.writeDouble(12);
    locations.add(new TLocation(buf));
    //Test IWorldPosition
    locations.add(new TLocation(new IWorldPosition() {

        @Override
        public World world() {
            return world;
        }

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    //Test world, IPos3D
    locations.add(new TLocation(world, new IPos3D() {

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    //Test world, vec3
    locations.add(new TLocation(world, Vec3.createVectorHelper(10, 11, 12)));
    //Test world, moving object
    locations.add(new TLocation(world, new MovingObjectPosition(10, 11, 12, 0, Vec3.createVectorHelper(10, 11, 12))));
    for (int i = 0; i < locations.size(); i++) {
        TLocation location = locations.get(i);
        assertTrue("" + i, location.world == world);
        assertTrue("" + i, location.xi() == 10);
        assertTrue("" + i, location.yi() == 11);
        assertTrue("" + i, location.zi() == 12);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ArrayList(java.util.ArrayList) EntitySheep(net.minecraft.entity.passive.EntitySheep) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method destroyMultiBlockStructure.

/**
     * Breaks down the multiblock stucture linked to the host
     *
     * @param host     - host providing the layour of the structure
     * @param doDrops  - attempt to drop blocks?
     * @param offset   - offset the layout by the location of the host?
     * @param killHost - destroy the host block as well?
     */
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
    if (host != null) {
        HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
        if (map != null && !map.isEmpty()) {
            IWorldPosition center;
            if (host instanceof TileEntity) {
                center = new Location((TileEntity) host);
            } else if (host instanceof IWorldPosition) {
                center = (IWorldPosition) host;
            } else {
                logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
                return;
            }
            for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
                Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
                if (offset) {
                    pos = pos.add(center);
                }
                TileEntity tile = pos.getTileEntity(center.world());
                if (tile instanceof IMultiTile) {
                    ((IMultiTile) tile).setHost(null);
                    pos.setBlockToAir(center.world());
                }
            }
            if (doDrops) {
                InventoryUtility.dropBlockAsItem(center, killHost);
            } else if (killHost) {
                center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
            }
        } else {
            logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 3 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method updateStructure.

/**
     * Runs a world update on all members of the structure
     *
     * @param world
     * @param host
     * @param offset - off set the location data by the center of the host
     */
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
    //TODO junit test
    if (!(host instanceof TileEntity)) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    if (world == null) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
    if (map != null && !map.isEmpty()) {
        int x = ((TileEntity) host).xCoord;
        int y = ((TileEntity) host).yCoord;
        int z = ((TileEntity) host).zCoord;
        Pos center = new Pos(x, y, z);
        for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
            Location pos = new Location(world, entry.getKey());
            if (offset) {
                pos = pos.add(center);
            }
            pos.markForUpdate();
        }
        center.markForUpdate(world);
    } else {
        logger.error("Tile[" + host + "]'s structure map is empty");
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 4 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.

the class FXElectricBolt2 method split.

/**
	 * Slits a large segment into multiple smaller ones.
	 *
	 * @param splitAmount - The amount of splits
	 * @param offset      - The multiplier scale for the offset.
	 * @param splitChance - The chance of creating a split.
	 * @param splitLength - The length of each split.
	 * @param splitAngle  - The angle of the split.
	 */
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
    /** Temporarily store old segments in a new array */
    List<BoltSegment> oldSegments = this.segments;
    this.segments = new ArrayList();
    /** Previous segment */
    BoltSegment prev = null;
    for (BoltSegment segment : oldSegments) {
        prev = segment.prev;
        /** Length of each subsegment */
        Pos subSegment = segment.difference.clone().multiply(1.0F / splitAmount);
        /**
			 * Creates an array of new bolt points. The first and last points of the bolts are the
			 * respected start and end points of the current segment.
			 */
        BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
        Pos startPoint = segment.start;
        newPoints[0] = segment.start;
        newPoints[splitAmount] = segment.end;
        /**
			 * Create bolt points.
			 */
        for (int i = 1; i < splitAmount; i++) {
            Pos newOffset = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
            Pos basePoint = startPoint.clone().add(subSegment.clone().multiply(i));
            newPoints[i] = new BoltPoint(basePoint, newOffset);
        }
        for (int i = 0; i < splitAmount; i++) {
            BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.alpha, segment.id * splitAmount + i, segment.splitID);
            next.prev = prev;
            if (prev != null) {
                prev.next = next;
            }
            if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                IPos3D splitrot = next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360, next.difference));
                Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
                this.maxSplitID += 1;
                this.parentIDMap.put(this.maxSplitID, next.splitID);
                BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().add(diff)), segment.alpha / 2f, next.id, this.maxSplitID);
                split.prev = prev;
                this.segments.add(split);
            }
            prev = next;
            this.segments.add(next);
        }
        if (segment.next != null) {
            segment.next.prev = prev;
        }
    }
    this.segmentCount *= splitAmount;
}
Also used : IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion)

Example 5 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project ICBM-Classic by BuiltBrokenModding.

the class BlastSonic method doPreExplode.

@Override
public void doPreExplode() {
    if (!this.world().isRemote) {
        if (this.hasShockWave) {
            for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
                for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
                    for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
                        Location targetPosition = position.add(new Pos(x, y, z));
                        Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                        if (blockID != Blocks.air) {
                            Material material = blockID.getMaterial();
                            if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
                                targetPosition.setBlock(world(), Blocks.air);
                            }
                        }
                    }
                }
            }
        }
        this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {

            @Override
            public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
                float resistance = 0;
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    resistance = 1f;
                } else {
                    resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
                }
                return resistance;
            }
        });
        this.thread.start();
    }
    if (this.hasShockWave) {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    } else {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IThreadCallBack(icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack) Material(net.minecraft.block.material.Material) World(net.minecraft.world.World) ThreadLargeExplosion(icbm.classic.content.explosive.thread.ThreadLargeExplosion) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) BlockLiquid(net.minecraft.block.BlockLiquid) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Aggregations

IPos3D (com.builtbroken.jlib.data.vector.IPos3D)8 Location (com.builtbroken.mc.imp.transform.vector.Location)5 Pos (com.builtbroken.mc.imp.transform.vector.Pos)5 TileEntity (net.minecraft.tileentity.TileEntity)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)3 IWorldPosition (com.builtbroken.mc.api.IWorldPosition)2 Block (net.minecraft.block.Block)2 Entity (net.minecraft.entity.Entity)2 Quaternion (com.builtbroken.mc.imp.transform.rotation.Quaternion)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 ThreadLargeExplosion (icbm.classic.content.explosive.thread.ThreadLargeExplosion)1 IThreadCallBack (icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 Material (net.minecraft.block.material.Material)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EntitySheep (net.minecraft.entity.passive.EntitySheep)1