Search in sources :

Example 1 with Cube

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);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube)

Example 2 with Cube

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Cube(com.builtbroken.mc.imp.transform.region.Cube) RadioMap(com.builtbroken.mc.lib.world.radio.RadioMap)

Example 3 with Cube

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;
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) Cube(com.builtbroken.mc.imp.transform.region.Cube) ArrayList(java.util.ArrayList)

Example 4 with Cube

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);
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 5 with Cube

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);
}
Also used : PacketSelectionData(com.builtbroken.mc.core.network.packet.PacketSelectionData) Cube(com.builtbroken.mc.imp.transform.region.Cube) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ArrayList(java.util.ArrayList) Region(com.builtbroken.mc.modflag.Region)

Aggregations

Cube (com.builtbroken.mc.imp.transform.region.Cube)21 Pos (com.builtbroken.mc.imp.transform.vector.Pos)8 IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)5 ArrayList (java.util.ArrayList)4 Entity (net.minecraft.entity.Entity)4 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)3 Tile (com.builtbroken.mc.prefab.tile.Tile)3 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 Test (org.junit.Test)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)2 IRadioWaveSender (com.builtbroken.mc.api.map.radio.IRadioWaveSender)1 IMultiTileHost (com.builtbroken.mc.api.tile.multiblock.IMultiTileHost)1 PacketSelectionData (com.builtbroken.mc.core.network.packet.PacketSelectionData)1 RadioMap (com.builtbroken.mc.lib.world.radio.RadioMap)1 Region (com.builtbroken.mc.modflag.Region)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1