Search in sources :

Example 1 with FakeModularGui

use of gregtech.api.gui.impl.FakeModularGui in project GregTech by GregTechCEu.

the class FakeGuiPluginBehavior method createFakeGui.

public void createFakeGui() {
    if (this.holder == null || this.screen == null || !this.screen.isValid())
        return;
    try {
        fakePlayer = new GregFakePlayer(this.screen.getWorld());
        MetaTileEntity mte = getRealMTE();
        if (mte == null || (this.partIndex > 0 && this.holder.getMetaTileEntity() == mte)) {
            fakeModularUIContainer = null;
            if (this.screen.getWorld().isRemote) {
                fakeModularGui = null;
            }
            return;
        }
        ModularUI ui = (ModularUI) methodCreateUI.invoke(mte, fakePlayer);
        if (ui == null) {
            fakeModularUIContainer = null;
            if (this.screen.getWorld().isRemote) {
                fakeModularGui = null;
            }
            return;
        }
        List<Widget> widgets = new ArrayList<>();
        boolean hasPlayerInventory = false;
        for (Widget widget : ui.guiWidgets.values()) {
            if (widget instanceof SlotWidget) {
                IInventory handler = ((SlotWidget) widget).getHandle().inventory;
                if (handler instanceof PlayerMainInvWrapper || handler instanceof InventoryPlayer) {
                    hasPlayerInventory = true;
                    continue;
                }
            }
            widgets.add(widget);
        }
        ModularUI.Builder builder = new ModularUI.Builder(ui.backgroundPath, ui.getWidth(), ui.getHeight() - (hasPlayerInventory ? 80 : 0));
        for (Widget widget : widgets) {
            builder.widget(widget);
        }
        ui = builder.build(ui.holder, ui.entityPlayer);
        fakeModularUIContainer = new FakeModularUIPluginContainer(ui, this);
        if (this.screen.getWorld().isRemote) {
            fakeModularGui = new FakeModularGui(ui, fakeModularUIContainer);
            writePluginAction(GregtechDataCodes.ACTION_PLUGIN_CONFIG, buffer -> {
            });
        }
    } catch (Exception e) {
        GTLog.logger.error(e);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) PlayerMainInvWrapper(net.minecraftforge.items.wrapper.PlayerMainInvWrapper) Widget(gregtech.api.gui.Widget) FakeModularGui(gregtech.api.gui.impl.FakeModularGui) GregFakePlayer(gregtech.api.util.GregFakePlayer) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ModularUI(gregtech.api.gui.ModularUI) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) FakeModularUIPluginContainer(gregtech.common.gui.impl.FakeModularUIPluginContainer)

Example 2 with FakeModularGui

use of gregtech.api.gui.impl.FakeModularGui in project GregTech by GregTechCEu.

the class MetaTileEntityClipboard method createFakeGui.

public void createFakeGui() {
    // Basically just the original function from the PluginBehavior, but with a lot of now useless stuff stripped out.
    try {
        GregFakePlayer fakePlayer = new GregFakePlayer(this.getWorld());
        fakePlayer.setHeldItem(EnumHand.MAIN_HAND, this.getClipboard());
        ModularUI ui = this.createUI(fakePlayer);
        ModularUI.Builder builder = new ModularUI.Builder(ui.backgroundPath, ui.getWidth(), ui.getHeight());
        builder.shouldColor(false);
        List<Widget> widgets = new ArrayList<>(ui.guiWidgets.values());
        for (Widget widget : widgets) {
            builder.widget(widget);
        }
        ui = builder.build(ui.holder, ui.entityPlayer);
        FakeModularUIContainerClipboard fakeModularUIContainer = new FakeModularUIContainerClipboard(ui, this);
        this.guiContainerCache = fakeModularUIContainer;
        if (getWorld().isRemote)
            this.guiCache = new FakeModularGui(ui, fakeModularUIContainer);
        this.writeCustomData(CREATE_FAKE_UI, buffer -> {
        });
    } catch (Exception e) {
        GTLog.logger.error(e);
    }
}
Also used : ModularUI(gregtech.api.gui.ModularUI) Widget(gregtech.api.gui.Widget) ArrayList(java.util.ArrayList) FakeModularGui(gregtech.api.gui.impl.FakeModularGui) GregFakePlayer(gregtech.api.util.GregFakePlayer) FakeModularUIContainerClipboard(gregtech.common.gui.impl.FakeModularUIContainerClipboard)

Aggregations

ModularUI (gregtech.api.gui.ModularUI)2 Widget (gregtech.api.gui.Widget)2 FakeModularGui (gregtech.api.gui.impl.FakeModularGui)2 GregFakePlayer (gregtech.api.util.GregFakePlayer)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 FakeModularUIContainerClipboard (gregtech.common.gui.impl.FakeModularUIContainerClipboard)1 FakeModularUIPluginContainer (gregtech.common.gui.impl.FakeModularUIPluginContainer)1 ArrayList (java.util.ArrayList)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 PlayerMainInvWrapper (net.minecraftforge.items.wrapper.PlayerMainInvWrapper)1