下面列出了怎么用org.bukkit.inventory.BrewerInventory的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* This event makes sure that any acid bottles become potions without the
* warning
*
* @param e - event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBrewComplete(final BrewEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
if (e.getBlock().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
//if (Settings.acidBottle && Settings.acidDamage>0 && e.getBlock().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
plugin.getLogger().info("DEBUG: Brew Event called");
BrewerInventory inv = e.getContents();
int i = 0;
for (ItemStack item : inv.getContents()) {
if (item != null) {
// Remove lore
ItemMeta meta = item.getItemMeta();
plugin.getLogger().info("DEBUG: " + meta.getDisplayName());
meta.setDisplayName(null);
inv.setItem(i, item);
}
i++;
}
}
}
@Override
public BrewerInventory getInventory() {
if (!this.isPlaced()) {
return this.getSnapshotInventory();
}
return new CraftInventoryBrewer(this.getTileEntity());
}
static ItemStack withdrawFromVanillaInventory(Block node, ItemStack template, Inventory inv) {
ItemStack[] contents = inv.getContents();
int minSlot = 0;
int maxSlot = contents.length;
if (inv instanceof FurnaceInventory) {
minSlot = 2;
maxSlot = 3;
}
else if (inv instanceof BrewerInventory) {
maxSlot = 3;
}
ItemStackWrapper wrapper = new ItemStackWrapper(template);
for (int slot = minSlot; slot < maxSlot; slot++) {
// Changes to this ItemStack are synchronized with the Item in the Inventory
ItemStack itemInSlot = contents[slot];
if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true) && matchesFilter(node, itemInSlot)) {
if (itemInSlot.getAmount() > template.getAmount()) {
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
return template;
}
else {
ItemStack clone = itemInSlot.clone();
itemInSlot.setAmount(0);
return clone;
}
}
}
return null;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBrew(BrewEvent event) {
if (!config.recipe.enabled) {
return;
}
BrewerInventory inventory = event.getContents();
BrewingStandWindow window = BrewingStandWindow.fromArray(inventory.getContents());
if (!window.ingredient.getType().equals(config.recipe.ingredient)) {
return;
}
boolean[] modified = new boolean[BrewingStandWindow.SLOTS];
for (int i = 0; i < BrewingStandWindow.SLOTS; i++) {
ItemStack result = window.results[i];
if (result == null) {
continue; // nothing in this slot
}
ItemMeta itemMeta = result.getItemMeta();
if (!(itemMeta instanceof PotionMeta)) {
continue;
}
PotionMeta potionMeta = (PotionMeta) itemMeta;
if (potionMeta.getBasePotionData().getType().equals(config.recipe.basePotion)) {
result.setItemMeta(this.convert(potionMeta));
modified[i] = true;
}
}
// delay this, because nms changes item stacks after BrewEvent is called
this.plugin.getServer().getScheduler().runTask(this.plugin, () -> {
for (int i = 0; i < BrewingStandWindow.SLOTS; i++) {
if (modified[i]) {
ItemStack[] contents = inventory.getContents();
contents[i] = window.getResult(i);
inventory.setContents(contents);
}
}
});
}
@Override
BrewerInventory getInventory();
@Override
BrewerInventory getSnapshotInventory();
public BrewEvent(Block brewer, BrewerInventory contents, int fuelLevel) {
super(brewer);
this.contents = contents;
this.fuelLevel = fuelLevel;
}
@Override
public BrewerInventory getSnapshotInventory() {
return new CraftInventoryBrewer(this.getSnapshot());
}
public BrewerInventory getInventory() {
return new CraftInventoryBrewer(brewingStand);
}
static ItemStack insertIntoVanillaInventory(ItemStack stack, Inventory inv) {
ItemStack[] contents = inv.getContents();
int minSlot = 0;
int maxSlot = contents.length;
// Check if it is a normal furnace
if (inv instanceof FurnaceInventory) {
// Check if it is fuel or not
if (stack.getType().isFuel()) {
maxSlot = 2;
// Any non-smeltable items should not land in the upper slot
if (!isSmeltable(stack, true)) {
minSlot = 1;
}
}
else {
maxSlot = 1;
}
}
else if (inv instanceof BrewerInventory) {
if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
// Potions slot
maxSlot = 3;
}
else if (stack.getType() == Material.BLAZE_POWDER) {
// Blaze Powder slot
minSlot = 4;
maxSlot = 5;
}
else {
// Input slot
minSlot = 3;
maxSlot = 4;
}
}
ItemStackWrapper wrapper = new ItemStackWrapper(stack);
for (int slot = minSlot; slot < maxSlot; slot++) {
// Changes to this ItemStack are synchronized with the Item in the Inventory
ItemStack itemInSlot = contents[slot];
if (itemInSlot == null) {
inv.setItem(slot, stack);
return null;
}
else {
int maxStackSize = itemInSlot.getType().getMaxStackSize();
if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false) && itemInSlot.getAmount() < maxStackSize) {
int amount = itemInSlot.getAmount() + stack.getAmount();
if (amount > maxStackSize) {
stack.setAmount(amount - maxStackSize);
}
else {
stack = null;
}
itemInSlot.setAmount(Math.min(amount, maxStackSize));
// Setting item in inventory will clone the ItemStack
inv.setItem(slot, itemInSlot);
return stack;
}
}
}
return stack;
}
/**
* Gets the contents of the Brewing Stand.
*
* @return the contents
*/
public BrewerInventory getContents() {
return contents;
}