當前位置: 首頁>>代碼示例>>Java>>正文


Java Player.isSurvival方法代碼示例

本文整理匯總了Java中cn.nukkit.Player.isSurvival方法的典型用法代碼示例。如果您正苦於以下問題:Java Player.isSurvival方法的具體用法?Java Player.isSurvival怎麽用?Java Player.isSurvival使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cn.nukkit.Player的用法示例。


在下文中一共展示了Player.isSurvival方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);

    if (chunk == null) {
        return false;
    }

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", block.getX() + 0.5))
                    .add(new DoubleTag("", block.getY()))
                    .add(new DoubleTag("", block.getZ() + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", new Random().nextFloat() * 360))
                    .add(new FloatTag("", 0)));

    if (this.hasCustomName()) {
        nbt.putString("CustomName", this.getCustomName());
    }

    Entity entity = Entity.createEntity(this.meta, chunk, nbt);

    if (entity != null) {
        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();
        return true;
    }

    return false;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:40,代碼來源:ItemSpawnEgg.java

示例2: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (face != BlockFace.UP) return false;
    EntityBoat boat = new EntityBoat(
            level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("")
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", block.getX() + 0.5))
                    .add(new DoubleTag("", block.getY() - 0.0625))
                    .add(new DoubleTag("", block.getZ() + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (float) ((player.yaw + 90f) % 360)))
                    .add(new FloatTag("", 0)))
            .putByte("woodID", this.getDamage())
    );

    if (player.isSurvival()) {
        Item item = player.getInventory().getItemInHand();
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item);
    }

    boat.spawnToAll();
    return true;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:29,代碼來源:ItemBoat.java

示例3: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = getLevel().getBlockEntity(this);
    if (!(blockEntity instanceof BlockEntityFlowerPot)) return false;
    if (blockEntity.namedTag.getShort("item") != 0 || blockEntity.namedTag.getInt("mData") != 0) return false;
    int itemID;
    int itemMeta;
    if (!canPlaceIntoFlowerPot(item.getId())) {
        if (!canPlaceIntoFlowerPot(item.getBlock().getId())) {
            return true;
        }
        itemID = item.getBlock().getId();
        itemMeta = item.getDamage();
    } else {
        itemID = item.getId();
        itemMeta = item.getDamage();
    }
    blockEntity.namedTag.putShort("item", itemID);
    blockEntity.namedTag.putInt("data", itemMeta);

    this.meta = 1;
    this.getLevel().setBlock(this, this, true);
    ((BlockEntityFlowerPot) blockEntity).spawnToAll();

    if (player.isSurvival()) {
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item.getCount() > 0 ? item : Item.get(Item.AIR));
    }
    return true;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:31,代碼來源:BlockFlowerPot.java

示例4: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
    BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity;
    if (itemFrame.getItem().getId() == Item.AIR) {
        // We can't use Item.get(item.getId(), item.getDamage(), 1) because
        // we need to keep the item's NBT tags
        Item itemOnFrame = item.clone(); // So we clone the item
        itemOnFrame.setCount(1); // Change it to only one item (if we keep +1, visual glitches will happen)
        itemFrame.setItem(itemOnFrame); // And then we set it on the item frame
        // The item will be removed from the player's hand a few lines ahead
        this.getLevel().addSound(new ItemFrameItemAddedSound(this));
        if (player != null && player.isSurvival()) {
            int count = item.getCount();
            if (count-- <= 0) {
                player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                return true;
            }
            item.setCount(count);
            player.getInventory().setItemInHand(item);
        }
    } else {
        int itemRot = itemFrame.getItemRotation();
        if (itemRot >= 7) {
            itemRot = 0;
        } else {
            itemRot++;
        }
        itemFrame.setItemRotation(itemRot);
        this.getLevel().addSound(new ItemFrameItemRotated(this));
    }
    return true;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:34,代碼來源:BlockItemFrame.java

示例5: BlockBreakEvent

