Exemplo n.º 1
0
 public BlockMaterial getBlockMaterial(int xx, int yy, int zz) {
   final Vector3f transformed = transform(xx, yy, zz);
   return position
       .getWorld()
       .getBlockMaterial(
           transformed.getFloorX(), transformed.getFloorY(), transformed.getFloorZ());
 }
Exemplo n.º 2
0
 @Override
 public int hashCode() {
   int hash = 5;
   hash = 89 * hash + (min != null ? min.hashCode() : 0);
   hash = 89 * hash + (max != null ? max.hashCode() : 0);
   return hash;
 }
Exemplo n.º 3
0
 public void setBlockMaterial(int xx, int yy, int zz, BlockMaterial material, short data) {
   final Vector3f transformed = transform(xx, yy, zz);
   position
       .getWorld()
       .setBlockMaterial(
           transformed.getFloorX(),
           transformed.getFloorY(),
           transformed.getFloorZ(),
           material,
           data,
           null);
   if (material instanceof Directional) {
     final Directional directional = (Directional) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = directional.getFacing(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       directional.setFacing(
           block,
           BlockFace.fromYaw(
               face.getDirection().getAxesAngleDeg().getY() + rotation.getAxesAngleDeg().getY()));
     }
   } else if (material instanceof Attachable) {
     final Attachable attachable = (Attachable) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = attachable.getAttachedFace(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       attachable.setAttachedFace(
           block,
           BlockFace.fromYaw(
               face.getDirection().getAxesAngleDeg().getY() + rotation.getAxesAngleDeg().getY()),
           null);
     }
   }
 }
Exemplo n.º 4
0
  @Override
  protected void populate(
      CuboidBlockMaterialBuffer blockData, Vector3f chunk, Vector3f originChunk, Random random) {
    if (chunk.getFloorY() < 0 || chunk.getFloorY() >= 120) {
      return;
    }

    if (random.nextInt(5) != 0) {
      return;
    }

    final int numberOfCaves = random.nextInt(random.nextInt(random.nextInt(10) + 1) + 1);

    for (int caveCount = 0; caveCount < numberOfCaves; caveCount++) {
      final Vector3f target =
          new Vector3f(
              chunk.getX() + random.nextInt(16),
              random.nextInt(random.nextInt(120) + 8),
              chunk.getZ() + random.nextInt(16));
      int numberOfSmallCaves = 1;

      if (random.nextInt(4) == 0) {
        generateLargeCaveBranch(blockData, originChunk, target, new Random(random.nextLong()));
        numberOfSmallCaves += random.nextInt(4);
      }

      for (int count = 0; count < numberOfSmallCaves; count++) {
        final double randomHorizontalAngle = random.nextDouble() * Math.PI * 2;
        final double randomVerticalAngle = ((random.nextDouble() - 0.5f) * 2) / 8;
        double horizontalScale = random.nextDouble() * 2 + random.nextDouble();
        generateCaveBranch(
            blockData,
            originChunk,
            target,
            horizontalScale,
            1,
            randomHorizontalAngle,
            randomVerticalAngle,
            0,
            0,
            new Random(random.nextLong()));
      }
    }
  }
Exemplo n.º 5
0
 @Override
 public Iterable<AStarNode> getNeighbours() {
   List<AStarNode> nodes = Lists.newArrayList();
   for (int x = -1; x <= 1; x++) {
     for (int y = -1; y <= 1; y++) {
       for (int z = -1; z <= 1; z++) {
         if (x == 0 && y == 0 && z == 0) {
           continue;
         }
         Vector3f mod = location.add(x, y, z);
         if (mod.equals(location)) {
           continue;
         }
         VectorNode sub = getNewNode(mod);
         if (!isPassable(sub)) {
           continue;
         }
         nodes.add(sub);
       }
     }
   }
   return nodes;
 }
Exemplo n.º 6
0
 public void placeObject(int xx, int yy, int zz, WorldGeneratorObject object) {
   final Vector3f transformed = transform(xx, yy, zz);
   if (object.canPlaceObject(
       position.getWorld(),
       transformed.getFloorX(),
       transformed.getFloorY(),
       transformed.getFloorZ())) {
     object.placeObject(
         position.getWorld(),
         transformed.getFloorX(),
         transformed.getFloorY(),
         transformed.getFloorZ());
   }
 }
