Search in sources :

Example 16 with Vector3

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

the class ProjectileDispenseBehavior method dispense.

@Override
public void dispense(BlockDispenser source, Item item) {
    Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel());
    CompoundTag nbt = Entity.getDefaultNBT(dispensePos);
    this.correctNBT(nbt);
    BlockFace face = source.getFacing();
    Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt);
    if (projectile == null) {
        return;
    }
    projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6));
    projectile.spawnToAll();
}
Also used : Entity(cn.nukkit.entity.Entity) Position(cn.nukkit.level.Position) BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 17 with Vector3

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

the class EntityLiving method knockBack.

public void knockBack(Entity attacker, double damage, double x, double z, double base) {
    double f = Math.sqrt(x * x + z * z);
    if (f <= 0) {
        return;
    }
    f = 1 / f;
    Vector3 motion = new Vector3(this.motionX, this.motionY, this.motionZ);
    motion.x /= 2d;
    motion.y /= 2d;
    motion.z /= 2d;
    motion.x += x * f * base;
    motion.y += base;
    motion.z += z * f * base;
    if (motion.y > base) {
        motion.y = base;
    }
    this.setMotion(motion);
}
Also used : Vector3(cn.nukkit.math.Vector3)

Example 18 with Vector3

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

the class ParticleCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 7) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Level level;
    if (sender instanceof Player) {
        level = ((Player) sender).getLevel();
    } else {
        level = sender.getServer().getDefaultLevel();
    }
    String name = args[0].toLowerCase();
    float[] floats = new float[6];
    for (int i = 0; i < floats.length; i++) {
        try {
            double d = Double.valueOf(args[i + 1]);
            floats[i] = (float) d;
        } catch (Exception e) {
            return false;
        }
    }
    Vector3 pos = new Vector3(floats[0], floats[1], floats[2]);
    float xd = floats[3];
    float yd = floats[4];
    float zd = floats[5];
    int count = 1;
    if (args.length > 7) {
        try {
            double c = Double.valueOf(args[7]);
            count = (int) c;
        } catch (Exception e) {
        // ignore
        }
    }
    count = Math.max(1, count);
    Integer data = null;
    if (args.length > 8) {
        try {
            double d = Double.valueOf(args[8]);
            data = (int) d;
        } catch (Exception e) {
        // ignore
        }
    }
    Particle particle = this.getParticle(name, pos, xd, yd, zd, data);
    if (particle == null) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.particle.notFound", name));
        return true;
    }
    sender.sendMessage(new TranslationContainer("commands.particle.success", new String[] { name, String.valueOf(count) }));
    Random random = new Random(System.currentTimeMillis());
    for (int i = 0; i < count; i++) {
        particle.setComponents(pos.x + (random.nextFloat() * 2 - 1) * xd, pos.y + (random.nextFloat() * 2 - 1) * yd, pos.z + (random.nextFloat() * 2 - 1) * zd);
        level.addParticle(particle);
    }
    return true;
}
Also used : Player(cn.nukkit.Player) Vector3(cn.nukkit.math.Vector3) Random(java.util.Random) TranslationContainer(cn.nukkit.lang.TranslationContainer) Level(cn.nukkit.level.Level)

Example 19 with Vector3

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

the class EntityEnderPearl method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    this.timing.startTiming();
    boolean hasUpdate = super.onUpdate(currentTick);
    if (this.isCollided && this.shootingEntity instanceof Player) {
        this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL);
        if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0)
            this.shootingEntity.attack(5);
        this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL);
    }
    if (this.age > 1200 || this.isCollided) {
        this.kill();
        hasUpdate = true;
    }
    this.timing.stopTiming();
    return hasUpdate;
}
Also used : Player(cn.nukkit.Player) Vector3(cn.nukkit.math.Vector3)

Example 20 with Vector3

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

the class ContainerInventory method onOpen.

@Override
public void onOpen(Player who) {
    super.onOpen(who);
    ContainerOpenPacket pk = new ContainerOpenPacket();
    pk.windowId = who.getWindowId(this);
    pk.type = this.getType().getNetworkType();
    InventoryHolder holder = this.getHolder();
    if (holder instanceof Vector3) {
        pk.x = (int) ((Vector3) holder).getX();
        pk.y = (int) ((Vector3) holder).getY();
        pk.z = (int) ((Vector3) holder).getZ();
    } else {
        pk.x = pk.y = pk.z = 0;
    }
    who.dataPacket(pk);
    this.sendContents(who);
}
Also used : Vector3(cn.nukkit.math.Vector3) ContainerOpenPacket(cn.nukkit.network.protocol.ContainerOpenPacket)

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