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);
}
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);
}
}
}
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());
}
}
}
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;
}
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();
}
Aggregations