Package se.llbit.chunky.world

Examples of se.llbit.chunky.world.Block


        break;
      }

      double pSpecular = 0;

      Block currentBlock = ray.getCurrentBlock();
      Block prevBlock = ray.getPrevBlock();

      if (!scene.stillWater && ray.n.y != 0 &&
          ((currentBlock == Block.WATER && prevBlock == Block.AIR) ||
          (currentBlock == Block.AIR && prevBlock == Block.WATER))) {
View Full Code Here


        workItems * Sizeof.cl_uint2, Pointer.to(buf),
        0, null, null);

    float[] blockColor = new float[256*3];
    for (int j = 0; j < 256; ++j) {
      Block block = Block.get(j);
      float[] color;
      switch (block.id) {
      case Block.LEAVES_ID:
      case Block.GRASS_ID:
      case Block.TALLGRASS_ID:
        color = Biomes.getGrassColorLinear(0);
        System.out.print(String.format("\t0x%08X,", Biomes.getGrassColor(0)));
        break;
      default:
        color = block.getTexture(0).getAvgColorLinear();
        System.out.print(String.format("\t0x%08X,", block.getTexture(0).getAvgColor()));
      }
      if (j > 0 && j % 8 == 0)
        System.out.println();
      blockColor[j*3] = color[0];
      blockColor[j*3 + 1] = color[1];
View Full Code Here

      if (ray.currentMaterial == -1) {
        ray.prevMaterial = 0;
        ray.currentMaterial = node.type;
      }

      Block currentBlock = Block.get(node.type);
      Block prevBlock = Block.get(ray.currentMaterial);

      ray.prevMaterial = ray.currentMaterial;
      ray.currentMaterial = node.type;

View Full Code Here

        ly = y >>> level;
        lz = z >>> level;
        node = node.children[((lx&1)<<2) | ((ly&1)<<1) | (lz&1)];
      }

      Block currentBlock = Block.get(node.type);
      Block prevBlock = Block.get(ray.currentMaterial);

      ray.prevMaterial = ray.currentMaterial;
      ray.currentMaterial = node.type;

      if (currentBlock.localIntersect) {
View Full Code Here

        for (int cz = 0; cz < 16; ++cz) {
          int z = cz + cp.z*16 - origin.z;
          for (int cx = 0; cx < 16; ++cx) {
            int x = cx + cp.x*16 - origin.x;
            int index = Chunk.chunkIndex(cx, cy, cz);
            Block block = Block.get(blocks[index]);

            if (cx > 0 && cx < 15 && cz > 0 && cz < 15 && cy > 0 && cy < 255 &&
                block != Block.STONE && block.isOpaque) {

              // set obscured blocks to stone
              if (Block.get(blocks[index-1]).isOpaque &&
                  Block.get(blocks[index+1]).isOpaque &&
                  Block.get(blocks[index-Chunk.X_MAX]).isOpaque &&
                  Block.get(blocks[index+Chunk.X_MAX]).isOpaque &&
                  Block.get(blocks[index-Chunk.X_MAX*Chunk.Z_MAX]).isOpaque &&
                  Block.get(blocks[index+Chunk.X_MAX*Chunk.Z_MAX]).isOpaque) {
                octree.set(Block.STONE.id, x, cy - origin.y, z);
                continue;
              }
            }

            int metadata = 0xFF & data[index/2];
            metadata >>= (cx % 2) * 4;
            metadata &= 0xF;

            if (block == Block.STATIONARYWATER)
              block = Block.WATER;
            else if (block == Block.STATIONARYLAVA)
              block = Block.LAVA;

            int type = block.id;
            // store metadata
            switch (block.id) {
            case Block.VINES_ID:
              if (cy < 255) {
                // is this the top vine block?
                index = Chunk.chunkIndex(cx, cy+1, cz);
                Block above = Block.get(blocks[index]);
                if (above.isSolid) {
                  type = type | (1<<BlockData.VINE_TOP);
                }
              }
              break;

            case Block.WATER_ID:
              if (cy < 255) {
                // is there water above?
                index = Chunk.chunkIndex(cx, cy+1, cz);
                Block above = Block.get(blocks[index]);
                if (above.isWater()) {
                  type |= (1<<WaterModel.FULL_BLOCK);
                } else if (above == Block.LILY_PAD) {
                  type |= (1<<BlockData.LILY_PAD);
                  long wx = cp.x * 16L + cx;
                  long wy = cy + 1;
                  long wz = cp.z * 16L + cz;
                  long pr = (wx * 3129871L) ^ (wz * 116129781L) ^ (wy);
                  pr = pr * pr * 42317861L + pr * 11L;
                  int dir = 3 & (int)(pr >> 16);
                  type |= (dir<<BlockData.LILY_PAD_ROTATION);
                }
              }
              break;

            case Block.LAVA_ID:
              if (cy < 255) {
                // is there lava above?
                index = Chunk.chunkIndex(cx, cy+1, cz);
                Block above = Block.get(blocks[index]);
                if (above.isLava()) {
                  type = type | (1<<WaterModel.FULL_BLOCK);
                }
              }
              break;

View Full Code Here

          g.drawLine(x0-4, y0, x0+4, y0);
          Ray ray = rayPool.get();
          trace(ray);
          g.setFont(infoFont);
          if (ray.hit) {
            Block block = ray.getCurrentBlock();
            g.drawString(String.format("target: %.2f m", ray.distance), 5, height-18);
            g.drawString(String.format("[0x%08X] %s (%s)",
                ray.currentMaterial,
                block,
                block.description(ray.getBlockData())),
                5, height-5);
          }
          Vector3d pos = camera.getPosition();
          g.drawString(String.format("(%.1f, %.1f, %.1f)",
              pos.x, pos.y, pos.z), 5, 11);
View Full Code Here

  @Override
  public Component getListCellRendererComponent(JList list, Object value,
      int index, boolean isSelected, boolean hasFocus) {

    Block selected = ((Block) value);

    if (isSelected) {
      setBackground(list.getSelectionBackground());
      setForeground(list.getSelectionForeground());
    } else {
      setBackground(list.getBackground());
      setForeground(list.getForeground());
    }

    ImageIcon icon = new ImageIcon(selected.getTexture(0).getImage());
    setIcon(icon);
    setText(selected.toString());
    setFont(list.getFont());

    return this;
  }
View Full Code Here

        }

        // find caves
        int luftspalt = 0;
        for (; y > 1; --y) {
          Block block = Block.get(blocksArray[Chunk.chunkIndex(x, y, z)]);
          if (block.isCave()) {
            y -= 1;
            Block block1 = Block.get(blocksArray[Chunk.chunkIndex(x, y, z)]);
            if (block1.isCave()) {
              luftspalt++;
              y -= 1;
            }
          }
        }
View Full Code Here

        float[] color = new float[4];

        colorloop:
        for (; y >= 0 && color[3] < 1.f;) {
          Block block = Block.get(blocksArray[Chunk.chunkIndex(x, y, z)]);
          float[] blockColor = new float[4];
          int biomeId = 0xFF & biomes[Chunk.chunkXZIndex(x, z)];

          int data = 0xFF & blockData[Chunk.chunkIndex(x, y, z)/2];
          data >>= (x % 2) * 4;
          data &= 0xF;

          switch (block.id) {

          case Block.LEAVES_ID:
          case Block.LEAVES2_ID:
            Color.getRGBComponents(Biomes.getFoliageColor(biomeId), blockColor);
            blockColor[3] = 1.f;// foliage colors don't include alpha

            y -= 1;
            break;

          case Block.GRASS_ID:
          case Block.VINES_ID:
          case Block.TALLGRASS_ID:
            Color.getRGBComponents(Biomes.getGrassColor(biomeId), blockColor);
            blockColor[3] = 1.f;// grass colors don't include alpha

            y -= 1;
            break;

          case Block.ICE_ID:
            Color.getRGBAComponents(block.getTexture(data).getAvgColor(), blockColor);
            color = blend(color, blockColor);
            y -= 1;

            for (; y >= 0; --y) {
              if (Block.get(blocksArray[Chunk.chunkIndex(x, y, z)]).isOpaque) {
                Color.getRGBAComponents(block.getTexture(data).getAvgColor(), blockColor);
                break;
              }
            }
            break;

          case Block.WATER_ID:
          case Block.STATIONARYWATER_ID:
            int depth = 1;
            y -= 1;
            for (; y >= 0; --y) {
              Block block1 = Block.get(blocksArray[Chunk.chunkIndex(x, y, z)]);
              if (!block1.isWater())
                break;
              depth += 1;
            }

            Color.getRGBAComponents(Block.WATER.getTexture(data).getAvgColor(), blockColor);
View Full Code Here

      for (int cz = 0; cz < 16; ++cz) {
        int z = cz + cp.z*16 - origin.z;
        for (int cx = 0; cx < 16; ++cx) {
          int x = cx + cp.x*16 - origin.x;
          int type = octree.get(x, cy, z);
          Block block = Block.get(type);

          // set non-visible blocks to be stone, in order to merge large patches
          if ((cx == 0 || cx == 15 || cz == 0 || cz == 15) &&
              cy > -origin.y && cy < Chunk.Y_MAX-origin.y-1 &&
              block != Block.STONE && block.isOpaque) {
            if (Block.get(octree.get(x-1, cy, z)).isOpaque &&
                Block.get(octree.get(x+1, cy, z)).isOpaque &&
                Block.get(octree.get(x, cy-1, z)).isOpaque &&
                Block.get(octree.get(x, cy+1, z)).isOpaque &&
                Block.get(octree.get(x, cy, z-1)).isOpaque &&
                Block.get(octree.get(x, cy, z+1)).isOpaque) {
              octree.set(Block.STONE.id, x, cy, z);
              continue;
            }
          }

          int fullBlock;
          int data;
          int level0;
          int level;
          int corner0;
          int corner1;
          int corner2;
          int corner3;
          int connections;
          int dir;
          int bd;
          int bd_alt;
          int tex;

          Block other;
          Block other_alt;
          Block above;
          Block west;
          Block east;
          Block north;
          Block south;
          switch (block.id) {
          case Block.LARGE_FLOWER_ID:
            data = type >> BlockData.OFFSET;
            if ((data&8) != 0) {
              // get flower kind from block beneath
              int kind = (octree.get(x, cy-1, z) >> BlockData.OFFSET)&7;
              type = (type & ~(15<<BlockData.OFFSET)) | ( (8|kind) << BlockData.OFFSET);
              octree.set(type, x, cy, z);
            }
            break;
          case Block.WATER_ID:
            fullBlock = (type >> WaterModel.FULL_BLOCK) & 1;
            if (fullBlock != 0) break;

            level0 = 8 - (0xF & (type >> 8));
            corner0 = level0;
            corner1 = level0;
            corner2 = level0;
            corner3 = level0;

            data = octree.get(x-1, cy, z);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner3 += level;
            corner0 += level;

            data = octree.get(x-1, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner0 += level;

            data = octree.get(x, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner0 += level;
            corner1 += level;

            data = octree.get(x+1, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner1 += level;

            data = octree.get(x+1, cy, z);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner1 += level;
            corner2 += level;

            data = octree.get(x+1, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner2 += level;

            data = octree.get(x, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner2 += level;
            corner3 += level;

            data = octree.get(x-1, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.WATER) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner3 += level;

            corner0 = Math.min(7, 8 - (corner0 / 4));
            corner1 = Math.min(7, 8 - (corner1 / 4));
            corner2 = Math.min(7, 8 - (corner2 / 4));
            corner3 = Math.min(7, 8 - (corner3 / 4));
            type |= (corner0 << 16);
            type |= (corner1 << 20);
            type |= (corner2 << 24);
            type |= (corner3 << 28);
            octree.set(type, x, cy, z);
            break;
          case Block.LAVA_ID:
            fullBlock = (type >> WaterModel.FULL_BLOCK) & 1;
            if (fullBlock != 0) break;

            level0 = 8 - (0xF & (type >> 8));
            corner0 = level0;
            corner1 = level0;
            corner2 = level0;
            corner3 = level0;

            data = octree.get(x-1, cy, z);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner3 += level;
            corner0 += level;

            data = octree.get(x-1, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner0 += level;

            data = octree.get(x, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner0 += level;
            corner1 += level;

            data = octree.get(x+1, cy, z+1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner1 += level;

            data = octree.get(x+1, cy, z);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner1 += level;
            corner2 += level;

            data = octree.get(x+1, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner2 += level;

            data = octree.get(x, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner2 += level;
            corner3 += level;

            data = octree.get(x-1, cy, z-1);
            level = level0;
            if (Block.get(data) == Block.LAVA) {
              fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
              level = 8 - (1-fullBlock) * (7 & (data >> 8));
            } else if (!Block.get(data).isSolid) {
              level = 0;
            }
            corner3 += level;

            corner0 = Math.min(7, 8 - (corner0 / 4));
            corner1 = Math.min(7, 8 - (corner1 / 4));
            corner2 = Math.min(7, 8 - (corner2 / 4));
            corner3 = Math.min(7, 8 - (corner3 / 4));
            type |= (corner0 << 16);
            type |= (corner1 << 20);
            type |= (corner2 << 24);
            type |= (corner3 << 28);
            octree.set(type, x, cy, z);
            break;
          case Block.TRIPWIRE_ID:
            other = Block.get(octree.get(x - 1, cy, z));
            if (other == Block.TRIPWIRE || other == Block.TRIPWIREHOOK) {
              type |= 1 << 12;
            } else {
              other = Block.get(octree.get(x + 1, cy, z));
              if (other == Block.TRIPWIRE || other == Block.TRIPWIREHOOK) {
                type |= 1 << 12;
              }
            }
            octree.set(type, x, cy, z);
            break;
          case Block.REDSTONEWIRE_ID:
            above = Block.get(octree.get(x, cy + 1, z));
            west = Block.get(octree.get(x - 1, cy, z));
            east = Block.get(octree.get(x + 1, cy, z));
            north = Block.get(octree.get(x, cy, z - 1));
            south = Block.get(octree.get(x, cy, z + 1));

            if (above == Block.AIR) {
              Block westAbove = Block.get(octree.get(x - 1, cy + 1, z));
              if (west.isSolid && westAbove == Block.REDSTONEWIRE) {
                // wire on west block side
                type |= 1 << BlockData.RSW_WEST_CONNECTION;
                type |= 1 << BlockData.RSW_WEST_SIDE;
              }
              Block eastAbove = Block.get(octree.get(x + 1, cy + 1, z));
              if (east.isSolid && eastAbove == Block.REDSTONEWIRE) {
                // wire on east block side
                type |= 1 << BlockData.RSW_EAST_CONNECTION;
                type |= 1 << BlockData.RSW_EAST_SIDE;
              }
              Block northAbove = Block.get(octree.get(x, cy + 1, z - 1));
              if (north.isSolid && northAbove == Block.REDSTONEWIRE) {
                // wire on north block side
                type |= 1 << BlockData.RSW_NORTH_CONNECTION;
                type |= 1 << BlockData.RSW_NORTH_SIDE;
              }
              Block southAbove = Block.get(octree.get(x, cy + 1, z + 1));
              if (south.isSolid && southAbove == Block.REDSTONEWIRE) {
                // wire on south block side
                type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
                type |= 1 << BlockData.RSW_SOUTH_SIDE;
              }
            }

            if (west.isRedstoneWireConnector()) {
              type |= 1 << BlockData.RSW_WEST_CONNECTION;
            } else if (west == Block.AIR) {
              Block westBelow = Block.get(octree.get(x - 1, cy - 1, z));
              if (westBelow == Block.REDSTONEWIRE) {
                type |= 1 << BlockData.RSW_WEST_CONNECTION;
              }
            }

            if (east.isRedstoneWireConnector()) {
              type |= 1 << BlockData.RSW_EAST_CONNECTION;
            } else if (east == Block.AIR) {
              Block eastBelow = Block.get(octree.get(x + 1, cy - 1, z));
              if (eastBelow == Block.REDSTONEWIRE) {
                type |= 1 << BlockData.RSW_EAST_CONNECTION;
              }
            }

            if (north.isRedstoneWireConnector() || south.isRedstoneWireConnector()) {
              type |= 1 << BlockData.RSW_NORTH_CONNECTION;
            } else if (north == Block.AIR) {
              Block northBelow = Block.get(octree.get(x, cy - 1, z - 1));
              if (northBelow == Block.REDSTONEWIRE) {
                type |= 1 << BlockData.RSW_NORTH_CONNECTION;
              }
            }

            if (south.isRedstoneWireConnector()) {
              type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
            } else if (south == Block.AIR) {
              Block southBelow = Block.get(octree.get(x, cy - 1, z + 1));
              if (southBelow == Block.REDSTONEWIRE) {
                type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
              }
            }

View Full Code Here

TOP

Related Classes of se.llbit.chunky.world.Block

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.