@Override
  public void updateTick(World world, int x, int y, int z, Random rand) {

    if (world.isRemote) return;

    int meta = world.getBlockMetadata(x, y, z);
    l:
    if (meta != 0) {
      ForgeDirection dir = ForgeDirection.getOrientation(meta - 1);
      if (world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ).equals(this))
        if (world.getBlockMetadata(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == meta)
          return;
        else break l;
      TileEntity te = world.getTileEntity(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
      if (te instanceof IFactoryLaserSource && ((IFactoryLaserSource) te).canFormBeamFrom(dir))
        return;
      world.setBlockMetadataWithNotify(x, y, z, 0, 0);
    }

    Block upperId = world.getBlock(x, y + 1, z);
    if (!upperId.equals(this)
        && !(world.getTileEntity(x, y + 1, z) instanceof TileEntityLaserDrill)) {
      world.setBlockToAir(x, y, z);
      return;
    }

    Block lowerId = world.getBlock(x, y - 1, z);
    if ((!lowerId.equals(this) || world.getBlockMetadata(x, y - 1, z) != 0)
        && TileEntityLaserDrill.canReplaceBlock(lowerId, world, x, y - 1, z)) {
      world.setBlock(x, y - 1, z, this);
    }
  }
示例#2
0
  // Try to flow into an adjacent block.
  private boolean flowSideways(World world, int x, int y, int z, int xOffset, int zOffset) {
    if (world.getBlock(x, y, z) == BlockQuickSand.instance) {
      // A bit viscous; won't flow into an adjacent quicksand block unless its quicksand level is at
      // least 2 less.
      if (world.getBlockMetadata(x, y, z) < 15
          && (world.isAirBlock(x + xOffset, y, z + zOffset)
              || (world.getBlock(x + xOffset, y, z + zOffset) == BlockQuickSand.instance
                  && getQuicksandLevel(world, x, y, z)
                      > getQuicksandLevel(world, x + xOffset, y, z + zOffset) + 2))) {
        // Only flow one piece of the block sideways, in the given direction.
        int sandAmount = getQuicksandLevel(world, x, y, z);
        int amountFlowed = flowIntoBlock(world, x + xOffset, y, z + zOffset, 1);

        if (amountFlowed > 0) {
          if (sandAmount <= amountFlowed) {
            world.setBlockToAir(x, y, z);
            return true; // This should never happen! But it's here just in case.
          } else {
            world.setBlockMetadataWithNotify(x, y, z, 16 - (sandAmount - amountFlowed), 3);
            return true;
          }
        }
      }
    }
    return false;
  }
  // a Shrubbery is a small tree with a 1 block high fence trunk and 2-4 blocks of leaves.
  public boolean generate(World world, Random random, int locX, int locY, int locZ) {
    this.worldObj = world;
    this.random = random;

    // finds top block for the given x,z position (excluding leaves and grass)
    for (boolean var6 = false;
        (worldObj.isAirBlock(locX, locY, locZ) || world.getBlock(locX, locY, locZ) == Blocks.leaves)
            && locY > 0;
        --locY) ;
    // locY is now the highest solid terrain block

    if (!(world.getBlock(locX, locY, locZ) == Blocks.grass
        || world.getBlock(locX, locY, locZ) == Blocks.dirt)) return false;

    // generates the trunk
    locY++;
    int treeHeight = minHeight + random.nextInt(maxHeight);
    setBlockInWorld(locX, locY, locZ, this.wood, this.woodMeta);

    // generate leaves above trunk
    int leafHeight = random.nextInt(3) + 2;
    for (int i = 1; i < leafHeight; i++) {
      setBlockInWorld(locX, locY + 1, locZ, this.leaves, this.leavesMeta);
    }

    this.worldObj = null;
    return true;
  }
示例#4
0
  private void direction(World world, int x, int y, int z) {
    if (!world.isRemote) {
      Block direction = world.getBlock(x, y, z - 1);
      Block direction1 = world.getBlock(x, y, z + 1);
      Block direction2 = world.getBlock(x - 1, y, z);
      Block direction3 = world.getBlock(x + 1, y, z);
      byte byte0 = 3;

      if (direction.func_149730_j() && direction.func_149730_j()) {
        byte0 = 3;
      }

      if (direction1.func_149730_j() && direction1.func_149730_j()) {
        byte0 = 2;
      }

      if (direction2.func_149730_j() && direction2.func_149730_j()) {
        byte0 = 5;
      }

      if (direction3.func_149730_j() && direction3.func_149730_j()) {
        byte0 = 4;
      }

      world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
    }
  }
示例#5
0
  @SubscribeEvent
  public void onPlayerInteract0(PlayerInteractEvent event) {
    if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
      World world = event.world;
      EntityPlayer player = event.entityPlayer;
      int x = event.x;
      int y = event.y;
      int z = event.z;

      if (world == null || world.isRemote) return;
      if (player.isSneaking()) return;

      if (EtFuturum.enableEnchants) {
        TileEntityEnchantmentTable tile =
            Utils.getTileEntity(world, x, y, z, TileEntityEnchantmentTable.class);
        if (tile != null && world.getBlock(x, y, z) == Blocks.enchanting_table) {
          player.openGui(EtFuturum.instance, GUIsID.ENCHANTING_TABLE, world, x, y, z);
          event.setCanceled(true);
          return;
        }
      }

      if (EtFuturum.enableAnvil)
        if (world.getBlock(x, y, z) == Blocks.anvil) {
          player.openGui(EtFuturum.instance, GUIsID.ANVIL, world, x, y, z);
          event.setCanceled(true);
          return;
        }
    }
  }
 @Override
 public boolean onItemUse(
     ItemStack item,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float par8,
     float par9,
     float par10) {
   if (!ReikaWorldHelper.softBlocks(world.getBlock(x, y, z))) {
     if (side == 0) --y;
     if (side == 1) ++y;
     if (side == 2) --z;
     if (side == 3) ++z;
     if (side == 4) --x;
     if (side == 5) ++x;
   }
   Block idbelow = world.getBlock(x, y - 1, z);
   if ((!ReikaWorldHelper.softBlocks(world.getBlock(x, y, z)))
       || !ReikaPlantHelper.SAPLING.canPlantAt(world, x, y, z)) return false;
   if (!player.canPlayerEdit(x, y, z, 0, item)) return false;
   else {
     if (!player.capabilities.isCreativeMode) --item.stackSize;
     world.setBlock(x, y, z, ChromaBlocks.PLANT.getBlockInstance(), item.getItemDamage() % 16, 3);
     ReikaSoundHelper.playPlaceSound(world, x, y, z, Blocks.grass);
     return true;
   }
 }
 private boolean checkAndBuildWorktable(World world, int x, int y, int z) {
   if (!ReikaWorldHelper.matchWithItemStack(world, x, y - 1, z, ItemStacks.steelblock))
     return false;
   if (world.getBlock(x, y - 2, z) != Blocks.redstone_block) return false;
   for (int i = -1; i <= 1; i++) {
     for (int k = -1; k <= 1; k++) {
       if (i != 0 || k != 0) {
         if (world.getBlock(x + i, y - 1, z + k) != Blocks.brick_block) return false;
         if (!ReikaWorldHelper.matchWithItemStack(
             world, x + i, y - 2, z + k, ReikaItemHelper.stoneDoubleSlab)) return false;
       }
     }
   }
   for (int i = -1; i <= 1; i++) {
     for (int k = -1; k <= 1; k++) {
       world.setBlock(x + i, y - 1, z + k, Blocks.air);
       world.setBlock(x + i, y - 2, z + k, Blocks.air);
     }
   }
   world.setBlock(x, y, z, Blocks.air);
   SoundRegistry.CRAFT.playSoundAtBlock(world, x, y, z);
   world.setBlock(
       x,
       y - 2,
       z,
       MachineRegistry.WORKTABLE.getBlock(),
       MachineRegistry.WORKTABLE.getMachineMetadata(),
       3);
   return true;
 }
  @Override
  public boolean generate(World var1, Random var2, int var3, int var4, int var5) {
    if (var1.getBlock(var3, var4 - 1, var5) != growOn) {
      return false;
    }

    for (int i = 0; i < 4; i++) {
      if (var1.getBlock(var3, var4 + i, var5) != Blocks.air) {
        return false;
      }
    }

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (var1.getBlock(var3 - 1 + i, var4 + 2, var5 - 1 + j) != Blocks.air) {
          return false;
        }
      }
    }

    for (int i = 0; i < 3; i++) {
      var1.setBlock(var3, var4 + i, var5, this.woodId, this.woodMeta, 3);
    }

    setBlockIfEmpty(var3, var4 + 3, var5, this.leavesId, this.leavesMeta, 3, var1);
    setBlockIfEmpty(var3 + 1, var4 + 2, var5, this.leavesId, this.leavesMeta, 3, var1);
    setBlockIfEmpty(var3 - 1, var4 + 2, var5, this.leavesId, this.leavesMeta, 3, var1);
    setBlockIfEmpty(var3, var4 + 2, var5 + 1, this.leavesId, this.leavesMeta, 3, var1);
    setBlockIfEmpty(var3, var4 + 2, var5 - 1, this.leavesId, this.leavesMeta, 3, var1);

    return true;
  }
  public boolean locationIsValidSpawn(World world, int x, int y, int z) {
    int distanceToAir = 0;
    Block check = world.getBlock(x, y, z);

    while (check != Blocks.air) {
      if (distanceToAir > 3) {
        return false;
      }

      distanceToAir++;
      check = world.getBlock(x, y + distanceToAir, z);
    }

    y += distanceToAir - 1;

    Block block = world.getBlock(x, y, z);
    Block blockAbove = world.getBlock(x, y + 1, z);
    Block blockBelow = world.getBlock(x, y - 1, z);

    for (Block validBlock : validBlocks) {
      if (blockAbove != Blocks.air) {
        return false;
      }
      if (block == validBlock) {
        return true;
      } else if (block == Blocks.snow && blockBelow == validBlock) {
        return true;
      }
    }

    return false;
  }
