示例#1
0
 @Inject(method = "trySpawnGolem", at = @At("HEAD"), cancellable = true)
 private void checkChunkBeforeTrySpawnGolem(World world, BlockPos pos, CallbackInfo callbackInfo) {
   final Chunk chunk = world.getChunkFromBlockCoords(pos);
   if (chunk == null || chunk.isEmpty() || !chunk.isTerrainPopulated()) {
     callbackInfo.cancel();
   }
 }
  private int getFirstUncoveredBlock(World world, int x, int z) {
    int h = world.getChunkFromBlockCoords(x, z).heightMap[(z & 15) << 4 | (x & 15)];

    if (h > 1) {
      return h;
    } else {
      int var3;
      int max = 130;
      boolean solid = false;
      int ah = world.provider.getAverageGroundLevel() - 3;
      for (var3 = 0; var3 < max && !world.canBlockSeeTheSky(x, var3, z); ++var3) {
        if (!solid && world.getBlockId(x, var3, z) != 0) {
          solid = true;
        }
        if ((var3 > 8 && var3 < ah) && solid) {
          var3 = ah;

          if (var3 < 8) {
            var3 = 8;
          }
        }
      }

      if (var3 >= max || !solid) {
        return -1;
      }

      return var3;
    }
  }
 public void setBiome(
     int biome,
     Vector3f loc) { // not quite working yet, the client needs to reload to see the change
   byte[] bytes = new byte[16 * 16];
   for (int i = 0; i < bytes.length; i++) {
     bytes[i] = (byte) biome;
   }
   Chunk chk = _world.getChunkFromBlockCoords((int) loc.getX(), (int) loc.getZ());
   chk.setBiomeArray(bytes);
   chk.setChunkModified();
 }
示例#4
0
  public static int getTopBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z));
    return y;
  }
示例#5
0
  @Override
  public ItemStack onItemRightClick(
      ItemStack itemStack, World world, final EntityPlayer entityPlayer) {

    if (!world.isRemote) {
      return itemStack;
    }

    NBTTagCompound tag = itemStack.getTagCompound();
    boolean tagsSet = tag != null && tag.getBoolean(KEY_IO_SET);

    if (tag != null && tag.getBoolean(KEY_IO_SET)) {

      int x = tag.getInteger(KEY_IO_X);
      int y = tag.getInteger(KEY_IO_Y);
      int z = tag.getInteger(KEY_IO_Z);
      int dimension = tag.getInteger(KEY_DIMENSION);

      if (world.provider.dimensionId != dimension) {
        ChatMessageComponent c =
            ChatMessageComponent.func_111066_d("EnderIO block is in a different dimension.");
        entityPlayer.sendChatToPlayer(c);
        return itemStack;
      }

      Chunk c = world.getChunkFromBlockCoords(x, z);
      if (c == null || !c.isChunkLoaded) {
        ChatMessageComponent cm =
            ChatMessageComponent.func_111066_d("EnderIO block's chunk is not loaded.");
        entityPlayer.sendChatToPlayer(cm);
        return itemStack;
      }
      int blockId = world.getBlockId(x, y, z);
      if (blockId != EnderIO.blockEnderIo.blockID) {
        ChatMessageComponent cm =
            ChatMessageComponent.func_111066_d("EnderIO block has been destroyed.");
        entityPlayer.sendChatToPlayer(cm);
        return itemStack;
      }
      entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_ENDERFACE, world, x, y, z);
      return itemStack;
    }
    ChatMessageComponent cm =
        ChatMessageComponent.func_111066_d(" Enderface not synchronized with EnderIO.");
    entityPlayer.sendChatToPlayer(cm);
    return itemStack;
  }
示例#6
0
  public static int getSurfaceBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z)
        || block.isReplaceable(world, x, y, z)
        || block.isLeaves(world, x, y, z)
        || block.isFoliage(world, x, y, z)
        || block.canBeReplacedByLeaves(world, x, y, z));
    return y;
  }
 @Override
 public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
   if (!world.isRemote) {
     if (entity != null) {
       Chunk chunk =
           world.getChunkFromBlockCoords(
               MathHelper.floor_double(entity.posX), MathHelper.floor_double(entity.posZ));
       int previousDamage = stack.getItemDamage();
       stack.setItemDamage(chunk.getRandomWithSeed(987234911L).nextInt(10) == 0 ? 1 : 0);
       if (previousDamage != stack.getItemDamage() && previousDamage == 0) {
         world.playSoundAtEntity(entity, "openblocks:slimalyzer.signal", 1F, 1F);
       }
     } else {
       stack.setItemDamage(0);
     }
   }
 }
