Search in sources :

Example 31 with Pos

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

the class PathfinderAStar method findNodes.

@Override
public boolean findNodes(Pos start) {
    this.reset();
    this.openSet.add(start);
    this.gScore.put(start, 0d);
    this.fScore.put(start, this.gScore.get(start) + getHeuristicEstimatedCost(start, this.goal));
    while (!this.openSet.isEmpty()) {
        // Current is the node in openset having the lowest f_score[] value
        Pos currentNode = null;
        double lowestFScore = 0;
        for (Pos node : this.openSet) {
            if (currentNode == null || this.fScore.get(node) < lowestFScore) {
                currentNode = node;
                lowestFScore = this.fScore.get(node);
            }
        }
        if (currentNode == null) {
            break;
        }
        if (this.callBackCheck.onSearch(this, start, currentNode)) {
            return false;
        }
        if (currentNode.equals(this.goal)) {
            this.results = reconstructPath(this.navigationMap, goal);
            return true;
        }
        this.openSet.remove(currentNode);
        this.closedSet.add(currentNode);
        for (Pos neighbor : getNeighborNodes(currentNode)) {
            double tentativeGScore = this.gScore.get(currentNode) + currentNode.distance(neighbor);
            if (this.closedSet.contains(neighbor)) {
                if (tentativeGScore >= this.gScore.get(neighbor)) {
                    continue;
                }
            }
            if (!this.openSet.contains(neighbor) || tentativeGScore < this.gScore.get(neighbor)) {
                this.navigationMap.put(neighbor, currentNode);
                this.gScore.put(neighbor, tentativeGScore);
                this.fScore.put(neighbor, gScore.get(neighbor) + getHeuristicEstimatedCost(neighbor, goal));
                this.openSet.add(neighbor);
            }
        }
    }
    return false;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 32 with Pos

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

the class TestAbstractLocation method testToVector3.

/**
 * Tests {@link AbstractLocation#toVector3()
 */
public void testToVector3() {
    TLocation location = new TLocation(world, 20, 10, 10);
    Pos pos = location.toVector3();
    assertTrue(pos.equals(new Pos(20, 10, 10)));
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 33 with Pos

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

the class Vector3Test method testSubtraction.

/**
 * Simple addition test for Vector3
 */
public void testSubtraction() throws Exception {
    Pos vec = new Pos(0, 1, 0);
    vec = vec.subtract(1, 1, 1);
    Assert.assertEquals(0.0, vec.y(), 0);
    Assert.assertEquals(-1.0, vec.x(), 0);
    Assert.assertEquals(-1.0, vec.z(), 0);
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 34 with Pos

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

the class Vector3Test method testAddition.

/**
 * Simple addition test for Vector3
 */
public void testAddition() throws Exception {
    Pos vec = new Pos(0, 1, 0);
    vec = vec.add(1, 1, 1);
    Assert.assertEquals(2.0, vec.y(), 0);
    Assert.assertEquals(1.0, vec.x(), 0);
    Assert.assertEquals(1.0, vec.z(), 0);
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 35 with Pos

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

the class Vector3Sorter method newVector.

private Pos newVector(List<Pos> list, int x, int y, int z) {
    Pos vec = new Pos(x, y, z);
    list.add(vec);
    return vec;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

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