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


Java Item类代码示例

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


Item类属于cn.nukkit.item包,在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:24,代码来源:BaseInventory.java

示例2: place

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    short[] faces = new short[]{
            0,
            0,
            0b1000,
            0b1000,
            0b0100,
            0b0100
    };

    this.meta = ((this.meta & 0x03) | faces[face.getIndex()]);
    this.getLevel().setBlock(block, this, true, true);

    return true;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:17,代码来源:BlockWood.java

示例3: 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:FrontierDevs,项目名称:Jenisys3,代码行数:19,代码来源:BlockGrass.java

示例4: getDrops

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public Item[] getDrops(Item item) {
    boolean dropInside = false;
    int insideID = 0;
    int insideMeta = 0;
    BlockEntity blockEntity = getLevel().getBlockEntity(this);
    if (blockEntity instanceof BlockEntityFlowerPot) {
        dropInside = true;
        insideID = blockEntity.namedTag.getShort("item");
        insideMeta = blockEntity.namedTag.getInt("data");
    }

    if (dropInside) {
        return new Item[]{
                new ItemFlowerPot(),
                Item.get(insideID, insideMeta, 1)
        };
    } else {
        return new Item[]{
                new ItemFlowerPot()
        };
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:24,代码来源:BlockFlowerPot.java

示例5: registerFurnace

import cn.nukkit.item.Item; //导入依赖的package包/类
protected void registerFurnace() {
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.STONE, 0, 1), Item.get(Item.COBBLESTONE, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.STONE_BRICK, BlockBricksStone.CRACKED, 1), Item.get(Item.STONE_BRICK, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.GLASS, 0, 1), Item.get(Item.SAND, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COAL, 1, 1), Item.get(Item.TRUNK, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.GOLD_INGOT, 0, 1), Item.get(Item.GOLD_ORE, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.IRON_INGOT, 0, 1), Item.get(Item.IRON_ORE, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.EMERALD, 0, 1), Item.get(Item.EMERALD_ORE, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.DIAMOND, 0, 1), Item.get(Item.DIAMOND_ORE, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.NETHER_BRICK, 0, 1), Item.get(Item.NETHERRACK, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COOKED_PORKCHOP, 0, 1), Item.get(Item.RAW_PORKCHOP, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.BRICK, 0, 1), Item.get(Item.CLAY, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COOKED_FISH, 0, 1), Item.get(Item.RAW_FISH, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COOKED_FISH, 1, 1), Item.get(Item.RAW_FISH, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.DYE, 2, 1), Item.get(Item.CACTUS, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.DYE, 1, 1), Item.get(Item.RED_MUSHROOM, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.STEAK, 0, 1), Item.get(Item.RAW_BEEF, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COOKED_CHICKEN, 0, 1), Item.get(Item.RAW_CHICKEN, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.BAKED_POTATO, 0, 1), Item.get(Item.POTATO, null, 1)));
    this.registerRecipe(new FurnaceRecipe(Item.get(Item.COOKED_MUTTON, 0, 1), Item.get(Item.RAW_MUTTON, null, 1)));

    this.registerRecipe(new FurnaceRecipe(Item.get(Item.HARDENED_CLAY, 0, 1), Item.get(Item.CLAY_BLOCK, null, 1)));
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:24,代码来源:CraftingManager.java

示例6: sendArmorContents

import cn.nukkit.item.Item; //导入依赖的package包/类
public void sendArmorContents(Player[] players) {
    Item[] armor = this.getArmorContents();

    MobArmorEquipmentPacket pk = new MobArmorEquipmentPacket();
    pk.eid = this.getHolder().getId();
    pk.slots = armor;
    pk.encode();
    pk.isEncoded = true;

    for (Player player : players) {
        if (player.equals(this.getHolder())) {
            InventoryContentPacket pk2 = new InventoryContentPacket();
            pk2.inventoryId = InventoryContentPacket.SPECIAL_ARMOR;
            pk2.slots = armor;
            player.dataPacket(pk2);
        } else {
            player.dataPacket(pk);
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:21,代码来源:PlayerInventory.java

示例7: BlockEntityChest

import cn.nukkit.item.Item; //导入依赖的package包/类
public BlockEntityChest(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.inventory = new ChestInventory(this);

    if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
        this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    }

    /* for (int i = 0; i < this.getSize(); i++) {
        this.inventory.setItem(i, this.getItem(i));
    } */
    
    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:19,代码来源:BlockEntityChest.java

示例8: place

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (face != BlockFace.UP) return false;
    CompoundTag nbt = new CompoundTag()
            .putString("id", BlockEntity.FLOWER_POT)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z)
            .putShort("item", 0)
            .putInt("data", 0);
    if (item.hasCustomBlockData()) {
        for (Tag aTag : item.getCustomBlockData().getAllTags()) {
            nbt.put(aTag.getName(), aTag);
        }
    }
    new BlockEntityFlowerPot(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);

    this.getLevel().setBlock(block, this, true, true);
    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:21,代码来源:BlockFlowerPot.java

示例9: sendContents

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public void sendContents(Player... players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    /*//Because PE is stupid and shows 9 less slots than you send it, give it 9 dummy slots so it shows all the REAL slots.
    for(int i = this.getSize(); i < this.getSize() + this.getHotbarSize(); ++i){
        pk.slots[i] = new ItemBlock(new BlockAir());
    }
        pk.slots[i] = new ItemBlock(new BlockAir());
    }*/

    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk.clone());

    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:27,代码来源:PlayerInventory.java

示例10: sendContents

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public void sendContents(Player[] players) {
    ContainerSetContentPacket pk = new ContainerSetContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }

    for (Player player : players) {
        pk.eid = player.getId();
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.windowid = (byte) id;
        player.dataPacket(pk);
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:20,代码来源:BaseInventory.java

示例11: place

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    Block down = this.down();
    if (down.isSolid()) {
        this.getLevel().setBlock(block, this, true);

        return true;
    }
    return false;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:11,代码来源:BlockSnowLayer.java

示例12: 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,代码来源:BlockMushroomRed.java

示例13: getDrops

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public int[][] getDrops(Item item) {
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
        return new int[][]{
                {Item.IRON_BARS, 0, 1}
        };
    } else {
        return new int[0][0];
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:11,代码来源:BlockIronBars.java

示例14: getFishingResult

import cn.nukkit.item.Item; //导入依赖的package包/类
public static Item getFishingResult(int fortuneLevel, int lureLevel) {
    float treasureChance = limitRange(0, 1, 0.05f + 0.01f * fortuneLevel - 0.01f * lureLevel);
    float junkChance = limitRange(0, 1, 0.05f - 0.025f * fortuneLevel - 0.01f * lureLevel);
    float fishChance = limitRange(0, 1, 1 - treasureChance - junkChance);
    putSelector(FISHES, fishChance);
    putSelector(TREASURES, treasureChance);
    putSelector(JUNKS, junkChance);
    Object result = selectFrom(ROOT_FISHING);
    if (result instanceof Item) return (Item) result;
    return null;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:12,代码来源:Fishing.java

示例15: place

import cn.nukkit.item.Item; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (down().getId() != Block.AIR) {
        getLevel().setBlock(block, this, true, true);

        return true;
    }
    return false;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:10,代码来源:BlockCake.java


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