예제 #1
0
  public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
    int dir = world.getBlockMetadata(i, j, k);

    if (dir == 0) {
      if (!world.isBlockOpaqueCube(i, j, k + 1)) {
        this.breakBlock(world, i, j, k, blockID, dir);
        world.setBlock(i, j, k, 0);
      }
    } else if (dir == 1) {
      if (!world.isBlockOpaqueCube(i - 1, j, k)) {
        this.breakBlock(world, i, j, k, blockID, dir);
        world.setBlock(i, j, k, 0);
      }
    } else if (dir == 2) {
      if (!world.isBlockOpaqueCube(i, j, k - 1)) {
        this.breakBlock(world, i, j, k, blockID, dir);
        world.setBlock(i, j, k, 0);
      }
    } else if (dir == 3) {
      if (!world.isBlockOpaqueCube(i + 1, j, k)) {
        this.breakBlock(world, i, j, k, blockID, dir);
        world.setBlock(i, j, k, 0);
      }
    }
  }
예제 #2
0
 @Override
 public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
   boolean check = false;
   for (int h = -1; h <= 1; h++) {
     for (int g = -1; g <= 1; g++) {
       for (int f = -1; f <= 1; f++) {
         if (world.getBlockId(i + h, j + g, k + f) == blockID
             && world.getBlockMetadata(i + h, j + g, k + f) == world.getBlockMetadata(i, j, k)) {
           check = true;
         }
       }
     }
   }
   if (!check) {
     world.setBlock(i, j, k, 0);
   }
 }
 @Override
 public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
   boolean check = false;
   for (int h = -2; h <= 2; h++) {
     for (int g = -2; g <= 2; g++) {
       for (int f = -2; f <= 2; f++) {
         if (world.getBlockId(i + h, j + g, k + f) == blockID
             && world.getBlockMetadata(i + h, j + g, k + f) == world.getBlockMetadata(i, j, k)) {
           check = true;
         }
       }
     }
   }
   if (!check) {
     world.setBlock(i, j, k, 0);
     dropBlockAsItem_do(world, i, j, k, new ItemStack(Item.itemsList[TFCItems.Logs.itemID], 1, l));
   }
 }
예제 #4
0
  public void SurroundWithLeaves(World world, int i, int j, int k) {
    for (int y = 0; y <= 1; y++) {
      for (int x = 1; x >= -1; x--) {
        for (int z = 1; z >= -1; z--) {
          if (world.getBlockId(i + x, j + y, k + z) == 0
              && (world.getBlockId(i + x, j + y + 1, k + z) == 0
                  || world.getBlockId(i + x, j + y + 2, k + z) == 0)) {
            int meta = world.getBlockMetadata(i, j, k);
            int id =
                meta < 8 ? TFCBlocks.fruitTreeLeaves.blockID : TFCBlocks.fruitTreeLeaves2.blockID;

            if (world.getBlockId(i, j, k) != TFCBlocks.fruitTreeWood.blockID) id = 0;

            world.setBlockAndMetadata(i + x, j + y, k + z, id, world.getBlockMetadata(i, j, k));
          }
        }
      }
    }
  }
예제 #5
0
  /** Ticks the block if it's been scheduled */
  public void updateTick(World world, int x, int y, int z, Random random) {
    // Initialize variables
    int volume = 0;
    int remainder = 0;
    int direction = 0;
    boolean[] optimal = new boolean[4];

    int meta = world.getBlockMetadata(x, y, z);

    // Try to move down
    if (moveToBlock(world, x, y, z, x, y - 1, z)) {
      return;
    }

    // Get optimal flow direction
    optimal = getOptimalFlowDirections(world, x, y, z);

    // Move
    if (optimal[0]) {
      if (!moveToBlock(world, x, y, z, x - 1, y, z))
        if (!moveToBlock(world, x, y, z, x, y, z + 1))
          if (!moveToBlock(world, x, y, z, x, y, z - 1))
            if (!moveToBlock(world, x, y, z, x + 1, y, z)) ;
    } else if (optimal[1]) {
      if (!moveToBlock(world, x, y, z, x + 1, y, z))
        if (!moveToBlock(world, x, y, z, x, y, z + 1))
          if (!moveToBlock(world, x, y, z, x, y, z - 1))
            if (!moveToBlock(world, x, y, z, x - 1, y, z)) ;
    } else if (optimal[2]) {
      if (!moveToBlock(world, x, y, z, x, y, z - 1))
        if (!moveToBlock(world, x, y, z, x - 1, y, z))
          if (!moveToBlock(world, x, y, z, x + 1, y, z))
            if (!moveToBlock(world, x, y, z, x, y, z + 1)) ;
    } else if (optimal[3]) {
      if (!moveToBlock(world, x, y, z, x, y, z + 1))
        if (!moveToBlock(world, x, y, z, x - 1, y, z))
          if (!moveToBlock(world, x, y, z, x + 1, y, z))
            if (!moveToBlock(world, x, y, z, x, y, z - 1)) ;
    }

    //		if (meta == world.getBlockMetadata(x, y, z) && meta > 5)
    //		{
    //		    if(random.nextInt(100) < 10)
    //		    {
    //		        if(meta > 1)
    //		            world.setBlockMetadata(x, y, z, meta-1);
    //		        else
    //		            world.setBlock(x, y, z, 0);
    //		    }
    //		}
  }
예제 #6
0
  /**
   * Returns a boolean array indicating which flow directions are optimal based on each direction's
   * calculated flow cost. Each array index corresponds to one of the four cardinal directions. A
   * value of true indicates the direction is optimal.
   */
  private boolean[] getOptimalFlowDirections(World par1World, int par2, int par3, int par4) {
    int var5;
    int var6;

    for (var5 = 0; var5 < 4; ++var5) {
      this.flowCost[var5] = 1000;
      var6 = par2;
      int var8 = par4;

      if (var5 == 0) {
        var6 = par2 - 1;
      }

      if (var5 == 1) {
        ++var6;
      }

      if (var5 == 2) {
        var8 = par4 - 1;
      }

      if (var5 == 3) {
        ++var8;
      }

      if (!this.blockBlocksFlow(par1World, var6, par3, var8)
          && (par1World.getBlockId(var6, par3, var8) != this.blockID
              || par1World.getBlockMetadata(var6, par3, var8) != 0)) {
        if (!this.blockBlocksFlow(par1World, var6, par3 - 1, var8)) {
          this.flowCost[var5] = 0;
        } else {
          this.flowCost[var5] = this.calculateFlowCost(par1World, var6, par3, var8, 1, var5);
        }
      }
    }

    var5 = this.flowCost[0];

    for (var6 = 1; var6 < 4; ++var6) {
      if (this.flowCost[var6] < var5) {
        var5 = this.flowCost[var6];
      }
    }

    for (var6 = 0; var6 < 4; ++var6) {
      this.isOptimalFlowDirection[var6] = this.flowCost[var6] == var5;
    }

    return this.isOptimalFlowDirection;
  }
예제 #7
0
  @Override
  public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
    int dir = world.getBlockMetadata(i, j, k);

    if (dir == 0) {
      return AxisAlignedBB.getBoundingBox(i + 0.0F, j + 0F, k + 0.85F, i + 1F, j + 1F, k + 1F);
    } else if (dir == 1) {
      return AxisAlignedBB.getBoundingBox(i + 0.0F, j + 0F, k + 0.0F, i + 0.15F, j + 1F, k + 1F);
    } else if (dir == 2) {
      return AxisAlignedBB.getBoundingBox(i + 0.0F, j + 0F, k + 0.00F, i + 1F, j + 1F, k + 0.15F);
    } else if (dir == 3) {
      return AxisAlignedBB.getBoundingBox(i + 0.85F, j + 0F, k + 0.0F, i + 1F, j + 1F, k + 1F);
    }

    return AxisAlignedBB.getBoundingBox(i, j, k, i + 1, j + 1, k + 1);
  }
