Search in sources :

Example 51 with Vector3

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

the class Block method calculateIntercept.

public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) {
    AxisAlignedBB bb = this.getBoundingBox();
    if (bb == null) {
        return null;
    }
    Vector3 v1 = pos1.getIntermediateWithXValue(pos2, bb.getMinX());
    Vector3 v2 = pos1.getIntermediateWithXValue(pos2, bb.getMaxX());
    Vector3 v3 = pos1.getIntermediateWithYValue(pos2, bb.getMinY());
    Vector3 v4 = pos1.getIntermediateWithYValue(pos2, bb.getMaxY());
    Vector3 v5 = pos1.getIntermediateWithZValue(pos2, bb.getMinZ());
    Vector3 v6 = pos1.getIntermediateWithZValue(pos2, bb.getMaxZ());
    if (v1 != null && !bb.isVectorInYZ(v1)) {
        v1 = null;
    }
    if (v2 != null && !bb.isVectorInYZ(v2)) {
        v2 = null;
    }
    if (v3 != null && !bb.isVectorInXZ(v3)) {
        v3 = null;
    }
    if (v4 != null && !bb.isVectorInXZ(v4)) {
        v4 = null;
    }
    if (v5 != null && !bb.isVectorInXY(v5)) {
        v5 = null;
    }
    if (v6 != null && !bb.isVectorInXY(v6)) {
        v6 = null;
    }
    Vector3 vector = v1;
    if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) {
        vector = v2;
    }
    if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) {
        vector = v3;
    }
    if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) {
        vector = v4;
    }
    if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) {
        vector = v5;
    }
    if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) {
        vector = v6;
    }
    if (vector == null) {
        return null;
    }
    int f = -1;
    if (vector == v1) {
        f = 4;
    } else if (vector == v2) {
        f = 5;
    } else if (vector == v3) {
        f = 0;
    } else if (vector == v4) {
        f = 1;
    } else if (vector == v5) {
        f = 2;
    } else if (vector == v6) {
        f = 3;
    }
    return MovingObjectPosition.fromBlock((int) this.x, (int) this.y, (int) this.z, f, vector.add(this.x, this.y, this.z));
}
Also used : AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) Vector3(cn.nukkit.math.Vector3)

Example 52 with Vector3

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

the class BlockButton method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (this.isActivated()) {
        return false;
    }
    this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    this.setDamage(this.getDamage() ^ 0x08);
    this.level.setBlock(this, this, true, false);
    this.level.addSound(this.add(0.5, 0.5, 0.5), Sound.RANDOM_CLICK);
    this.level.scheduleUpdate(this, 30);
    Vector3 pos = getLocation();
    level.updateAroundRedstone(pos, null);
    level.updateAroundRedstone(pos.getSide(getFacing().getOpposite()), null);
    return true;
}
Also used : BlockRedstoneEvent(cn.nukkit.event.block.BlockRedstoneEvent) Vector3(cn.nukkit.math.Vector3)

Example 53 with Vector3

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

the class SetWorldSpawnCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    Level level;
    Vector3 pos;
    if (args.length == 0) {
        if (sender instanceof Player) {
            level = ((Player) sender).getLevel();
            pos = ((Player) sender).round();
        } else {
            sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
            return true;
        }
    } else if (args.length == 3) {
        level = sender.getServer().getDefaultLevel();
        try {
            pos = new Vector3(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
        } catch (NumberFormatException e1) {
            sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
            return true;
        }
    } else {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    level.setSpawnLocation(pos);
    DecimalFormat round2 = new DecimalFormat("##0.00");
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.setworldspawn.success", new String[] { round2.format(pos.x), round2.format(pos.y), round2.format(pos.z) }));
    return true;
}
Also used : Player(cn.nukkit.Player) TranslationContainer(cn.nukkit.lang.TranslationContainer) DecimalFormat(java.text.DecimalFormat) Level(cn.nukkit.level.Level) Vector3(cn.nukkit.math.Vector3)

Example 54 with Vector3

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

the class EntityBoat 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;
    boolean hasUpdate = this.entityBaseTick(tickDiff);
    if (this.isAlive()) {
        super.onUpdate(currentTick);
        this.motionY = (this.level.getBlock(new Vector3(this.x, this.y, this.z)).getBoundingBox() != null || this.isInsideOfWater()) ? getGravity() : -0.08;
        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;
        }
        Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level);
        Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level);
        this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this));
        if (!from.equals(to)) {
            this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
        }
        this.updateMovement();
    }
    return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001;
}
Also used : VehicleUpdateEvent(cn.nukkit.event.vehicle.VehicleUpdateEvent) VehicleMoveEvent(cn.nukkit.event.vehicle.VehicleMoveEvent) Vector3(cn.nukkit.math.Vector3) Location(cn.nukkit.level.Location)

Example 55 with Vector3

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

the class HugeTreesGenerator method growLeavesLayerStrict.

/**
 * grow leaves in a circle with the outsides being within the circle
 */
protected void growLeavesLayerStrict(ChunkManager worldIn, Vector3 layerCenter, int width) {
    int i = width * width;
    for (int j = -width; j <= width + 1; ++j) {
        for (int k = -width; k <= width + 1; ++k) {
            int l = j - 1;
            int i1 = k - 1;
            if (j * j + k * k <= i || l * l + i1 * i1 <= i || j * j + i1 * i1 <= i || l * l + k * k <= i) {
                Vector3 blockpos = layerCenter.add(j, 0, k);
                int id = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z);
                if (id == Block.AIR || id == Block.LEAVES) {
                    this.setBlockAndNotifyAdequately(worldIn, blockpos, this.leavesMetadata);
                }
            }
        }
    }
}
Also used : 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