Package Hexel.blocks.types

Examples of Hexel.blocks.types.BlockWood


    }
    else if (b instanceof BlockStone){
      return BlockStone.Make(newHealth);
    }
    else if (b instanceof BlockWood){
      BlockWood bw = (BlockWood)b;
      return BlockWood.Make(new BlockWoodData(newHealth, bw.data.level, bw.data.branchLevel, bw.data.branches, bw.data.alive));
    }
    else{
      try {
        throw new Exception("can't update health, unknown block type");
View Full Code Here


  private Vector3i tmp3i = new Vector3i();
 
  @Override
  public int run(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
      HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
    BlockWood woodBlock = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, 0, 0, 0, true));
    blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(bx, by, bz, woodBlock, chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
    return BlockSimulator.DONT_RUN;
  }
View Full Code Here

        @Override
        public boolean canApply(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
          BlockWood wb = (BlockWood) b;
          if (!wb.data.alive)
            return false;
          Block nb = chunks.getBlock(bx + neighbor.x, by + neighbor.y, bz + neighbor.z, tmp3i, c);
          if (!(nb instanceof BlockEmpty || nb instanceof BlockLeaf))
            return false;
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
         
          boolean isBranch = nx != bx || ny != by;

          if (nz < bz)
            return false;
          if(wb.data.level < 4 && isBranch)
            return false;
 
          int h = 1;
          h = 31*h + nx;
          h = 31*h + ny;
          h = 31*h + nz;
         
          if (wb.data.level != 0){
            double chanceGrow = 0;
            if (isBranch){
              chanceGrow =   .5*((wb.data.level-wb.data.branchLevel)%2) +
                        .05*(wb.data.level-10)
                       )
                       *(1-wb.data.branchLevel*.25)
                       *(1-wb.data.branches*.25);
            }
            else {
              chanceGrow = 3.0 - .1*wb.data.level*(wb.data.branchLevel*10000+1);
            }
            if (Util.hashToDouble(h) > chanceGrow)
              return false;
          }
         
          return true;
        }

        @Override
        public int probabilisticRun(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          BlockWood wb = (BlockWood) b;
         
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
         
          boolean isBranch = nx != bx || ny != by;
         
          tmp3i.x = nx;
          tmp3i.y = ny;
          tmp3i.z = nz;
          if (blockDeltaAdder.hasBlockDelta(tmp3i)){
            return 1;
          }
          tmp3i.x = bx;
          tmp3i.y = by;
          tmp3i.z = bz;
          if (blockDeltaAdder.hasBlockDelta(tmp3i)){
            return 1;
          }

          BlockWood grownWB;
          BlockWood newWB;
          if (isBranch){
            grownWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level+1, wb.data.branchLevel+1, 0, true));
            newWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level, wb.data.branchLevel, wb.data.branches+1, true));
          }
          else {
            grownWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level+1, wb.data.branchLevel, 0, true));
            newWB = BlockWood.Make(new BlockWoodData(BlockWood.MAX_HEALTH, wb.data.level, wb.data.branchLevel, wb.data.branches, true));
          }
          blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(nx, ny, nz, grownWB, chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
          blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(bx, by, bz, newWB, chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
          return BlockSimulator.DONT_RUN;
        }
      });
//
      //==========LEAFS=========
      woodRules.add(new ProbabilisticFreqBlockRule(500, .5){
       
        @Override
        public boolean canApply(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
          BlockWood wb = (BlockWood) b;
          if (!wb.data.alive)
            return false;
          if(wb.data.level < 4)
            return false;
          if (!(chunks.getBlock(bx + neighbor.x, by + neighbor.y, bz + neighbor.z, tmp3i, c) instanceof BlockEmpty))
            return false;
         
          int nx = bx + neighbor.x;
          int ny = by + neighbor.y;
          int nz = bz + neighbor.z;
 
          int h = 1;
          h = 31*h + nx;
          h = 31*h + ny;
          h = 31*h + nz;
          if (wb.data.level != 0){
            double chanceGrow = 0;
            chanceGrow = Math.min(Math.max(.1*(wb.data.level-5), 0), .75) + Math.min(.5*wb.data.branchLevel, .75);
            if (Util.hashToDouble(h) > chanceGrow)
              return false;
          }
          return true;
        }

        @Override
        public int probabilisticRun(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
            HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
          BlockWood wb = (BlockWood) b;
         
          Vector3i[] neighbors = HexGeometry.getAllNeighbors(bx);
          Vector3i neighbor = neighbors[neighborIndex];
         
          int nx = bx + neighbor.x;
View Full Code Here

TOP

Related Classes of Hexel.blocks.types.BlockWood

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.