Exemple #1
0
  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (this.blockMaterial == Material.lava) {
      if (worldIn.getGameRules().getGameRuleBooleanValue("doFireTick")) {
        int var5 = rand.nextInt(3);

        if (var5 > 0) {
          BlockPos var6 = pos;

          for (int var7 = 0; var7 < var5; ++var7) {
            var6 = var6.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1);
            Block var8 = worldIn.getBlockState(var6).getBlock();

            if (var8.blockMaterial == Material.air) {
              if (this.isSurroundingBlockFlammable(worldIn, var6)) {
                worldIn.setBlockState(var6, Blocks.fire.getDefaultState());
                return;
              }
            } else if (var8.blockMaterial.blocksMovement()) {
              return;
            }
          }
        } else {
          for (int var9 = 0; var9 < 3; ++var9) {
            BlockPos var10 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1);

            if (worldIn.isAirBlock(var10.offsetUp()) && this.getCanBlockBurn(worldIn, var10)) {
              worldIn.setBlockState(var10.offsetUp(), Blocks.fire.getDefaultState());
            }
          }
        }
      }
    }
  }
Exemple #2
0
  public static void breakBlock(World world, int x, int y, int z, int forcedLifespan) {
    int blockId = world.getBlockId(x, y, z);

    if (blockId != 0
        && BuildCraftCore.dropBrokenBlocks
        && !world.isRemote
        && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
      List<ItemStack> items =
          Block.blocksList[blockId].getBlockDropped(
              world, x, y, z, world.getBlockMetadata(x, y, z), 0);

      for (ItemStack item : items) {
        float var = 0.7F;
        double dx = world.rand.nextFloat() * var + (1.0F - var) * 0.5D;
        double dy = world.rand.nextFloat() * var + (1.0F - var) * 0.5D;
        double dz = world.rand.nextFloat() * var + (1.0F - var) * 0.5D;
        EntityItem entityitem = new EntityItem(world, x + dx, y + dy, z + dz, item);

        entityitem.lifespan = forcedLifespan;
        entityitem.delayBeforeCanPickup = 10;

        world.spawnEntityInWorld(entityitem);
      }
    }

    world.setBlock(x, y, z, 0);
  }
