Add some javadoc, add container to callback
This commit is contained in:
parent
c6954add09
commit
66a7c382cd
4 changed files with 28 additions and 11 deletions
|
@ -26,6 +26,14 @@ import java.util.UUID;
|
|||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Zontreck's ChestGUI Interface
|
||||
* <p>
|
||||
* This was heavily inspired by some of the ChestGUI's seen in Spigot mods.
|
||||
* The reason for creating this system is to rapidly prototype interfaces. This is meant to be a helper to add a GUI quickly and easily without all the mess and fuss of making a menu or a screen. This is meant to be a stepping stone, not a permanent replacement to a proper UI.
|
||||
* <p>
|
||||
* This implementation is unlikely to ever change much, as it is just meant to accomplish the above task, and it does, successfully.
|
||||
*/
|
||||
public class ChestGUI
|
||||
{
|
||||
private ItemStackHandler container = new ItemStackHandler((9*3));
|
||||
|
@ -104,9 +112,7 @@ public class ChestGUI
|
|||
{
|
||||
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_REM.get(), 1);
|
||||
|
||||
ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> {
|
||||
onRemove.run(stack);
|
||||
}, new Vector2i(2, 3));
|
||||
ChestGUIButton rem = new ChestGUIButton(remStack, onRemove, new Vector2i(2, 3));
|
||||
|
||||
removeBtn = rem;
|
||||
|
||||
|
@ -117,9 +123,7 @@ public class ChestGUI
|
|||
{
|
||||
ItemStack resStack = new ItemStack(ModItems.CHESTGUI_RESET.get(), 1);
|
||||
|
||||
ChestGUIButton rem = new ChestGUIButton(resStack, (stack)-> {
|
||||
onReset.run(stack);
|
||||
}, new Vector2i(2, 4));
|
||||
ChestGUIButton rem = new ChestGUIButton(resStack, onReset, new Vector2i(2, 4));
|
||||
|
||||
resetBtn = rem;
|
||||
|
||||
|
@ -132,9 +136,7 @@ public class ChestGUI
|
|||
|
||||
ItemStack remStack = new ItemStack(ModItems.CHESTGUI_ADD.get(), 1);
|
||||
|
||||
ChestGUIButton rem = new ChestGUIButton(remStack, (stack)-> {
|
||||
onAdd.run(stack);
|
||||
}, new Vector2i(2, 5));
|
||||
ChestGUIButton rem = new ChestGUIButton(remStack, onAdd, new Vector2i(2, 5));
|
||||
|
||||
addBtn = rem;
|
||||
|
||||
|
|
|
@ -29,12 +29,18 @@ public class ChestGUIButton
|
|||
private Vector2i position;
|
||||
private ItemStack built;
|
||||
|
||||
/**
|
||||
* Sets the name of the ChestGUI Button (Item Name)
|
||||
* @param name Name to set
|
||||
* @return Button instance
|
||||
*/
|
||||
public ChestGUIButton withName(String name)
|
||||
{
|
||||
this.name=name;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ChestGUIButton(Item icon, String name, IChestGUIButtonCallback callback, Vector2i position)
|
||||
{
|
||||
this.icon = icon;
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
package dev.zontreck.libzontreck.chestgui;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
/**
|
||||
* This should be used in place of Runnable for ChestGUI
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IChestGUIButtonCallback
|
||||
{
|
||||
void run(ItemStack stack);
|
||||
/**
|
||||
* A callback function that when invoked will pass the ChestGUI ItemStack
|
||||
* @param stack A temporary itemstack that is used for the ChestGUI
|
||||
* @param container The container object for manipulating other items when this is invoked
|
||||
*/
|
||||
void run(ItemStack stack, ItemStackHandler container);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CreditsCommand {
|
|||
int y = 0;
|
||||
for(CreditsEntry entry : HeadCache.CREDITS)
|
||||
{
|
||||
gui = gui.withButton(new ChestGUIButton(entry.compile(), (stack)->{
|
||||
gui = gui.withButton(new ChestGUIButton(entry.compile(), (stack, container)->{
|
||||
}, new Vector2i(x,y)));
|
||||
|
||||
//LibZontreck.LOGGER.info("Add gui button : " + entry.name);
|
||||
|
|
Reference in a new issue