import cn.nukkit.Player; //導入方法依賴的package包/類
public BlockBreakEvent(Player player, Block block, Item item, boolean instaBreak, boolean fastBreak) {
    super(block);
    this.item = item;
    this.player = player;
    this.instaBreak = instaBreak;
    this.blockDrops = player.isSurvival() ? block.getDrops(item) : new Item[0];
    this.fastBreak = fastBreak;
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:9,代碼來源:BlockBreakEvent.java

示例6: onCollideWithPlayer

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public void onCollideWithPlayer(Player player) {
    if(this.getPickupDelay() > 0) {
        return;
    }

    Item item = this.getItem();
    PlayerInventory playerInventory = player.getInventory();

    if(!(item instanceof Item) || (player.isSurvival() && !playerInventory.canAddItem(item))) {
        return;
    }

    InventoryPickupItemEvent ev;
    this.server.getPluginManager().callEvent(ev = new InventoryPickupItemEvent(playerInventory, this));
    if(ev.isCancelled()) {
        return;
    }

    TakeItemEntityPacket pk = new TakeItemEntityPacket();
    pk.entityRuntimeId = player.getId();
    pk.target = this.getId();
    Server.broadcastPacket(this.getViewers().values(), pk);

    playerInventory.addItem(item);
    this.kill();
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:28,代碼來源:EntityItem.java

示例7: onCollideWithPlayer

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public void onCollideWithPlayer(Player player) {
    if(!this.hadCollision) {
        return;
    }

    Item item = new Item(Item.ARROW, 0, 1);
    PlayerInventory playerInventory = player.getInventory();

    if(player.isSurvival() && playerInventory.canAddItem(item)) {
        return;
    }

    InventoryPickupArrowEvent ev;
    this.server.getPluginManager().callEvent(ev = new InventoryPickupArrowEvent(playerInventory, this));
    if(ev.isCancelled()) {
        return;
    }

    TakeItemEntityPacket pk = new TakeItemEntityPacket();
    pk.entityRuntimeId = player.getId();
    pk.target = this.getId();
    Server.broadcastPacket(this.getViewers().values(), pk);

    playerInventory.addItem(item);
    this.kill();
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:28,代碼來源:EntityArrow.java

示例8: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);
    if (chunk == null) {
        return false;
    }

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", block.getX() + 0.5))
                    .add(new DoubleTag("", block.getY()))
                    .add(new DoubleTag("", block.getZ() + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", this.getDirection(player.yaw)))
                    .add(new FloatTag("", 0)));

    if (this.hasCustomName()) {
        nbt.putString("CustomName", this.getCustomName());
    }

    Entity entity = Entity.createEntity("ArmorStand", chunk, nbt);

    if (entity != null) {
        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();
        return true;
    }
    return false;
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:38,代碼來源:ItemArmorStand.java

示例9: BlockBreakEvent

import cn.nukkit.Player; //導入方法依賴的package包/類
public BlockBreakEvent(Player player, Block block, Item item, boolean instaBreak, boolean fastBreak, int dropExp) {
    super(block);
    this.item = item;
    this.player = player;
    this.instaBreak = instaBreak;
    this.blockDrops = player.isSurvival() ? block.getDrops(item) : new Item[0];
    this.fastBreak = fastBreak;
    this.dropExp = dropExp;
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:10,代碼來源:BlockBreakEvent.java

示例10: onActivate

import cn.nukkit.Player; //導入方法依賴的package包/類
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);

    if (chunk == null) {
        return false;
    }

    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        int[] direction = {2, 0, 1, 3};
        int[] right = {4, 5, 3, 2};

        List<EntityPainting.Motive> validMotives = new ArrayList<>();
        for (EntityPainting.Motive motive : EntityPainting.motives) {
            boolean valid = true;
            for (int x = 0; x < motive.width && valid; x++) {
                for (int z = 0; z < motive.height && valid; z++) {
                    if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() ||
                            target.up(z).isTransparent() ||
                            block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() ||
                            block.up(z).isSolid()) {
                        valid = false;
                    }
                }
            }

            if (valid) {
                validMotives.add(motive);
            }
        }

        CompoundTag nbt = new CompoundTag()
                .putByte("Direction", direction[face.getIndex() - 2])
                .putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title)
                .putList(new ListTag<DoubleTag>("Pos")
                        .add(new DoubleTag("0", target.x))
                        .add(new DoubleTag("1", target.y))
                        .add(new DoubleTag("2", target.z)))
                .putList(new ListTag<DoubleTag>("Motion")
                        .add(new DoubleTag("0", 0))
                        .add(new DoubleTag("1", 0))
                        .add(new DoubleTag("2", 0)))
                .putList(new ListTag<FloatTag>("Rotation")
                        .add(new FloatTag("0", direction[face.getIndex() - 2] * 90))
                        .add(new FloatTag("1", 0)));

        EntityPainting entity = new EntityPainting(chunk, nbt);

        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();

        return true;
    }

    return false;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:61,代碼來源:ItemPainting.java


注:本文中的cn.nukkit.Player.isSurvival方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。