use of mcjty.xnet.clientinfo.ConnectedBlockClientInfo in project XNet by McJty.
the class TileEntityController method findConnectedBlocks.
@Nonnull
private List<ConnectedBlockClientInfo> findConnectedBlocks() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
Set<ConnectedBlockClientInfo> set = new HashSet<>();
for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
String name = "";
TileEntity te = getWorld().getTileEntity(consumerPos);
if (te instanceof ConnectorTileEntity) {
// Should always be the case. @todo error?
name = ((ConnectorTileEntity) te).getConnectorName();
} else {
XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
BlockPos pos = consumerPos.offset(facing);
SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
IBlockState state = getWorld().getBlockState(pos);
ItemStack item = state.getBlock().getItem(getWorld(), pos, state);
ConnectedBlockClientInfo info = new ConnectedBlockClientInfo(sidedPos, item, name);
set.add(info);
}
}
}
List<ConnectedBlockClientInfo> list = new ArrayList<>(set);
list.sort(Comparator.comparing(ConnectedBlockClientInfo::getBlockUnlocName).thenComparing(ConnectedBlockClientInfo::getPos));
return list;
}
use of mcjty.xnet.clientinfo.ConnectedBlockClientInfo in project XNet by McJty.
the class GuiController method hilightSelectedContainer.
private void hilightSelectedContainer(int index) {
if (index < 0) {
return;
}
ConnectedBlockClientInfo c = fromServer_connectedBlocks.get(index);
if (c != null) {
XNet.instance.clientInfo.hilightBlock(c.getPos().getPos(), System.currentTimeMillis() + 1000 * 5);
Logging.message(mc.player, "The block is now highlighted");
mc.player.closeScreen();
}
}
use of mcjty.xnet.clientinfo.ConnectedBlockClientInfo in project XNet by McJty.
the class TileEntityController method getConnectedBlockPositions.
@Override
public List<SidedPos> getConnectedBlockPositions() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
List<SidedPos> result = new ArrayList<>();
Set<ConnectedBlockClientInfo> set = new HashSet<>();
for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
String name = "";
TileEntity te = getWorld().getTileEntity(consumerPos);
if (te instanceof ConnectorTileEntity) {
// Should always be the case. @todo error?
name = ((ConnectorTileEntity) te).getConnectorName();
} else {
XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
BlockPos pos = consumerPos.offset(facing);
SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
result.add(sidedPos);
}
}
}
return result;
}
use of mcjty.xnet.clientinfo.ConnectedBlockClientInfo in project XNet by McJty.
the class GuiController method populateList.
private void populateList() {
if (!listsReady()) {
return;
}
if (!needsRefresh) {
return;
}
needsRefresh = false;
connectorList.removeChildren();
int sel = connectorList.getSelected();
BlockPos prevPos = null;
String selectedText = searchBar.getText().trim().toLowerCase();
for (ConnectedBlockClientInfo connectedBlock : fromServer_connectedBlocks) {
SidedPos sidedPos = connectedBlock.getPos();
BlockPos coordinate = sidedPos.getPos();
String name = connectedBlock.getName();
String blockUnlocName = connectedBlock.getBlockUnlocName();
String blockName = I18n.format(blockUnlocName).trim();
int color = StyleConfig.colorTextInListNormal;
Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0));
if (!selectedText.isEmpty()) {
if (blockName.toLowerCase().contains(selectedText)) {
panel.setFilledBackground(0xffddeeaa);
}
}
BlockRender br;
if (coordinate.equals(prevPos)) {
br = new BlockRender(mc, this);
} else {
br = new BlockRender(mc, this).setRenderItem(connectedBlock.getConnectedBlock());
prevPos = coordinate;
}
br.setUserObject("block");
panel.addChild(br);
if (!name.isEmpty()) {
br.setTooltips(TextFormatting.GREEN + "Connector: " + TextFormatting.WHITE + name, TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
} else {
br.setTooltips(TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
}
panel.addChild(new Label(mc, this).setText(sidedPos.getSide().getName().substring(0, 1).toUpperCase()).setColor(color).setDesiredWidth(18));
for (int i = 0; i < MAX_CHANNELS; i++) {
Button but = new Button(mc, this).setDesiredWidth(14);
ChannelClientInfo info = fromServer_channels.get(i);
if (info != null) {
ConnectorClientInfo clientInfo = findClientInfo(info, sidedPos);
if (clientInfo != null) {
IndicatorIcon icon = clientInfo.getConnectorSettings().getIndicatorIcon();
if (icon != null) {
but.setImage(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh());
}
String indicator = clientInfo.getConnectorSettings().getIndicator();
but.setText(indicator != null ? indicator : "");
}
}
int finalI = i;
but.addButtonEvent(parent -> {
selectConnectorEditor(sidedPos, finalI);
});
panel.addChild(but);
}
connectorList.addChild(panel);
}
connectorList.setSelected(sel);
}
Aggregations