Search in sources :

Example 31 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class PacketGetConnectedBlocks method onMessage.

@Override
public PacketConnectedBlocksReady onMessage(PacketGetConnectedBlocks message, MessageContext ctx) {
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    Map<Coordinate, BlockInfo> connectedBlocks = new HashMap<Coordinate, BlockInfo>();
    findConnectedBlocks(connectedBlocks, player.worldObj, message.x, message.y, message.z);
    if (connectedBlocks.size() > NetworkMonitorConfiguration.maximumBlocks) {
        connectedBlocks = compactConnectedBlocks(connectedBlocks, message.x, message.y, message.z, NetworkMonitorConfiguration.maximumBlocks);
    }
    int minx = 300000000;
    int miny = 300000000;
    int minz = 300000000;
    for (Coordinate coordinate : connectedBlocks.keySet()) {
        minx = Math.min(minx, coordinate.getX());
        miny = Math.min(miny, coordinate.getY());
        minz = Math.min(minz, coordinate.getZ());
    }
    return new PacketConnectedBlocksReady(connectedBlocks, minx, miny, minz);
}
Also used : Coordinate(mcjty.lib.varia.Coordinate) BlockInfo(mcjty.rftools.BlockInfo) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 32 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class GuiNetworkMonitor method refreshList.

private void refreshList(boolean recalcPerTick) {
    long millis = System.currentTimeMillis();
    boolean rftick = showRfPerTick.isPressed();
    for (Map.Entry<Coordinate, BlockInfo> me : connectedBlocks.entrySet()) {
        BlockInfo blockInfo = me.getValue();
        int energy = blockInfo.getEnergyStored();
        int maxEnergy = blockInfo.getMaxEnergyStored();
        EnergyBar energyLabel = labelMap.get(me.getKey());
        // First test if this label isn't filtered out.
        if (energyLabel != null) {
            setEnergyLabel(millis, rftick, recalcPerTick, me, energy, maxEnergy, energyLabel);
        }
    }
}
Also used : Coordinate(mcjty.lib.varia.Coordinate) BlockInfo(mcjty.rftools.BlockInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class GuiNetworkMonitor method populateList.

private void populateList() {
    requestConnectedBlocksFromServer();
    if (serverConnectedBlocks == null) {
        return;
    }
    boolean rftick = showRfPerTick.isPressed();
    long millis = System.currentTimeMillis();
    boolean recalcPerTick = previousRfMillis == 0 || (millis - previousRfMillis) > 1000;
    if (serverConnectedBlocks.equals(connectedBlocks)) {
        refreshList(recalcPerTick);
    } else {
        connectedBlocks = new HashMap<Coordinate, BlockInfo>(serverConnectedBlocks);
        Map<Coordinate, EnergyBar> oldLabelMap = labelMap;
        labelMap = new HashMap<Coordinate, EnergyBar>();
        indexToCoordinate = new HashMap<Integer, Coordinate>();
        list.removeChildren();
        int index = 0;
        for (Map.Entry<Coordinate, BlockInfo> me : connectedBlocks.entrySet()) {
            BlockInfo blockInfo = me.getValue();
            Coordinate coordinate = me.getKey();
            Block block = mc.theWorld.getBlock(coordinate.getX(), coordinate.getY(), coordinate.getZ());
            if (block == null || block.isAir(mc.theWorld, coordinate.getX(), coordinate.getY(), coordinate.getZ())) {
                continue;
            }
            int energy = blockInfo.getEnergyStored();
            int maxEnergy = blockInfo.getMaxEnergyStored();
            int color = getTextColor(blockInfo);
            int meta = mc.theWorld.getBlockMetadata(coordinate.getX(), coordinate.getY(), coordinate.getZ());
            String displayName = BlockInfo.getReadableName(block, coordinate, meta, mc.theWorld);
            if (filter != null) {
                if (!displayName.toLowerCase().contains(filter)) {
                    continue;
                }
            }
            Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout());
            panel.addChild(new BlockRender(mc, this).setRenderItem(block));
            panel.addChild(new Label(mc, this).setColor(StyleConfig.colorTextInListNormal).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setText(displayName).setColor(color).setDesiredWidth(100));
            panel.addChild(new Label(mc, this).setColor(StyleConfig.colorTextInListNormal).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setText(coordinate.toString()).setColor(color).setDesiredWidth(75));
            EnergyBar energyLabel = oldLabelMap == null ? null : oldLabelMap.get(coordinate);
            if (energyLabel == null) {
                energyLabel = new EnergyBar(mc, this).setHorizontal();
            }
            setEnergyLabel(millis, rftick, recalcPerTick, me, energy, maxEnergy, energyLabel);
            panel.addChild(energyLabel);
            list.addChild(panel);
            labelMap.put(coordinate, energyLabel);
            indexToCoordinate.put(index, coordinate);
            index++;
        }
    }
    if (rftick && recalcPerTick) {
        previousRfMillis = millis;
        previousRf = new HashMap<Coordinate, Integer>(connectedBlocks.size());
        for (Map.Entry<Coordinate, BlockInfo> me : connectedBlocks.entrySet()) {
            previousRf.put(me.getKey(), me.getValue().getEnergyStored());
        }
    }
}
Also used : Label(mcjty.lib.gui.widgets.Label) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) Coordinate(mcjty.lib.varia.Coordinate) BlockInfo(mcjty.rftools.BlockInfo) Block(net.minecraft.block.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class GuiNetworkMonitor method getTextColor.

private int getTextColor(BlockInfo blockInfo) {
    int color;
    Coordinate c = blockInfo.getCoordinate();
    if (c.getX() == selectedX && c.getY() == selectedY && c.getZ() == selectedZ) {
        color = SEL_TEXT_COLOR;
    } else {
        color = TEXT_COLOR;
    }
    return color;
}
Also used : Coordinate(mcjty.lib.varia.Coordinate)

Example 35 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class GuiNetworkMonitor method hilightBlock.

private void hilightBlock(int index) {
    if (index == -1) {
        return;
    }
    Coordinate c = indexToCoordinate.get(index);
    RFTools.instance.clientInfo.hilightBlock(c, System.currentTimeMillis() + 1000 * NetworkMonitorConfiguration.hilightTime);
    Logging.message(mc.thePlayer, "The block is now highlighted");
    Minecraft.getMinecraft().thePlayer.closeScreen();
}
Also used : Coordinate(mcjty.lib.varia.Coordinate)

Aggregations

Coordinate (mcjty.lib.varia.Coordinate)181 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)63 TileEntity (net.minecraft.tileentity.TileEntity)30 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)19 Block (net.minecraft.block.Block)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)13 World (net.minecraft.world.World)12 NBTTagList (net.minecraft.nbt.NBTTagList)11 Callback (li.cil.oc.api.machine.Callback)10 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)10 Panel (mcjty.lib.gui.widgets.Panel)10 ItemStack (net.minecraft.item.ItemStack)10 ArrayList (java.util.ArrayList)9 Label (mcjty.lib.gui.widgets.Label)8 BlockInfo (mcjty.rftools.BlockInfo)7 SyncedCoordinate (mcjty.lib.entity.SyncedCoordinate)5 ChoiceEvent (mcjty.lib.gui.events.ChoiceEvent)4 TeleportDestinationClientInfo (mcjty.rftools.blocks.teleporter.TeleportDestinationClientInfo)4