use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.
the class SurvivalSlimefunGuide method displayItem.
private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object item, ItemStack output, RecipeType recipeType, ItemStack[] recipe, AsyncRecipeChoiceTask task) {
addBackButton(menu, 0, p, profile);
MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> {
try {
if (itemstack != null && itemstack.getType() != Material.BARRIER) {
displayItem(profile, itemstack, 0, true);
}
} catch (Exception | LinkageError x) {
printErrorMessage(pl, x);
}
return false;
};
boolean isSlimefunRecipe = item instanceof SlimefunItem;
for (int i = 0; i < 9; i++) {
ItemStack recipeItem = getDisplayItem(p, isSlimefunRecipe, recipe[i]);
menu.addItem(recipeSlots[i], recipeItem, clickHandler);
if (recipeItem != null && item instanceof MultiBlockMachine) {
for (Tag<Material> tag : MultiBlock.getSupportedTags()) {
if (tag.isTagged(recipeItem.getType())) {
task.add(recipeSlots[i], tag);
break;
}
}
}
}
menu.addItem(10, recipeType.getItem(p), ChestMenuUtils.getEmptyClickHandler());
menu.addItem(16, output, ChestMenuUtils.getEmptyClickHandler());
}
use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.
the class SurvivalSlimefunGuide method showMinecraftRecipe.
private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
Recipe recipe = recipes[index];
ItemStack[] recipeItems = new ItemStack[9];
RecipeType recipeType = RecipeType.NULL;
ItemStack result = null;
Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(recipe);
AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
if (optional.isPresent()) {
showRecipeChoices(recipe, recipeItems, task);
recipeType = new RecipeType(optional.get());
result = recipe.getResult();
} else {
recipeItems = new ItemStack[] { null, null, null, null, new CustomItemStack(Material.BARRIER, "&4We are somehow unable to show you this Recipe :/"), null, null, null, null };
}
ChestMenu menu = create(p);
if (addToHistory) {
profile.getGuideHistory().add(item, index);
}
displayItem(menu, profile, p, item, result, recipeType, recipeItems, task);
if (recipes.length > 1) {
for (int i = 27; i < 36; i++) {
menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
menu.addItem(28, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index > 0) {
showMinecraftRecipe(recipes, index - 1, item, profile, p, true);
}
return false;
});
menu.addItem(34, ChestMenuUtils.getNextButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index < recipes.length - 1) {
showMinecraftRecipe(recipes, index + 1, item, profile, p, true);
}
return false;
});
}
menu.open(p);
if (!task.isEmpty()) {
task.start(menu.toInventory());
}
}
use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.
the class SurvivalSlimefunGuide method displayItem.
@Override
@ParametersAreNonnullByDefault
public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) {
Player p = profile.getPlayer();
if (p == null) {
return;
}
ChestMenu menu = create(p);
Optional<String> wiki = item.getWikipage();
if (wiki.isPresent()) {
menu.addItem(8, new CustomItemStack(Material.KNOWLEDGE_BOOK, ChatColor.WHITE + Slimefun.getLocalization().getMessage(p, "guide.tooltips.wiki"), "", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup")));
menu.addMenuClickHandler(8, (pl, slot, itemstack, action) -> {
pl.closeInventory();
ChatUtils.sendURL(pl, wiki.get());
return false;
});
}
AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask();
if (addToHistory) {
profile.getGuideHistory().add(item);
}
ItemStack result = item.getRecipeOutput();
RecipeType recipeType = item.getRecipeType();
ItemStack[] recipe = item.getRecipe();
displayItem(menu, profile, p, item, result, recipeType, recipe, task);
if (item instanceof RecipeDisplayItem) {
displayRecipes(p, profile, menu, (RecipeDisplayItem) item, 0);
}
menu.open(p);
if (!task.isEmpty()) {
task.start(menu.toInventory());
}
}
use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project Slimefun4 by Slimefun.
the class SurvivalSlimefunGuide method displaySlimefunItem.
private void displaySlimefunItem(ChestMenu menu, ItemGroup itemGroup, Player p, PlayerProfile profile, SlimefunItem sfitem, int page, int index) {
Research research = sfitem.getResearch();
if (isSurvivalMode() && !hasPermission(p, sfitem)) {
List<String> message = Slimefun.getPermissionsService().getLore(sfitem);
menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNoPermissionItem(), sfitem.getItemName(), message.toArray(new String[0])));
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
} else if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + Slimefun.getLocalization().getMessage(p, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)"));
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
research.unlockFromGuide(this, p, profile, sfitem, itemGroup, page);
return false;
});
} else {
menu.addItem(index, sfitem.getItem());
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
try {
if (isSurvivalMode()) {
displayItem(profile, sfitem, true);
} else {
if (sfitem instanceof MultiBlockMachine) {
Slimefun.getLocalization().sendMessage(pl, "guide.cheat.no-multiblocks");
} else {
ItemStack clonedItem = sfitem.getItem().clone();
if (action.isShiftClicked()) {
clonedItem.setAmount(clonedItem.getMaxStackSize());
}
pl.getInventory().addItem(clonedItem);
}
}
} catch (Exception | LinkageError x) {
printErrorMessage(pl, x);
}
return false;
});
}
}
use of me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu in project SupremeExpansion by RelativoBR.
the class AbstractQuarry method showMachine.
@ParametersAreNonnullByDefault
protected void showMachine(Player p, Block b) {
Validate.notNull(p, "The Player should not be null");
Validate.notNull(b, "The Block should not be null");
ChestMenu menu = new ChestMenu(getItemName());
menu.setPlayerInventoryClickable(false);
menu.setEmptySlotsClickable(false);
ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_BORDER);
ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_OUTPUT);
ChestMenuUtils.drawBackground(menu, InventoryRecipe.QUARRY_OUTPUT_BORDER);
for (int i = 0; i < InventoryRecipe.QUARRY_INPUT_BORDER.length; ++i) {
int slot = InventoryRecipe.QUARRY_INPUT_BORDER[i];
menu.addItem(slot, ChestMenuUtils.getInputSlotTexture(), ChestMenuUtils.getEmptyClickHandler());
}
final String powerPerSecond = LoreBuilder.powerPerSecond(getEnergyConsumption());
final String powerCharged = LoreBuilder.powerCharged(energyCharge, getCapacity());
final String infoSpeed = UtilEnergy.timePerItem((TICK_DELAY * delaySpeed) / 2);
if (energyCharge < getEnergyConsumption() || !this.enabled) {
menu.addItem(InventoryRecipe.QUARRY_STATUS, new CustomItemStack(Material.OBSIDIAN, ChatColor.RED + "NOT-ACTIVE", powerPerSecond, powerCharged, infoSpeed));
menu.addMenuClickHandler(InventoryRecipe.QUARRY_STATUS, ChestMenuUtils.getEmptyClickHandler());
} else {
menu.addItem(InventoryRecipe.QUARRY_STATUS, new CustomItemStack(Material.GLOWSTONE, ChatColor.GREEN + "ACTIVE", powerPerSecond, powerCharged, infoSpeed));
menu.addMenuClickHandler(InventoryRecipe.QUARRY_STATUS, ChestMenuUtils.getEmptyClickHandler());
}
if (enabled) {
menu.addItem(InventoryRecipe.QUARRY_BUTTON, new CustomItemStack(Material.EMERALD_BLOCK, Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.enabled")));
menu.addMenuClickHandler(InventoryRecipe.QUARRY_BUTTON, (pl, item, slot, action) -> {
enabled = false;
showMachine(p, b);
return false;
});
} else {
menu.addItem(InventoryRecipe.QUARRY_BUTTON, new CustomItemStack(Material.REDSTONE_BLOCK, Slimefun.getLocalization().getMessages(p, "messages.auto-crafting.tooltips.disabled")));
menu.addMenuClickHandler(InventoryRecipe.QUARRY_BUTTON, (pl, item, slot, action) -> {
enabled = true;
showMachine(p, b);
return false;
});
}
p.playSound(p.getLocation(), Sound.BLOCK_BARREL_OPEN, 1, 1);
menu.open(p);
}
Aggregations