当前位置: 首页>>代码示例>>Java>>正文


Java Item.getDamage方法代码示例

本文整理汇总了Java中cn.nukkit.item.Item.getDamage方法的典型用法代码示例。如果您正苦于以下问题:Java Item.getDamage方法的具体用法?Java Item.getDamage怎么用?Java Item.getDamage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cn.nukkit.item.Item的用法示例。


在下文中一共展示了Item.getDamage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerShapedRecipe

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void registerShapedRecipe(ShapedRecipe recipe) {
    Item result = recipe.getResult();
    this.recipes.put(recipe.getId(), recipe);
    Map<Integer, Map<Integer, Item>> ingredients = recipe.getIngredientMap();
    String hash = "";
    for (Map<Integer, Item> v : ingredients.values()) {
        for (Item item : v.values()) {
            if (item != null && item.getId() != Item.AIR) {
                hash += item.getId() + ":" + (!item.hasMeta() ? "?" : item.getDamage()) + "x" + item.getCount() + ",";
            }
        }

        hash += ";";
    }

    String index = result.getId() + ":" + (result.hasMeta() ? result.getDamage() : "");
    if (!this.recipeLookup.containsKey(index)) {
        this.recipeLookup.put(index, new HashMap<>());
    }

    this.recipeLookup.get(index).put(hash, recipe);
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:23,代码来源:CraftingManager.java

示例2: 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;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:17,代码来源:BaseInventory.java

示例3: onEnchant

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void onEnchant(Player who, Item before, Item after) {
    Item result = (before.getId() == Item.BOOK) ? new ItemBookEnchanted() : before;
    if (!before.hasEnchantments() && after.hasEnchantments() && after.getId() == result.getId() && this.levels != null && this.entries != null) {
        Enchantment[] enchantments = after.getEnchantments();
        for (int i = 0; i < 3; i++) {
            if (Arrays.equals(enchantments, this.entries[i].getEnchantments())) {
                Item lapis = this.getItem(1);
                int level = who.getExperienceLevel();
                int exp = who.getExperience();
                int cost = this.entries[i].getCost();
                if (lapis.getId() == Item.DYE && lapis.getDamage() == DyeColor.BLUE.getDyeData() && lapis.getCount() > i && level >= cost) {
                    result.addEnchantment(enchantments);
                    this.setItem(0, result);
                    lapis.setCount(lapis.getCount() - i - 1);
                    this.setItem(1, lapis);
                    who.setExperience(exp, level - cost);
                    break;
                }
            }
        }
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:23,代码来源:EnchantInventory.java

示例4: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
        item.count--;
        ObjectTallGrass.growGrass(this.getLevel(), this, new NukkitRandom(), 15, 10);
        return true;
    } else if (item.isHoe()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockFarmland());
        return true;
    } else if (item.isShovel()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockGrassPath());
        return true;
    }

    return false;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:BlockGrass.java

示例5: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        Block block = this.clone();
        if (this.meta / 4 < 2) {
            block.meta += 4;
            BlockGrowEvent ev = new BlockGrowEvent(this, block);
            Server.getInstance().getPluginManager().callEvent(ev);

            if (ev.isCancelled()) {
                return false;
            }
            this.getLevel().setBlock(this, ev.getNewState(), true, true);
        }

        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        item.count--;
        return true;
    }

    return false;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:23,代码来源:BlockCocoa.java

示例6: putSlot

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void putSlot(Item item) {
    if (item == null || item.getId() == 0) {
        this.putVarInt(0);
        return;
    }

    this.putVarInt(item.getId());
    int auxValue = (((item.hasMeta() ? item.getDamage() : -1) & 0x7fff) << 8) | item.getCount();
    this.putVarInt(auxValue);
    byte[] nbt = item.getCompoundTag();
    this.putLShort(nbt.length);
    this.put(nbt);
    this.putVarInt(0); //TODO CanPlaceOn entry count
    this.putVarInt(0); //TODO CanDestroy entry count
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:16,代码来源:BinaryStream.java

示例7: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    //Bone meal
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        BlockCrops block = (BlockCrops) this.clone();
        if (this.meta < 7) {
            block.meta += new Random().nextInt(3) + 2;
            if (block.meta > 7) {
                block.meta = 7;
            }
            BlockGrowEvent ev = new BlockGrowEvent(this, block);
            Server.getInstance().getPluginManager().callEvent(ev);

            if (ev.isCancelled()) {
                return false;
            }

            this.getLevel().setBlock(this, ev.getNewState(), true, true);
        }

        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        item.count--;
        return true;
    }

    return false;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:28,代码来源:BlockCrops.java

示例8: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == DyeColor.WHITE.getDyeData()) {
        if (this.level.rand.nextFloat() < 0.4) {
            this.grow();
        }

        this.level.addParticle(new BoneMealParticle(this));
        return true;
    }
    return false;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:13,代码来源:BlockMushroomBrown.java

