CommunicationUtils
CommunicationUtils
groups functions for communicating with users.
Click events
This feature allows localized strings
Since 1.8 Minecraft provides the possibility to click on custom elements in chat. The method clickEvent(sender, msg, options...)
gives this feature to the mod.
As this feature is being reworked, just a quick look-over:
Currently this command creates a simple choice list. Example:
clickEvent(sender, "Stop server?", new Pair<>(" [Yes]", ()-> System.exit(0)), new Pair<>(" [No]", ()-> MessageUtils.messageToSender(sender, "Okay.")))
Player chat:
Stop server? [Yes] [No]
Inventory Menus
To create your own menu BaseIO provides a fast construction method:public InventoryMenu(String title, boolean doBackButton, Pair<ItemStack, TriConsumer<EntityPlayerMP, InventoryMenu, Object[]>>... items
(same also available with items as an iterator)
title describes the name of the container (Example: "[Shop] Buy Menu")
doBackButton defines wether the first slot in the inventory should be a back button (to a menu before)
items is a list (or varargs) of Pairs. The index in the list defines the position of the item. The first element of the Pair is the item that should be displayed at the slot, the second is a method (TriConsumer, here implemented with a lambda) that will be called when the player clicks on the slot. The custom ItemStack creation helps creating the ItemStack.
An example constructor would be (Java 8):
InventoryMenu myMenu = new InventoryMenu("My Menu", false,
Pair.create(new DisplayStackGen(Items.APPLE).name("give apple!").gen(), (player, menu, args)-> player.inventory.addItemStackToInventory(new ItemStack(Items.APPLE))),
null,
Pair.create(new DisplayStackGen(Blocks.STONE).name("STONE").ench().gen(), null)
)
As you can see the menu creation is pretty simple.
This example would create a menu with an apple in the first slot and a stone in the third slot. If you click on the apple the server will give you an apple. The stone has no interaction.
Value input
When the user is in an InventoryMenu it is not possible to make an input via chat. You should use AnvilEdit instead.
AnvilEdit opens an anvil GUI
No Comments