Search in sources :

Example 1 with BlockInfo

use of mcjty.rftools.BlockInfo 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<>(serverConnectedBlocks);
        Map<BlockPos, EnergyBar> oldLabelMap = labelMap;
        labelMap = new HashMap<>();
        indexToCoordinate = new HashMap<>();
        list.removeChildren();
        int index = 0;
        for (Map.Entry<BlockPos, BlockInfo> me : connectedBlocks.entrySet()) {
            BlockInfo blockInfo = me.getValue();
            BlockPos coordinate = me.getKey();
            if (mc.world.isAirBlock(coordinate)) {
                continue;
            }
            int energy = blockInfo.getEnergyStored();
            int maxEnergy = blockInfo.getMaxEnergyStored();
            int color = getTextColor(blockInfo);
            IBlockState state = mc.world.getBlockState(coordinate);
            String displayName = BlockTools.getReadableName(mc.world, coordinate);
            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(state.getBlock()));
            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(BlockPosTools.toString(coordinate)).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<>(connectedBlocks.size());
        for (Map.Entry<BlockPos, BlockInfo> me : connectedBlocks.entrySet()) {
            previousRf.put(me.getKey(), me.getValue().getEnergyStored());
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) BlockInfo(mcjty.rftools.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with BlockInfo

use of mcjty.rftools.BlockInfo 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<BlockPos, 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 : BlockInfo(mcjty.rftools.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with BlockInfo

use of mcjty.rftools.BlockInfo in project RFTools by McJty.

the class PacketConnectedBlocksReady method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    minx = buf.readInt();
    miny = buf.readInt();
    minz = buf.readInt();
    int size = buf.readInt();
    blockInfoMap = new HashMap<>();
    for (int i = 0; i < size; i++) {
        BlockPos coordinate = new BlockPos(buf.readShort() + minx, buf.readShort() + miny, buf.readShort() + minz);
        BlockInfo blockInfo = new BlockInfo(coordinate, buf.readInt(), buf.readInt());
        blockInfoMap.put(coordinate, blockInfo);
    }
}
Also used : BlockInfo(mcjty.rftools.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockInfo

use of mcjty.rftools.BlockInfo in project RFTools by McJty.

the class PacketConnectedBlocksReady method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(minx);
    buf.writeInt(miny);
    buf.writeInt(minz);
    buf.writeInt(blockInfoMap.size());
    for (Map.Entry<BlockPos, BlockInfo> me : blockInfoMap.entrySet()) {
        BlockPos c = me.getKey();
        buf.writeShort(c.getX() - minx);
        buf.writeShort(c.getY() - miny);
        buf.writeShort(c.getZ() - minz);
        buf.writeInt(me.getValue().getEnergyStored());
        buf.writeInt(me.getValue().getMaxEnergyStored());
    }
}
Also used : BlockInfo(mcjty.rftools.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BlockInfo (mcjty.rftools.BlockInfo)4 BlockPos (net.minecraft.util.math.BlockPos)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 IBlockState (net.minecraft.block.state.IBlockState)1