示例#10
0
  /** Gets the nearest empty chunk coordinates for the player to wake up from a bed into. */
  public static ChunkCoordinates getNearestEmptyChunkCoordinates(
      World par0World, int par1, int par2, int par3, int par4) {
    int i1 = par0World.getBlockMetadata(par1, par2, par3);
    int j1 = BlockDirectional.getDirection(i1);

    for (int k1 = 0; k1 <= 1; ++k1) {
      int l1 = par1 - footBlockToHeadBlockMap[j1][0] * k1 - 1;
      int i2 = par3 - footBlockToHeadBlockMap[j1][1] * k1 - 1;
      int j2 = l1 + 2;
      int k2 = i2 + 2;

      for (int l2 = l1; l2 <= j2; ++l2) {
        for (int i3 = i2; i3 <= k2; ++i3) {
          if (World.doesBlockHaveSolidTopSurface(par0World, l2, par2 - 1, i3)
              && !par0World.getBlock(l2, par2, i3).getMaterial().isOpaque()
              && !par0World.getBlock(l2, par2 + 1, i3).getMaterial().isOpaque()) {
            if (par4 <= 0) return new ChunkCoordinates(l2, par2, i3);

            --par4;
          }
        }
      }
    }

    return null;
  }
示例#11
0
  public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int meta) {
    System.out.println("Breaking with " + x + ":" + y + ":" + z);
    if (meta == 0) x--;
    if (meta == 1) {
      x--;
      z--;
    }
    if (meta == 2) z--;
    if (meta == 3) {
      x++;
      z--;
    }
    if (meta == 4) x++;
    if (meta == 5) {
      x++;
      z++;
    }
    if (meta == 6) z++;
    if (meta == 7) {
      x--;
      z++;
    }

    System.out.println("Breaking " + x + ":" + y + ":" + z + ":" + world.getBlock(x, y, z));
    world.getBlock(x, y, z).breakBlock(world, x, y, z, world.getBlock(x, y, z), 0);
  }