示例#8
0
 @Override
 public void updateMeteorBlockAch(World world) {
   EntityPlayer player = Minecraft.getMinecraft().thePlayer;
   ChunkCoordIntPair chunkCoords =
       world.getChunkFromBlockCoords((int) player.posX, (int) player.posZ).getChunkCoordIntPair();
   List lCoords = MeteorsMod.proxy.meteorHandler.safeChunksWithOwners;
   for (int i = 0; i < lCoords.size(); i++) {
     SafeChunkCoordsIntPair coords = (SafeChunkCoordsIntPair) lCoords.get(i);
     if ((coords.hasCoords(chunkCoords.chunkXPos, chunkCoords.chunkZPos))
         && (coords.getOwner().equalsIgnoreCase(player.username))) {
       Minecraft.getMinecraft()
           .thePlayer
           .addChatMessage("\247a" + LangLocalization.get("MeteorShield.meteorBlocked"));
       Minecraft.getMinecraft().thePlayer.addStat(HandlerAchievement.meteorBlocked, 1);
       break;
     }
   }
 }
  private int getTopBlock(World world, int x, int z) {
    Chunk chunk = world.getChunkFromBlockCoords(x, z);
    int y = chunk.getTopFilledSegment() + 15;

    int trimmedX = x & 15;
    int trimmedZ = z & 15;

    for (; y > 0; --y) {
      Block block = chunk.getBlock(trimmedX, y, trimmedZ);

      if (block.isAir(world, x, y, z)) {
        continue;
      }

      if (block instanceof BlockStaticLiquid) {
        return y;
      }

      if (block instanceof BlockFluidBase) {
        return y;
      }

      if (block instanceof IFluidBlock) {
        return y;
      }

      if (!block.getMaterial().blocksMovement()) {
        continue;
      }

      if (block instanceof BlockFlower) {
        continue;
      }

      return y - 1;
    }

    return -1;
  }
  public void spawnCaves(Vector3f pos, int chunkWidth, boolean addRavines, boolean newGen) {
    final Random rand_new = new Random(_world.rand.nextLong());
    MapGenCaves caves = new MapGenCaves();
    MapGenRavine ravines = new MapGenRavine();
    if (newGen) {
      caves =
          new MapGenCaves() {
            @Override
            public void generate(
                IChunkProvider par1iChunkProvider,
                World par2World,
                int par3,
                int par4,
                byte[] par5ArrayOfByte) {
              this.rand.setSeed(rand_new.nextLong());
              super.generate(par1iChunkProvider, par2World, par3, par4, par5ArrayOfByte);
            }
          };
      ravines =
          new MapGenRavine() {
            @Override
            public void generate(
                IChunkProvider par1iChunkProvider,
                World par2World,
                int par3,
                int par4,
                byte[] par5ArrayOfByte) {
              this.rand.setSeed(rand_new.nextLong());
              super.generate(par1iChunkProvider, par2World, par3, par4, par5ArrayOfByte);
            }
          };
    }
    Chunk baseChunk = _world.getChunkFromBlockCoords((int) pos.getX(), (int) pos.getZ());
    for (int x = baseChunk.xPosition - chunkWidth; x < baseChunk.xPosition + chunkWidth; x++) {
      for (int z = baseChunk.zPosition - chunkWidth; z < baseChunk.zPosition + chunkWidth; z++) {
        byte[] bteArray = new byte[32768]; // this might cause problems
        Arrays.fill(bteArray, (byte) 1);
        caves.generate(_world.getChunkProvider(), _world, x, z, bteArray);
        if (addRavines) {
          ravines.generate(_world.getChunkProvider(), _world, x, z, bteArray);
        }

        Chunk chk = _world.getChunkFromChunkCoords(x, z);

        // for compatability's sake this is based off built in minecraft code after being modifyed
        int var5 = bteArray.length / 256;

        for (int var6 = 0; var6 < 16; ++var6) {
          for (int var7 = 0; var7 < 16; ++var7) {
            for (int var8 = 0; var8 < var5; ++var8) {
              /* FORGE: The following change, a cast from unsigned byte to int,
               * fixes a vanilla bug when generating new chunks that contain a block ID > 127 */
              int var9 = bteArray[var6 << 11 | var7 << 7 | var8] & 0xFF;
              if (var9 != (byte) 1) {
                _world.setBlockWithNotify(
                    var6 + (x * 16),
                    var8,
                    var7 + (z * 16),
                    0); // no lava sorry, covering super flat in lava is not nice
              }
            }
          }
        }
      }
    }
  }
  public void spawnStructure(String type, Vector3f pos) throws ScriptErrorException {
    final Chunk chk = _world.getChunkFromBlockCoords((int) pos.getX(), (int) pos.getZ());
    BiomeGenBase biome = _world.getBiomeGenForCoords((int) pos.getX(), (int) pos.getZ());
    if (type.toLowerCase() == "village") {
      if (MapGenVillage.villageSpawnBiomes instanceof AbstractList) {
        MapGenVillage.villageSpawnBiomes = new ArrayList(MapGenVillage.villageSpawnBiomes);
      }
      boolean added = false;
      if (!MapGenVillage.villageSpawnBiomes.contains(biome)) {
        MapGenVillage.villageSpawnBiomes.add(biome);
        added = true;
      }
      MapGenVillage vilGen =
          new MapGenVillage() {
            @Override
            protected boolean canSpawnStructureAtCoords(int par1, int par2) {
              return par1 == chk.xPosition && par2 == chk.zPosition;
            }
          };
      vilGen.generate(
          _world.getChunkProvider(), _world, chk.xPosition, chk.zPosition, new byte[] {});
      for (int var11 = chk.xPosition - 8; var11 <= chk.xPosition + 8; ++var11) {
        for (int var12 = chk.zPosition - 8; var12 <= chk.zPosition + 8; ++var12) {
          vilGen.generateStructuresInChunk(_world, _world.rand, var11, var12);
        }
      }
      if (added) {
        MapGenVillage.villageSpawnBiomes.remove(biome);
      }
    } else if (type.toLowerCase() == "stronghold") {
      if (MapGenStronghold.allowedBiomes instanceof AbstractList) {
        MapGenStronghold.allowedBiomes = new ArrayList(MapGenStronghold.allowedBiomes);
      }
      boolean added = false;
      if (!MapGenStronghold.allowedBiomes.contains(biome)) {
        MapGenStronghold.allowedBiomes.add(biome);
        added = true;
      }
      MapGenStronghold strGen =
          new MapGenStronghold() {
            @Override
            protected boolean canSpawnStructureAtCoords(int par1, int par2) {
              return par1 == chk.xPosition && par2 == chk.zPosition;
            }

            @Override
            protected List getCoordList() {
              return new ArrayList();
            }
          };
      strGen.generate(
          _world.getChunkProvider(), _world, chk.xPosition, chk.zPosition, new byte[] {});
      for (int var11 = chk.xPosition - 8; var11 <= chk.xPosition + 8; ++var11) {
        for (int var12 = chk.zPosition - 8; var12 <= chk.zPosition + 8; ++var12) {
          strGen.generateStructuresInChunk(_world, _world.rand, var11, var12);
        }
      }
      if (added) {
        MapGenStronghold.allowedBiomes.remove(biome);
      }
    } else if (type.toLowerCase() == "netherfort") {
      MapGenNetherBridge strGen =
          new MapGenNetherBridge() {
            @Override
            protected boolean canSpawnStructureAtCoords(int par1, int par2) {
              return par1 == chk.xPosition && par2 == chk.zPosition;
            }

            @Override
            protected List getCoordList() {
              return new ArrayList();
            }
          };
      strGen.generate(
          _world.getChunkProvider(), _world, chk.xPosition, chk.zPosition, new byte[] {});
      for (int var11 = chk.xPosition - 8; var11 <= chk.xPosition + 8; ++var11) {
        for (int var12 = chk.zPosition - 8; var12 <= chk.zPosition + 8; ++var12) {
          strGen.generateStructuresInChunk(_world, _world.rand, var11, var12);
        }
      }
    } else {
      // no mineshafts sorry, it has the bad tendancy to crash the client
      throw new ScriptErrorException("type needs to be village, stronghold or mineshaft");
    }
  }