예제 #8
0
 public boolean onBlockActivated(
     World world,
     int i,
     int j,
     int k,
     EntityPlayer entityplayer,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!world.isRemote) {
     TileEntityToolRack te = (TileEntityToolRack) world.getBlockTileEntity(i, j, k);
     int dir = world.getBlockMetadata(i, j, k);
     if (te != null) {
       if (dir == 0) {
         if (hitX < 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 0, 0);
         } else if (hitX > 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 1, 0);
         } else if (hitX < 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 2, 0);
         } else if (hitX > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 3, 0);
         }
       } else if (dir == 1) {
         if (hitZ < 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 0, 1);
         } else if (hitZ > 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 1, 1);
         } else if (hitZ < 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 2, 1);
         } else if (hitZ > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 3, 1);
         }
       } else if (dir == 2) {
         if (hitX < 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 0, 2);
         } else if (hitX > 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 1, 2);
         } else if (hitX < 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 2, 2);
         } else if (hitX > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 3, 2);
         }
       } else if (dir == 3) {
         if (hitZ < 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 0, 3);
         } else if (hitZ > 0.5 && hitY > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 1, 3);
         } else if (hitZ < 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 2, 3);
         } else if (hitZ > 0.5) {
           handleArea(world, i, j, k, entityplayer, te, 3, 3);
         }
       }
       te.broadcastPacketInRange(te.createUpdatePacket());
       return true;
     }
   }
   return false;
 }
 private boolean checkOut(World world, int i, int j, int k, int l) {
   if (world.getBlockId(i, j, k) == blockID && world.getBlockMetadata(i, j, k) == l) {
     return true;
   }
   return false;
 }
예제 #10
0
 @Override
 public void onBlockDestroyedByExplosion(World world, int i, int j, int k, Explosion ex) {
   ProcessTree(world, i, j, k, world.getBlockMetadata(i, j, k), null);
 }
