这是Spigot.mc上帖子的副本:https://www.spigotmc.org/threads/1-13-2-when-crafting-the-required-items-increases.359924/
我的问题是,当我使用项目堆栈作为配方来制作项目时,所需的项目甚至会超出堆栈限制。我正在使用“ PrepareItemCraftEvent”来检查食谱是否包含所需的项目(名称,知识)。 我当前的代码是:
ggplot(mtcars, aes(x=mpg, y=wt)) +
geom_point(aes(size=wt, color = as.factor(new_var)), shape=21, fill="black") +
scale_color_manual(values=c("red", "black")) +
guides(color=FALSE)
请注意,我唯一的问题在于此代码内:
import java.util.HashMap;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
public class ItemstackCrafting implements Listener {
private int i = 0;
@SuppressWarnings("serial")
@EventHandler
public void onPlayerCraftItem(PrepareItemCraftEvent e){
if(e.getInventory().getMatrix().length < 9){
return;
}
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier1(), 9), e.getInventory(), new HashMap<Integer, ItemStack>(){{
put(0, CoustomItems.rareEmeraldTier2());
}});
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier2(), 1), e.getInventory(), new HashMap<Integer, ItemStack>(){{
for(int n = 0; n < 9; n++) {
put(n, CoustomItems.rareEmeraldTier1());
}
}});
i = 0;
while (i < 9) {
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier2(), 9), e.getInventory(), new HashMap<Integer, ItemStack>(){{
put(i, CoustomItems.rareEmeraldTier3());
i++;
}});
}
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier3(), 1), e.getInventory(), new HashMap<Integer, ItemStack>(){{
for(int n = 0; n < 9; n++) {
put(n, CoustomItems.rareEmeraldTier2());
}
}});
i = 0;
while (i < 9) {
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier3(), 9), e.getInventory(), new HashMap<Integer, ItemStack>(){{
put(i, CoustomItems.rareEmeraldTier4());
i++;
}});
}
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier4(), 1), e.getInventory(), new HashMap<Integer, ItemStack>(){{
for(int n = 0; n < 9; n++) {
put(n, CoustomItems.rareEmeraldTier3());
}
}});
i = 0;
while (i < 9) {
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier4(), 9), e.getInventory(), new HashMap<Integer, ItemStack>(){{
put(i, CoustomItems.rareEmeraldTier5());
i++;
}});
}
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier5(), 1), e.getInventory(), new HashMap<Integer, ItemStack>(){{
for(int n = 0; n < 9; n++) {
put(n, CoustomItems.rareEmeraldTier4());
}
}});
i = 0;
while (i < 9) {
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldTier5(), 9), e.getInventory(), new HashMap<Integer, ItemStack>(){{
put(i, CoustomItems.rareEmeraldBlockTier5());
i++;
}});
}
checkCraft(CoustomItems.changeAmount(CoustomItems.rareEmeraldBlockTier5(), 1), e.getInventory(), new HashMap<Integer, ItemStack>(){{
for(int n = 0; n < 9; n++) {
put(n, CoustomItems.rareEmeraldTier5());
}
}});
}
public void checkCraft(ItemStack result, CraftingInventory inv, HashMap<Integer, ItemStack> ingredients){
ItemStack[] matrix = inv.getMatrix();
for(int n = 0; n < 9; n++){
if(ingredients.containsKey(n)){
if(matrix[n] == null
|| !matrix[n].getItemMeta().getDisplayName().equals(ingredients.get(n).getItemMeta().getDisplayName())
|| !matrix[n].getItemMeta().getLore().equals(ingredients.get(n).getItemMeta().getLore())){
return;
}
} else {
if(matrix[n] != null){
return;
}
}
}
inv.setResult(result);
}
}
这是一种简略的配方,可以在9个插槽中的任何一个中放置一个方块,以便能够转换为早期Tier Emerald的9个。 我可以添加自定义项目类,但是它仅包含创建自定义ItemStack并更改ItemStack包含的数量的方法。 如果您不理解我的示例,我将提供1张图片和1张gif文件,以直接显示问题: 图片 https://gyazo.com/83bc55ac2efaccb1fbc524e90cc88887