Search in sources :

Example 1 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class BlockRail method place.

// Information from http://minecraft.gamepedia.com/Rail
@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 == null || down.isTransparent()) {
        return false;
    }
    Map<BlockRail, BlockFace> railsAround = this.checkRailsAroundAffected();
    List<BlockRail> rails = new ArrayList<>(railsAround.keySet());
    List<BlockFace> faces = new ArrayList<>(railsAround.values());
    if (railsAround.size() == 1) {
        BlockRail other = rails.get(0);
        this.setDamage(this.connect(other, railsAround.get(other)).metadata());
    } else if (railsAround.size() == 4) {
        if (this.isAbstract()) {
            this.setDamage(this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata());
        } else {
            this.setDamage(this.connect(rails.get(faces.indexOf(EAST)), EAST, rails.get(faces.indexOf(WEST)), WEST).metadata());
        }
    } else if (!railsAround.isEmpty()) {
        if (this.isAbstract()) {
            if (railsAround.size() == 2) {
                BlockRail rail1 = rails.get(0);
                BlockRail rail2 = rails.get(1);
                this.setDamage(this.connect(rail1, railsAround.get(rail1), rail2, railsAround.get(rail2)).metadata());
            } else {
                List<BlockFace> cd = Stream.of(CURVED_SOUTH_EAST, CURVED_NORTH_EAST, CURVED_SOUTH_WEST).filter(o -> o.connectingDirections().stream().allMatch(faces::contains)).findFirst().get().connectingDirections();
                BlockFace f1 = cd.get(0);
                BlockFace f2 = cd.get(1);
                this.setDamage(this.connect(rails.get(faces.indexOf(f1)), f1, rails.get(faces.indexOf(f2)), f2).metadata());
            }
        } else {
            BlockFace f = faces.stream().sorted((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1)).findFirst().get();
            BlockFace fo = f.getOpposite();
            if (faces.contains(fo)) {
                // Opposite connectable
                this.setDamage(this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata());
            } else {
                this.setDamage(this.connect(rails.get(faces.indexOf(f)), f).metadata());
            }
        }
    }
    this.level.setBlock(this, this, true, true);
    if (!isAbstract()) {
        level.scheduleUpdate(this, this, 0);
    }
    return true;
}
Also used : SOUTH(cn.nukkit.math.BlockFace.SOUTH) ItemTool(cn.nukkit.item.ItemTool) java.util(java.util) BlockFace(cn.nukkit.math.BlockFace) NORTH(cn.nukkit.math.BlockFace.NORTH) Level(cn.nukkit.level.Level) AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) EAST(cn.nukkit.math.BlockFace.EAST) BlockColor(cn.nukkit.utils.BlockColor) Rail(cn.nukkit.utils.Rail) Collectors(java.util.stream.Collectors) WEST(cn.nukkit.math.BlockFace.WEST) Orientation(cn.nukkit.utils.Rail.Orientation) Stream(java.util.stream.Stream) Player(cn.nukkit.Player) Item(cn.nukkit.item.Item) BlockFace(cn.nukkit.math.BlockFace)

Example 2 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class BlockEntityBrewingStand method sendBrewTime.

protected void sendBrewTime() {
    ContainerSetDataPacket pk = new ContainerSetDataPacket();
    pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_BREW_TIME;
    pk.value = this.brewTime;
    for (Player p : this.inventory.getViewers()) {
        int windowId = p.getWindowId(this.inventory);
        if (windowId > 0) {
            pk.windowId = windowId;
            p.dataPacket(pk);
        }
    }
}
Also used : Player(cn.nukkit.Player) ContainerSetDataPacket(cn.nukkit.network.protocol.ContainerSetDataPacket)

Example 3 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class BlockEntityFurnace method onUpdate.

