Search in sources :

Example 6 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos 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.lib.transform.vector.Pos) Quaternion(com.builtbroken.mc.lib.transform.rotation.Quaternion)

Example 7 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Selection method getLocationsWithin.

/**
 * Grabs all blocks near the point and within the distance.
 * <p/>
 * Note this search pattern does start at most negative corner
 * TODO replace search pattern with same code the blasts use
 * to select blocks in a bubble
 *
 * @param location - center point of the search
 * @param size     - number of items to return
 * @param distance - distance to search
 * @return list of locations of non air blocks sorted to closest to location
 */
public List<Pos> getLocationsWithin(Location location, int size, int distance) {
    List<Pos> list = new LinkedList<>();
    if (distance > 0) {
        int min_y = (int) Math.max(min().yi(), location.y() - distance);
        int max_y = (int) Math.min(max().yi(), location.y() + distance);
        int min_x = (int) Math.max(min().xi(), location.x() - distance);
        int max_x = (int) Math.min(max().xi(), location.x() + distance);
        int min_z = (int) Math.max(min().zi(), location.z() - distance);
        int max_z = (int) Math.min(max().zi(), location.z() + distance);
        for (int y = min_y; y <= max_y; y++) {
            for (int x = min_x; x <= max_x; x++) {
                for (int z = min_z; z <= max_z; z++) {
                    if (size > 0 && list.size() >= size) {
                        Collections.sort(list, new Vector3DistanceComparator(location));
                        return list;
                    }
                    Pos pos = new Pos(x, y, z);
                    if (location.distance(pos) <= distance) {
                        Block b = pos.getBlock(location.world());
                        if (b != null && !pos.isAirBlock(location.world()) && pos.getHardness(location.world()) >= 0) {
                            list.add(pos);
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : Vector3DistanceComparator(com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator) Pos(com.builtbroken.mc.lib.transform.vector.Pos) Block(net.minecraft.block.Block) LinkedList(java.util.LinkedList)

Example 8 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class SchematicMap method init.

public void init() {
    if (this.schematicSize != null) {
        this.init = true;
        this.schematicCenter = new Pos(this.schematicSize.x() / 2, 0, this.schematicSize.z() / 2);
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 9 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class SchematicMap method load.

@Override
public void load(NBTTagCompound nbt) {
    schematicSize = new Pos(nbt.getInteger("sizeX"), nbt.getInteger("sizeY"), nbt.getInteger("sizeZ"));
    schematicCenter = new Pos(nbt.getInteger("centerX"), nbt.getInteger("centerY"), nbt.getInteger("centerZ"));
    NBTTagCompound blockDataSave = nbt.getCompoundTag(BLOCK_LIST_SAVE_NAME);
    for (int blockCount = 0; blockCount < blockDataSave.getInteger("count"); blockCount++) {
        String blockString = blockDataSave.getString("Block" + blockCount);
        String[] blockData = blockString.split(":");
        // int blockID = 0;
        Block block = null;
        int blockMeta = 0;
        Pos blockPostion = new Pos();
        if (blockData != null) {
            try {
                if (blockData.length > 0) {
                    if (SchematicMap.BLOCK_SAVE_MAP.containsKey(blockData[0])) {
                        block = SchematicMap.BLOCK_SAVE_MAP.get(blockData[0]);
                    } else {
                        // TODO: Fix up, wrong implementation
                        block = Block.getBlockById(Integer.parseInt(blockData[0]));
                    }
                }
                if (blockData.length > 1) {
                    blockMeta = Integer.parseInt(blockData[1]);
                }
                int x = 0;
                int y = 0;
                int z = 0;
                if (blockData.length > 2) {
                    x = Integer.parseInt(blockData[2]);
                }
                if (blockData.length > 3) {
                    y = Integer.parseInt(blockData[3]);
                }
                if (blockData.length > 4) {
                    z = Integer.parseInt(blockData[4]);
                }
                blockPostion = new Pos(x, y, z);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.block_map.put(blockPostion, new Pair<>(block, blockMeta));
        }
    }
    if (!init) {
        this.init();
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block)

Example 10 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Sphere method getEntities.

public <E extends Entity> List<E> getEntities(World world, Class<E> clazz) {
    List<E> list = new ArrayList();
    int minX = MathHelper.floor_double((r - World.MAX_ENTITY_RADIUS) / 16.0D);
    int maxX = MathHelper.floor_double((r + World.MAX_ENTITY_RADIUS) / 16.0D);
    int minZ = MathHelper.floor_double((r - World.MAX_ENTITY_RADIUS) / 16.0D);
    int maxZ = MathHelper.floor_double((r + World.MAX_ENTITY_RADIUS) / 16.0D);
    // world.getEntitiesWithinAABB()
    for (int i1 = minX; i1 <= maxX; i1++) {
        for (int j1 = minZ; j1 <= maxZ; j1++) {
            if (world.getChunkProvider().chunkExists(i1, j1)) {
                Chunk chunk = world.getChunkFromChunkCoords(i1, j1);
                int i = MathHelper.floor_double((r - World.MAX_ENTITY_RADIUS) / 16.0D);
                int j = MathHelper.floor_double((r + World.MAX_ENTITY_RADIUS) / 16.0D);
                i = MathHelper.clamp_int(i, 0, chunk.entityLists.length - 1);
                j = MathHelper.clamp_int(j, 0, chunk.entityLists.length - 1);
                for (int k = i; k <= j; k++) {
                    List list1 = chunk.entityLists[k];
                    for (int l = 0; l < list1.size(); l++) {
                        Entity entity = (Entity) list1.get(l);
                        if (clazz.isAssignableFrom(entity.getClass()) && distance(new Pos(entity)) <= r) {
                            list.add((E) entity);
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

Pos (com.builtbroken.mc.lib.transform.vector.Pos)68 Block (net.minecraft.block.Block)11 TileEntity (net.minecraft.tileentity.TileEntity)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)7 Cube (com.builtbroken.mc.lib.transform.region.Cube)6 Test (org.junit.Test)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Pair (com.builtbroken.jlib.type.Pair)3 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 Quaternion (com.builtbroken.mc.lib.transform.rotation.Quaternion)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3