예제 #11
0
  private boolean moveToBlock(World world, int x, int y, int z, int x2, int y2, int z2) {
    int blockID2 = world.getBlockId(x2, y2, z2);
    int originMeta = world.getBlockMetadata(x, y, z);
    int destMeta = world.getBlockMetadata(x2, y2, z2);
    if (blockID2 == this.blockID) {
      if (destMeta > originMeta || y > y2) {
        if (originMeta < 7 && destMeta > 0) {
          world.setBlockMetadata(x, y, z, originMeta + 1);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else if (destMeta > 0) {
          world.setBlockWithNotify(x, y, z, 0);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } else if (liquidCanDisplaceBlock(world, x2, y2, z2)) {
      if (blockID2 > 0) {
        if (this.blockMaterial == Material.lava) {
          this.triggerLavaMixEffects(world, x2, y2, z2);
        } else if (blockID2 == Block.waterMoving.blockID || blockID2 == Block.waterStill.blockID) {
          if (originMeta < 7) {
            world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
            world.markBlockForUpdate(x, y, z);
            return true;
          } else {
            world.setBlockWithNotify(x, y, z, 0);
            world.markBlockForUpdate(x, y, z);
            return true;
          }
        } else {
          Block.blocksList[blockID2].dropBlockAsItem(
              world, x2, y2, z2, world.getBlockMetadata(x2, y2, z2), 0);
        }
      }

      if (y2 < y) {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, originMeta);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
      if (originMeta < 7) {
        world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      } else if (world.getBlockId(x - 1, y, z) != this.blockID
          && world.getBlockId(x + 1, y, z) != this.blockID
          && world.getBlockId(x, y + 1, z) != this.blockID
          && world.getBlockId(x, y, z - 1) != this.blockID
          && world.getBlockId(x, y, z + 1) != this.blockID) {
        world.setBlockWithNotify(x, y, z, 0);
        return true;
      } else {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
    } else {
      return false;
    }
  }
예제 #12
0
  @Override
  public void updateTick(World world, int i, int j, int k, Random rand) {
    FloraManager manager = FloraManager.getInstance();
    FloraIndex fi = manager.findMatchingIndex(this.getType(world.getBlockMetadata(i, j, k)));

    float temp = TFC_Climate.getHeightAdjustedTemp(i, j, k);

    if (!world.isRemote
        && world.getBlockTileEntity(i, j, k) != null
        && TFC_Time.currentMonth < 6
        && fi != null
        && temp >= fi.minTemp
        && temp < fi.maxTemp) {
      TileEntityFruitTreeWood te = (TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k);
      int t = 1;
      if (TFC_Time.currentMonth < 3) t = 2;

      int leafGrowthRate = 20;
      int trunkGrowTime = 30;
      int branchGrowTime = 20;

      // grow upward
      if (te.birthTimeWood + trunkGrowTime < TFC_Time.totalDays()
          && te.height < 3
          && te.isTrunk
          && rand.nextInt(16 / t) == 0
          && (world.getBlockId(i, j + 1, k) == 0
              || world.getBlockId(i, j + 1, k) == TFCBlocks.fruitTreeLeaves.blockID)) {
        world.setBlockAndMetadata(i, j + 1, k, this.blockID, world.getBlockMetadata(i, j, k));
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setTrunk(true);
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setHeight(te.height + 1);
        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setBirth();

        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(trunkGrowTime);
      } else if (te.birthTimeWood + branchGrowTime < TFC_Time.totalDays()
          && te.height == 2
          && te.isTrunk
          && rand.nextInt(16 / t) == 0
          && world.getBlockId(i, j + 1, k) != blockID) {
        int r = rand.nextInt(4);
        if (r == 0 && world.getBlockId(i + 1, j, k) == 0
            || world.getBlockId(i + 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i + 1, j, k, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setBirth();
        } else if (r == 1 && world.getBlockId(i, j, k - 1) == 0
            || world.getBlockId(i, j, k - 1) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i, j, k - 1, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setBirth();
        } else if (r == 2 && world.getBlockId(i - 1, j, k) == 0
            || world.getBlockId(i - 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i - 1, j, k, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setBirth();
        } else if (r == 3 && world.getBlockId(i, j, k + 1) == 0
            || world.getBlockId(i, j, k + 1) == TFCBlocks.fruitTreeLeaves.blockID) {
          world.setBlockAndMetadata(i, j, k + 1, this.blockID, world.getBlockMetadata(i, j, k));
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setTrunk(false);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setHeight(te.height);
          ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setBirth();
        }

        ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(branchGrowTime);
      } else if (te.birthTimeWood + 1 < TFC_Time.totalDays()
          && rand.nextInt(leafGrowthRate) == 0
          && world.getBlockId(i, j + 2, k) != blockID) {
        if (world.getBlockId(i, j + 1, k) == 0
            && world.getBlockId(i, j + 2, k) == 0
            && BlockFruitLeaves.canStay(
                world, i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID)) // above
        {
          world.setBlockAndMetadata(
              i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j + 1, k);
        } else if (world.getBlockId(i + 1, j, k) == 0
            && world.getBlockId(i + 1, j + 1, k) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // +x
        {
          world.setBlockAndMetadata(
              i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k);
        } else if (world.getBlockId(i - 1, j, k) == 0
            && world.getBlockId(i - 1, j + 1, k) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // -x
        {
          world.setBlockAndMetadata(
              i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k);
        } else if (world.getBlockId(i, j, k + 1) == 0
            && world.getBlockId(i, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +z
        {
          world.setBlockAndMetadata(
              i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j, k + 1);
        } else if (world.getBlockId(i, j, k - 1) == 0
            && world.getBlockId(i, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -z
        {
          world.setBlockAndMetadata(
              i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i, j, k - 1);
        } else if (world.getBlockId(i + 1, j, k - 1) == 0
            && world.getBlockId(i + 1, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/-z
        {
          world.setBlockAndMetadata(
              i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k - 1);
        } else if (world.getBlockId(i + 1, j, k + 1) == 0
            && world.getBlockId(i + 1, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/+z
        {
          world.setBlockAndMetadata(
              i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i + 1, j, k + 1);
        } else if (world.getBlockId(i - 1, j, k - 1) == 0
            && world.getBlockId(i - 1, j + 1, k - 1) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/-z
        {
          world.setBlockAndMetadata(
              i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k - 1);
        } else if (world.getBlockId(i - 1, j, k + 1) == 0
            && world.getBlockId(i - 1, j + 1, k + 1) == 0
            && BlockFruitLeaves.canStay(
                world, i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/+z
        {
          world.setBlockAndMetadata(
              i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k));
          world.markBlockForUpdate(i - 1, j, k + 1);
        }
      }
    }
  }