Package org.spout.math.vector

Examples of org.spout.math.vector.Vector3f


    return false;
  }

  @Override
  public float getCost(BlockSource source, PathPoint point) {
    Vector3f pos = point.getVector();
    Material above = source.getMaterialAt(pos.add(UP));
    Material below = source.getMaterialAt(pos.add(DOWN));
    Material in = source.getMaterialAt(pos);
    if (above == VanillaMaterials.WEB || in == VanillaMaterials.WEB) {
      return 1F;
    }
    if (below == VanillaMaterials.SOUL_SAND || below == VanillaMaterials.ICE) {
View Full Code Here


    return contains(materials, VanillaMaterials.WATER, VanillaMaterials.STATIONARY_WATER, VanillaMaterials.LAVA, VanillaMaterials.STATIONARY_LAVA);
  }

  @Override
  public boolean isPassable(BlockSource source, PathPoint point) {
    Vector3f pos = point.getVector();
    Material above = source.getMaterialAt(pos.add(UP));
    Material below = source.getMaterialAt(pos.add(DOWN));
    Material in = source.getMaterialAt(pos);
    if (!(below instanceof BlockMaterial) || !canStandOn(below)) {
      return false;
    }
    return !(!canStandIn(above) || !canStandIn(in));
View Full Code Here

   */
  public ExplosionSlot createSlot(final double dx, final double dy, final double dz) {
    int x = GenericMath.floor(dx * this.index + 0.5);
    int y = GenericMath.floor(dy * this.index + 0.5);
    int z = GenericMath.floor(dz * this.index + 0.5);
    Vector3f pos = new Vector3f(x, y, z);
    ExplosionSlot slot = this.tmpSlotMap.get(pos);
    if (slot == null) {
      slot = new ExplosionSlot(this.model.getBlock(pos));
      this.tmpSlotMap.put(pos, slot);
    }
View Full Code Here

        data = 7;
      }
      // Add +1 to change direction
      if (cause instanceof EntityCause) {
        // set data using direction
        Vector3f direction = block.getPosition().sub((((EntityCause) cause).getSource()).getPhysics().getPosition());
        direction = direction.abs();
        if (direction.getX() > direction.getZ()) {
          data++;
        }
      } else {
        data += (int) Math.round(Math.random());
      }
View Full Code Here

    if (item.getMaterial().equals(VanillaMaterials.TNT)) {
      //Place Activated TNT entity at direction of Dispenser
      if (facingBlock.getMaterial().getShape() != null) {
        World world = facingBlock.getWorld();
        Tnt tnt = world.createEntity(facingBlock.getPosition(), Tnt.class).add(Tnt.class);
        tnt.getOwner().getPhysics().force(new Vector3f(0.5D, 0.5D, 0.5D));
        world.spawnEntity(tnt.getOwner());
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof SpawnEgg) {
      if (facingBlock.getMaterial().getShape() != null) {
        Entity entity = facingBlock.getWorld().createEntity(facingBlock.getPosition(), ((SpawnEgg) item.getMaterial()).getSpawnedComponent());
        entity.getPhysics().translate(new Vector3f(0.5D, 0.5D, 0.5D));
        facingBlock.getWorld().spawnEntity(entity);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof FullBucket) {
      //Attempt to place any FullBucket with it's placement material
      if (facingBlock.getMaterial().getShape() != null) {
        facingBlock.setMaterial(((FullBucket) item.getMaterial()).getPlacedMaterial());
        item.setMaterial(VanillaMaterials.BUCKET);
        //TODO: update physics properly after block has been changed to the liquid
        return true;
      }
    } else if (item.getMaterial().equals(VanillaMaterials.FLINT_AND_STEEL)) {
      if (facingBlock.getMaterial().equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, new BlockCause(block));
        slot.addData(1);
        return true;
      } else {
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(facingBlock, (short) 0, new BlockCause(block))) {
          VanillaMaterials.FIRE.onCreate(facingBlock, (short) 0, new BlockCause(block));
          slot.addData(1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(VanillaMaterials.BUCKET)) {
      if (facingBlock.getMaterial() instanceof Liquid) {
        Liquid liquid = (Liquid) facingBlock.getMaterial();
        if (liquid.isSource(facingBlock)) {
          item.setMaterial(liquid.getContainerMaterial());
          facingBlock.setMaterial(VanillaMaterials.AIR);
          //TODO: physics update necessary here
          return true;
        }
      }
    } else if (item.getMaterial() instanceof Armor) {
      for (Player player : block.getWorld().getNearbyPlayers(block.getPosition(), 2)) {
        if (player.getPhysics().getPosition().getBlock().equals(facingBlock)) {
          PlayerInventory inv = player.get(PlayerInventory.class);
          int armorSlot = ((Armor) item.getMaterial()).getEquipableSlot();
          if (inv.getArmor().get(armorSlot) != null) {
            return false;
          }
          boolean canSet = inv.getArmor().canSet(armorSlot, item);
          InventoryCanSetEvent event = player.getEngine().getEventManager().callEvent(new InventoryCanSetEvent(inv.getArmor(), new BlockCause(block), armorSlot, item, !canSet));
          if (event.isCancelled()) {
            return false;
          }
          inv.getArmor().set(armorSlot, item, true);
          slot.addAmount(-1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(Dye.BONE_MEAL)) {
      if (facingBlock.getMaterial() instanceof Growing && ((Growing) facingBlock.getMaterial()).grow(facingBlock, Dye.BONE_MEAL)) {
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof MinecartItem) {
      if (facingBlock.getMaterial() instanceof RailBase) {
        MinecartItem<?> mineItem = (MinecartItem<?>) item.getMaterial();
        mineItem.spawnEntity(facingBlock, Vector3f.ZERO);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof BoatItem) {
      Point placePos;
      if (facingBlock.getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 1f, .5f);
      } else if (facingBlock.getMaterial().equals(VanillaMaterials.AIR) && facingBlock.translate(BlockFace.BOTTOM).getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 0f, .5f);
      } else {
        return false;
      }
      Boat boat = ((BoatItem) item.getMaterial()).spawnEntity(placePos);
      block.getWorld().spawnEntity(boat.getOwner());
      slot.addAmount(-1);
      return true;
    } else {
      // Try to shoot the item selected if we can't do anything else with it
      final Random rand = GenericMath.getRandom();
      Vector3f direction = this.getFacing(block).getOffset();

      // Calculate position to shoot from
      Point position = block.getPosition().add(direction.mul(0.6));
      VanillaEntityComponent toLaunch = null;

      // Calculate shooting velocity using facing direction
      Vector3f velocity = direction.mul(rand.nextDouble() * 0.1 + 0.2);
      // Set velocity y to above (0.2)
      velocity = velocity.mul(1.0, 0.0, 1.0).add(0.0, 0.2, 0.0);
      velocity = velocity.add(0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian(), 0.045 * rand.nextGaussian());

      Effect shootEffect;
      Material material = item.getMaterial();
      //TODO: Implement the following 'special' shoot cases:
      // - eggs, arrows, fireballs and snowballs
View Full Code Here

    x = rm.convertX((int) Math.floor(pos.getX() * p));
    y = rm.convertY((int) Math.floor(pos.getY() * p));
    z = rm.convertZ((int) Math.floor(pos.getZ() * p));

    double v = 3.9d;
    Vector3f factor = new Vector3f(v, v, v);

    Vector3f velocity;
    if (entity.getPhysics().isActivated()) {
      velocity = entity.getPhysics().getMovementVelocity(); //TODO: Check if it's alright.
    } else {
      velocity = Vector3f.ZERO;
    }

    velocity = velocity.max(factor.mul(-1)).min(factor);

    double s = 8000d;
    speedX = (short) (velocity.getX() * s);
    speedY = (short) (velocity.getY() * s);
    speedZ = (short) (velocity.getZ() * s);

    final Vector3f axesAngles = transform.getRotation().getAxesAngleDeg();
    pitch = (byte) VanillaByteBufUtils.protocolifyPitch(axesAngles.getX());
    yaw = (byte) VanillaByteBufUtils.protocolifyYaw(axesAngles.getY());
  }
View Full Code Here

  }

  public void onInteract(Entity entity, Action type, float mass) {
    super.onInteract(entity, type);
    if (type == Action.RIGHT_CLICK) {
      Substance item = this.spawnEntity(entity, new Vector3f(0, 1.6f, 0));
      PhysicsComponent physics = item.getOwner().getPhysics();
      physics.activate(mass, new SphereShape(1f), false, true);
      if (item instanceof Projectile) {
        ((Projectile) item).setShooter(entity);
      }
View Full Code Here

          continue;
        }
      }
    }

    Vector3f base = material.getBase();
    int baseX = base.getFloorX();
    int baseY = base.getFloorY();
    int baseZ = base.getFloorZ();

    Vector3f top = material.getTop();
    int topX = top.getFloorX();
    int topY = top.getFloorY();
    int topZ = top.getFloorZ();

    IntVector4 v;
    while ((v = fifo.read()) != null) {
      int center = getLightLevel(light, v.getX(), v.getY(), v.getZ());
View Full Code Here

        fifo.write(lightLevel, v.getX(), v.getY(), v.getZ());
        log("(Lower) Set (0) and added to FIFO for ", v, lightLevel);
      }
    }

    Vector3f base = material.getBase();
    int baseX = base.getFloorX();
    int baseY = base.getFloorY();
    int baseZ = base.getFloorZ();

    Vector3f top = material.getTop();
    int topX = top.getFloorX();
    int topY = top.getFloorY();
    int topZ = top.getFloorZ();

    IntVector4 v;
    while ((v = fifo.read()) != null) {
      int center = v.getW();
View Full Code Here

  public abstract void bulkEmittingInitialize(ImmutableCuboidBlockMaterialBuffer buffer, int[][][] light, int[][] height);

  @Override
  public VanillaCuboidLightBuffer[][][] bulkInitialize(ImmutableCuboidBlockMaterialBuffer buffer, int[][] height) {
    Vector3f size = buffer.getSize();

    final int sizeX = size.getFloorX();
    final int sizeY = size.getFloorY();
    final int sizeZ = size.getFloorZ();

    Vector3f base = buffer.getBase();

    final int baseX = base.getFloorX();
    final int baseY = base.getFloorY();
    final int baseZ = base.getFloorZ();

    Vector3f top = buffer.getTop();

    final int topX = top.getFloorX();
    final int topY = top.getFloorY();
    final int topZ = top.getFloorZ();

    // TODO - this should be passed as a input parameter
    //        It still needs to scan the new buffer, since it hasn't been added to the column

    final boolean[][][] dirty = new boolean[sizeX + 2][sizeY + 2][sizeZ + 2];
    final int[][][] newLight = new int[sizeX + 2][sizeY + 2][sizeZ + 2];
    final IntVector3FIFO fifo = new IntVector3FIFO((sizeX + 2) * (sizeY + 2) * (sizeZ + 2));

    bulkEmittingInitialize(buffer, newLight, height);

    // Mark the edges as dirty so they don't get added to the FIFO

    for (int x = 0; x <= sizeX + 1; x++) {
      for (int y = 0; y <= sizeY + 1; y++) {
        dirty[x][y][0] = true;
        dirty[x][y][sizeZ + 1] = true;
      }
    }

    for (int x = 0; x <= sizeX + 1; x++) {
      for (int z = 0; z <= sizeZ + 1; z++) {
        dirty[x][0][z] = true;
        dirty[x][sizeY + 1][z] = true;
      }
    }

    for (int y = 0; y <= sizeY + 1; y++) {
      for (int z = 0; z <= sizeZ + 1; z++) {
        dirty[0][y][z] = true;
        dirty[sizeX + 1][y][z] = true;
      }
    }

    for (int x = 1; x <= sizeX; x++) {
      for (int y = 1; y <= sizeY; y++) {
        for (int z = 1; z <= sizeZ; z++) {
          if (newLight[x][y][z] > 0) {
            fifo.write(x, y, z);
            dirty[x][y][z] = true;
          }
        }
      }
    }

    IntVector3 v;

    while ((v = fifo.read()) != null) {

      int x = v.getX();
      int y = v.getY();
      int z = v.getZ();

      BlockMaterial m = buffer.get(x + baseX - 1, y + baseY - 1, z + baseZ - 1);

      ByteBitSet occulusion = m.getOcclusion(m.getData());

      int center = newLight[x][y][z];

      for (BlockFace face : allFaces) {
        if (occulusion.get(face)) {
          continue;
        }
        IntVector3 off = face.getIntOffset();
        int nx = x + off.getX();
        int ny = y + off.getY();
        int nz = z + off.getZ();
        if (nx <= 0 || nx > sizeX || ny <= 0 || ny > sizeY || nz <= 0 || nz > sizeZ) {
          continue;
        }
        BlockMaterial other = buffer.get(nx + baseX - 1, ny + baseY - 1, nz + baseZ - 1);

        int opacity = other.getOpacity() + 1;

        int newLevel = center - opacity;

        if (newLevel > newLight[nx][ny][nz] && !other.getOcclusion(other.getData()).get(face.getOpposite())) {
          newLight[nx][ny][nz] = newLevel;
          if (!dirty[nx][ny][nz]) {
            dirty[nx][ny][nz] = true;
            fifo.write(nx, ny, nz);
          }
        }
      }
      dirty[x][y][z] = false;
    }

    int cx = sizeX >> Chunk.BLOCKS.BITS;
    int cy = sizeY >> Chunk.BLOCKS.BITS;
    int cz = sizeZ >> Chunk.BLOCKS.BITS;

    VanillaCuboidLightBuffer[][][] lightBufferArray = new VanillaCuboidLightBuffer[cx][cy][cz];

    for (int x = 0; x < cx; x++) {
      for (int y = 0; y < cy; y++) {
        for (int z = 0; z < cz; z++) {

          int shift = Chunk.BLOCKS.BITS;
          int chunkSize = Chunk.BLOCKS.SIZE;

          VanillaCuboidLightBuffer light = newLightBuffer(null, baseX + (cx << shift), baseY + (cy << shift), baseZ + (cz << shift), chunkSize, chunkSize, chunkSize);

          Vector3f lightBase = light.getBase();

          int lightBaseX = lightBase.getFloorX();
          int lightBaseY = lightBase.getFloorY();
          int lightBaseZ = lightBase.getFloorZ();

          int arrayStart = 1 + (z << shift);
          int arrayEnd = arrayStart + chunkSize;

          int xOff = 1 + (x << shift);
View Full Code Here

TOP

Related Classes of org.spout.math.vector.Vector3f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.