Search in sources :

Example 91 with Pos

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

the class OreGenReplace method generateBranch.

/**
     * Picks a random location in the chunk based on a random rotation and Y value
     *
     * @param world - world
     * @param rand  - random
     * @param varX  - randomX
     * @param varY  - randomY
     * @param varZ  - randomZ
     * @return true if it placed blocks
     */
public int generateBranch(World world, Random rand, int chunkCornerX, int chunkCornerZ, int varX, int varY, int varZ) {
    int blocksPlaced = 0;
    //MC default ore gen code, doesn't work well.... avoid
    if (generatorType == 0) {
        float angle = rand.nextFloat() * (float) Math.PI;
        double rxUpper = varX + 8 + MathHelper.sin(angle) * settings.amountPerBranch / 8.0F;
        double rxLower = varX + 8 - MathHelper.sin(angle) * settings.amountPerBranch / 8.0F;
        double rzUpper = varZ + 8 + MathHelper.cos(angle) * settings.amountPerBranch / 8.0F;
        double rzLower = varZ + 8 - MathHelper.cos(angle) * settings.amountPerBranch / 8.0F;
        double randomY = varY + rand.nextInt(3) - 2;
        double randomY2 = varY + rand.nextInt(3) - 2;
        for (int b = 0; b <= settings.amountPerBranch; ++b) {
            double var20 = rxUpper + (rxLower - rxUpper) * b / settings.amountPerBranch;
            double var22 = randomY + (randomY2 - randomY) * b / settings.amountPerBranch;
            double var24 = rzUpper + (rzLower - rzUpper) * b / settings.amountPerBranch;
            double var26 = rand.nextDouble() * settings.amountPerBranch / 16.0D;
            double var28 = (MathHelper.sin(b * (float) Math.PI / settings.amountPerBranch) + 1.0F) * var26 + 1.0D;
            double var30 = (MathHelper.sin(b * (float) Math.PI / settings.amountPerBranch) + 1.0F) * var26 + 1.0D;
            int startX = MathHelper.floor_double(var20 - var28 / 2.0D);
            int startY = MathHelper.floor_double(var22 - var30 / 2.0D);
            int startZ = MathHelper.floor_double(var24 - var28 / 2.0D);
            int endX = MathHelper.floor_double(var20 + var28 / 2.0D);
            int endY = MathHelper.floor_double(var22 + var30 / 2.0D);
            int endZ = MathHelper.floor_double(var24 + var28 / 2.0D);
            for (int px = startX; px <= endX; ++px) {
                double deltaX = (px + 0.5D - var20) / (var28 / 2.0D);
                if (deltaX * deltaX < 1.0D) {
                    for (int py = startY; py <= endY; ++py) {
                        double dy = (py + 0.5D - var22) / (var30 / 2.0D);
                        if (deltaX * deltaX + dy * dy < 1.0D) {
                            for (int pz = startZ; pz <= endZ; ++pz) {
                                double dz = (pz + 0.5D - var24) / (var28 / 2.0D);
                                Block block = world.getBlock(px, py, pz);
                                if (deltaX * deltaX + dy * dy + dz * dz < 1.0D && (settings.replaceBlock == null || block == settings.replaceBlock)) {
                                    if (world.setBlock(px, py, pz, this.oreBlock, this.oreMeta, 2)) {
                                        blocksPlaced++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else //Path finder ore gen
    if (generatorType == 1) {
        //Positions already pathed
        List<Pos> pathed = new ArrayList();
        //Positions to path next
        Queue<Pos> toPath = new LinkedList();
        //First location to path
        toPath.add(new Pos(varX, varY, varZ));
        List<ForgeDirection> directions = new ArrayList();
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            directions.add(dir);
        }
        //Breadth first search
        while (!toPath.isEmpty() && blocksPlaced < settings.amountPerBranch) {
            Pos next = toPath.poll();
            pathed.add(next);
            //Place block
            Block block = next.getBlock(world);
            if (settings.replaceBlock == null || block == settings.replaceBlock) {
                if (next.setBlock(world, oreBlock, oreMeta, 2)) {
                    blocksPlaced += 1;
                }
            }
            //Find new locations to place blocks
            Collections.shuffle(directions);
            for (ForgeDirection direction : directions) {
                //TODO randomize next path
                Pos pos = next.add(direction);
                if (!pathed.contains(pos) && world.rand.nextBoolean()) {
                    if (pos.isInsideMap()) {
                        boolean insideX = pos.xi() >= chunkCornerX && pos.xi() < (chunkCornerX + 16);
                        boolean insideZ = pos.zi() >= chunkCornerZ && pos.zi() < (chunkCornerZ + 16);
                        boolean insideY = pos.yi() >= settings.minGenerateLevel && pos.yi() <= settings.maxGenerateLevel;
                        if (insideX && insideZ && insideY) {
                            block = pos.getBlock(world);
                            if (settings.replaceBlock == null || block == settings.replaceBlock) {
                                toPath.add(pos);
                            }
                        }
                    }
                    if (!toPath.contains(pos)) {
                        pathed.add(pos);
                    }
                }
            }
        }
    } else //Pre-cache ore gen
    if (generatorType == 2) {
        int blockToPlace = 1 + com.builtbroken.jlib.helpers.MathHelper.rand.nextInt(Math.max(1, settings.amountPerBranch - 1));
    //TODO find templates that match block count
    }
    return blocksPlaced;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block)

Example 92 with Pos

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

the class FXElectricBolt method split.

/**
	 * Slits a large segment into multiple smaller ones.
	 *
	 * @param splitAmount - The amount of splits
	 * @param offset      - The multiplier multiply 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) {
    if (!this.isCalculated) {
        /** Temporarily store old segments in a new array */
        ArrayList<BoltSegment> oldSegments = this.segments;
        this.segments = new ArrayList();
        /** Previous segment */
        BoltSegment prev = null;
        for (BoltSegment segment : oldSegments) {
            prev = segment.prevSegment;
            Pos subSegment = segment.difference.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.startBolt.point;
            newPoints[0] = segment.startBolt;
            newPoints[splitAmount] = segment.endBolt;
            for (int i = 1; i < splitAmount; i++) {
                //Vector3 offsetVec = segment.difference.perpendicular().rotate(this.rand.nextFloat() * 360.0F, segment.difference).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos offsetVec = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360.0F, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos basepoint = startPoint.clone().add(subSegment.clone().multiply(i));
                newPoints[i] = new BoltPoint(basepoint, offsetVec);
            }
            for (int i = 0; i < splitAmount; i++) {
                BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.weight, segment.segmentID * splitAmount + i, segment.splitID);
                next.prevSegment = prev;
                if (prev != null) {
                    prev.nextSegment = next;
                }
                if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                    //Vector3 splitrot = next.difference.xCross().rotate(this.rand.nextFloat() * 360.0F, next.difference);
                    Pos splitrot = new Pos(next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360.0F, next.difference)));
                    //Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).multiply(splitLength);
                    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.splitparents.put(this.maxSplitID, next.splitID);
                    BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].basePoint, newPoints[(i + 1)].offSet.clone().add(diff)), segment.weight / 2.0F, next.segmentID, this.maxSplitID);
                    split.prevSegment = prev;
                    this.segments.add(split);
                }
                prev = next;
                this.segments.add(next);
            }
            if (segment.nextSegment != null) {
                segment.nextSegment.prevSegment = prev;
            }
        }
        this.segmentCount *= splitAmount;
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion)