示例#12
0
 @Override
 public boolean onItemUseFirst(
     ItemStack stack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!player.isSneaking()) {
     DebugHelper.debug(player, world, x, y, z);
   } else if (world.getBlock(x, y, z) instanceof BlockBush) {
     if (player.isSneaking()) {
       world.getBlock(x, y, z).updateTick(world, x, y, z, world.rand);
     }
   } else {
     if (!world.isRemote) {
       EntityVillager entityvillager = new EntityVillagerFarmer(world, WorldGen.getVillagerId());
       entityvillager.setLocationAndAngles(
           (double) x + 0.5D, (double) y + 1, (double) z + 0.5D, 0.0F, 0.0F);
       world.spawnEntityInWorld(entityvillager);
     }
   }
   return false;
 }
示例#13
0
  private void setDefaultDirection(World world, int x, int y, int z) {
    if (!world.isRemote) {
      Block b1 = world.getBlock(x, y, z - 1);
      Block b2 = world.getBlock(x, y, z + 1);
      Block b3 = world.getBlock(x - 1, y, z);
      Block b4 = world.getBlock(x + 1, y, z);

      byte b0 = 3;

      if (b1.func_149730_j() && !b2.func_149730_j()) {
        b0 = 3;
      }

      if (b2.func_149730_j() && !b1.func_149730_j()) {
        b0 = 2;
      }

      if (b3.func_149730_j() && !b4.func_149730_j()) {
        b0 = 5;
      }

      if (b4.func_149730_j() && !b3.func_149730_j()) {
        b0 = 4;
      }

      world.setBlockMetadataWithNotify(x, y, x, b0, 2);
    }
  }
