Search in sources :

Example 1 with GregFakePlayer

use of gregtech.api.util.GregFakePlayer 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 GregFakePlayer

use of gregtech.api.util.GregFakePlayer in project GregTech by GregTechCEu.

the class MetaTileEntityClipboard method createUI.

@Override
public ModularUI createUI(EntityPlayer entityPlayer) {
    if (getClipboard().isItemEqual(CLIPBOARD.getStackForm())) {
        List<IItemBehaviour> behaviours = ((MetaItem<?>) getClipboard().getItem()).getBehaviours(getClipboard());
        Optional<IItemBehaviour> clipboardBehaviour = behaviours.stream().filter((x) -> x instanceof ClipboardBehavior).findFirst();
        if (!clipboardBehaviour.isPresent())
            return null;
        if (clipboardBehaviour.get() instanceof ClipboardBehavior) {
            // We can't have this actually set the player's hand
            PlayerInventoryHolder holder = new PlayerInventoryHolder(new GregFakePlayer(entityPlayer.world), EnumHand.MAIN_HAND);
            holder.setCustomValidityCheck(this::isValid).setCurrentItem(this.getClipboard());
            if (entityPlayer instanceof GregFakePlayer) {
                // This is how to tell if this is being called in-world or not
                return ((ClipboardBehavior) clipboardBehaviour.get()).createMTEUI(holder, entityPlayer);
            } else {
                return ((ClipboardBehavior) clipboardBehaviour.get()).createUI(holder, entityPlayer);
            }
        }
    }
    return null;
}
Also used : Vector3(codechicken.lib.vec.Vector3) EnumHand(net.minecraft.util.EnumHand) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakeModularUIContainerClipboard(gregtech.common.gui.impl.FakeModularUIContainerClipboard) InaccessibleItemStackHandler(gregtech.api.items.itemhandlers.InaccessibleItemStackHandler) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Pair(org.apache.commons.lang3.tuple.Pair) MetaItem(gregtech.api.items.metaitem.MetaItem) CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) NonNullList(net.minecraft.util.NonNullList) GregtechDataCodes(gregtech.api.capability.GregtechDataCodes) ClipboardBehavior(gregtech.common.items.behaviors.ClipboardBehavior) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Capability(net.minecraftforge.common.capabilities.Capability) List(java.util.List) GregFakePlayer(gregtech.api.util.GregFakePlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Optional(java.util.Optional) ModularUI(gregtech.api.gui.ModularUI) RayTracer(codechicken.lib.raytracer.RayTracer) PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) GTUtility(gregtech.api.util.GTUtility) IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) Matrix4(codechicken.lib.vec.Matrix4) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) Blocks(net.minecraft.init.Blocks) FakeModularGui(gregtech.api.gui.impl.FakeModularGui) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) CLIPBOARD_RENDERER(gregtech.client.renderer.texture.Textures.CLIPBOARD_RENDERER) MetaTileEntityUIFactory(gregtech.api.metatileentity.MetaTileEntityUIFactory) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) CreativeTabs(net.minecraft.creativetab.CreativeTabs) Nullable(javax.annotation.Nullable) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) CCRenderState(codechicken.lib.render.CCRenderState) NBTTagInt(net.minecraft.nbt.NBTTagInt) GTLog(gregtech.api.util.GTLog) World(net.minecraft.world.World) NBTBase(net.minecraft.nbt.NBTBase) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IBlockState(net.minecraft.block.state.IBlockState) CLIPBOARD(gregtech.common.items.MetaItems.CLIPBOARD) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) PacketBuffer(net.minecraft.network.PacketBuffer) Cuboid6(codechicken.lib.vec.Cuboid6) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) MetaItem(gregtech.api.items.metaitem.MetaItem) PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) GregFakePlayer(gregtech.api.util.GregFakePlayer) ClipboardBehavior(gregtech.common.items.behaviors.ClipboardBehavior)

Example 3 with GregFakePlayer

use of gregtech.api.util.GregFakePlayer 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)3 Widget (gregtech.api.gui.Widget)3 FakeModularGui (gregtech.api.gui.impl.FakeModularGui)3 GregFakePlayer (gregtech.api.util.GregFakePlayer)3 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 FakeModularUIContainerClipboard (gregtech.common.gui.impl.FakeModularUIContainerClipboard)2 ArrayList (java.util.ArrayList)2 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)1 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 RayTracer (codechicken.lib.raytracer.RayTracer)1 CCRenderState (codechicken.lib.render.CCRenderState)1 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Matrix4 (codechicken.lib.vec.Matrix4)1 Vector3 (codechicken.lib.vec.Vector3)1 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)1 PlayerInventoryHolder (gregtech.api.items.gui.PlayerInventoryHolder)1 InaccessibleItemStackHandler (gregtech.api.items.itemhandlers.InaccessibleItemStackHandler)1 MetaItem (gregtech.api.items.metaitem.MetaItem)1 IItemBehaviour (gregtech.api.items.metaitem.stats.IItemBehaviour)1