示例9: registerShapelessRecipe

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void registerShapelessRecipe(ShapelessRecipe recipe) {
    Item result = recipe.getResult();
    this.recipes.put(recipe.getId(), recipe);
    String hash = "";
    List<Item> ingredients = recipe.getIngredientList();
    ingredients.sort(this.comparator);
    for (Item item : ingredients) {
        hash += item.getId() + ":" + (!item.hasMeta() ? "?" : item.getDamage()) + "x" + item.getCount() + ",";
    }

    if (!this.recipeLookup.containsKey(result.getId() + ":" + result.getDamage())) {
        this.recipeLookup.put(result.getId() + ":" + result.getDamage(), new HashMap<>());
    }
    this.recipeLookup.get(result.getId() + ":" + result.getDamage()).put(hash, recipe);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:16,代码来源:CraftingManager.java

示例10: toString

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public String toString(Item item) {
	StringBuilder str = new StringBuilder();
	str.append(item.getId());

	if (item.getDamage() != 0) {
		str.append(":" + item.getDamage());
	}
	if (item.getCount() == 1) {
		str.append(":" + item.getCount());
	}
	return str.toString();

}
 
开发者ID:angelless,项目名称:MineLess,代码行数:14,代码来源:DataBase.java

示例11: 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;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:14,代码来源:BaseInventory.java

示例12: SlotEntityData

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public SlotEntityData(int id, Item item) {
    this(id, item.getId(), (byte) (item.hasMeta() ? item.getDamage() : 0), item.getCount());
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:4,代码来源:SlotEntityData.java

示例13: readMetadata

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public static EntityMetadata readMetadata(byte[] payload) {
    BinaryStream stream = new BinaryStream();
    stream.setBuffer(payload);
    long count = stream.getUnsignedVarInt();
    EntityMetadata m = new EntityMetadata();
    for (int i = 0; i < count; i++) {
        int key = (int) stream.getUnsignedVarInt();
        int type = (int) stream.getUnsignedVarInt();
        EntityData value = null;
        switch (type) {
            case Entity.DATA_TYPE_BYTE:
                value = new ByteEntityData(key, stream.getByte());
                break;
            case Entity.DATA_TYPE_SHORT:
                value = new ShortEntityData(key, stream.getLShort());
                break;
            case Entity.DATA_TYPE_INT:
                value = new IntEntityData(key, stream.getVarInt());
                break;
            case Entity.DATA_TYPE_FLOAT:
                value = new FloatEntityData(key, stream.getLFloat());
                break;
            case Entity.DATA_TYPE_STRING:
                value = new StringEntityData(key, stream.getString());
                break;
            case Entity.DATA_TYPE_SLOT:
                Item item = stream.getSlot();
                value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount());
                break;
            case Entity.DATA_TYPE_POS:
                BlockVector3 v3 = stream.getBlockCoords();
                value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
                break;
            case Entity.DATA_TYPE_LONG:
                value = new LongEntityData(key, stream.getVarLong());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                value = new Vector3fEntityData(key, stream.getVector3f());
                break;
        }
        if (value != null) m.put(value);
    }
    return m;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:45,代码来源:Binary.java

示例14: readMetadata

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public static EntityMetadata readMetadata(byte[] payload) {
    BinaryStream stream = new BinaryStream();
    stream.setBuffer(payload);
    long count = stream.getUnsignedVarInt();
    EntityMetadata m = new EntityMetadata();
    for (int i = 0; i < count; i++) {
        int key = (int) stream.getUnsignedVarInt();
        int type = (int) stream.getUnsignedVarInt();
        EntityData value = null;
        switch (type) {
            case Entity.DATA_TYPE_BYTE:
                value = new ByteEntityData(key, stream.getByte());
                break;
            case Entity.DATA_TYPE_SHORT:
                value = new ShortEntityData(key, stream.getLShort());
                break;
            case Entity.DATA_TYPE_INT:
                value = new IntEntityData(key, stream.getVarInt());
                break;
            case Entity.DATA_TYPE_FLOAT:
                value = new FloatEntityData(key, stream.getLFloat());
                break;
            case Entity.DATA_TYPE_STRING:
                value = new StringEntityData(key, stream.getString());
                break;
            case Entity.DATA_TYPE_SLOT:
                Item item = stream.getSlot();
                value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount());
                break;
            case Entity.DATA_TYPE_POS:
                BlockVector3 v3 = stream.getSignedBlockPosition();
                value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
                break;
            case Entity.DATA_TYPE_LONG:
                value = new LongEntityData(key, stream.getVarLong());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                value = new Vector3fEntityData(key, stream.getVector3f());
                break;
        }
        if (value != null) m.put(value);
    }
    return m;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:45,代码来源:Binary.java


注:本文中的cn.nukkit.item.Item.getDamage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。