Search in sources :

Example 11 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project LogisticsPipes by RS485.

the class MainProxy method sendPacketToAllWatchingChunk.

public static void sendPacketToAllWatchingChunk(int X, int Z, int dimensionId, ModernPacket packet) {
    if (!MainProxy.isServer()) {
        System.err.println("sendPacketToAllWatchingChunk called clientside !");
        new Exception().printStackTrace();
        return;
    }
    ChunkCoordIntPair chunk = new ChunkCoordIntPair(X >> 4, Z >> 4);
    PlayerCollectionList players = LogisticsEventListener.watcherList.get(chunk);
    if (players != null) {
        for (EntityPlayer player : players.players()) {
            if (MainProxy.getDimensionForWorld(player.worldObj) == dimensionId) {
                MainProxy.sendPacketToPlayer(packet, player);
            }
        }
        return;
    }
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList)

Example 12 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.

the class AMChunkLoader method releaseStaticChunkLoad.

public void releaseStaticChunkLoad(Class clazz, int x, int y, int z, World world) {
    Ticket ticket = getTicket(new TicketIdentifier(x, y, z, world.provider.dimensionId));
    if (ticket == null) {
        LogHelper.warn("No ticket for specified location.  No chunk to unload!");
        return;
    }
    ChunkCoordIntPair pair = new ChunkCoordIntPair(x >> 4, z >> 4);
    ForgeChunkManager.unforceChunk(ticket, pair);
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair)

Example 13 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.

the class AMChunkLoader method ticketsLoaded.

@Override
public void ticketsLoaded(List<Ticket> tickets, World world) {
    for (Ticket ticket : tickets) {
        NBTTagCompound compound = ticket.getModData();
        int[] coords = compound.getIntArray("StaticLoadCoords");
        String clazzName = compound.getString("ChunkLoadClass");
        Class clazz = null;
        try {
            clazz = Class.forName(clazzName);
        } catch (ClassNotFoundException e) {
            LogHelper.info("Cached class not found (%s) when attempting to load a chunk loading ticket.  This ticket will be discarded, and the chunk may not be loaded.  Block Coords: %d, %d", clazzName, coords[0], coords[2]);
            ForgeChunkManager.releaseTicket(ticket);
            continue;
        }
        TileEntity te = world.getTileEntity(coords[0], coords[1], coords[2]);
        if (te != null && te.getClass().isAssignableFrom(clazz)) {
            ChunkCoordIntPair pair = new ChunkCoordIntPair(coords[0] >> 4, coords[2] >> 4);
            ForgeChunkManager.forceChunk(ticket, pair);
        } else {
            LogHelper.info("Either no tile entity was found or it did not match the cached class.  This chunk loading ticket will be discarded, and the chunk may not be loaded.  Block Coords: %d, %d", coords[0], coords[2]);
            ForgeChunkManager.releaseTicket(ticket);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 14 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.

the class AMChunkLoader method requestStaticChunkLoad.

/**
	 * Requests a static chunk load.  This is a non-moving chunk load, and will be assumed that the specified class will exist as a tile entity
	 *
	 * @param clazz the class to look for
	 * @param x     the x coordinate of the tile entity
	 * @param y     the y coordinate of the tile entity
	 * @param z     the z coordinate of the tile entity
	 * @param world The world object of the tile entity
	 */
public void requestStaticChunkLoad(Class clazz, int x, int y, int z, World world) {
    Ticket ticket = requestTicket(x, y, z, world);
    if (ticket == null) {
        LogHelper.warn("Unable to get a ticket for chunk loading!  The chunk identified by %d, %d is *not* loaded!", x, z);
        return;
    }
    NBTTagCompound compound = ticket.getModData();
    compound.setIntArray("StaticLoadCoords", new int[] { x, y, z });
    compound.setString("ChunkLoadClass", clazz.getName());
    ChunkCoordIntPair pair = new ChunkCoordIntPair(x >> 4, z >> 4);
    ForgeChunkManager.forceChunk(ticket, pair);
}
Also used : Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 15 with ChunkCoordIntPair

use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.

the class PowerNodeRegistry method getAllNearbyNodes.

/**
	 * Returns all power nodes within POWER_SEARCH_RADIUS
	 *
	 * @param location The center point to search from
	 * @param power    The power type that the provider needs to supply or accept to be considered valid
	 * @return An array of IPowerNodes
	 */
public IPowerNode[] getAllNearbyNodes(World world, AMVector3 location, PowerTypes power) {
    //get the list of chunks we'll need to search in
    ChunkCoordIntPair[] search = getSearchChunks(location);
    //build the list of nodes from that chunk
    HashMap<AMVector3, PowerNodeEntry> nodesToSearch = new HashMap<AMVector3, PowerNodeEntry>();
    for (ChunkCoordIntPair pair : search) {
        HashMap<AMVector3, PowerNodeEntry> nodesInChunk = powerNodes.get(pair);
        if (nodesInChunk != null) {
            //Add only vectors that are less than or equal to POWER_SEARCH_RADIUS_SQ away
            for (AMVector3 vector : nodesInChunk.keySet()) {
                if (location.distanceSqTo(vector) <= POWER_SEARCH_RADIUS_SQ && !vector.equals(location)) {
                    nodesToSearch.put(vector, nodesInChunk.get(vector));
                }
            }
        }
    }
    //spin through and create our list of providers
    ArrayList<IPowerNode> nodes = new ArrayList<IPowerNode>();
    int deadNodesRemoved = 0;
    for (AMVector3 vector : nodesToSearch.keySet()) {
        if (!world.checkChunksExist((int) vector.x, (int) vector.y, (int) vector.z, (int) vector.x, (int) vector.y, (int) vector.z)) {
            continue;
        }
        Chunk chunk = world.getChunkFromBlockCoords((int) vector.x, (int) vector.z);
        if (!chunk.isChunkLoaded)
            continue;
        TileEntity te = world.getTileEntity((int) vector.x, (int) vector.y, (int) vector.z);
        if (te == null || !(te instanceof IPowerNode)) {
            //opportune time to remove dead power nodes
            removePowerNode(chunk.getChunkCoordIntPair(), vector);
            deadNodesRemoved++;
            continue;
        }
        IPowerNode node = (IPowerNode) te;
        nodes.add(node);
    }
    if (deadNodesRemoved > 0)
        LogHelper.trace("Removed %d dead power nodes", deadNodesRemoved);
    IPowerNode[] nodeArray = nodes.toArray(new IPowerNode[nodes.size()]);
    LogHelper.trace("Located %d nearby power providers", nodeArray.length);
    return nodeArray;
}
Also used : ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Chunk(net.minecraft.world.chunk.Chunk) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) IPowerNode(am2.api.power.IPowerNode)

Aggregations

ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 ArrayList (java.util.ArrayList)4 TileEntity (net.minecraft.tileentity.TileEntity)4 AMVector3 (am2.api.math.AMVector3)3 IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)3 RadarObject (com.builtbroken.mc.lib.world.radar.data.RadarObject)3 Chunk (net.minecraft.world.chunk.Chunk)3 Ticket (net.minecraftforge.common.ForgeChunkManager.Ticket)3 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)2 World (net.minecraft.world.World)2 IPowerNode (am2.api.power.IPowerNode)1 IRadioWaveSender (com.builtbroken.mc.api.map.radio.IRadioWaveSender)1 Cube (com.builtbroken.mc.imp.transform.region.Cube)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1