net.minecraft.client.gui.GuiScreenBook Java Examples

The following examples show how to use net.minecraft.client.gui.GuiScreenBook. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NickHider.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@InvokeEvent
public void bookCheck(TickEvent event) {
    GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
    if (currentScreen == null) return;

    if (currentScreen instanceof GuiScreenBook) {
        NBTTagList bookPages = ((IMixinGuiScreenBook) currentScreen).getBookPages();
        int currPage = ((IMixinGuiScreenBook) currentScreen).getCurrPage();

        if (currPage < bookPages.tagCount()) {
            try {
                String textWithoutFormattingCodes = EnumChatFormatting.getTextWithoutFormattingCodes(
                    IChatComponent.Serializer.jsonToComponent(bookPages.getStringTagAt(currPage)).getUnformattedText().replace("\n", " "));
                Matcher matcher = newNick.matcher(textWithoutFormattingCodes);
                if (matcher.find()) {
                    String nick = matcher.group("nick");
                    remap(nick, override == null ? Minecraft.getMinecraft().getSession().getProfile().getName() : override);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example #2
Source File: GuiMinecoprocessor.java    From Minecoprocessors with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void actionPerformed(GuiButton button) {
  if (button == buttonReset) {
    Minecoprocessors.NETWORK.sendToServer(new MessageProcessorAction(minecoprocessor.getPos(), Action.RESET));
  }
  if (button == buttonPause) {
    Minecoprocessors.NETWORK.sendToServer(new MessageProcessorAction(minecoprocessor.getPos(), Action.PAUSE));
  }
  if (button == buttonStep) {
    Minecoprocessors.NETWORK.sendToServer(new MessageProcessorAction(minecoprocessor.getPos(), Action.STEP));
  }
  if (button == buttonHelp) {
    // TODO override the book GUI so that it returns the processor GUI when closed
    this.mc.displayGuiScreen(new GuiScreenBook(mc.player, BookCreator.manual, false));
  }
}
 
Example #3
Source File: BookBot.java    From ForgeHax with MIT License 4 votes vote down vote up
@Override
public void run() {
  try {
    while (!stopped) {
      // check to see if we've finished the book
      if (!parser.hasNext()) {
        this.status = Status.FINISHED;
        break;
      }
      
      sleep();
      
      // wait for screen
      if (MC.currentScreen != null) {
        this.status = Status.AWAITING_GUI_CLOSE;
        continue;
      }
      
      // search for empty book
      int slot = -1;
      ItemStack selected = null;
      for (int i = 0; i < InventoryPlayer.getHotbarSize(); i++) {
        ItemStack stack = getLocalPlayer().inventory.getStackInSlot(i);
        if (stack != null
            && !stack.equals(ItemStack.EMPTY)
            && stack.getItem() instanceof ItemWritableBook) {
          slot = i;
          selected = stack;
          break;
        }
      }
      
      // make sure we found a book
      if (slot == -1) {
        this.status = Status.NEED_EMPTY_BOOKS_IN_HOTBAR;
        continue;
      }
      
      // set selected item to that slot
      while (getLocalPlayer().inventory.currentItem != slot) {
        getLocalPlayer().inventory.currentItem = slot;
        this.status = Status.CHANGING_HELD_ITEM;
        sleep();
      }
      
      final ItemStack item = selected;
      
      // open the book gui screen
      this.status = Status.OPENING_BOOK;
      MC.addScheduledTask(() -> getLocalPlayer().openBook(item, EnumHand.MAIN_HAND));
      
      // wait for gui to open
      while (!(MC.currentScreen instanceof GuiScreenBook)) {
        sleep();
      }
      
      // send book to server
      this.status = Status.WRITING_BOOK;
      MC.addScheduledTask(
          () -> {
            sendBook(item);
            MC.displayGuiScreen(null);
          });
      
      // wait for screen to close
      while (MC.currentScreen != null) {
        sleep();
      }
    }
  } catch (Throwable t) {
    this.status = Status.ERROR;
  } finally {
    if (finalListener != null) {
      finalListener.accept(this);
      finalListener = null;
    }
    
    // set stopped to true
    this.stopped = true;
    
    if (!this.status.equals(Status.FINISHED) && !this.status.equals(Status.ERROR)) {
      this.status = Status.STOPPED;
    }
  }
}