Exemplo n.º 7
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null || getClass() != obj.getClass()) {
     return false;
   }
   VectorNode other = (VectorNode) obj;
   if (location == null) {
     if (other.location != null) {
       return false;
     }
   } else if (!location.equals(other.location)) {
     return false;
   }
   return true;
 }
  @Override
  public void onTick(float dt) {
    final Client client = (Client) Spout.getEngine();
    final Transform playerTransform = client.getPlayer().getPhysics().getTransform();
    final PlayerInputState state = client.getPlayer().input();
    final float speed = 50f;
    Vector3f motion = Vector3f.ZERO;
    if (state.getForward()) {
      motion = motion.add(playerTransform.forwardVector().mul(speed * -dt));
    }
    if (state.getBackward()) {
      motion = motion.add(playerTransform.forwardVector().mul(speed * dt));
    }
    if (state.getLeft()) {
      motion = motion.add(playerTransform.rightVector().mul(speed * -dt)); // TODO getLeftVector
    }
    if (state.getRight()) {
      motion = motion.add(playerTransform.rightVector().mul(speed * dt));
    }
    if (state.getJump()) {
      motion = motion.add(playerTransform.upVector().mul(speed * dt));
    }
    if (state.getCrouch()) {
      motion = motion.add(playerTransform.upVector().mul(speed * -dt));
    }

    client
        .getPlayer()
        .getPhysics()
        .setRotation(
            Quaternionf.fromAxesAnglesDeg(
                state.pitch(),
                state.yaw(),
                playerTransform.getRotation().getAxesAngleDeg().getZ()));

    if (!motion.equals(Vector3f.ZERO)) {
      client.getPlayer().getPhysics().translate(motion);
    }
  }
Exemplo n.º 9
0
 boolean at(Vector3f goal) {
   return location.distanceSquared(goal) <= 4;
 }
Exemplo n.º 10
0
 @Override
 public int hashCode() {
   final int prime = 31;
   return prime + ((location == null) ? 0 : location.hashCode());
 }
Exemplo n.º 11
0
 private boolean canPlace() {
   for (int x = start.getFloorX(); x < end.getFloorX(); x++) {
     for (int z = start.getFloorZ(); z < end.getFloorZ(); z++) {
       for (int y = end.getFloorY() + 1; y >= start.getFloorY() - 1; y--) {
         if (blockData.get(chunk.getFloorX() + x, y, chunk.getFloorZ() + z) instanceof Lava) {
           return false;
         }
         if (y != start.getFloorY() - 1
             && x != start.getFloorX()
             && x != end.getFloorX() - 1
             && z != start.getFloorZ()
             && z != end.getFloorZ() - 1) {
           y = start.getFloorY();
         }
       }
     }
   }
   return true;
 }
Exemplo n.º 12
0
 public float distance(VectorNode to) {
   return (float) location.distanceSquared(to.location);
 }
Exemplo n.º 13
0
 public float getZSize() {
   return max.getZ() - min.getZ();
 }
Exemplo n.º 14
0
 public boolean intersects(BoundingBox box) {
   final Vector3f rMax = box.getMax();
   if (rMax.getX() < min.getX() || rMax.getY() < min.getY() || rMax.getZ() < min.getZ()) {
     return false;
   }
   final Vector3f rMin = box.getMin();
   return !(rMin.getX() > max.getX() || rMin.getY() > max.getY() || rMin.getZ() > max.getZ());
 }
Exemplo n.º 15
0
 public float getXSize() {
   return max.getX() - min.getX();
 }
Exemplo n.º 16
0
 public float getYSize() {
   return max.getY() - min.getY();
 }
Exemplo n.º 17
0
 public BoundingBox(Vector3f cornerA, Vector3f cornerB) {
   this.min = cornerA.min(cornerB);
   this.max = cornerA.max(cornerB);
 }
Exemplo n.º 18
0
 public Vector3f getSize() {
   return max.sub(min);
 }
Exemplo n.º 19
0
 public void offsetPosition(Vector3f offset) {
   offsetPosition(offset.getFloorX(), offset.getFloorY(), offset.getFloorZ());
 }
Exemplo n.º 20
0
 public float heuristicDistance(Vector3f goal) {
   return (float) (location.distance(goal) + getBlockCost()) * TIEBREAKER;
 }
