Search in sources :

Example 1 with PlayerInventoryHolder

use of gregtech.api.items.gui.PlayerInventoryHolder in project GregTech by GregTechCEu.

the class ClipboardBehavior method createMTEUI.

public ModularUI createMTEUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer) {
    // So that people don't click on any text fields
    initNBT(holder.getCurrentItem());
    ModularUI.Builder builder = ModularUI.builder(GuiTextures.CLIPBOARD_PAPER_BACKGROUND, 170, 238);
    builder.image(18, 8, 130, 14, GuiTextures.CLIPBOARD_TEXT_BOX);
    builder.widget(new SimpleTextWidget(20, 10, "", TEXT_COLOR, () -> getTitle(holder), true).setCenter(false));
    for (int i = 0; i < 8; i++) {
        int finalI = i;
        builder.widget(new ImageCycleButtonWidget(6, 37 + 20 * i, 15, 15, GuiTextures.CLIPBOARD_BUTTON, 4, () -> getButtonState(holder, finalI), (x) -> setButton(holder, finalI, x)));
        builder.image(22, 38 + 20 * i, 140, 12, GuiTextures.CLIPBOARD_TEXT_BOX);
        builder.widget(new SimpleTextWidget(24, 40 + 20 * i, "", TEXT_COLOR, () -> getString(holder, finalI), true).setCenter(false));
    }
    builder.widget(new ClickButtonWidget(30, 200, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? -10 : -1)).setButtonTexture(GuiTextures.BUTTON_LEFT).setShouldClientCallback(true));
    builder.widget(new ClickButtonWidget(124, 200, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? 10 : 1)).setButtonTexture(GuiTextures.BUTTON_RIGHT).setShouldClientCallback(true));
    builder.widget(new SimpleTextWidget(85, 208, "", TEXT_COLOR, () -> (getPageNum(holder) + 1) + " / " + MAX_PAGES, true));
    builder.shouldColor(false);
    return builder.build(holder, entityPlayer);
}
Also used : SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget) MetaItems(gregtech.common.items.MetaItems) MACHINE(gregtech.common.blocks.MetaBlocks.MACHINE) EnumHand(net.minecraft.util.EnumHand) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) Block(net.minecraft.block.Block) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemUIFactory(gregtech.api.items.gui.ItemUIFactory) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) BlockPos(net.minecraft.util.math.BlockPos) MetaTileEntityClipboard(gregtech.common.metatileentities.MetaTileEntityClipboard) GuiTextures(gregtech.api.gui.GuiTextures) ActionResult(net.minecraft.util.ActionResult) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) RayTracer(codechicken.lib.raytracer.RayTracer) ModularUI(gregtech.api.gui.ModularUI) PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) CLIPBOARD_TILE(gregtech.common.metatileentities.MetaTileEntities.CLIPBOARD_TILE) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ModularUI(gregtech.api.gui.ModularUI) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget)

Example 2 with PlayerInventoryHolder

use of gregtech.api.items.gui.PlayerInventoryHolder in project GregTech by GregTechCEu.

the class ClipboardBehavior method createUI.