示例#12
0
  public static int getHighestY(World world, int x, int z) {

    return world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;
  }
示例#13
0
  public void updateMapData(World par1World, Entity par2Entity, MapData par3MapData) {
    if (par1World.provider.dimensionId == par3MapData.dimension
        && par2Entity instanceof EntityPlayer) {
      int var4 = 1 << par3MapData.scale;
      int var5 = par3MapData.xCenter;
      int var6 = par3MapData.zCenter;
      int var7 = MathHelper.floor_double(par2Entity.posX - (double) var5) / var4 + 64;
      int var8 = MathHelper.floor_double(par2Entity.posZ - (double) var6) / var4 + 64;
      int var9 = 128 / var4;

      if (par1World.provider.hasNoSky) {
        var9 /= 2;
      }

      MapData.MapInfo var10 = par3MapData.func_82568_a((EntityPlayer) par2Entity);
      ++var10.field_82569_d;

      for (int var11 = var7 - var9 + 1; var11 < var7 + var9; ++var11) {
        if ((var11 & 15) == (var10.field_82569_d & 15)) {
          int var12 = 255;
          int var13 = 0;
          double var14 = 0.0D;

          for (int var16 = var8 - var9 - 1; var16 < var8 + var9; ++var16) {
            if (var11 >= 0 && var16 >= -1 && var11 < 128 && var16 < 128) {
              int var17 = var11 - var7;
              int var18 = var16 - var8;
              boolean var19 = var17 * var17 + var18 * var18 > (var9 - 2) * (var9 - 2);
              int var20 = (var5 / var4 + var11 - 64) * var4;
              int var21 = (var6 / var4 + var16 - 64) * var4;
              HashMultiset var22 = HashMultiset.create();
              Chunk var23 = par1World.getChunkFromBlockCoords(var20, var21);

              if (!var23.isEmpty()) {
                int var24 = var20 & 15;
                int var25 = var21 & 15;
                int var26 = 0;
                double var27 = 0.0D;
                int var29;

                if (par1World.provider.hasNoSky) {
                  var29 = var20 + var21 * 231871;
                  var29 = var29 * var29 * 31287121 + var29 * 11;

                  if ((var29 >> 20 & 1) == 0) {
                    var22.add(Blocks.dirt.getMapColor(0), 10);
                  } else {
                    var22.add(Blocks.stone.getMapColor(0), 100);
                  }

                  var27 = 100.0D;
                } else {
                  for (var29 = 0; var29 < var4; ++var29) {
                    for (int var30 = 0; var30 < var4; ++var30) {
                      int var31 = var23.getHeightValue(var29 + var24, var30 + var25) + 1;
                      Block var32 = Blocks.air;
                      int var33 = 0;

                      if (var31 > 1) {
                        do {
                          --var31;
                          var32 = var23.func_150810_a(var29 + var24, var31, var30 + var25);
                          var33 = var23.getBlockMetadata(var29 + var24, var31, var30 + var25);
                        } while (var32.getMapColor(var33) == MapColor.field_151660_b && var31 > 0);

                        if (var31 > 0 && var32.getMaterial().isLiquid()) {
                          int var34 = var31 - 1;
                          Block var35;

                          do {
                            var35 = var23.func_150810_a(var29 + var24, var34--, var30 + var25);
                            ++var26;
                          } while (var34 > 0 && var35.getMaterial().isLiquid());
                        }
                      }

                      var27 += (double) var31 / (double) (var4 * var4);
                      var22.add(var32.getMapColor(var33));
                    }
                  }
                }

                var26 /= var4 * var4;
                double var36 =
                    (var27 - var14) * 4.0D / (double) (var4 + 4)
                        + ((double) (var11 + var16 & 1) - 0.5D) * 0.4D;
                byte var39 = 1;

                if (var36 > 0.6D) {
                  var39 = 2;
                }

                if (var36 < -0.6D) {
                  var39 = 0;
                }

                MapColor var38 =
                    (MapColor)
                        Iterables.getFirst(
                            Multisets.copyHighestCountFirst(var22), MapColor.field_151660_b);

                if (var38 == MapColor.field_151662_n) {
                  var36 = (double) var26 * 0.1D + (double) (var11 + var16 & 1) * 0.2D;
                  var39 = 1;

                  if (var36 < 0.5D) {
                    var39 = 2;
                  }

                  if (var36 > 0.9D) {
                    var39 = 0;
                  }
                }

                var14 = var27;

                if (var16 >= 0
                    && var17 * var17 + var18 * var18 < var9 * var9
                    && (!var19 || (var11 + var16 & 1) != 0)) {
                  byte var37 = par3MapData.colors[var11 + var16 * 128];
                  byte var40 = (byte) (var38.colorIndex * 4 + var39);

                  if (var37 != var40) {
                    if (var12 > var16) {
                      var12 = var16;
                    }

                    if (var13 < var16) {
                      var13 = var16;
                    }

                    par3MapData.colors[var11 + var16 * 128] = var40;
                  }
                }
              }
            }
          }

          if (var12 <= var13) {
            par3MapData.setColumnDirty(var11, var12, var13);
          }
        }
      }
    }
  }
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    if (args.length < 7) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      throw new WrongUsageException("info.cofh.command." + getCommandName() + ".syntax");
    }
    World world = sender.getEntityWorld();
    if (world.isRemote) {
      return;
    }

    ChunkCoordinates center = null;
    int i = 1;
    int xS, xL;
    if ("@".equals(args[i])) {
      center = sender.getPlayerCoordinates();
      ++i;
      xS = CommandBase.parseInt(sender, args[i++]);
    } else {
      try {
        xS = CommandBase.parseInt(sender, args[i++]);
      } catch (Throwable t) {
        center = CommandBase.getPlayer(sender, args[i - 1]).getPlayerCoordinates();
        xS = CommandBase.parseInt(sender, args[i++]);
      }
    }
    int yS = CommandBase.parseInt(sender, args[i++]), yL;
    int zS = CommandBase.parseInt(sender, args[i++]), zL;
    int t = i + 1;

    try {
      xL = CommandBase.parseInt(sender, args[i++]);
      yL = CommandBase.parseInt(sender, args[i++]);
      zL = CommandBase.parseInt(sender, args[i++]);
    } catch (Throwable e) {
      if (i > t || center == null) {
        throw Throwables.propagate(e);
      }
      --i;
      xL = xS;
      yL = yS;
      zL = zS;
    }

    if (center != null) {
      xS = center.posX - xS;
      yS = center.posY - yS;
      zS = center.posZ - zS;

      xL = center.posX + xL;
      yL = center.posY + yL;
      zL = center.posZ + zL;
    }

    yS &= ~yS >> 31; // max(yS, 0)
    yL &= ~yL >> 31; // max(yL, 0)

    if (xL < xS) {
      t = xS;
      xS = xL;
      xL = t;
    }
    if (yL < yS) {
      t = yS;
      yS = yL;
      yL = t;
    }
    if (zL < zS) {
      t = zS;
      zS = zL;
      zL = t;
    }

    if (yS > 255) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
      return;
    } else if (yL > 255) {
      yL = 255;
    }

    Block replBlock;
    int replMeta;
    String blockReplRaw;
    {
      int meta = 0;
      String blockRaw = args[i];
      blockReplRaw = blockRaw;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air || meta > 15 || meta < 0) {
        sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
        sender.addChatMessage(
            new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
        // TODO: more descriptive error
        return;
      }
      replBlock = block;
      replMeta = meta;
    }

    long blockCounter = ((long) xL - xS) * ((long) yL - yS) * ((long) zL - zS);
    CommandHandler.logAdminCommand(
        sender,
        this,
        "info.cofh.command.replaceblocks.start",
        blockCounter,
        xS,
        yS,
        zS,
        xL,
        yL,
        zL,
        blockReplRaw);

    THashSet<Chunk> set = new THashSet<Chunk>();

    blockCounter = 0;
    for (int e = args.length; i < e; ++i) {
      String blockRaw = args[i];
      if (blockRaw.charAt(0) == '*') {
        if (blockRaw.equals("*fluid")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial().isLiquid()) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*tree")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isWood(world, x, y, z) || block.isLeaves(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*repl")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceable(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*stone")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*rock")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.rock) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*sand")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.sand) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*dirt")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.grass
                    || m == Material.ground
                    || m == Material.clay
                    || m == Material.snow
                    || m == Material.craftedSnow
                    || m == Material.ice
                    || m == Material.packedIce) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*plant")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.plants
                    || m == Material.vine
                    || m == Material.cactus
                    || m == Material.leaves) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*fire")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.fire || m == Material.lava || block.isBurning(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        }
        continue;
      }
      int meta = -1;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air) {
        continue;
      }

      for (int x = xS; x <= xL; ++x) {
        for (int z = zS; z <= zL; ++z) {
          Chunk chunk = world.getChunkFromBlockCoords(x, z);
          int cX = x & 15, cZ = z & 15;
          for (int y = yS; y <= yL; ++y) {
            boolean v = meta == -1 || chunk.getBlockMetadata(cX, y, cZ) == meta;
            if (v && chunk.getBlock(cX, y, cZ) == block) {
              if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                ++blockCounter;
                set.add(chunk);
              }
            }
          }
        }
      }
    }
    if (!set.isEmpty()) {
      CommandHandler.logAdminCommand(
          sender,
          this,
          "info.cofh.command.replaceblocks.success",
          blockCounter,
          xS,
          yS,
          zS,
          xL,
          yL,
          zL,
          blockReplRaw);
    } else {
      CommandHandler.logAdminCommand(sender, this, "info.cofh.command.replaceblocks.failure");
    }

    if (world instanceof WorldServer) {
      TObjectHashIterator<Chunk> c = set.iterator();
      for (int k = 0, e = set.size(); k < e; ++k) {
        Chunk chunk = c.next();
        PlayerManager manager = ((WorldServer) world).getPlayerManager();
        if (manager == null) {
          return;
        }
        PlayerInstance watcher =
            manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false);
        if (watcher != null) {
          watcher.sendToAllPlayersWatchingChunk(new S21PacketChunkData(chunk, false, -1));
        }
      }
    }
  }
  public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
    ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
    int x = dat.readInt();
    int y = dat.readInt();
    int z = dat.readInt();
    int typ = dat.readInt();
    World world = ModularForceFieldSystem.proxy.getClientWorld();

    switch (typ) {
      case 100:
        String DataPacket = dat.readUTF();

        for (String blockupdate : DataPacket.split(">")) {
          if (blockupdate.length() > 0) {
            String[] projector = blockupdate.split("<");
            String[] Corrdinaten = projector[1].split("/");
            String[] temp = projector[0].split("!");
            String[] Dim = temp[1].split("/");
            String[] ProjectorCorr = temp[0].split("/");

            if (Integer.parseInt(Dim[0].trim()) == world.provider.dimensionId) {
              if (world.getChunkFromBlockCoords(
                      Integer.parseInt(Corrdinaten[0].trim()),
                      Integer.parseInt(Corrdinaten[2].trim()))
                  .isChunkLoaded) {
                TileEntity te =
                    world.getBlockTileEntity(
                        Integer.parseInt(Corrdinaten[0].trim()),
                        Integer.parseInt(Corrdinaten[1].trim()),
                        Integer.parseInt(Corrdinaten[2].trim()));
                if ((te instanceof TileEntityForceField)) {
                  TileEntity proj =
                      world.getBlockTileEntity(
                          Integer.parseInt(ProjectorCorr[2].trim()),
                          Integer.parseInt(ProjectorCorr[1].trim()),
                          Integer.parseInt(ProjectorCorr[0].trim()));
                  if ((proj instanceof TileEntityProjector)) {
                    ((TileEntityForceField) te)
                        .setTexturfile(((TileEntityProjector) proj).getForceFieldTexturfile());
                    ((TileEntityForceField) te)
                        .setTexturid(((TileEntityProjector) proj).getForceFieldTexturID());
                    ((TileEntityForceField) te)
                        .setForcefieldCamoblockid(
                            ((TileEntityProjector) proj).getForcefieldCamoblockid());
                    ((TileEntityForceField) te)
                        .setForcefieldCamoblockmeta(
                            ((TileEntityProjector) proj).getForcefieldCamoblockmeta());
                  }
                }
              }
            }
          }
        }

        break;
      case 1:
        String fieldname = dat.readUTF();

        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if ((tileEntity instanceof TileEntityMFFS)) {
          try {
            Field f = ReflectionHelper.findField(TileEntityMFFS.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityCapacitor)) {
          try {
            Field f =
                ReflectionHelper.findField(TileEntityCapacitor.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityExtractor)) {
          try {
            Field f =
                ReflectionHelper.findField(TileEntityExtractor.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityConverter)) {
          try {
            Field f =
                ReflectionHelper.findField(TileEntityConverter.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityProjector)) {
          try {
            Field f =
                ReflectionHelper.findField(TileEntityProjector.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityDefenseStation)) {
          try {
            Field f =
                ReflectionHelper.findField(
                    TileEntityDefenseStation.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntitySecurityStation)) {
          try {
            Field f =
                ReflectionHelper.findField(
                    TileEntitySecurityStation.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntitySecStorage)) {
          try {
            Field f =
                ReflectionHelper.findField(TileEntitySecStorage.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        }

        if ((tileEntity instanceof TileEntityControlSystem))
          try {
            Field f =
                ReflectionHelper.findField(TileEntityControlSystem.class, new String[] {fieldname});
            reflectionsetvalue(f, tileEntity, dat, fieldname);
          } catch (Exception e) {
          }
        break;
    }
  }