示例#14
0
  @Override
  @SideOnly(Side.CLIENT)
  public boolean func_150936_a(
      World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
    int i1 = x;
    int j1 = y;
    int k1 = z;
    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block == field_150939_a && meta == 2) return true;
    else {
      if (side == 0) y--;
      if (side == 1) y++;
      if (side == 2) z--;
      if (side == 3) z++;
      if (side == 4) x--;
      if (side == 5) x++;

      Block block1 = world.getBlock(x, y, z);
      return block1 == field_150939_a
          ? true
          : super.func_150936_a(world, i1, j1, k1, side, player, stack);
    }
  }
示例#15
0
  public IInventory func_149951_m(World world, int x, int y, int z) {
    Object object = (TileEntityBlueMateriaChest) world.getTileEntity(x, y, z);

    if (object == null) {
      return null;
    } else if (world.isSideSolid(x, y + 1, z, DOWN)) {
      return null;
    } else if (SittingOcelot(world, x, y, z)) {
      return null;
    } else if (world.getBlock(x - 1, y, z) == this
        && (world.isSideSolid(x - 1, y + 1, z, DOWN) || SittingOcelot(world, x - 1, y, z))) {
      return null;
    } else if (world.getBlock(x + 1, y, z) == this
        && (world.isSideSolid(x + 1, y + 1, z, DOWN) || SittingOcelot(world, x + 1, y, z))) {
      return null;
    } else if (world.getBlock(x, y, z - 1) == this
        && (world.isSideSolid(x, y + 1, z - 1, DOWN) || SittingOcelot(world, x, y, z - 1))) {
      return null;
    } else if (world.getBlock(x, y, z + 1) == this
        && (world.isSideSolid(x, y + 1, z + 1, DOWN) || SittingOcelot(world, x, y, z + 1))) {
      return null;
    } else {
      return (IInventory) object;
    }
  }
示例#16
0
  public void newDay(Collection<TownBuilding> buildings) {
    Set<GatheringLocation> previous = new HashSet(locations);
    locations = new HashSet();

    // Remove all previous locations
    for (GatheringLocation location : previous) {
      World world = DimensionManager.getWorld(location.dimension);
      if (world.getBlock(location.x, location.y, location.z) == location.block) {
        if (world.getBlockMetadata(location.x, location.y, location.z) == location.meta) {
          world.setBlockToAir(location.x, location.y, location.z);
        }
      }
    }

    // Create some new spawn spots based on where we have buildings
    for (TownBuilding building : buildings) {
      World world = DimensionManager.getWorld(building.dimension);
      int placed = 0;
      for (int i = 0; i < 64 && placed < 10; i++) {
        int x = building.xCoord + 32 - world.rand.nextInt(64);
        int y = building.yCoord + 4 - world.rand.nextInt(8);
        int z = building.zCoord + 32 - world.rand.nextInt(64);
        if (world.getBlock(x, y, z) == Blocks.grass
            && world.getBlock(x, y + 1, z).isAir(world, x, y + 1, z)) {
          ItemStack random = getRandomBlock();
          Block block = Block.getBlockFromItem(random.getItem());
          int meta = random.getItemDamage();
          if (world.setBlock(x, y + 1, z, block, meta, 2)) {
            locations.add(new GatheringLocation(block, meta, building.dimension, x, y + 1, z));
            placed++;
          }
        }
      }
    }
  }
示例#17
0
  private void setDispenserDefaultDirection(World par1World, int par2, int par3, int par4) {
    if (!par1World.isRemote) {
      Block l = par1World.getBlock(par2, par3, par4 - 1);
      Block i1 = par1World.getBlock(par2, par3, par4 + 1);
      Block j1 = par1World.getBlock(par2 - 1, par3, par4);
      Block k1 = par1World.getBlock(par2 + 1, par3, par4);
      byte b0 = 3;
      if (l.isOpaqueCube() && !i1.isOpaqueCube()) {
        b0 = 3;
      }

      if (i1.isOpaqueCube() && !l.isOpaqueCube()) {
        b0 = 2;
      }

      if (j1.isOpaqueCube() && !k1.isOpaqueCube()) {
        b0 = 5;
      }

      if (k1.isOpaqueCube() && !j1.isOpaqueCube()) {
        b0 = 4;
      }

      par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
    }
  }
