use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.
the class TestAbstractLocation method testInit.
/**
* Tests constructors
*/
public void testInit() {
List<TLocation> locations = new ArrayList();
//Test main method
locations.add(new TLocation(world, 10, 11, 12));
//Test entity method
Entity entity = new EntitySheep(world);
entity.setPosition(10, 11, 12);
locations.add(new TLocation(entity));
//Test tile
TileEntity tile = new TileEntity();
tile.setWorldObj(world);
tile.xCoord = 10;
tile.yCoord = 11;
tile.zCoord = 12;
locations.add(new TLocation(tile));
//Test NBT method
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("dimension", world.provider.dimensionId);
tag.setDouble("x", 10);
tag.setDouble("y", 11);
tag.setDouble("z", 12);
locations.add(new TLocation(tag));
//Test byte buf method
ByteBuf buf = Unpooled.buffer();
buf.writeInt(world.provider.dimensionId);
buf.writeDouble(10);
buf.writeDouble(11);
buf.writeDouble(12);
locations.add(new TLocation(buf));
//Test IWorldPosition
locations.add(new TLocation(new IWorldPosition() {
@Override
public World world() {
return world;
}
@Override
public double x() {
return 10;
}
@Override
public double y() {
return 11;
}
@Override
public double z() {
return 12;
}
}));
//Test world, IPos3D
locations.add(new TLocation(world, new IPos3D() {
@Override
public double x() {
return 10;
}
@Override
public double y() {
return 11;
}
@Override
public double z() {
return 12;
}
}));
//Test world, vec3
locations.add(new TLocation(world, Vec3.createVectorHelper(10, 11, 12)));
//Test world, moving object
locations.add(new TLocation(world, new MovingObjectPosition(10, 11, 12, 0, Vec3.createVectorHelper(10, 11, 12))));
for (int i = 0; i < locations.size(); i++) {
TLocation location = locations.get(i);
assertTrue("" + i, location.world == world);
assertTrue("" + i, location.xi() == 10);
assertTrue("" + i, location.yi() == 11);
assertTrue("" + i, location.zi() == 12);
}
}
use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method destroyMultiBlockStructure.
/**
* Breaks down the multiblock stucture linked to the host
*
* @param host - host providing the layour of the structure
* @param doDrops - attempt to drop blocks?
* @param offset - offset the layout by the location of the host?
* @param killHost - destroy the host block as well?
*/
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
if (host != null) {
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
IWorldPosition center;
if (host instanceof TileEntity) {
center = new Location((TileEntity) host);
} else if (host instanceof IWorldPosition) {
center = (IWorldPosition) host;
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
return;
}
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
if (offset) {
pos = pos.add(center);
}
TileEntity tile = pos.getTileEntity(center.world());
if (tile instanceof IMultiTile) {
((IMultiTile) tile).setHost(null);
pos.setBlockToAir(center.world());
}
}
if (doDrops) {
InventoryUtility.dropBlockAsItem(center, killHost);
} else if (killHost) {
center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
}
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
}
}
}
use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method updateStructure.
/**
* Runs a world update on all members of the structure
*
* @param world
* @param host
* @param offset - off set the location data by the center of the host
*/
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
//TODO junit test
if (!(host instanceof TileEntity)) {
Engine.error("Tile host is not an instance of TileEntity");
}
if (world == null) {
Engine.error("Tile host is not an instance of TileEntity");
}
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
int x = ((TileEntity) host).xCoord;
int y = ((TileEntity) host).yCoord;
int z = ((TileEntity) host).zCoord;
Pos center = new Pos(x, y, z);
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Location pos = new Location(world, entry.getKey());
if (offset) {
pos = pos.add(center);
}
pos.markForUpdate();
}
center.markForUpdate(world);
} else {
logger.error("Tile[" + host + "]'s structure map is empty");
}
}
use of com.builtbroken.jlib.data.vector.IPos3D 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.jlib.data.vector.IPos3D in project ICBM-Classic by BuiltBrokenModding.
the class BlastSonic method doPreExplode.
@Override
public void doPreExplode() {
if (!this.world().isRemote) {
if (this.hasShockWave) {
for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
Location targetPosition = position.add(new Pos(x, y, z));
Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
if (blockID != Blocks.air) {
Material material = blockID.getMaterial();
if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
targetPosition.setBlock(world(), Blocks.air);
}
}
}
}
}
}
this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {
@Override
public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
float resistance = 0;
if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
resistance = 1f;
} else {
resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
}
return resistance;
}
});
this.thread.start();
}
if (this.hasShockWave) {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
} else {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
}
Aggregations