Example 93 with Pos

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

the class MultiBlockListener method onMultiTileBroken.

@Override
public boolean onMultiTileBroken(IMultiTile tileMulti, Object source, boolean harvest) {
    if (!_destroyingStructure && tileMulti instanceof TileEntity) {
        Pos pos = new Pos((TileEntity) tileMulti).floor().sub(new Pos(this).floor());
        if (getLayoutOfMultiBlock().containsKey(pos)) {
            _destroyingStructure = true;
            MultiBlockHelper.destroyMultiBlockStructure(getMultiTileHost() != null ? getMultiTileHost() : this, harvest, true, true);
            _destroyingStructure = false;
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 94 with Pos

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

the class BlockUtility method setBlockSneaky.

/**
     * Sets a block in a sneaky way to bypass some restraints.
     */
public static void setBlockSneaky(World world, Pos position, Block block, int metadata, TileEntity tileEntity) {
    if (block != null && world != null) {
        Chunk chunk = world.getChunkFromChunkCoords(position.xi() >> 4, position.zi() >> 4);
        Pos chunkPosition = new Pos(position.xi() & 0xF, position.yi() & 0xF, position.zi() & 0xF);
        int heightMapIndex = chunkPosition.zi() << 4 | chunkPosition.xi();
        if (position.yi() >= chunk.precipitationHeightMap[heightMapIndex] - 1) {
            chunk.precipitationHeightMap[heightMapIndex] = -999;
        }
        int heightMapValue = chunk.heightMap[heightMapIndex];
        world.removeTileEntity(position.xi(), position.yi(), position.zi());
        ExtendedBlockStorage extendedBlockStorage = chunk.getBlockStorageArray()[position.yi() >> 4];
        if (extendedBlockStorage == null) {
            extendedBlockStorage = new ExtendedBlockStorage((position.yi() >> 4) << 4, !world.provider.hasNoSky);
            chunk.getBlockStorageArray()[position.yi() >> 4] = extendedBlockStorage;
        }
        extendedBlockStorage.func_150818_a(chunkPosition.xi(), chunkPosition.yi(), chunkPosition.zi(), block);
        extendedBlockStorage.setExtBlockMetadata(chunkPosition.xi(), chunkPosition.yi(), chunkPosition.zi(), metadata);
        if (position.yi() >= heightMapValue) {
            chunk.generateSkylightMap();
        } else {
            //chunk.getBlockLightOpacity(chunkPosition.xi(), position.yi(), chunkPosition.zi())
            if (chunk.getBlockLightValue(chunkPosition.xi(), position.yi(), chunkPosition.zi(), 0) > 0) {
                if (position.yi() >= heightMapValue) {
                    relightBlock(chunk, chunkPosition.clone().add(new Pos(0, 1, 0)));
                }
            } else if (position.yi() == heightMapValue - 1) {
                relightBlock(chunk, chunkPosition);
            }
            propagateSkylightOcclusion(chunk, chunkPosition);
        }
        chunk.isModified = true;
        //updateAllLightTypes
        world.func_147451_t(position.xi(), position.yi(), position.zi());
        if (tileEntity != null) {
            world.setTileEntity(position.xi(), position.yi(), position.zi(), tileEntity);
        }
        world.markBlockForUpdate(position.xi(), position.yi(), position.zi());
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage)

Example 95 with Pos

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

the class CuboidTest method testCollisionOverlap.

public void testCollisionOverlap() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Pos vec = new Pos(dir).multiply(0.3);
        Cube c = cube.add(vec);
        if (!cube.doesOverlap(c)) {
            System.out.println("Cube:  " + cube);
            System.out.println("Above: " + c.toString());
            assertEquals("x check failed", cube.isOutSideX(c.min().x(), c.max().x()), dir == ForgeDirection.EAST || dir == ForgeDirection.WEST);
            assertEquals("y check failed", cube.isOutSideY(c.min().y(), c.max().y()), dir == ForgeDirection.DOWN || dir == ForgeDirection.UP);
            assertEquals("z check failed", cube.isOutSideZ(c.min().z(), c.max().z()), dir == ForgeDirection.NORTH || dir == ForgeDirection.SOUTH);
            fail("Didn't collide for side " + dir);
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)105 Block (net.minecraft.block.Block)25 TileEntity (net.minecraft.tileentity.TileEntity)13 Location (com.builtbroken.mc.imp.transform.vector.Location)11 Entity (net.minecraft.entity.Entity)11 Cube (com.builtbroken.mc.imp.transform.region.Cube)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Test (org.junit.Test)7 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)6 EntityMissile (icbm.classic.content.entity.EntityMissile)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)5 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)5 ItemStack (net.minecraft.item.ItemStack)5 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4