use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class JsonConverterCube method fromJsonObject.
public static Cube fromJsonObject(JsonObject object) {
JsonProcessor.ensureValuesExist(object, "min", "max");
Pos min = JsonConverterPos.fromJson(object.get("min"));
Pos max = JsonConverterPos.fromJson(object.get("max"));
return new Cube(min, max);
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class WirelessNetwork method updateConnections.
/**
* Called to update all connections
*/
public void updateConnections() {
//Update list if we still have a sender
if (hub != null && hub.getWirelessCoverageArea() != null) {
//================================
//==Discovery Phase===============
//================================
//Get all receivers in range
Cube range = hub.getWirelessCoverageArea();
RadioMap map = RadioRegistry.getRadioMapForWorld(hub.world());
List<IRadioWaveReceiver> receivers = map.getReceiversInRange(range, hub instanceof IRadioWaveReceiver ? (IRadioWaveReceiver) hub : null);
//Loop threw receivers
if (!receivers.isEmpty()) {
for (IRadioWaveReceiver receiver : receivers) {
if (receiver instanceof IWirelessConnector) {
if (!addConnector((IWirelessConnector) receiver) && wirelessConnectors.contains(receiver)) {
//Update connection list as connector is not going to update every tick
for (IWirelessNetworkObject object : ((IWirelessConnector) receiver).getWirelessNetworkObjects()) {
addConnection(((IWirelessConnector) receiver), object);
}
}
}
}
}
//Ensure we have added the primary sender if it is a connector
if (getPrimarySender() instanceof IWirelessConnector) {
addConnector((IWirelessConnector) getPrimarySender());
}
//================================
//==Clean Up Phase================
//================================
//Clear invalid connectors
Iterator<IWirelessConnector> it2 = wirelessConnectors.iterator();
while (it2.hasNext()) {
IWirelessConnector con = it2.next();
if (con instanceof TileEntity && ((TileEntity) con).isInvalid() || con instanceof Entity && !((Entity) con).isEntityAlive()) {
it2.remove();
clearConnections(con);
con.removeWirelessNetwork(this, ConnectionRemovedReason.TILE_INVALIDATE);
}
}
//Clear invalid attached devices
Iterator<IWirelessNetworkObject> it = attachedDevices.iterator();
while (it.hasNext()) {
IWirelessNetworkObject obj = it.next();
if (obj instanceof TileEntity && ((TileEntity) obj).isInvalid() || obj instanceof Entity && !((Entity) obj).isEntityAlive()) {
it.remove();
obj.removeWirelessNetwork(this, ConnectionRemovedReason.TILE_INVALIDATE);
if (obj instanceof IWirelessDataPoint) {
dataPoints.remove(obj);
//TODO notify listeners
}
}
}
} else {
kill();
}
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class RadioMap method getReceiversInRange.
/**
* Gets a list of all receivers in the range
*
* @param range - range to check inside
* @param excludeList - tiles to ignore
* @return list of receivers, or empty list
*/
public List<IRadioWaveReceiver> getReceiversInRange(Cube range, List excludeList) {
List<IRadioWaveReceiver> receivers = new ArrayList();
receivers.addAll(fullMapRangeReceives);
if (range != null) {
for (IRadioWaveReceiver receiver : receive_to_chunks.keySet()) {
if (receiver != null && (excludeList == null || !excludeList.contains(receiver))) {
Cube receiverRange = receiver.getRadioReceiverRange();
if (receiverRange != null && range.doesOverlap(receiverRange)) {
receivers.add(receiver);
}
}
}
}
return receivers;
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class CuboidTest method testCollisionCorners.
public void testCollisionCorners() {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
for (int side = 0; side < 4; side++) {
Pos vec = new Pos(dir).multiply(0.3);
switch(dir) {
case DOWN:
case UP:
switch(side) {
case 0:
vec.add(0.3, 0, 0.3);
break;
case 1:
vec.add(-0.3, 0, 0.3);
break;
case 2:
vec.add(0.3, 0, -0.3);
break;
case 3:
vec.add(-0.3, 0, -0.3);
break;
}
case NORTH:
case SOUTH:
switch(side) {
case 0:
vec.add(0.3, 0.3, 0);
break;
case 1:
vec.add(-0.3, 0.3, 0);
break;
case 2:
vec.add(0.3, -0.3, 0);
break;
case 3:
vec.add(-0.3, -0.3, 0);
break;
}
break;
case WEST:
case EAST:
switch(side) {
case 0:
vec.add(0, 0.3, 0.3);
break;
case 1:
vec.add(0, -0.3, 0.3);
break;
case 2:
vec.add(0, 0.3, -0.3);
break;
case 3:
vec.add(0, -0.3, -0.3);
break;
}
break;
}
Cube c = cube.clone().add(vec);
if (!cube.doesOverlap(c)) {
System.out.println("Cube: " + cube);
System.out.println("Above: " + c.toString());
System.out.println("Is outside X limits -> " + cube.isOutSideX(c.min().x(), c.max().x()));
System.out.println("Is outside Y limits -> " + cube.isOutSideY(c.min().y(), c.max().y()));
System.out.println("Is outside Z limits -> " + cube.isOutSideZ(c.min().z(), c.max().z()));
fail("Didn't collide for side " + dir + " and corner " + side);
}
}
}
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class SelectionHandler method updatePlayerRenderData.
public static void updatePlayerRenderData(EntityPlayerMP player) {
List<Cube> cubes = new ArrayList();
List<Cube> regions = new ArrayList();
Cube selection = getSelection(player);
for (Cube cube : selections.values()) {
if (cube != selection && cube.distance(new Pos(player)) <= 160) {
cubes.add(cube);
}
}
for (Region region : RegionManager.getControllerForWorld(player.worldObj).getRegionsNear(player, 160)) {
for (Cube cube : region.segments) {
if (cube.isCloseToAnyCorner(new Pos(player), 160)) {
regions.add(cube);
}
}
}
Engine.instance.packetHandler.sendToPlayer(new PacketSelectionData(selection, cubes, regions), player);
}
Aggregations