use of gregtech.api.net.PacketUIOpen in project GregTech by GregTechCE.
the class UIFactory method openUI.
public final void openUI(E holder, EntityPlayerMP player) {
if (player instanceof FakePlayer) {
return;
}
ModularUI uiTemplate = createUITemplate(holder, player);
uiTemplate.initWidgets();
player.getNextWindowId();
player.closeContainer();
int currentWindowId = player.currentWindowId;
PacketBuffer serializedHolder = new PacketBuffer(Unpooled.buffer());
writeHolderToSyncData(serializedHolder, holder);
int uiFactoryId = FACTORY_REGISTRY.getIDForObject(this);
ModularUIContainer container = new ModularUIContainer(uiTemplate);
container.windowId = currentWindowId;
// accumulate all initial updates of widgets in open packet
container.accumulateWidgetUpdateData = true;
uiTemplate.guiWidgets.values().forEach(Widget::detectAndSendChanges);
container.accumulateWidgetUpdateData = false;
ArrayList<PacketUIWidgetUpdate> updateData = new ArrayList<>(container.accumulatedUpdates);
container.accumulatedUpdates.clear();
PacketUIOpen packet = new PacketUIOpen(uiFactoryId, serializedHolder, currentWindowId, updateData);
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(packet), player);
container.addListener(player);
player.openContainer = container;
// and fire forge event only in the end
MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}
Aggregations