Search in sources :

Example 51 with Pos

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

the class BlastBasic method expand.

/**
 * Called to map another iteration to expand outwards from the center of the explosion
 *
 * @param map       - hash map to store data for block placement to energy used
 * @param vec       - next block to expand from, and to log to map
 * @param energy    - current energy at block
 * @param side      - side not to expand in, and direction we came from
 * @param iteration - current iteration count from center, use this to stop the iteration if they get too far from center
 */
protected void expand(HashMap<BlockEdit, Float> map, BlockEdit vec, float energy, EnumFacing side, int iteration) {
    long timeStart = System.nanoTime();
    if (iteration < size * 2) {
        float e = getEnergyCostOfTile(vec, energy);
        profile.tilesPathed++;
        if (e >= 0) {
            // Add block to effect list
            vec.energy = energy;
            onBlockMapped(vec, e, energy - e);
            map.put(vec, energy - e);
            // Only iterate threw sides if we have more energy
            if (e > 1) {
                // Get valid sides to iterate threw
                List<BlockEdit> sides = new ArrayList();
                for (EnumFacing dir : EnumFacing.values()) {
                    if (dir != side) {
                        BlockEdit v = new BlockEdit(world, vec.x(), vec.y(), vec.z());
                        v.doDrops();
                        v = v.add(dir);
                        v.face = dir;
                        v.logPrevBlock();
                        sides.add(v);
                    }
                }
                Collections.sort(sides, new Vector3DistanceComparator(new Pos(x(), y(), z())));
                profile.blockIterationTimes.add(System.nanoTime() - timeStart);
                // Iterate threw sides expending energy outwards
                for (BlockEdit f : sides) {
                    float eToSpend = (e / sides.size()) + (e % sides.size());
                    e -= eToSpend;
                    EnumFacing face = side == null ? getOpposite(f.face) : side;
                    if (!map.containsKey(f) || map.get(f) < eToSpend) {
                        f.face = face;
                        expand(map, f, eToSpend, face, iteration + 1);
                    }
                }
            }
        }
    }
}
Also used : Vector3DistanceComparator(com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator) Pos(com.builtbroken.mc.lib.transform.vector.Pos) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit)

Example 52 with Pos

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

the class EulerAngle method toAngleAxis.

/**
 * Converts object to {@link AngleAxis}
 *
 * @return new {@link AngleAxis}
 */
public AngleAxis toAngleAxis() {
    double c1 = Math.cos(yaw / 2);
    double s1 = Math.sin(yaw / 2);
    double c2 = Math.cos(pitch / 2);
    double s2 = Math.sin(pitch / 2);
    double c3 = Math.cos(roll / 2);
    double s3 = Math.sin(roll / 2);
    double c1c2 = c1 * c2;
    double s1s2 = s1 * s2;
    double w = c1c2 * c3 - s1s2 * s3;
    double x = c1c2 * s3 + s1s2 * c3;
    double y = s1 * c2 * c3 + c1 * s2 * s3;
    double z = c1 * s2 * c3 - s1 * c2 * s3;
    double angle = 2 * Math.acos(w);
    Pos axis = new Pos(x, y, z);
    if (axis.magnitudeSquared() < 0.001) {
        axis = new Pos(0, 0, -1);
    } else {
        axis = axis.normalize();
    }
    return new AngleAxis(angle, axis);
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 53 with Pos

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

the class BlockTile method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    Tile tile = inject(world, x, y, z);
    boolean value = tile.onPlayerActivated(player, side, new Pos(hitX, hitY, hitZ));
    eject();
    return value;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 54 with Pos

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

the class BlockTile method getExplosionResistance.

@Override
public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
    Tile tile = inject(world, x, y, z);
    float resistance = tile.getExplosionResistance(entity, new Pos(explosionX, explosionY, explosionZ));
    eject();
    return resistance;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 55 with Pos

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

the class InternalInventoryHandler method tryPlaceInPosition.

/**
 * Tries to place an itemStack in a specific position if it is an inventory.
 *
 * @return The ItemStack remained after place attempt
 */
public ItemStack tryPlaceInPosition(ItemStack itemStack, Pos position, ForgeDirection dir) {
    TileEntity tileEntity = position.getTileEntity(world);
    ForgeDirection direction = dir.getOpposite();
    if (tileEntity != null && itemStack != null) {
        if (tileEntity instanceof TileEntityChest) {
            TileEntityChest[] chests = { (TileEntityChest) tileEntity, null };
            /**
             * Try to find a double chest.
             */
            for (int i = 2; i < 6; i++) {
                ForgeDirection searchDirection = ForgeDirection.getOrientation(i);
                Pos searchPosition = position.clone();
                searchPosition.add(searchDirection);
                if (searchPosition.getTileEntity(world) != null) {
                    if (searchPosition.getTileEntity(world).getClass() == chests[0].getClass()) {
                        chests[1] = (TileEntityChest) searchPosition.getTileEntity(world);
                        break;
                    }
                }
            }
            for (TileEntityChest chest : chests) {
                if (chest != null) {
                    for (int i = 0; i < chest.getSizeInventory(); i++) {
                        itemStack = this.addStackToInventory(i, chest, itemStack);
                        if (itemStack == null) {
                            return null;
                        }
                    }
                }
            }
        } else if (tileEntity instanceof IExtendedStorage) {
            return ((IExtendedStorage) tileEntity).addStackToStorage(itemStack);
        } else if (tileEntity instanceof ISidedInventory) {
            ISidedInventory inventory = (ISidedInventory) tileEntity;
            int[] slots = inventory.getAccessibleSlotsFromSide(direction.ordinal());
            for (int i = 0; i < slots.length; i++) {
                if (inventory.canInsertItem(slots[i], itemStack, direction.ordinal())) {
                    itemStack = this.addStackToInventory(slots[i], inventory, itemStack);
                }
                if (itemStack == null) {
                    return null;
                }
            }
        } else if (tileEntity instanceof IInventory) {
            IInventory inventory = (IInventory) tileEntity;
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                itemStack = this.addStackToInventory(i, inventory, itemStack);
                if (itemStack == null) {
                    return null;
                }
            }
        }
    }
    if (itemStack == null || itemStack.stackSize <= 0) {
        return null;
    }
    return itemStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IExtendedStorage(com.builtbroken.mc.api.tile.IExtendedStorage) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

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