Exemplo n.º 21
0
  private void generateCaveBranch(
      CuboidBlockMaterialBuffer blockData,
      Vector3f chunk,
      Vector3f target,
      double horizontalScale,
      double verticalScale,
      double horizontalAngle,
      double verticalAngle,
      int startingNode,
      int nodeAmount,
      Random random) {

    final Vector3f middle = new Vector3f(chunk.getX() + 8, 0, chunk.getZ() + 8);
    double horizontalOffset = 0;
    double verticalOffset = 0;
    random = new Random(random.nextLong());

    if (nodeAmount <= 0) {
      final int size = (OVERLAP - 1) * 16;
      nodeAmount = size - random.nextInt(size / 4);
    }

    final int intersectionNode = random.nextInt(nodeAmount / 2) + nodeAmount / 4;
    final boolean extraVerticalScale = random.nextInt(6) == 0;
    final boolean lastNode;

    if (startingNode == -1) {
      startingNode = nodeAmount / 2;
      lastNode = true;
    } else {
      lastNode = false;
    }

    for (; startingNode < nodeAmount; startingNode++) {
      final double horizontalSize =
          1.5 + TrigMath.sin((float) (startingNode * Math.PI / nodeAmount)) * horizontalScale;
      final double verticalSize = horizontalSize * verticalScale;
      target = target.add(Vector3f.createDirection((float) horizontalAngle, (float) verticalAngle));

      if (extraVerticalScale) {
        verticalAngle *= 0.92;
      } else {
        verticalAngle *= 0.7;
      }

      verticalAngle += verticalOffset * 0.1;
      horizontalAngle += horizontalOffset * 0.1;
      verticalOffset *= 0.9;
      horizontalOffset *= 0.75;
      verticalOffset += (random.nextDouble() - random.nextDouble()) * random.nextDouble() * 2;
      horizontalOffset += (random.nextDouble() - random.nextDouble()) * random.nextDouble() * 4;

      if (!lastNode) {

        if (startingNode == intersectionNode && horizontalScale > 1) {
          generateCaveBranch(
              blockData,
              chunk,
              target,
              random.nextDouble() * 0.5f + 0.5f,
              1,
              horizontalAngle - ((float) Math.PI / 2),
              verticalAngle / 3,
              startingNode,
              nodeAmount,
              new Random(random.nextLong()));
          generateCaveBranch(
              blockData,
              chunk,
              target,
              random.nextDouble() * 0.5f + 0.5f,
              1,
              horizontalAngle + ((float) Math.PI / 2),
              verticalAngle / 3,
              startingNode,
              nodeAmount,
              new Random(random.nextLong()));
          return;
        }

        if (random.nextInt(4) == 0) {
          continue;
        }
      }

      final double xOffset = target.getX() - middle.getX();
      final double zOffset = target.getZ() - middle.getZ();
      final double nodesLeft = nodeAmount - startingNode;
      final double offsetHorizontalScale = horizontalScale + 18;

      if ((xOffset * xOffset + zOffset * zOffset) - nodesLeft * nodesLeft
          > offsetHorizontalScale * offsetHorizontalScale) {
        return;
      }

      if (target.getX() < middle.getX() - 16 - horizontalSize * 2
          || target.getZ() < middle.getZ() - 16 - horizontalSize * 2
          || target.getX() > middle.getX() + 16 + horizontalSize * 2
          || target.getZ() > middle.getZ() + 16 + horizontalSize * 2) {
        continue;
      }

      final Vector3f start =
          new Vector3f(
              GenericMath.floor(target.getX() - horizontalSize) - chunk.getFloorX() - 1,
              GenericMath.floor(target.getY() - verticalSize) - 1,
              GenericMath.floor(target.getZ() - horizontalSize) - chunk.getFloorZ() - 1);
      final Vector3f end =
          new Vector3f(
              GenericMath.floor(target.getX() + horizontalSize) - chunk.getFloorX() + 1,
              GenericMath.floor(target.getY() + verticalSize) + 1,
              GenericMath.floor(target.getZ() + horizontalSize) - chunk.getFloorZ() + 1);
      final NetherCaveNode node =
          new NetherCaveNode(blockData, chunk, start, end, target, verticalSize, horizontalSize);

      if (node.canPlace()) {
        node.place();
      }

      if (lastNode) {
        break;
      }
    }
  }
Exemplo n.º 22
0
 private void place() {
   for (int x = start.getFloorX(); x < end.getFloorX(); x++) {
     final double xOffset = (chunk.getX() + x + 0.5f - target.getX()) / horizontalSize;
     for (int z = start.getFloorZ(); z < end.getFloorZ(); z++) {
       final double zOffset = (chunk.getZ() + z + 0.5f - target.getZ()) / horizontalSize;
       if (xOffset * xOffset + zOffset * zOffset >= 1) {
         continue;
       }
       for (int y = end.getFloorY() - 1; y >= start.getFloorY(); y--) {
         final double yOffset = (y + 0.5f - target.getY()) / verticalSize;
         if (yOffset > -0.7 && xOffset * xOffset + yOffset * yOffset + zOffset * zOffset < 1) {
           final int xx = chunk.getFloorX() + x;
           final int zz = chunk.getFloorZ() + z;
           final BlockMaterial material = blockData.get(xx, y, zz);
           if (material.equals(VanillaMaterials.NETHERRACK)) {
             blockData.set(xx, y, zz, VanillaMaterials.AIR);
           }
         }
       }
     }
   }
 }
Exemplo n.º 23
0
 private static Vector3f clamp(Vector3f point) {
   return new Vector3f(
       GenericMath.clamp(point.getFloorX(), 0, 16),
       GenericMath.clamp(point.getFloorY(), 1, 120),
       GenericMath.clamp(point.getFloorZ(), 0, 16));
 }