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;
}
java类org.bukkit.inventory.CraftingInventory的实例源码
SimpleShapedRecipe.java 文件源码
项目:CustomRecipes
阅读 108
收藏 0
点赞 0
评论 0
SimpleCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 24
收藏 0
点赞 0
评论 0
/**
* {@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;
}
SimpleShapelessRecipe.java 文件源码
项目:CustomRecipes
阅读 19
收藏 0
点赞 0
评论 0
/**
* {@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();
}
WaterBottleCrafting.java 文件源码
项目:SurvivalPlus
阅读 19
收藏 0
点赞 0
评论 0
@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;
}
}
}
}
}
CrowbarListener.java 文件源码
项目:HCFCore
阅读 22
收藏 0
点赞 0
评论 0
@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());
}
}
}
CrowbarListener.java 文件源码
项目:HCFCore
阅读 27
收藏 0
点赞 0
评论 0
@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());
}
}
}
ArmorListener.java 文件源码
项目:ViaVersion
阅读 22
收藏 0
点赞 0
评论 0
@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);
}
}
}
SimpleShapedRecipe.java 文件源码
项目:CustomRecipes
阅读 23
收藏 0
点赞 0
评论 0
/**
* {@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;
}
CRCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 20
收藏 0
点赞 0
评论 0
@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);
}
CRCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 20
收藏 0
点赞 0
评论 0
@Override
public List<CraftItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);
return nmsRecipe.b(nmsCraftingInventory).stream()
.map(CraftItemStack::asCraftMirror)
.collect(Collectors.toList());
}
NoSwordModule.java 文件源码
项目:SurvivalAPI
阅读 24
收藏 0
点赞 0
评论 0
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));
}
RapidToolsModule.java 文件源码
项目:SurvivalAPI
阅读 19
收藏 0
点赞 0
评论 0
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)));
}
BottledExpListener.java 文件源码
项目:HCFCore
阅读 24
收藏 0
点赞 0
评论 0
@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));
}
}
}
BottledExpListener.java 文件源码
项目:HCFCore
阅读 19
收藏 0
点赞 0
评论 0
@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));
}
}
}
ModuleDisableCrafting.java 文件源码
项目:BukkitOldCombatMechanics
阅读 22
收藏 0
点赞 0
评论 0
@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);
}
MainListener.java 文件源码
项目:ArmorStandTools
阅读 21
收藏 0
点赞 0
评论 0
@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;
}
}
}
CraftingListener.java 文件源码
项目:BelovedBlocks
阅读 20
收藏 0
点赞 0
评论 0
/**
* - 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);
}
}
}
KeyCraftEvent.java 文件源码
项目:manco2
阅读 19
收藏 0
点赞 0
评论 0
@EventHandler
public void onPrepare(PrepareItemCraftEvent e) {
CraftingInventory inv = e.getInventory();
if(inv.getRecipe().getResult().hasItemMeta()) {
if(inv.getRecipe().getResult().getItemMeta().hasDisplayName()) {
if(inv.getRecipe().getResult().getItemMeta().getDisplayName().equalsIgnoreCase("crate")) {
if(inv.getItem(5) != null) {
if(inv.getItem(5).hasItemMeta()) {
if(inv.getItem(5).getItemMeta().hasDisplayName()) {
if(pl.isCrate(inv.getItem(5).getItemMeta().getDisplayName())) {
Crate crate = pl.getCrate(inv.getItem(5).getItemMeta().getDisplayName());
if(crate.needsKey()) {
if(inv.getItem(5).getType() == (crate.getType() == CrateType.NORMAL ? Material.GOLD_INGOT : Material.DIAMOND)) {
inv.setResult(crate.getKeyItem());
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
}
}
}
}
}
SilkyBreakerModule.java 文件源码
项目:sensibletoolbox
阅读 23
收藏 0
点赞 0
评论 0
@Override
public boolean validateCrafting(CraftingInventory inventory) {
for (ItemStack stack : inventory.getMatrix()) {
if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) stack.getItemMeta();
if (meta.getStoredEnchantLevel(Enchantment.SILK_TOUCH) < 1) {
return false;
}
}
}
return true;
}
KeyCraftEvent.java 文件源码
项目:ManCo
阅读 19
收藏 0
点赞 0
评论 0
@EventHandler
public void onPrepare(PrepareItemCraftEvent e) {
CraftingInventory inv = e.getInventory();
if(inv.getRecipe().getResult().hasItemMeta()) {
if(inv.getRecipe().getResult().getItemMeta().hasDisplayName()) {
if(inv.getRecipe().getResult().getItemMeta().getDisplayName().equalsIgnoreCase("crate")) {
if(inv.getItem(5) != null) {
if(inv.getItem(5).hasItemMeta()) {
if(inv.getItem(5).getItemMeta().hasDisplayName()) {
if(pl.isCrate(inv.getItem(5).getItemMeta().getDisplayName())) {
Crate crate = pl.getCrate(inv.getItem(5).getItemMeta().getDisplayName());
if(crate.needsKey()) {
if(inv.getItem(5).getType() == (crate.getType() == CrateType.NORMAL ? Material.GOLD_INGOT : Material.DIAMOND)) {
inv.setResult(crate.getKeyItem());
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
} else {
inv.setResult(null);
}
}
}
}
}
}
InventoryListener.java 文件源码
项目:Ghosts
阅读 22
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.NORMAL)
public void onPrepareItemCraft(PrepareItemCraftEvent event) {
boolean isUpgradeRecipe = RecipeUtil.areEqual(event.getRecipe(), ResurrectionScroll.getResurrectionScrollUpgradeRecipe());
if (!isUpgradeRecipe) {
return;
}
CraftingInventory inventory = event.getInventory();
boolean resurrectionScrollFound = false;
int tier = 0;
for (ItemStack itemStack : inventory.getMatrix()) {
if (itemStack == null) {
continue;
}
if (ItemUtils.isResurrectionScroll(itemStack)) {
resurrectionScrollFound = true;
tier = Tier.getTier(itemStack).toNumerical();
}
}
if (!resurrectionScrollFound || tier >= 3) {
inventory.setResult(null);
return;
}
inventory.setResult(ResurrectionScroll.getResurrectionScroll(1, tier + 1));
}
ItemExchangeListener.java 文件源码
项目:ItemExchange
阅读 19
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
final Inventory top = event.getView().getTopInventory();
if(top instanceof CraftingInventory && event.getWhoClicked() instanceof Player) {
final Player player = (Player) event.getWhoClicked();
Bukkit.getScheduler().scheduleSyncDelayedTask(ItemExchangePlugin.instance, new Runnable() {
@SuppressWarnings("deprecation")
public void run() {
CraftingInventory inv = (CraftingInventory) top;
List<ExchangeRule> exchangeRules = new ArrayList<ExchangeRule>();
for(ItemStack item : inv.getMatrix()) {
if(item != null && item.getType() != Material.AIR) {
try {
exchangeRules.add(ExchangeRule.parseRuleBlock(item));
}
catch(ExchangeRuleParseException e) {
try {
exchangeRules.addAll(Arrays.asList(ExchangeRule.parseBulkRuleBlock(item)));
}
catch(ExchangeRuleParseException e2) {
return;
}
}
}
}
if(exchangeRules.size() > 0) {
inv.setResult(ExchangeRule.toBulkItemStack(exchangeRules));
player.updateInventory();
}
}
});
}
}
TypeRepair.java 文件源码
项目:EpicQuest
阅读 22
收藏 0
点赞 0
评论 0
@EventHandler
public void onCraftItem(CraftItemEvent event){
Player player = (Player)event.getInventory().getHolder();
EpicPlayer epicPlayer = EpicSystem.getEpicPlayer(player.getUniqueId());
List<EpicQuestTask> taskList = epicPlayer.getTasksByType(TaskTypes.REPAIR_ITEM);
for(EpicQuestTask task : taskList){
if(event.getInventory().getType() == InventoryType.CRAFTING){
CraftingInventory craftInventory = (CraftingInventory)event.getInventory();
ItemStack[] content = craftInventory.getContents();
String itemNeeded = task.getTaskID();
Material craftedItem = content[0].getType();
if(craftedItem != Material.matchMaterial(itemNeeded)) return;
int itemsFound = 0;
for(int i = 1; i < 5; i++){
if(content[i].getType() == craftedItem) itemsFound++;
}
if(itemsFound == 2) task.ProgressTask(1, epicPlayer, true);
return;
}
}
}
SimpleCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 21
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*/
@Override
public ItemStack craftItem(CraftingInventory craftingInventory) {
return result == null ? null : result.clone();
}
CRCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 21
收藏 0
点赞 0
评论 0
@Override
public CraftItemStack craftItem(CraftingInventory craftingInventory) {
InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);
return CraftItemStack.asCraftMirror(nmsRecipe.craftItem(nmsCraftingInventory));
}
CRCraftingRecipe.java 文件源码
项目:CustomRecipes
阅读 20
收藏 0
点赞 0
评论 0
public static InventoryCrafting getNmsCraftingInventory(CraftingInventory bukkitInventory) {
return (InventoryCrafting) ReflectionUtil.getDeclaredFieldValue(bukkitInventory, "inventory");
}
KillForEnchantmentModule.java 文件源码
项目:SurvivalAPI
阅读 17
收藏 0
点赞 0
评论 0
private static void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
if (recipe.getResult().getType() == Material.ENCHANTMENT_TABLE)
inventory.setResult(new ItemStack(Material.AIR));
}
OneWorkbenchModule.java 文件源码
项目:SurvivalAPI
阅读 21
收藏 0
点赞 0
评论 0
private void onCraftItem(Recipe recipe, CraftingInventory inventory, HumanEntity human)
{
if (recipe.getResult().getType() == Material.WORKBENCH && this.crafters.contains(human.getUniqueId()))
inventory.setResult(new ItemStack(Material.AIR, 1));
}
DisableSpeckedMelonModule.java 文件源码
项目:SurvivalAPI
阅读 20
收藏 0
点赞 0
评论 0
private static void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
if (recipe.getResult().getType() == Material.SPECKLED_MELON && inventory.contains(Material.GOLD_NUGGET))
inventory.setResult(new ItemStack(Material.AIR));
}
DisableNotchAppleModule.java 文件源码
项目:SurvivalAPI
阅读 19
收藏 0
点赞 0
评论 0
private static void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
if (recipe.getResult().getType() == Material.GOLDEN_APPLE && recipe.getResult().getDurability() == 1)
inventory.setResult(new ItemStack(Material.AIR));
}