Search in sources :

Example 16 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class AbstractTileTest method testGetSelectBounds.

@Test
public void testGetSelectBounds() {
    FakeWorld world = FakeWorld.newWorld("TestGetSelectBounds");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    Cube cube = tile.getSelectBounds();
    assertTrue(cube != null);
//TODO add check to ensure cube size and values are good
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) PacketTile(com.builtbroken.mc.core.network.packet.PacketTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) Test(org.junit.Test)

Example 17 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class RadioMap method updateCache.

/**
     * Updates the list of receivers for this sender.
     * <p>
     * Make sure if you call this you clear your
     * cache when the sender is no longer valid
     * use {@link TileEntity#invalidate()}
     * or {@link Entity#setDead()} to
     * clear the cache.
     * <p>
     * As well make sure to call this method
     * every so often. As the cache is not maintained
     * often or quickly. It is only updated
     * when receives are added or removed. So
     * if the sender's range changes this method
     * needs to be called.
     * <p>
     * Make sure to not call this method often
     * as its a high CPU task.
     *
     * @param sender - object that needs to
     *               have receivers cache. Needs
     *               to have a valid {@link IRadioWaveSender#getRadioSenderRange()}
     *               value in order to be cached.
     */
public void updateCache(IRadioWaveSender sender) {
    //Clear cache value
    sender_to_receivers_cache.remove(sender);
    Cube range = sender.getRadioSenderRange();
    if (range != null) {
        sender_to_receivers_cache.put(sender, getReceiversInRange(range, sender instanceof IRadioWaveReceiver ? (IRadioWaveReceiver) sender : (IRadioWaveReceiver) null));
    }
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) Cube(com.builtbroken.mc.imp.transform.region.Cube)

Example 18 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class RadioMap method update.

/**
     * Called to update data about the receiver. Used
     * when the receiver's range changes.
     *
     * @param receiver
     */
public void update(IRadioWaveReceiver receiver) {
    if (!receive_to_range.containsKey(receiver) || receive_to_range.get(receiver) == null || receive_to_range.get(receiver).equals(receiver.getRadioReceiverRange())) {
        Cube range = receiver.getRadioReceiverRange();
        if (range != null) {
            updateChunkCache(receiver, range);
            updateSenderCache(receiver, range);
        }
    }
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube)

Example 19 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class RadioMap method popMessage.

/**
     * Called to send a message over the network
     *
     * @param sender - object that sent the message
     * @param hz     - frequency of the message
     * @param header - descriptive header of the message, mainly an ID system
     * @param data   - data being sent in the message
     */
public void popMessage(IRadioWaveSender sender, float hz, String header, Object[] data) {
    //Cache for senders that know they will be active
    if (sender_to_receivers_cache.containsKey(sender)) {
        for (IRadioWaveReceiver receiver : sender_to_receivers_cache.get(sender)) {
            receiver.receiveRadioWave(hz, sender, header, data);
        }
        return;
    }
    //Receivers that have full map range, used for legacy systems mainly
    for (IRadioWaveReceiver receiver : fullMapRangeReceives) {
        receiver.receiveRadioWave(hz, sender, header, data);
    }
    //Slow way to update receives with messages
    Cube range = sender.getRadioSenderRange();
    if (range != null) {
        //Use simpler method if the range of number of entries is small
        if (//20 chunks
        receive_to_chunks.size() < 200 || range.getSizeX() > 320 || range.getSizeY() > 320) {
            for (IRadioWaveReceiver receiver : receive_to_chunks.keySet()) {
                if (receiver != null && receiver != sender) {
                    Cube receiverRange = receiver.getRadioReceiverRange();
                    if (range.doesOverlap(receiverRange) || receiverRange.doesOverlap(range)) {
                        receiver.receiveRadioWave(hz, sender, header, data);
                    }
                }
            }
        } else //Complex method only used if number of receive is very high, e.g. is faster~ish than the above method
        {
            List<ChunkCoordIntPair> coords = range.getChunkCoords();
            List<IRadioWaveReceiver> receivers = new ArrayList();
            for (ChunkCoordIntPair pair : coords) {
                List<IRadioWaveReceiver> l = chunk_to_entities.get(pair);
                if (l != null && l.size() > 0) {
                    for (IRadioWaveReceiver r : l) {
                        if (r != null && r != sender && !receivers.contains(r)) {
                            receivers.add(r);
                        }
                    }
                }
            }
            for (IRadioWaveReceiver receiver : receivers) {
                receiver.receiveRadioWave(hz, sender, header, data);
            }
        }
    }
}
Also used : IRadioWaveReceiver(com.builtbroken.mc.api.map.radio.IRadioWaveReceiver) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Cube(com.builtbroken.mc.imp.transform.region.Cube) ArrayList(java.util.ArrayList)

Example 20 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class RadioMap method add.

public boolean add(IRadioWaveReceiver receiver) {
    Cube range = receiver.getRadioReceiverRange();
    if (range != null) {
        if (range == RadioRegistry.INFINITE) {
            if (!fullMapRangeReceives.contains(receiver)) {
                fullMapRangeReceives.add(receiver);
            }
            return true;
        }
        if (!receive_to_chunks.containsKey(receiver)) {
            updateChunkCache(receiver, range);
            updateSenderCache(receiver, range);
            return true;
        }
    }
    return false;
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube)

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