示例#18
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    if (par1World.getBlock(par3, par4, par5).getMaterial() != Material.water) {
      return false;
    } else {
      int var6 = par2Random.nextInt(this.radius - 2) + 2;
      byte var7 = 2;

      for (int var8 = par3 - var6; var8 <= par3 + var6; ++var8) {
        for (int var9 = par5 - var6; var9 <= par5 + var6; ++var9) {
          int var10 = var8 - par3;
          int var11 = var9 - par5;

          if (var10 * var10 + var11 * var11 <= var6 * var6) {
            for (int var12 = par4 - var7; var12 <= par4 + var7; ++var12) {
              Block var13 = par1World.getBlock(var8, var12, var9);

              if (var13 == Blocks.dirt || var13 == Blocks.grass) {
                par1World.setBlock(var8, var12, var9, this.field_150517_a, 0, 2);
              }
            }
          }
        }
      }

      return true;
    }
  }
  private void setDefaultDirection(World world, int x, int y, int z) {

    if (!world.isRemote) {
      Block block1 = world.getBlock(x, y, z - 1);
      Block block2 = world.getBlock(x, y, z + 1);
      Block block3 = world.getBlock(x - 1, y, z);
      Block block4 = world.getBlock(x + 1, y, z);

      byte b = 3;

      if (block1.func_149730_j() && !block2.func_149730_j()) {
        b = 3;
      }
      if (block2.func_149730_j() && !block1.func_149730_j()) {
        b = 2;
      }
      if (block3.func_149730_j() && !block4.func_149730_j()) {
        b = 5;
      }
      if (block4.func_149730_j() && !block3.func_149730_j()) {
        b = 4;
      }

      world.setBlockMetadataWithNotify(x, y, z, b, 2);
    }
  }
示例#20
0
  public boolean generate(World world, Random random, int x, int y, int z) {

    if (!world.blockExists(x, y, z)) {
      return false;
    }

    int i = y;
    while (world.getBlock(x, i, z) != Blocks.stone) {
      if (i > 96) return false; // Don't generate marble over y96
      i++;
      addBlock(x, i, z, 6);
    }
    while ((this.marbleVein.size() > 0) && (this.numberOfBlocks > 0)) {
      List blocksToGenerate = (List) this.marbleVein.removeFirst();
      Integer[] blockToSet = (Integer[]) blocksToGenerate.toArray();
      if (world.getBlock(blockToSet[0], blockToSet[1], blockToSet[2]) == Blocks.stone) {
        world.setBlock(blockToSet[0], blockToSet[1], blockToSet[2], this.block);
        if (blockToSet[3] > 0) {
          searchBlock(world, blockToSet[0], blockToSet[1], blockToSet[2], blockToSet[3] - 1);
        }
        this.numberOfBlocks -= 1;
      }
    }
    return true;
  }