@Override
public boolean onUpdate() {
    if (this.closed) {
        return false;
    }
    this.timing.startTiming();
    boolean ret = false;
    Item fuel = this.inventory.getFuel();
    Item raw = this.inventory.getSmelting();
    Item product = this.inventory.getResult();
    FurnaceRecipe smelt = this.server.getCraftingManager().matchFurnaceRecipe(raw);
    boolean canSmelt = (smelt != null && raw.getCount() > 0 && ((smelt.getResult().equals(product, true) && product.getCount() < product.getMaxStackSize()) || product.getId() == Item.AIR));
    if (burnTime <= 0 && canSmelt && fuel.getFuelTime() != null && fuel.getCount() > 0) {
        this.checkFuel(fuel);
    }
    if (burnTime > 0) {
        burnTime--;
        burnDuration = (int) Math.ceil(burnTime / maxTime * 200);
        if (smelt != null && canSmelt) {
            cookTime++;
            if (cookTime >= 200) {
                product = Item.get(smelt.getResult().getId(), smelt.getResult().getDamage(), product.getCount() + 1);
                FurnaceSmeltEvent ev = new FurnaceSmeltEvent(this, raw, product);
                this.server.getPluginManager().callEvent(ev);
                if (!ev.isCancelled()) {
                    this.inventory.setResult(ev.getResult());
                    raw.setCount(raw.getCount() - 1);
                    if (raw.getCount() == 0) {
                        raw = new ItemBlock(new BlockAir(), 0, 0);
                    }
                    this.inventory.setSmelting(raw);
                }
                cookTime -= 200;
            }
        } else if (burnTime <= 0) {
            burnTime = 0;
            cookTime = 0;
            burnDuration = 0;
        } else {
            cookTime = 0;
        }
        ret = true;
    } else {
        if (this.getBlock().getId() == Item.BURNING_FURNACE) {
            this.getLevel().setBlock(this, new BlockFurnace(this.getBlock().getDamage()), true);
        }
        burnTime = 0;
        cookTime = 0;
        burnDuration = 0;
    }
    for (Player player : this.getInventory().getViewers()) {
        int windowId = player.getWindowId(this.getInventory());
        if (windowId > 0) {
            ContainerSetDataPacket pk = new ContainerSetDataPacket();
            pk.windowId = windowId;
            pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_TICK_COUNT;
            ;
            pk.value = cookTime;
            player.dataPacket(pk);
            pk = new ContainerSetDataPacket();
            pk.windowId = windowId;
            pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_LIT_TIME;
            pk.value = burnDuration;
            player.dataPacket(pk);
        }
    }
    this.lastUpdate = System.currentTimeMillis();
    this.timing.stopTiming();
    return ret;
}
Also used : BlockAir(cn.nukkit.block.BlockAir) Item(cn.nukkit.item.Item) BlockFurnace(cn.nukkit.block.BlockFurnace) Player(cn.nukkit.Player) ContainerSetDataPacket(cn.nukkit.network.protocol.ContainerSetDataPacket) FurnaceRecipe(cn.nukkit.inventory.FurnaceRecipe) ItemBlock(cn.nukkit.item.ItemBlock) FurnaceSmeltEvent(cn.nukkit.event.inventory.FurnaceSmeltEvent)

Example 4 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class EntityItem method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    int tickDiff = currentTick - this.lastUpdate;
    if (tickDiff <= 0 && !this.justCreated) {
        return true;
    }
    this.lastUpdate = currentTick;
    this.timing.startTiming();
    boolean hasUpdate = this.entityBaseTick(tickDiff);
    if (this.isAlive()) {
        if (this.pickupDelay > 0 && this.pickupDelay < 32767) {
            this.pickupDelay -= tickDiff;
            if (this.pickupDelay < 0) {
                this.pickupDelay = 0;
            }
        } else {
            for (Entity entity : this.level.getNearbyEntities(this.boundingBox.grow(1, 0.5, 1), this)) {
                if (entity instanceof Player) {
                    if (((Player) entity).pickupEntity(this, true)) {
                        return true;
                    }
                }
            }
        }
        this.motionY -= this.getGravity();
        if (this.checkObstruction(this.x, this.y, this.z)) {
            hasUpdate = true;
        }
        this.move(this.motionX, this.motionY, this.motionZ);
        double friction = 1 - this.getDrag();
        if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) {
            friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor();
        }
        this.motionX *= friction;
        this.motionY *= 1 - this.getDrag();
        this.motionZ *= friction;
        if (this.onGround) {
            this.motionY *= -0.5;
        }
        this.updateMovement();
        if (this.age > 6000) {
            ItemDespawnEvent ev = new ItemDespawnEvent(this);
            this.server.getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                this.age = 0;
            } else {
                this.kill();
                hasUpdate = true;
            }
        }
    }
    this.timing.stopTiming();
    return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001;
}
Also used : Entity(cn.nukkit.entity.Entity) Player(cn.nukkit.Player) ItemDespawnEvent(cn.nukkit.event.entity.ItemDespawnEvent)

Example 5 with Player

use of cn.nukkit.Player in project Nukkit by Nukkit.

the class EntityMinecartAbstract method close.

@Override
public void close() {
    super.close();
    if (linkedEntity instanceof Player) {
        linkedEntity.riding = null;
        linkedEntity = null;
    }
    SmokeParticle particle = new SmokeParticle(this);
    level.addParticle(particle);
}
Also used : Player(cn.nukkit.Player) SmokeParticle(cn.nukkit.level.particle.SmokeParticle)

Aggregations

Player (cn.nukkit.Player)85 TranslationContainer (cn.nukkit.lang.TranslationContainer)24 Entity (cn.nukkit.entity.Entity)13 BlockEntity (cn.nukkit.blockentity.BlockEntity)10 Item (cn.nukkit.item.Item)10 Level (cn.nukkit.level.Level)7 IOException (java.io.IOException)6 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)5 Block (cn.nukkit.block.Block)4 ItemBlock (cn.nukkit.item.ItemBlock)4 BlockAir (cn.nukkit.block.BlockAir)3 EventHandler (cn.nukkit.event.EventHandler)3 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)3 InventoryContentPacket (cn.nukkit.network.protocol.InventoryContentPacket)3 InventorySlotPacket (cn.nukkit.network.protocol.InventorySlotPacket)3 User (me.lucko.luckperms.common.model.User)3 IPlayer (cn.nukkit.IPlayer)2 CommandSender (cn.nukkit.command.CommandSender)2 EntityItem (cn.nukkit.entity.item.EntityItem)2 EntityArrow (cn.nukkit.entity.projectile.EntityArrow)2