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