本文整理汇总了Java中cn.nukkit.item.Item.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Item.equals方法的具体用法?Java Item.equals怎么用?Java Item.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.item.Item
的用法示例。
在下文中一共展示了Item.equals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canAddItem
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean canAddItem(Item item) {
item = item.clone();
boolean checkDamage = item.hasMeta();
boolean checkTag = item.getCompoundTag() != null;
for (int i = 0; i < this.getSize(); ++i) {
Item slot = this.getItem(i);
if (item.equals(slot, checkDamage, checkTag)) {
int diff;
if ((diff = slot.getMaxStackSize() - slot.getCount()) > 0) {
item.setCount(item.getCount() - diff);
}
} else if (slot.getId() == Item.AIR) {
item.setCount(item.getCount() - this.getMaxStackSize());
}
if (item.getCount() <= 0) {
return true;
}
}
return false;
}
示例2: getFreeSpace
import cn.nukkit.item.Item; //导入方法依赖的package包/类
public int getFreeSpace(Item item) {
int maxStackSize = Math.min(item.getMaxStackSize(), this.getMaxStackSize());
int space = (this.getSize() - this.slots.size()) * maxStackSize;
for (Item slot : this.getContents().values()) {
if (slot == null || slot.getId() == 0) {
space += maxStackSize;
continue;
}
if (slot.equals(item, true, true)) {
space += maxStackSize - slot.getCount();
}
}
return space;
}
示例3: contains
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean contains(Item item) {
int count = Math.max(1, item.getCount());
boolean checkDamage = item.hasMeta() && item.getDamage() >= 0;
boolean checkTag = item.getCompoundTag() != null;
for (Item i : this.getContents().values()) {
if (item.equals(i, checkDamage, checkTag)) {
count -= i.getCount();
if (count <= 0) {
return true;
}
}
}
return false;
}
示例4: matchItems
import cn.nukkit.item.Item; //导入方法依赖的package包/类
protected boolean matchItems(List<Item> needItems, List<Item> haveItems) {
for (InventoryAction action : this.actions) {
if (action.getTargetItem().getId() != Item.AIR) {
needItems.add(action.getTargetItem());
}
if (!action.isValid(this.source)) {
return false;
}
if (action.getSourceItem().getId() != Item.AIR) {
haveItems.add(action.getSourceItem());
}
}
for (Item needItem : new ArrayList<>(needItems)) {
for (Item haveItem : new ArrayList<>(haveItems)) {
if (needItem.equals(haveItem)) {
int amount = Math.min(haveItem.getCount(), needItem.getCount());
needItem.setCount(needItem.getCount() - amount);
haveItem.setCount(haveItem.getCount() - amount);
if (haveItem.getCount() == 0) {
haveItems.remove(haveItem);
}
if (needItem.getCount() == 0) {
needItems.remove(needItem);
break;
}
}
}
}
return haveItems.isEmpty() && needItems.isEmpty();
}
示例5: first
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public int first(Item item) {
int count = Math.max(1, item.getCount());
boolean checkDamage = item.hasMeta();
boolean checkTag = item.getCompoundTag() != null;
for (Map.Entry<Integer, Item> entry : this.getContents().entrySet()) {
if (item.equals(entry.getValue(), checkDamage, checkTag) && entry.getValue().getCount() >= count) {
return entry.getKey();
}
}
return -1;
}
示例6: all
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public Map<Integer, Item> all(Item item) {
Map<Integer, Item> slots = new HashMap<>();
boolean checkDamage = item.hasMeta() && item.getDamage() >= 0;
boolean checkTag = item.getCompoundTag() != null;
for (Map.Entry<Integer, Item> entry : this.getContents().entrySet()) {
if (item.equals(entry.getValue(), checkDamage, checkTag)) {
slots.put(entry.getKey(), entry.getValue());
}
}
return slots;
}
示例7: remove
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public void remove(Item item) {
boolean checkDamage = item.hasMeta();
boolean checkTag = item.getCompoundTag() != null;
for (Map.Entry<Integer, Item> entry : this.getContents().entrySet()) {
if (item.equals(entry.getValue(), checkDamage, checkTag)) {
this.clear(entry.getKey());
}
}
}
示例8: first
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public int first(Item item, boolean exact) {
int count = Math.max(1, item.getCount());
boolean checkDamage = item.hasMeta();
boolean checkTag = item.getCompoundTag() != null;
for (Map.Entry<Integer, Item> entry : this.getContents().entrySet()) {
if (item.equals(entry.getValue(), checkDamage, checkTag) && (entry.getValue().getCount() == count || (!exact && entry.getValue().getCount() > count))) {
return entry.getKey();
}
}
return -1;
}
示例9: removeIngredient
import cn.nukkit.item.Item; //导入方法依赖的package包/类
public ShapelessRecipe removeIngredient(Item item) {
for (Item ingredient : this.ingredients) {
if (item.getCount() <= 0) {
break;
}
if (ingredient.equals(item, item.hasMeta(), item.getCompoundTag() != null)) {
this.ingredients.remove(ingredient);
item.setCount(item.getCount() - 1);
}
}
return this;
}
示例10: all
import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public Map<Integer, Item> all(Item item) {
Map<Integer, Item> slots = new HashMap<>();
boolean checkDamage = item.hasMeta();
boolean checkTag = item.getCompoundTag() != null;
for (Map.Entry<Integer, Item> entry : this.getContents().entrySet()) {
if (item.equals(entry.getValue(), checkDamage, checkTag)) {
slots.put(entry.getKey(), entry.getValue());
}
}
return slots;
}