示例#21
0
  private boolean func_150094_e(
      World p_150094_1_, int p_150094_2_, int p_150094_3_, int p_150094_4_) {
    int l = p_150094_1_.getBlockMetadata(p_150094_2_, p_150094_3_, p_150094_4_);
    int i1 = l;

    if (l > 0) {
      for (int j1 = 0; j1 <= 3; ++j1) {
        int k1 = 1 << j1;

        if ((l & k1) != 0
            && !this.func_150093_a(
                p_150094_1_.getBlock(
                    p_150094_2_ + Direction.offsetX[j1],
                    p_150094_3_,
                    p_150094_4_ + Direction.offsetZ[j1]))
            && (p_150094_1_.getBlock(p_150094_2_, p_150094_3_ + 1, p_150094_4_) != this
                || (p_150094_1_.getBlockMetadata(p_150094_2_, p_150094_3_ + 1, p_150094_4_) & k1)
                    == 0)) {
          i1 &= ~k1;
        }
      }
    }

    if (i1 == 0
        && !this.func_150093_a(p_150094_1_.getBlock(p_150094_2_, p_150094_3_ + 1, p_150094_4_))) {
      return false;
    } else {
      if (i1 != l) {
        p_150094_1_.setBlockMetadataWithNotify(p_150094_2_, p_150094_3_, p_150094_4_, i1, 2);
      }

      return true;
    }
  }
  @Override
  public void onBlockAdded(World par1World, int par2, int par3, int par4) {
    super.onBlockAdded(par1World, par2, par3, par4);
    this.unifyAdjacentChests(par1World, par2, par3, par4);
    Block var5 = par1World.getBlock(par2, par3, par4 - 1);
    Block var6 = par1World.getBlock(par2, par3, par4 + 1);
    Block var7 = par1World.getBlock(par2 - 1, par3, par4);
    Block var8 = par1World.getBlock(par2 + 1, par3, par4);

    if (var5 == this) {
      this.unifyAdjacentChests(par1World, par2, par3, par4 - 1);
    }

    if (var6 == this) {
      this.unifyAdjacentChests(par1World, par2, par3, par4 + 1);
    }

    if (var7 == this) {
      this.unifyAdjacentChests(par1World, par2 - 1, par3, par4);
    }

    if (var8 == this) {
      this.unifyAdjacentChests(par1World, par2 + 1, par3, par4);
    }
  }
  @Override
  public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) {
    int var5 = 0;

    if (par1World.getBlock(par2 - 1, par3, par4) == this) {
      ++var5;
    }

    if (par1World.getBlock(par2 + 1, par3, par4) == this) {
      ++var5;
    }

    if (par1World.getBlock(par2, par3, par4 - 1) == this) {
      ++var5;
    }

    if (par1World.getBlock(par2, par3, par4 + 1) == this) {
      ++var5;
    }

    return var5 > 1
        ? false
        : this.isThereANeighborChest(par1World, par2 - 1, par3, par4)
            ? false
            : this.isThereANeighborChest(par1World, par2 + 1, par3, par4)
                ? false
                : this.isThereANeighborChest(par1World, par2, par3, par4 - 1)
                    ? false
                    : !this.isThereANeighborChest(par1World, par2, par3, par4 + 1);
  }
示例#24
0
  @Override
  public boolean onBlockDestroyed(
      ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {

    if (!(entity instanceof EntityPlayer)) {
      return false;
    }
    EntityPlayer player = (EntityPlayer) entity;

    if (block.getBlockHardness(world, x, y, z) != 0.0D) {
      if (isEmpowered(stack) && canHarvestBlock(block, stack)) {
        Material bMat = world.getBlock(x, y, z).getMaterial();
        Block adjBlock = world.getBlock(x, y - 1, z);
        if (adjBlock != null
            && adjBlock.getMaterial() == bMat
            && adjBlock.getBlockHardness(world, x, y - 1, z) != -1) {
          harvestBlock(world, x, y - 1, z, player);
        }
        adjBlock = world.getBlock(x, y + 1, z);
        if (adjBlock != null
            && adjBlock.getMaterial() == bMat
            && adjBlock.getBlockHardness(world, x, y + 1, z) != -1) {
          harvestBlock(world, x, y + 1, z, player);
        }
      }
      if (!player.capabilities.isCreativeMode) {
        useEnergy(stack, false);
      }
    }
    return true;
  }
  /** Called when the block is attempted to be harvested */
  public void onBlockHarvested(World world, int x, int y, int z, int i, EntityPlayer f) {
    if (func_149887_c(i)) {
      if (world.getBlock(x, y - 1, z) == this) {
        if (!f.capabilities.isCreativeMode) {
          int i1 = world.getBlockMetadata(x, y - 1, z);
          int j1 = func_149890_d(i1);

          if (j1 != 3 && j1 != 2) {
            world.func_147480_a(x, y - 1, z, true);
          } else {
            if (!world.isRemote
                && f.getCurrentEquippedItem() != null
                && f.getCurrentEquippedItem().getItem() == Items.shears) {
              this.func_149886_b(world, x, y, z, i1, f);
            }

            world.setBlockToAir(x, y - 1, z);
          }
        } else {
          world.setBlockToAir(x, y - 1, z);
        }
      }
    } else if (f.capabilities.isCreativeMode && world.getBlock(x, y + 1, z) == this) {
      world.setBlock(x, y + 1, z, Blocks.air, 0, 2);
    }

    super.onBlockHarvested(world, x, y, z, i, f);
  }
示例#26
0
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    if (par1World.getBlock(par3, par4, par5).getMaterial() != Material.water) {
      return false;
    } else {
      int l = par2Random.nextInt(this.radius - 2) + 2;
      byte b0 = 2;

      for (int i1 = par3 - l; i1 <= par3 + l; ++i1) {
        for (int j1 = par5 - l; j1 <= par5 + l; ++j1) {
          int k1 = i1 - par3;
          int l1 = j1 - par5;

          if (k1 * k1 + l1 * l1 <= l * l) {
            for (int i2 = par4 - b0; i2 <= par4 + b0; ++i2) {
              Block block = par1World.getBlock(i1, i2, j1);

              if (block == Blocks.dirt || block == Blocks.grass) {
                par1World.setBlock(i1, i2, j1, this.field_150517_a, 0, 2);
              }
            }
          }
        }
      }

      return true;
    }
  }
