本文整理匯總了Java中org.bukkit.inventory.CraftingInventory類的典型用法代碼示例。如果您正苦於以下問題:Java CraftingInventory類的具體用法?Java CraftingInventory怎麽用?Java CraftingInventory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CraftingInventory類屬於org.bukkit.inventory包,在下文中一共展示了CraftingInventory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: matrixMatch
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private boolean matrixMatch(CraftingInventory craftingInventory, int maxColumns, int maxRows, boolean mirrored) {
for (int c = 0; c < 3; c++) {
for (int r = 0; r < 3; r++) {
int colNum = c - maxColumns;
int rowNum = r - maxRows;
CraftingIngredient choiceIngredient = InventoryUtils::isEmptyStack;
if (colNum >= 0 && rowNum >= 0 && colNum < width && rowNum < heigth) {
if (mirrored) {
choiceIngredient = ingredients.get(width - 1 - colNum + rowNum * width);
} else {
choiceIngredient = ingredients.get(colNum + rowNum * width);
}
}
if (!choiceIngredient.isIngredient(craftingInventory.getItem(colNum + rowNum * width))) {
return false;
}
}
}
return true;
}
示例2: getLeftOverItems
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public List<? extends ItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
ItemStack[] matrix = craftingInventory.getMatrix();
List<ItemStack> leftOver = new ArrayList<>(matrix.length);
for (int i = 0; i < matrix.length; i++) {
ItemStack itemStack = matrix[i];
if (InventoryUtils.isEmptyStack(itemStack)) {
leftOver.add(null);
continue;
}
ItemStack clone = itemStack.clone();
MaterialData craftingResult = InventoryUtils.getSingleIngredientResult(itemStack.getData());
if (craftingResult.getItemType() != Material.AIR) {
clone.setData(craftingResult);
leftOver.add(clone);
continue;
}
}
craftingInventory.setContents(leftOver.toArray(new ItemStack[matrix.length]));
return leftOver;
}
示例3: matches
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
final List<ChoiceIngredient> ingredients = new ArrayList<>(this.ingredients);
final List<ItemStack> contents = Arrays.asList(craftingInventory.getMatrix())
.stream().filter(i -> !InventoryUtils.isEmptyStack(i))
.collect(Collectors.toList());
for (ItemStack stack : contents) {
boolean match = false;
for (int ingredientIndex = 0; ingredientIndex < ingredients.size(); ingredientIndex++) {
ChoiceIngredient ingredient = ingredients.get(ingredientIndex);
if (ingredient.isIngredient(stack)) {
ingredients.remove(ingredientIndex);
match = true;
break;
}
}
//there was no matching ingredient for the current ItemStack
if (!match) return false;
}
//return true if there are no unused ingredients left over
return ingredients.isEmpty();
}
示例4: onPrepareCraft
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler
public void onPrepareCraft(PrepareItemCraftEvent e)
{
CraftingInventory inv = e.getInventory();
ItemStack result = inv.getResult();
if(result != null && result.getType() != Material.GLASS_BOTTLE)
{
List<ItemStack> bottles = Arrays.asList(inv.getMatrix());
Iterator<ItemStack> it = bottles.iterator();
while(it.hasNext())
{
ItemStack bottle = it.next();
if(bottle == null) continue;
if(bottle.getType().equals(Material.POTION))
{
if(!checkWaterBottle(bottle))
{
inv.setResult(null);
return;
}
}
}
}
}
示例5: onPrepareCrowbarCraft
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPrepareCrowbarCraft(PrepareItemCraftEvent event) {
CraftingInventory inventory = event.getInventory();
if (event.isRepair() && event.getRecipe().getResult().getType() == Crowbar.CROWBAR_TYPE) {
int endFrameUses = 0;
int spawnerUses = 0;
boolean changed = false;
ItemStack[] matrix = inventory.getMatrix();
for (ItemStack ingredient : matrix) {
Optional<Crowbar> crowbarOptional = Crowbar.fromStack(ingredient);
if (crowbarOptional.isPresent()) {
Crowbar crowbar = crowbarOptional.get();
spawnerUses += crowbar.getSpawnerUses();
endFrameUses += crowbar.getEndFrameUses();
changed = true;
}
}
// Finally update the result.
if (changed) {
inventory.setResult(new Crowbar(spawnerUses, endFrameUses).getItemIfPresent());
}
}
}
示例6: onInventoryClick
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
HumanEntity human = e.getWhoClicked();
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
final Player player = (Player) human;
if (e.getCurrentItem() != null) {
if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) {
sendDelayedArmorUpdate(player);
return;
}
}
if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
sendDelayedArmorUpdate(player);
}
}
}
示例7: matches
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
int width, heigth;
//check boundaries for the crafting inventory
InventoryType type = craftingInventory.getType();
switch(type) {
case CRAFTING:
width = heigth = 2;
break;
case WORKBENCH:
width = heigth = 3;
break;
default: return false; //unknown crafting inventory type.
}
for (int w = 0; w <= width - this.width; w++) {
for (int h = 0; h <= heigth - this.heigth; h++) {
if (matrixMatch(craftingInventory, w, h, true)) {
return true;
}
if (matrixMatch(craftingInventory, w, h, false)) {
return true;
}
}
}
return false;
}
示例8: matches
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
CraftWorld cWorld = (CraftWorld) world;
WorldServer nmsWorld = cWorld.getHandle();
InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);
return nmsRecipe.a(nmsCraftingInventory, nmsWorld);
}
示例9: getLeftOverItems
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@Override
public List<CraftItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);
return nmsRecipe.b(nmsCraftingInventory).stream()
.map(CraftItemStack::asCraftMirror)
.collect(Collectors.toList());
}
示例10: onCraftItem
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private static void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
if (recipe.getResult().getType() == Material.WOOD_SWORD
|| recipe.getResult().getType() == Material.STONE_SWORD
|| recipe.getResult().getType() == Material.IRON_SWORD
|| recipe.getResult().getType() == Material.GOLD_SWORD
|| recipe.getResult().getType() == Material.DIAMOND_SWORD)
inventory.setResult(new ItemStack(Material.AIR));
}
示例11: onCraftItem
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
if (recipe.getResult().getType() == Material.WOOD_SWORD)
inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SWORD)));
else if (recipe.getResult().getType() == Material.WOOD_PICKAXE)
inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_PICKAXE)));
else if (recipe.getResult().getType() == Material.WOOD_AXE)
inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_AXE)));
else if (recipe.getResult().getType() == Material.WOOD_SPADE)
inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SPADE)));
}
示例12: onPrepareCraft
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPrepareCraft(PrepareItemCraftEvent event) {
if (event.getInventory().getHolder() instanceof Player) {
CraftingInventory inventory = event.getInventory();
Player player = (Player) inventory.getHolder();
if (isBottledExperience(inventory.getResult())) {
int exp = new ExperienceManager(player).getCurrentExp();
inventory.setResult(exp > 0 ? createExpBottle(exp) : new ItemStack(Material.AIR, 1));
}
}
}
示例13: onPrepareItemCraft
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler (priority = EventPriority.HIGHEST)
public void onPrepareItemCraft (PrepareItemCraftEvent e) {
if (e.getViewers().size() < 1) return;
World world = e.getViewers().get(0).getWorld();
if(!isEnabled(world)) return;
CraftingInventory inv = e.getInventory();
ItemStack result = inv.getResult();
if(result != null && denied.contains(result.getType()))
inv.setResult(null);
}
示例14: onCraftItem
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler
public void onCraftItem(CraftItemEvent event) {
if (event.isCancelled()) return;
final Player p = (Player) event.getWhoClicked();
CraftingInventory inventory = event.getInventory();
for(ItemStack is : inventory.getContents()) {
if(ArmorStandTool.isTool(is)) {
event.setCancelled(true);
//noinspection deprecation
p.updateInventory();
return;
}
}
}
示例15: onInventoryClick
import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
* - Workaround to fix the crafting grid being not updated when the item is
* taken from the grid.
* <p>
* - Used to prevent our blocks to be renamed using an anvil.
* <p>
* - Used to allow our tools to be enchanted (ensure the name is kept).
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent ev)
{
if (ev.getInventory() instanceof CraftingInventory && ev.getSlot() == 0)
{
InventoryUtils.updateInventoryLater(ev.getInventory());
}
// Disable Anvil overrides if not using item names.
else if (ev.getInventory() instanceof AnvilInventory && BBConfig.USE_ITEM_NAMES_FALLBACK.get())
{
ItemStack item = ev.getInventory().getItem(0);
ItemStack result = ev.getInventory().getItem(2);
if (item == null) return;
BelovedBlock block = BelovedBlocks.getBelovedBlocksManager().getFromItem(item);
// Items cannot be renamed
if(block != null)
{
ev.getInventory().setItem(2, new ItemStack(Material.AIR, 0));
return;
}
BelovedTool tool = BelovedBlocks.getToolsManager().getFromItem(item);
// Players can add enchantments to the tools.
if(tool != null)
{
ItemUtils.setDisplayName(result, tool.getDisplayName());
ev.getInventory().setItem(2, result);
}
}
}