Search in sources :

Example 31 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BlockUpdateScheduler method perform.

private void perform(long tick) {
    try {
        lastTick = tick;
        Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
        if (updates != null) {
            for (BlockUpdateEntry entry : updates) {
                Vector3 pos = entry.pos;
                if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
                    Block block = level.getBlock(entry.pos);
                    if (Block.equals(block, entry.block, false)) {
                        block.onUpdate(level.BLOCK_UPDATE_SCHEDULED);
                    }
                } else {
                    level.scheduleUpdate(entry.block, entry.pos, 0);
                }
            }
        }
    } finally {
        pendingUpdates = null;
    }
}
Also used : BlockUpdateEntry(cn.nukkit.utils.BlockUpdateEntry) Block(cn.nukkit.block.Block) Vector3(cn.nukkit.math.Vector3)

Example 32 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BlockRedstoneDiode method onBreak.

@Override
public boolean onBreak(Item item) {
    Vector3 pos = getLocation();
    this.level.setBlock(this, new BlockAir(), true, true);
    for (BlockFace face : BlockFace.values()) {
        this.level.updateAroundRedstone(pos.getSide(face), null);
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 33 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BlockRedstoneDiode method calculateInputStrength.

protected int calculateInputStrength() {
    BlockFace face = getFacing();
    Vector3 pos = this.getLocation().getSide(face);
    int power = this.level.getRedstonePower(pos, face);
    if (power >= 15) {
        return power;
    } else {
        Block block = this.level.getBlock(pos);
        return Math.max(power, block.getId() == Block.REDSTONE_WIRE ? block.getDamage() : 0);
    }
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 34 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BlockRedstoneDiode method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (!this.isLocked()) {
            Vector3 pos = getLocation();
            boolean shouldBePowered = this.shouldBePowered();
            if (this.isPowered && !shouldBePowered) {
                this.level.setBlock(pos, this.getUnpowered(), true, true);
                this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
            } else if (!this.isPowered) {
                this.level.setBlock(pos, this.getPowered(), true, true);
                this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
                if (!shouldBePowered) {
                    // System.out.println("schedule update 2");
                    level.scheduleUpdate(getPowered(), this, this.getDelay());
                }
            }
        }
    } else if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
        if (type == Level.BLOCK_UPDATE_NORMAL && this.getSide(BlockFace.DOWN).isTransparent()) {
            this.level.useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        } else {
            this.updateState();
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
Also used : Vector3(cn.nukkit.math.Vector3)

Example 35 with Vector3

use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.

the class BlockRedstoneWire method onBreak.

@Override
public boolean onBreak(Item item) {
    this.getLevel().setBlock(this, new BlockAir(), true, true);
    Vector3 pos = getLocation();
    this.updateSurroundingRedstone(false);
    for (BlockFace blockFace : BlockFace.values()) {
        this.level.updateAroundRedstone(pos.getSide(blockFace), null);
    }
    for (BlockFace blockFace : Plane.HORIZONTAL) {
        Vector3 v = pos.getSide(blockFace);
        if (this.level.getBlock(v).isNormalBlock()) {
            this.updateAround(v.up(), BlockFace.DOWN);
        } else {
            this.updateAround(v.down(), BlockFace.UP);
        }
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Aggregations

Vector3 (cn.nukkit.math.Vector3)62 BlockFace (cn.nukkit.math.BlockFace)16 Block (cn.nukkit.block.Block)5 Player (cn.nukkit.Player)3 Entity (cn.nukkit.entity.Entity)3 BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)3 Random (java.util.Random)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 EntityLiving (cn.nukkit.entity.EntityLiving)2 BlockRedstoneEvent (cn.nukkit.event.block.BlockRedstoneEvent)2 BlockSpreadEvent (cn.nukkit.event.block.BlockSpreadEvent)2 VehicleMoveEvent (cn.nukkit.event.vehicle.VehicleMoveEvent)2 VehicleUpdateEvent (cn.nukkit.event.vehicle.VehicleUpdateEvent)2 ItemBlock (cn.nukkit.item.ItemBlock)2 TranslationContainer (cn.nukkit.lang.TranslationContainer)2 Level (cn.nukkit.level.Level)2 Location (cn.nukkit.level.Location)2 AxisAlignedBB (cn.nukkit.math.AxisAlignedBB)2 NukkitRandom (cn.nukkit.math.NukkitRandom)2 Rail (cn.nukkit.utils.Rail)2