예제 #1
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);
          }
        }
      }
    }
  }
예제 #2
0
  @SubscribeEvent
  public void onServerTick(ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    // Prevent issues when clients switch to LAN servers
    if (server == null) return;

    if (event.phase == Phase.START) {
      if (MapUtil.calculatingMap.get()) MapUtil.BiomeMapNextTick();
      else if (!MapUtil.doneOverworldTexture) MapUtil.makeOverworldTexture();

      if (TickHandlerServer.spaceRaceData == null) {
        World world =
            FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(0);
        TickHandlerServer.spaceRaceData =
            (WorldDataSpaceRaces)
                world.mapStorage.loadData(
                    WorldDataSpaceRaces.class, WorldDataSpaceRaces.saveDataID);

        if (TickHandlerServer.spaceRaceData == null) {
          TickHandlerServer.spaceRaceData = new WorldDataSpaceRaces(WorldDataSpaceRaces.saveDataID);
          world.mapStorage.setData(WorldDataSpaceRaces.saveDataID, TickHandlerServer.spaceRaceData);
        }
      }

      SpaceRaceManager.tick();

      if (TickHandlerServer.tickCount % 100 == 0) {
        WorldServer[] worlds = server.worldServers;

        for (int i = 0; i < worlds.length; i++) {
          WorldServer world = worlds[i];
          ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;

          Map<Long, List<Footprint>> footprintMap =
              TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId);

          if (footprintMap != null) {
            boolean mapChanged = false;

            if (chunkProviderServer != null) {
              Iterator iterator = chunkProviderServer.loadedChunks.iterator();

              while (iterator.hasNext()) {
                Chunk chunk = (Chunk) iterator.next();
                long chunkKey = ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition);

                List<Footprint> footprints = footprintMap.get(chunkKey);

                if (footprints != null) {
                  List<Footprint> toRemove = new ArrayList<Footprint>();

                  for (int j = 0; j < footprints.size(); j++) {
                    footprints.get(j).age += 100;

                    if (footprints.get(j).age >= Footprint.MAX_AGE) {
                      toRemove.add(footprints.get(j));
                    }
                  }

                  if (!toRemove.isEmpty()) {
                    footprints.removeAll(toRemove);
                  }

                  footprintMap.put(chunkKey, footprints);
                  mapChanged = true;

                  GalacticraftCore.packetPipeline.sendToDimension(
                      new PacketSimple(
                          EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST,
                          new Object[] {
                            chunkKey, footprints.toArray(new Footprint[footprints.size()])
                          }),
                      worlds[i].provider.dimensionId);
                }
              }
            }

            if (mapChanged) {
              TickHandlerServer.serverFootprintMap.put(world.provider.dimensionId, footprintMap);
            }
          }
        }
      }

      if (!footprintBlockChanges.isEmpty()) {
        for (BlockVec3Dim targetPoint : footprintBlockChanges) {
          WorldServer[] worlds =
              FMLCommonHandler.instance().getMinecraftServerInstance().worldServers;

          for (int i = 0; i < worlds.length; i++) {
            WorldServer world = worlds[i];

            if (world.provider.dimensionId == targetPoint.dim) {
              long chunkKey =
                  ChunkCoordIntPair.chunkXZ2Int((int) targetPoint.x >> 4, (int) targetPoint.z >> 4);
              GalacticraftCore.packetPipeline.sendToAllAround(
                  new PacketSimple(
                      EnumSimplePacket.C_FOOTPRINTS_REMOVED,
                      new Object[] {
                        chunkKey, new BlockVec3(targetPoint.x, targetPoint.y, targetPoint.z)
                      }),
                  new NetworkRegistry.TargetPoint(
                      targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50));

              //                            Map<Long, List<Footprint>> footprintMap =
              // TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId);
              //
              //                            if (footprintMap != null && !footprintMap.isEmpty())
              //                            {
              //                                List<Footprint> footprints =
              // footprintMap.get(chunkKey);
              //                                if (footprints != null)
              //                                	GalacticraftCore.packetPipeline.sendToAllAround(new
              // PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, new Object[] { chunkKey,
              // footprints.toArray(new Footprint[footprints.size()]) }), new
              // NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y,
              // targetPoint.z, 50));
              //                            }
            }
          }
        }

        footprintBlockChanges.clear();
      }

      if (tickCount % 20 == 0) {
        if (!playersRequestingMapData.isEmpty()) {
          ArrayList<EntityPlayerMP> copy = new ArrayList<EntityPlayerMP>(playersRequestingMapData);
          for (EntityPlayerMP playerMP : copy) {
            GCPlayerStats stats = GCPlayerStats.get(playerMP);
            ChunkCoordIntPair chunkCoordIntPair =
                new ChunkCoordIntPair(
                    (int) Math.floor(stats.coordsTeleportedFromX) >> 4,
                    (int) Math.floor(stats.coordsTeleportedFromZ) >> 4);
            BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);

            for (int x0 = -12; x0 <= 12; x0++) {
              for (int z0 = -12; z0 <= 12; z0++) {
                Chunk chunk =
                    MinecraftServer.getServer()
                        .worldServerForDimension(0)
                        .getChunkFromChunkCoords(
                            chunkCoordIntPair.chunkXPos + x0, chunkCoordIntPair.chunkZPos + z0);

                if (chunk != null) {
                  for (int z = 0; z < 16; z++) {
                    for (int x = 0; x < 16; x++) {
                      int l4 = chunk.getHeightValue(x, z) + 1;
                      Block block = Blocks.air;
                      int i5 = 0;

                      if (l4 > 1) {
                        do {
                          --l4;
                          block = chunk.getBlock(x, l4, z);
                          i5 = chunk.getBlockMetadata(x, l4, z);
                        } while (block.getMapColor(i5) == MapColor.airColor && l4 > 0);
                      }

                      int col = block.getMapColor(i5).colorValue;
                      image.setRGB(x + (x0 + 12) * 16, z + (z0 + 12) * 16, col);
                    }
                  }
                }
              }
            }

            try {
              File baseFolder =
                  new File(
                      MinecraftServer.getServer().worldServerForDimension(0).getChunkSaveLocation(),
                      "galacticraft/overworldMap");

              if (!baseFolder.exists()) {
                if (!baseFolder.mkdirs()) {
                  GCLog.severe(
                      "Base folder(s) could not be created: " + baseFolder.getAbsolutePath());
                }
              }

              File outputFile =
                  new File(
                      baseFolder,
                      ""
                          + chunkCoordIntPair.chunkXPos
                          + "_"
                          + chunkCoordIntPair.chunkZPos
                          + ".jpg");

              if (!outputFile.exists() || (outputFile.canWrite() && outputFile.canRead())) {
                ImageIO.write(image, "jpg", outputFile);
              }
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          playersRequestingMapData.removeAll(copy);
        }
      }

      TickHandlerServer.tickCount++;

      if (TickHandlerServer.tickCount >= Long.MAX_VALUE) {
        TickHandlerServer.tickCount = 0;
      }

      EnergyNetwork.tickCount++;
    } else if (event.phase == Phase.END) {
      int maxPasses = 10;
      while (!TickHandlerServer.networkTicks.isEmpty()) {
        LinkedList<EnergyNetwork> pass = new LinkedList();
        pass.addAll(TickHandlerServer.networkTicks);
        TickHandlerServer.networkTicks.clear();
        for (EnergyNetwork grid : pass) {
          grid.tickEnd();
        }

        if (--maxPasses <= 0) {
          break;
        }
      }

      maxPasses = 10;
      while (!TickHandlerServer.oxygenTransmitterUpdates.isEmpty()) {
        LinkedList<TileEntityOxygenTransmitter> pass = new LinkedList();
        pass.addAll(TickHandlerServer.oxygenTransmitterUpdates);
        TickHandlerServer.oxygenTransmitterUpdates.clear();
        for (TileEntityOxygenTransmitter newTile : pass) {
          if (!newTile.isInvalid()) newTile.refresh();
        }

        if (--maxPasses <= 0) {
          break;
        }
      }

      maxPasses = 10;
      while (!TickHandlerServer.hydrogenTransmitterUpdates.isEmpty()) {
        LinkedList<TileEntityHydrogenPipe> pass = new LinkedList();
        pass.addAll(TickHandlerServer.hydrogenTransmitterUpdates);
        TickHandlerServer.hydrogenTransmitterUpdates.clear();
        for (TileEntityHydrogenPipe newTile : pass) {
          if (!newTile.isInvalid()) newTile.refresh();
        }

        if (--maxPasses <= 0) {
          break;
        }
      }

      maxPasses = 10;
      while (!TickHandlerServer.energyTransmitterUpdates.isEmpty()) {
        LinkedList<TileBaseConductor> pass = new LinkedList();
        pass.addAll(TickHandlerServer.energyTransmitterUpdates);
        TickHandlerServer.energyTransmitterUpdates.clear();
        for (TileBaseConductor newTile : pass) {
          if (!newTile.isInvalid()) newTile.refresh();
        }

        if (--maxPasses <= 0) {
          break;
        }
      }
    }
  }