@Override
public ModularUI createUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer) {
    ModularUI.Builder builder = ModularUI.builder(GuiTextures.CLIPBOARD_BACKGROUND, 186, 263);
    initNBT(holder.getCurrentItem());
    List<TextFieldWidget2> textFields = new ArrayList<>();
    builder.image(28, 28, 130, 12, GuiTextures.CLIPBOARD_TEXT_BOX);
    textFields.add(new TextFieldWidget2(30, 30, 126, 9, () -> getTitle(holder), val -> setTitle(holder, val)).setMaxLength(25).setCentered(true).setTextColor(TEXT_COLOR));
    for (int i = 0; i < 8; i++) {
        int finalI = i;
        builder.widget(new ImageCycleButtonWidget(14, 55 + 22 * i, 15, 15, GuiTextures.CLIPBOARD_BUTTON, 4, () -> getButtonState(holder, finalI), (x) -> setButton(holder, finalI, x)));
        builder.image(32, 58 + 22 * i, 140, 12, GuiTextures.CLIPBOARD_TEXT_BOX);
        textFields.add(new TextFieldWidget2(34, 60 + 22 * i, 136, 9, () -> getString(holder, finalI), val -> setString(holder, finalI, val)).setMaxLength(23).setTextColor(TEXT_COLOR));
    }
    for (TextFieldWidget2 textField : textFields) {
        builder.widget(textField.setOnFocus(textField2 -> textFields.forEach(textField3 -> {
            if (textField3 != textField2) {
                textField3.unFocus();
            }
        })));
    }
    builder.widget(new ClickButtonWidget(38, 231, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? -10 : -1)).setButtonTexture(GuiTextures.BUTTON_LEFT).setShouldClientCallback(true));
    builder.widget(new ClickButtonWidget(132, 231, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? 10 : 1)).setButtonTexture(GuiTextures.BUTTON_RIGHT).setShouldClientCallback(true));
    builder.widget(new SimpleTextWidget(93, 240, "", TEXT_COLOR, () -> (getPageNum(holder) + 1) + " / " + MAX_PAGES, true));
    builder.shouldColor(false);
    return builder.build(holder, entityPlayer);
}
Also used : SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget) MetaItems(gregtech.common.items.MetaItems) MACHINE(gregtech.common.blocks.MetaBlocks.MACHINE) EnumHand(net.minecraft.util.EnumHand) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) Block(net.minecraft.block.Block) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemUIFactory(gregtech.api.items.gui.ItemUIFactory) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) BlockPos(net.minecraft.util.math.BlockPos) MetaTileEntityClipboard(gregtech.common.metatileentities.MetaTileEntityClipboard) GuiTextures(gregtech.api.gui.GuiTextures) ActionResult(net.minecraft.util.ActionResult) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) RayTracer(codechicken.lib.raytracer.RayTracer) ModularUI(gregtech.api.gui.ModularUI) PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) CLIPBOARD_TILE(gregtech.common.metatileentities.MetaTileEntities.CLIPBOARD_TILE) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ModularUI(gregtech.api.gui.ModularUI) ArrayList(java.util.ArrayList) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget)

Example 3 with PlayerInventoryHolder

use of gregtech.api.items.gui.PlayerInventoryHolder 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 4 with PlayerInventoryHolder

use of gregtech.api.items.gui.PlayerInventoryHolder in project GregTech by GregTechCEu.

the class IntCircuitBehaviour method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack heldItem = player.getHeldItem(hand);
    if (!world.isRemote) {
        PlayerInventoryHolder holder = new PlayerInventoryHolder(player, hand);
        holder.openUI();
    }
    return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem);
}
Also used : PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) ItemStack(net.minecraft.item.ItemStack)

Example 5 with PlayerInventoryHolder

use of gregtech.api.items.gui.PlayerInventoryHolder in project GregTech by GregTechCE.

the class IntCircuitBehaviour method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack heldItem = player.getHeldItem(hand);
    if (!world.isRemote) {
        PlayerInventoryHolder holder = new PlayerInventoryHolder(player, hand);
        holder.openUI();
    }
    return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem);
}
Also used : PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) ItemStack(net.minecraft.item.ItemStack)

Aggregations

PlayerInventoryHolder (gregtech.api.items.gui.PlayerInventoryHolder)10 ItemStack (net.minecraft.item.ItemStack)10 RayTracer (codechicken.lib.raytracer.RayTracer)3 ModularUI (gregtech.api.gui.ModularUI)3 IItemBehaviour (gregtech.api.items.metaitem.stats.IItemBehaviour)3 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumFacing (net.minecraft.util.EnumFacing)3 EnumHand (net.minecraft.util.EnumHand)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)3 GuiTextures (gregtech.api.gui.GuiTextures)2 ClickButtonWidget (gregtech.api.gui.widgets.ClickButtonWidget)2 ImageCycleButtonWidget (gregtech.api.gui.widgets.ImageCycleButtonWidget)2 SimpleTextWidget (gregtech.api.gui.widgets.SimpleTextWidget)2