示例#27
0
  /**
   * Generates Ore in a specific pattern
   *
   * @param only if true only the listed bioms else not the listed Bioms
   */
  public void generateIt(
      Random random,
      int chunkX,
      int chunkZ,
      World world,
      IChunkProvider chunkGenerator,
      IChunkProvider chunkProvider,
      Block ID,
      Block target,
      String[] bioms,
      boolean only,
      int tries) {

    boolean nosucsess;
    int trieCount = 0;
    BiomeGenBase b = world.getBiomeGenForCoords(chunkX, chunkZ);
    int yRandom;
    int zRandom;
    int xRandom;

    if (isBiom(bioms, b.biomeName) == only) {
      do {
        zRandom = random.nextInt(16);
        xRandom = random.nextInt(16);

        int S1 = world.getTopSolidOrLiquidBlock(xRandom + chunkX * 16, zRandom + chunkZ * 16);

        if (S1 > 19) {
          yRandom = random.nextInt(S1 - 19);
        } else {
          yRandom = 2;
        }

        int x = chunkX * 16 + xRandom;
        int y = yRandom;
        int z = chunkZ * 16 + zRandom;

        if (world.getBlock(x, y, z).isReplaceableOreGen(world, x, y, z, target)
            && world.getBlock(x, y - 1, z).isReplaceableOreGen(world, x, y - 1, z, target)
            && world.getBlock(x + 1, y, z).isReplaceableOreGen(world, x, y, z, target)
            && world.getBlock(x + 1, y - 1, z).isReplaceableOreGen(world, x, y, z, target)) {

          world.setBlock(x, y, z, ID);
          world.setBlock(x, y - 1, z, ID);
          world.setBlock(x + 1, y, z, ID);
          world.setBlock(x + 1, y - 1, z, ID);
          nosucsess = false;
          LogHelper.debug(
              "Generated " + ID.getLocalizedName() + " at " + " X: " + x + " Y: " + y + " Z: " + z);
        } else {
          nosucsess = true;
          trieCount++;
          LogHelper.debug("Had no sucess,try :" + trieCount + "/" + tries);
        }

      } while (nosucsess && trieCount < tries);
    }
  }
示例#28
0
  public static Vec3 getFlowVector(World world, int x, int y, int z) {
    if (world.getBlock(x, y, z) instanceof BlockFluidBase)
      return ((BlockFluidBase) world.getBlock(x, y, z)).getFlowVector(world, x, y, z);
    else if (!(world.getBlock(x, y, z) instanceof BlockLiquid))
      return Vec3.createVectorHelper(0, 0, 0);

    BlockLiquid block = (BlockLiquid) world.getBlock(x, y, z);
    Vec3 vec3 = Vec3.createVectorHelper(0.0D, 0.0D, 0.0D);
    Material mat = block.getMaterial();
    int l = getEffectiveFlowDecay(world, x, y, z, mat);

    for (int i1 = 0; i1 < 4; ++i1) {
      int j1 = x;
      int k1 = z;

      if (i1 == 0) j1 = x - 1;
      if (i1 == 1) k1 = z - 1;
      if (i1 == 2) ++j1;
      if (i1 == 3) ++k1;
      int l1 = getEffectiveFlowDecay(world, j1, y, k1, mat);
      int i2;

      if (l1 < 0) {
        if (!world.getBlock(j1, y, k1).getMaterial().blocksMovement()) {
          l1 = getEffectiveFlowDecay(world, j1, y - 1, k1, mat);

          if (l1 >= 0) {
            i2 = l1 - (l - 8);
            vec3 =
                vec3.addVector(
                    (double) ((j1 - x) * i2), (double) ((y - y) * i2), (double) ((k1 - z) * i2));
          }
        }
      } else if (l1 >= 0) {
        i2 = l1 - l;
        vec3 =
            vec3.addVector(
                (double) ((j1 - x) * i2), (double) ((y - y) * i2), (double) ((k1 - z) * i2));
      }
    }

    if (world.getBlockMetadata(x, y, z) >= 8) {
      boolean flag = false;

      if (flag || block.isBlockSolid(world, x, y, z - 1, 2)) flag = true;
      if (flag || block.isBlockSolid(world, x, y, z + 1, 3)) flag = true;
      if (flag || block.isBlockSolid(world, x - 1, y, z, 4)) flag = true;
      if (flag || block.isBlockSolid(world, x + 1, y, z, 5)) flag = true;
      if (flag || block.isBlockSolid(world, x, y + 1, z - 1, 2)) flag = true;
      if (flag || block.isBlockSolid(world, x, y + 1, z + 1, 3)) flag = true;
      if (flag || block.isBlockSolid(world, x - 1, y + 1, z, 4)) flag = true;
      if (flag || block.isBlockSolid(world, x + 1, y + 1, z, 5)) flag = true;
      if (flag) vec3 = vec3.normalize().addVector(0.0D, -6.0D, 0.0D);
    }
    vec3 = vec3.normalize();
    return vec3;
  }
示例#29
0
  @Override
  public void updateEntity(World world, int x, int y, int z, int meta) {
    super.updateTileEntity();
    int temp = (int) (15 * this.getArraySize() * this.getArrayOverallBrightness());
    for (int i = -3; i <= 3; i++) {
      for (int j = -3; j <= 3; j++) {
        if (ConfigRegistry.BLOCKDAMAGE.getState()) {
          ReikaWorldHelper.temperatureEnvironment(world, x + i, y + 1, z + j, Math.min(temp, 1750));
          if (temp >= 1500) {
            this.delete();
            world.setBlock(x, y, z, Blocks.flowing_lava);
          }
        }
        AxisAlignedBB above =
            AxisAlignedBB.getBoundingBox(x + i, y + 1, z + j, x + i + 1, y + 2, z + j + 1);
        List<EntityLivingBase> in = world.getEntitiesWithinAABB(EntityLivingBase.class, above);
        for (EntityLivingBase e : in) {
          if (temp > 400) e.setFire(3);
        }
      }
    }
    if (world.getBlock(x, y - 1, z) == Blocks.air
        || MachineRegistry.getMachine(world, x, y - 1, z) != this.getMachine()) {
      // ReikaJavaLibrary.pConsole("TOWER: "+this.getTowerHeight()+";  SIZE: "+this.getArraySize());
      this.generatePower(world, x, y, z);
    } else {
      write = null;
    }
    if (world.getBlock(x, y + 1, z) != Blocks.air) return;

    mirrorTimer.update();
    if (mirrorTimer.checkCap()) {
      if (solarBlocks.isEmpty()) {
        lightMultiplier = 0;
        solarBlocks.recursiveAdd(world, x, y, z, this.getTileEntityBlockID());
        numberMirrors = solarBlocks.getSize();
        while (solarBlocks.getSize() > 0) {
          Coordinate c = solarBlocks.getNextAndMoveOn();
          MachineRegistry m = MachineRegistry.getMachine(world, c.xCoord, c.yCoord, c.zCoord);
          if (m == MachineRegistry.MIRROR) {
            TileEntityMirror te =
                (TileEntityMirror) world.getTileEntity(c.xCoord, c.yCoord, c.zCoord);
            te.targetloc = new Coordinate(x, y, z);
            float light = te.getLightLevel();
            lightMultiplier += light;
          } else numberMirrors--;
        }
        lightMultiplier /= 15F;
        lightMultiplier /= numberMirrors;
      }
    }

    if (write != null) {
      this.basicPowerReceiver();
    }
  }
示例#30
0
 private boolean canSpawnEnder(World world, int x, int y, int z) {
   if (world.getBlock(x, y, z) == null || world.isAirBlock(x, y, z)) {
     if (world.getBlock(x, y + 1, z) == null || world.isAirBlock(x, y + 1, z)) {
       if (world.getBlock(x, y + 2, z) == null || world.isAirBlock(x, y + 2, z)) {
         return true;
       }
     }
   }
   return false;
 }