Exemple #3
0
  /** Remove the tile entity too. */
  @Override
  public void breakBlock(World world, int x, int y, int z, int par5, int par6) {

    if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
      TileEntity te = world.getBlockTileEntity(x, y, z);

      if (te instanceof TileEntityCustomSlab
          && !((TileEntityCustomSlab) te).isConvertingToFullBlock) {
        TileEntityCustomBlock tef = (TileEntityCustomBlock) te;

        for (int i = 0; i < super.quantityDropped(null); i++) {
          ItemStack itemStack =
              createItemStackForSourceBlock(tef.getSourceBlockId(), tef.getSourceBlockMetadata());

          float f = 0.7F;
          double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
          entityitem.delayBeforeCanPickup = 10;
          world.spawnEntityInWorld(entityitem);
        }
      }
    }
    world.removeBlockTileEntity(x, y, z);
  }
  protected boolean neighbourChanged(World world, int x, int y, int z, Block block) {
    if (canPlaceAt(world, x, y, z)) {
      int metadata = world.getBlockMetadata(x, y, z);
      boolean canSupport = true;

      if (!world.isSideSolid(x - 1, y, z, EAST, true) && metadata == 1) {
        canSupport = false;
      } else if (!world.isSideSolid(x + 1, y, z, WEST, true) && metadata == 2) {
        canSupport = false;
      } else if (!world.isSideSolid(x, y, z - 1, SOUTH, true) && metadata == 3) {
        canSupport = false;
      } else if (!world.isSideSolid(x, y, z + 1, NORTH, true) && metadata == 4) {
        canSupport = false;
      } else if (!isSolid(world, x, y - 1, z) && metadata == 5) {
        canSupport = false;
      } else if (!isSolid(world, x, y + 1, z) && metadata == 6) {
        canSupport = false;
      }

      if (!canSupport) {
        if (new Random().nextInt(9) == 0) {
          if (!world.isRemote
              && world.getGameRules().getGameRuleBooleanValue("doTileDrops")
              && !world.restoringBlockSnapshots) // do not drop items while restoring blockstates,
          // prevents item dupe
          {
            float f = 0.7F;
            double motionX = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
            double motionY = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
            double motionZ = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
            EntityItem entityitem =
                new EntityItem(
                    world,
                    x + motionX,
                    y + motionY,
                    z + motionZ,
                    new ItemStack(TFBlocks.energonCrystal));
            entityitem.delayBeforeCanPickup = 10;
            world.spawnEntityInWorld(entityitem);
          }
        } else {
          this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
        }

        world.setBlockToAir(x, y, z);

        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  }
 @Override
 protected void dropBlockAsItem(World world, int x, int y, int z, ItemStack is) {
   if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
     clearStack(world, x, y, z);
     EntityItem ei = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, is);
     ei.motionX = 0;
     ei.motionY = 0;
     ei.motionZ = 0;
     ei.delayBeforeCanPickup = 10;
     world.spawnEntityInWorld(ei);
   }
 }
 @Override
 public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
   if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
     TileEntity te = world.getBlockTileEntity(x, y, z);
     if (!(te instanceof TileCapacitorBank)) {
       super.breakBlock(world, x, y, z, par5, par6);
       return;
     }
     TileCapacitorBank cb = (TileCapacitorBank) te;
     Util.dropItems(world, cb, x, y, z, true);
   }
   world.removeBlockTileEntity(x, y, z);
 }
  /** Block's chance to react to an entity falling on it. */
  public void onFallenUpon(
      World p_149746_1_,
      int p_149746_2_,
      int p_149746_3_,
      int p_149746_4_,
      Entity p_149746_5_,
      float p_149746_6_) {
    if (!p_149746_1_.isRemote && p_149746_1_.rand.nextFloat() < p_149746_6_ - 0.5F) {
      if (!(p_149746_5_ instanceof EntityPlayer)
          && !p_149746_1_.getGameRules().getGameRuleBooleanValue("mobGriefing")) {
        return;
      }

      p_149746_1_.setBlock(p_149746_2_, p_149746_3_, p_149746_4_, TcBlocks.tofuMomen);
    }
  }
 private void handleExplodePacket(ByteBufInputStream dat, World world) {
   try {
     newExplosion(
         world,
         null,
         dat.readDouble(),
         dat.readDouble(),
         dat.readDouble(),
         dat.readFloat(),
         true,
         world.getGameRules().getGameRuleBooleanValue("mobGriefing"));
   } catch (Exception e) {
     e.printStackTrace();
     return;
   }
 }
  @Override
  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (worldIn.getGameRules().getBoolean("doFireTick")) {
      if (!canPlaceBlockAt(worldIn, pos)) worldIn.setBlockToAir(pos);

      if (worldIn.isRaining() && canDie(worldIn, pos)) worldIn.setBlockToAir(pos);
      else {
        int i = state.getValue(AGE).intValue();

        if (i < 4) {
          state = state.withProperty(AGE, Integer.valueOf(i + rand.nextInt(3) / 2));
          worldIn.setBlockState(pos, state, 4);
        }

        worldIn.scheduleUpdate(pos, this, tickRate(worldIn) + rand.nextInt(10));

        if (!canNeighborCatchFire(worldIn, pos)) {
          if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)
              || i > 3) worldIn.setBlockToAir(pos);

          return;
        }

        if (!this.canCatchFire(worldIn, pos.down(), EnumFacing.UP)
            && i >= 4
            && rand.nextInt(4) == 0) {
          worldIn.setBlockToAir(pos);
          return;
        }

        boolean flag1 = worldIn.isBlockinHighHumidity(pos);
        int j = 0;

        if (flag1) j = -50;

        tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST);
        tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST);
        tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP);
        tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN);
        tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH);
        tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH);

        for (int k = -1; k <= 1; ++k)
          for (int l = -1; l <= 1; ++l)
            for (int i1 = -1; i1 <= 4; ++i1)
              if (k != 0 || i1 != 0 || l != 0) {
                int j1 = 100;

                if (i1 > 1) j1 += (i1 - 1) * 100;

                BlockPos blockpos = pos.add(k, i1, l);
                int k1 = getNeighborEncouragement(worldIn, blockpos);

                if (k1 > 0) {
                  int l1 = (k1 + 40 + worldIn.getDifficulty().getDifficultyId() * 7) / (i + 30);

                  if (flag1) l1 /= 2;

                  if (l1 > 0
                      && rand.nextInt(j1) <= l1
                      && (!worldIn.isRaining() || !canDie(worldIn, blockpos))) {
                    int i2 = i + rand.nextInt(5) / 4;

                    if (i2 > 15) i2 = 15;

                    worldIn.setBlockState(
                        blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
                  }
                }
              }
      }
    }
  }
 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
   if (par1World.getGameRules().getGameRuleBooleanValue("doFireTick")) {
     Block base = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
     boolean flag =
         (base != null)
             && (base.isFireSource(
                 par1World,
                 par2,
                 par3 - 1,
                 par4,
                 par1World.getBlockMetadata(par2, par3 - 1, par4),
                 ForgeDirection.UP));
     if (!canPlaceBlockAt(par1World, par2, par3, par4)) {
       par1World.setBlockToAir(par2, par3, par4);
     }
     if ((!flag)
         && (par1World.isRaining())
         && ((par1World.canLightningStrikeAt(par2, par3, par4))
             || (par1World.canLightningStrikeAt(par2 - 1, par3, par4))
             || (par1World.canLightningStrikeAt(par2 + 1, par3, par4))
             || (par1World.canLightningStrikeAt(par2, par3, par4 - 1))
             || (par1World.canLightningStrikeAt(par2, par3, par4 + 1)))) {
       par1World.setBlockToAir(par2, par3, par4);
     } else {
       int l = par1World.getBlockMetadata(par2, par3, par4);
       if (l < 15) {
         par1World.setBlockMetadataWithNotify(par2, par3, par4, l + par5Random.nextInt(3) / 2, 4);
       }
       par1World.scheduleBlockUpdate(
           par2, par3, par4, this.blockID, tickRate(par1World) + par5Random.nextInt(10));
       if ((!flag) && (!canNeighborBurn(par1World, par2, par3, par4))) {
         if ((!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4)) || (l > 3)) {
           par1World.setBlockToAir(par2, par3, par4);
         }
       } else if ((!flag)
           && (!canBlockCatchFire(par1World, par2, par3 - 1, par4, ForgeDirection.UP))
           && (l == 15)
           && (par5Random.nextInt(4) == 0)) {
         par1World.setBlockToAir(par2, par3, par4);
       } else {
         boolean flag1 = par1World.isBlockHighHumidity(par2, par3, par4);
         byte b0 = 0;
         if (flag1) {
           b0 = -50;
         }
         tryToCatchBlockOnFire(
             par1World, par2 + 1, par3, par4, 300 + b0, par5Random, l, ForgeDirection.WEST);
         tryToCatchBlockOnFire(
             par1World, par2 - 1, par3, par4, 300 + b0, par5Random, l, ForgeDirection.EAST);
         tryToCatchBlockOnFire(
             par1World, par2, par3 - 1, par4, 250 + b0, par5Random, l, ForgeDirection.UP);
         tryToCatchBlockOnFire(
             par1World, par2, par3 + 1, par4, 250 + b0, par5Random, l, ForgeDirection.DOWN);
         tryToCatchBlockOnFire(
             par1World, par2, par3, par4 - 1, 300 + b0, par5Random, l, ForgeDirection.SOUTH);
         tryToCatchBlockOnFire(
             par1World, par2, par3, par4 + 1, 300 + b0, par5Random, l, ForgeDirection.NORTH);
         for (int i1 = par2 - 1; i1 <= par2 + 1; i1++) {
           for (int j1 = par4 - 1; j1 <= par4 + 1; j1++) {
             for (int k1 = par3 - 1; k1 <= par3 + 4; k1++) {
               if ((i1 != par2) || (k1 != par3) || (j1 != par4)) {
                 int l1 = 100;
                 if (k1 > par3 + 1) {
                   l1 += (k1 - (par3 + 1)) * 100;
                 }
                 int i2 = getChanceOfNeighborsEncouragingFire(par1World, i1, k1, j1);
                 if (i2 > 0) {
                   int j2 = (i2 + 40 + par1World.difficultySetting * 7) / (l + 30);
                   if (flag1) {
                     j2 /= 2;
                   }
                   if ((j2 > 0)
                       && (par5Random.nextInt(l1) <= j2)
                       && ((!par1World.isRaining())
                           || (!par1World.canLightningStrikeAt(i1, k1, j1)))
                       && (!par1World.canLightningStrikeAt(i1 - 1, k1, par4))
                       && (!par1World.canLightningStrikeAt(i1 + 1, k1, j1))
                       && (!par1World.canLightningStrikeAt(i1, k1, j1 - 1))
                       && (!par1World.canLightningStrikeAt(i1, k1, j1 + 1))) {
                     int k2 = l + par5Random.nextInt(5) / 4;
                     if (k2 > 15) {
                       k2 = 15;
                     }
                     par1World.setBlock(i1, k1, j1, this.blockID, k2, 3);
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }