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);
}
}
}
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations