use of gregtech.api.net.PacketUIWidgetUpdate in project GregTech by GregTechCE.
the class Widget method writeUpdateInfo.
/**
* Writes data to be sent to client's {@link #readUpdateInfo}
*/
protected final void writeUpdateInfo(int id, Consumer<PacketBuffer> packetBufferWriter) {
PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
packetBuffer.writeInt(id);
packetBufferWriter.accept(packetBuffer);
int widgetId = gui.guiWidgets.inverse().get(this);
if (gui.entityPlayer instanceof EntityPlayerMP) {
int currentWindowId = gui.entityPlayer.openContainer.windowId;
PacketUIWidgetUpdate widgetUpdate = new PacketUIWidgetUpdate(currentWindowId, widgetId, packetBuffer);
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(widgetUpdate), (EntityPlayerMP) gui.entityPlayer);
}
}
use of gregtech.api.net.PacketUIWidgetUpdate in project GregTech by GregTechCE.
the class UIFactory method initClientUI.
@SideOnly(Side.CLIENT)
public final void initClientUI(PacketBuffer serializedHolder, int windowId, List<PacketUIWidgetUpdate> initialWidgetUpdates) {
E holder = readHolderFromSyncData(serializedHolder);
Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayerSP entityPlayer = minecraft.player;
ModularUI uiTemplate = createUITemplate(holder, entityPlayer);
uiTemplate.initWidgets();
ModularUIGui modularUIGui = new ModularUIGui(uiTemplate);
modularUIGui.inventorySlots.windowId = windowId;
for (PacketUIWidgetUpdate packet : initialWidgetUpdates) {
modularUIGui.handleWidgetUpdate(packet);
}
minecraft.addScheduledTask(() -> {
minecraft.displayGuiScreen(modularUIGui);
minecraft.player.openContainer.windowId = windowId;
});
}
use of gregtech.api.net.PacketUIWidgetUpdate in project GregTech by GregTechCE.
the class ModularUIGui method updateScreen.
@Override
public void updateScreen() {
super.updateScreen();
PacketUIWidgetUpdate packet = queuingWidgetUpdates.poll();
if (packet != null && packet.windowId == inventorySlots.windowId) {
Widget<?> widget = modularUI.guiWidgets.get(packet.widgetId);
int discriminator = packet.updateData.readInt();
if (widget != null)
widget.readUpdateInfo(discriminator, packet.updateData);
}
modularUI.guiWidgets.values().forEach(Widget::updateScreen);
}
use of gregtech.api.net.PacketUIWidgetUpdate in project GregTech by GregTechCE.
the class ModularUIContainer method writeUpdateInfo.
@Override
public void writeUpdateInfo(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
int widgetId = modularUI.guiWidgets.inverse().get(widget);
PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
packetBuffer.writeVarInt(updateId);
payloadWriter.accept(packetBuffer);
if (modularUI.entityPlayer instanceof EntityPlayerMP) {
PacketUIWidgetUpdate widgetUpdate = new PacketUIWidgetUpdate(windowId, widgetId, packetBuffer);
if (!accumulateWidgetUpdateData) {
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(widgetUpdate), (EntityPlayerMP) modularUI.entityPlayer);
} else {
accumulatedUpdates.add(widgetUpdate);
}
}
}
use of gregtech.api.net.PacketUIWidgetUpdate 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