Search in sources :

Example 1 with Vector3

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

the class BlockDispenser method getDispensePosition.

public Vector3 getDispensePosition() {
    BlockFace facing = getFacing();
    double x = this.getX() + 0.7 * facing.getXOffset();
    double y = this.getY() + 0.7 * facing.getYOffset();
    double z = this.getZ() + 0.7 * facing.getZOffset();
    return new Vector3(x, y, z);
}
Also used : BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3)

Example 2 with Vector3

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

the class BlockRailActivator method checkSurrounding.

/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    if (power >= 8) {
        return false;
    }
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));
    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }
    Rail.Orientation base = null;
    boolean onStraight = true;
    switch(block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            return false;
    }
    return canPowered(new Vector3(dx, dy, dz), base, power, relative) || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
Also used : Rail(cn.nukkit.utils.Rail) Vector3(cn.nukkit.math.Vector3)

Example 3 with Vector3

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

the class BlockRailPowered method checkSurrounding.

/**
 * Check the surrounding of the rail
 *
 * @param pos      The rail position
 * @param relative The relative of the rail that will be checked
 * @param power    The count of the rail that had been counted
 * @return Boolean of the surrounding area. Where the powered rail on!
 */
protected boolean checkSurrounding(Vector3 pos, boolean relative, int power) {
    // The powered rail can power up to 8 blocks only
    if (power >= 8) {
        return false;
    }
    // The position of the floor numbers
    int dx = pos.getFloorX();
    int dy = pos.getFloorY();
    int dz = pos.getFloorZ();
    // First: get the base block
    BlockRail block;
    Block block2 = level.getBlock(new Vector3(dx, dy, dz));
    // Second: check if the rail is Powered rail
    if (Rail.isRailBlock(block2)) {
        block = (BlockRail) block2;
    } else {
        return false;
    }
    // Used to check if the next ascending rail should be what
    Rail.Orientation base = null;
    boolean onStraight = true;
    // Third: Recalculate the base position
    switch(block.getOrientation()) {
        case STRAIGHT_NORTH_SOUTH:
            if (relative) {
                dz++;
            } else {
                dz--;
            }
            break;
        case STRAIGHT_EAST_WEST:
            if (relative) {
                dx--;
            } else {
                dx++;
            }
            break;
        case ASCENDING_EAST:
            if (relative) {
                dx--;
            } else {
                dx++;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_WEST:
            if (relative) {
                dx--;
                dy++;
                onStraight = false;
            } else {
                dx++;
            }
            base = Rail.Orientation.STRAIGHT_EAST_WEST;
            break;
        case ASCENDING_NORTH:
            if (relative) {
                dz++;
            } else {
                dz--;
                dy++;
                onStraight = false;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        case ASCENDING_SOUTH:
            if (relative) {
                dz++;
                dy++;
                onStraight = false;
            } else {
                dz--;
            }
            base = Rail.Orientation.STRAIGHT_NORTH_SOUTH;
            break;
        default:
            // Wrong rail?
            return false;
    }
    // Next check the if rail is on power state
    return canPowered(new Vector3(dx, dy, dz), base, power, relative) || onStraight && canPowered(new Vector3(dx, dy - 1, dz), base, power, relative);
}
Also used : Rail(cn.nukkit.utils.Rail) Vector3(cn.nukkit.math.Vector3)

Example 4 with Vector3

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

the class BlockFire method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_RANDOM) {
        if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        }
        return Level.BLOCK_UPDATE_NORMAL;
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
        boolean forever = this.down().getId() == Block.NETHERRACK;
        ThreadLocalRandom random = ThreadLocalRandom.current();
        if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        }
        if (!forever && this.getLevel().isRaining() && (this.getLevel().canBlockSeeSky(this) || this.getLevel().canBlockSeeSky(this.east()) || this.getLevel().canBlockSeeSky(this.west()) || this.getLevel().canBlockSeeSky(this.south()) || this.getLevel().canBlockSeeSky(this.north()))) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        } else {
            int meta = this.getDamage();
            if (meta < 15) {
                this.setDamage(meta + random.nextInt(3));
                this.getLevel().setBlock(this, this, true);
            }
            this.getLevel().scheduleUpdate(this, this.tickRate() + random.nextInt(10));
            if (!forever && !this.canNeighborBurn()) {
                if (!this.isBlockTopFacingSurfaceSolid(this.down()) || meta > 3) {
                    this.getLevel().setBlock(this, new BlockAir(), true);
                }
            } else if (!forever && !(this.down().getBurnAbility() > 0) && meta == 15 && random.nextInt(4) == 0) {
                this.getLevel().setBlock(this, new BlockAir(), true);
            } else {
                int o = 0;
                // TODO: decrease the o if the rainfall values are high
                this.tryToCatchBlockOnFire(this.east(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.west(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.down(), 250 + o, meta);
                this.tryToCatchBlockOnFire(this.up(), 250 + o, meta);
                this.tryToCatchBlockOnFire(this.south(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.north(), 300 + o, meta);
                for (int x = (int) (this.x - 1); x <= (int) (this.x + 1); ++x) {
                    for (int z = (int) (this.z - 1); z <= (int) (this.z + 1); ++z) {
                        for (int y = (int) (this.y - 1); y <= (int) (this.y + 4); ++y) {
                            if (x != (int) this.x || y != (int) this.y || z != (int) this.z) {
                                int k = 100;
                                if (y > this.y + 1) {
                                    k += (y - (this.y + 1)) * 100;
                                }
                                Block block = this.getLevel().getBlock(new Vector3(x, y, z));
                                int chance = this.getChanceOfNeighborsEncouragingFire(block);
                                if (chance > 0) {
                                    int t = (chance + 40 + this.getLevel().getServer().getDifficulty() * 7) / (meta + 30);
                                    if (t > 0 && random.nextInt(k) <= t) {
                                        int damage = meta + random.nextInt(5) / 4;
                                        if (damage > 15) {
                                            damage = 15;
                                        }
                                        BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.SPREAD);
                                        this.level.getServer().getPluginManager().callEvent(e);
                                        if (!e.isCancelled()) {
                                            this.getLevel().setBlock(block, new BlockFire(damage), true);
                                            this.getLevel().scheduleUpdate(block, this.tickRate());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Vector3(cn.nukkit.math.Vector3) BlockIgniteEvent(cn.nukkit.event.block.BlockIgniteEvent)

Example 5 with Vector3

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

the class BlockMycelium method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        // TODO: light levels
        NukkitRandom random = new NukkitRandom();
        x = random.nextRange((int) x - 1, (int) x + 1);
        y = random.nextRange((int) y - 1, (int) y + 1);
        z = random.nextRange((int) z - 1, (int) z + 1);
        Block block = this.getLevel().getBlock(new Vector3(x, y, z));
        if (block.getId() == Block.DIRT) {
            if (block.up().isTransparent()) {
                BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium());
                Server.getInstance().getPluginManager().callEvent(ev);
                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(block, ev.getNewState());
                }
            }
        }
    }
    return 0;
}
Also used : BlockSpreadEvent(cn.nukkit.event.block.BlockSpreadEvent) ItemBlock(cn.nukkit.item.ItemBlock) Vector3(cn.nukkit.math.Vector3) NukkitRandom(cn.nukkit.math.NukkitRandom)

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