@ForgeSubscribe
 public void chunkLoaded(ChunkWatchEvent event) {
   EntityPlayerMP p = event.player;
   ChunkCoordIntPair chunk = event.chunk;
   ArrayList<CloakedArea> cloaks =
       WarpDrive.instance.cloaks.getCloaksForPoint(
           p.worldObj.provider.dimensionId,
           chunk.getCenterXPos(),
           0,
           chunk.getCenterZPosition(),
           true);
   if (cloaks.size() == 0) return;
   for (CloakedArea area : cloaks) area.sendCloakPacketToPlayer(p, false);
 }
  protected List func_75052_o_() {
    ArrayList var1 = new ArrayList();
    ChunkCoordIntPair[] var2 = this.field_75057_g;
    int var3 = var2.length;

    for (int var4 = 0; var4 < var3; ++var4) {
      ChunkCoordIntPair var5 = var2[var4];
      if (var5 != null) {
        var1.add(var5.func_77271_a(64));
      }
    }

    return var1;
  }
 protected void recursivePopulate(
     World world, int xChunkCoord, int zChunkCoord, int origXChunkCoord, int origZChunkCoord) {
   Long key = Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(xChunkCoord, zChunkCoord));
   if (structureMap.containsKey(key)) {
     BaseStructureStart start = structureMap.get(key);
     start.populateChunk(world, origXChunkCoord, origZChunkCoord);
   } else {
     FMLLog.info(
         "No "
             + this.getName()
             + " for population for coords "
             + (xChunkCoord * 16)
             + "/"
             + (zChunkCoord * 16)
             + ", that's weird...");
   }
 }
 /**
  * Creates or gets an instance of BaseStructure, then makes it generate the current chunk
  *
  * @param world
  * @param xChunkCoord
  * @param zChunkCoord
  * @param origXChunkCoord
  * @param origZChunkCoord
  * @param arrayOfIDs
  * @param arrayOfMeta
  */
 protected void makeStructure(
     World world,
     int xChunkCoord,
     int zChunkCoord,
     int origXChunkCoord,
     int origZChunkCoord,
     Block[] arrayOfIDs,
     byte[] arrayOfMeta) {
   Long key = Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(xChunkCoord, zChunkCoord));
   BaseStructureStart start = null;
   if (!structureMap.containsKey(key)) {
     start =
         createNewStructure(
             xChunkCoord,
             zChunkCoord); // new GridVillageStart(xChunkCoord, zChunkCoord, this.rand);
     structureMap.put(key, start);
   } else {
     start = structureMap.get(key);
   }
   start.generateChunk(origXChunkCoord, origZChunkCoord, arrayOfIDs, arrayOfMeta);
 }
Example #5
0
  // sync stuff
  public void callStage2(QueuedChunk queuedChunk, net.minecraft.world.chunk.Chunk chunk)
      throws RuntimeException {
    if (chunk == null) {
      // If the chunk loading failed just do it synchronously (may generate)
      queuedChunk.provider.originalLoadChunk(queuedChunk.x, queuedChunk.z);
      return;
    }

    queuedChunk.loader.loadEntities(
        queuedChunk.world, queuedChunk.compound.getCompoundTag("Level"), chunk);
    chunk.setLastSaveTime(queuedChunk.provider.worldObj.getTotalWorldTime());
    queuedChunk.provider.id2ChunkMap.add(
        ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk);
    queuedChunk.provider.loadedChunks.add(chunk);
    chunk.onChunkLoad();

    if (queuedChunk.provider.serverChunkGenerator != null) {
      queuedChunk.provider.serverChunkGenerator.recreateStructures(
          chunk, queuedChunk.x, queuedChunk.z);
    }

    chunk.populateChunk(queuedChunk.provider, queuedChunk.provider, queuedChunk.x, queuedChunk.z);
  }
 public long getChunkXZHash() {
   return ChunkCoordIntPair.chunkXZ2Int(x >> 4, z >> 4);
 }
  /** Place an entity in a nearby portal which already exists. */
  @SuppressWarnings("unchecked")
  public boolean placeInExistingPortal(
      Entity par1Entity, double par2, double par4, double par6, float par8) {
    short short1 = 128;
    double d3 = -1.0D;
    int i = 0;
    int j = 0;
    int k = 0;
    int l = MathHelper.floor_double(par1Entity.posX);
    int i1 = MathHelper.floor_double(par1Entity.posZ);
    long j1 = ChunkCoordIntPair.chunkXZ2Int(l, i1);
    boolean flag = true;
    double d4;
    int k1;

    if (this.field_85191_c.containsItem(j1)) {
      PortalPosition portalposition = (PortalPosition) this.field_85191_c.getValueByKey(j1);
      d3 = 0.0D;
      i = portalposition.posX;
      j = portalposition.posY;
      k = portalposition.posZ;
      portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
      flag = false;
    } else {
      for (k1 = l - short1; k1 <= l + short1; ++k1) {
        double d5 = (double) k1 + 0.5D - par1Entity.posX;

        for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1) {
          double d6 = (double) l1 + 0.5D - par1Entity.posZ;

          for (int i2 = this.worldServerInstance.getActualHeight() - 1; i2 >= 0; --i2) {
            if (this.worldServerInstance.getBlock(k1, i2, l1) == DimBlocks.BlockDebug) {
              while (this.worldServerInstance.getBlock(k1, i2 - 1, l1) == DimBlocks.BlockDebug) {
                --i2;
              }

              d4 = (double) i2 + 0.5D - par1Entity.posY;
              double d7 = d5 * d5 + d4 * d4 + d6 * d6;

              if (d3 < 0.0D || d7 < d3) {
                d3 = d7;
                i = k1;
                j = i2;
                k = l1;
              }
            }
          }
        }
      }
    }

    if (d3 >= 0.0D) {
      if (flag) {
        // TODO ERROR?
        this.field_85191_c.add(
            j1, new PortalPosition(i, j, k, this.worldServerInstance.getTotalWorldTime()));
        this.field_85190_d.add(Long.valueOf(j1));
      }

      double d8 = (double) i + 0.5D;
      double d9 = (double) j + 0.5D;
      d4 = (double) k + 0.5D;
      int j2 = -1;

      if (this.worldServerInstance.getBlock(i - 1, j, k) == DimBlocks.BlockDebug) {
        j2 = 2;
      }

      if (this.worldServerInstance.getBlock(i + 1, j, k) == DimBlocks.BlockDebug) {
        j2 = 0;
      }

      if (this.worldServerInstance.getBlock(i, j, k - 1) == DimBlocks.BlockDebug) {
        j2 = 3;
      }

      if (this.worldServerInstance.getBlock(i, j, k + 1) == DimBlocks.BlockDebug) {
        j2 = 1;
      }

      int k2 = par1Entity.getTeleportDirection();

      if (j2 > -1) {
        int l2 = Direction.rotateLeft[j2];
        int i3 = Direction.offsetX[j2];
        int j3 = Direction.offsetZ[j2];
        int k3 = Direction.offsetX[l2];
        int l3 = Direction.offsetZ[l2];
        boolean flag1 =
            !this.worldServerInstance.isAirBlock(i + i3 + k3, j, k + j3 + l3)
                || !this.worldServerInstance.isAirBlock(i + i3 + k3, j + 1, k + j3 + l3);
        boolean flag2 =
            !this.worldServerInstance.isAirBlock(i + i3, j, k + j3)
                || !this.worldServerInstance.isAirBlock(i + i3, j + 1, k + j3);

        if (flag1 && flag2) {
          j2 = Direction.rotateOpposite[j2];
          l2 = Direction.rotateOpposite[l2];
          i3 = Direction.offsetX[j2];
          j3 = Direction.offsetZ[j2];
          k3 = Direction.offsetX[l2];
          l3 = Direction.offsetZ[l2];
          k1 = i - k3;
          d8 -= (double) k3;
          int i4 = k - l3;
          d4 -= (double) l3;
          flag1 =
              !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j, i4 + j3 + l3)
                  || !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j + 1, i4 + j3 + l3);
          flag2 =
              !this.worldServerInstance.isAirBlock(k1 + i3, j, i4 + j3)
                  || !this.worldServerInstance.isAirBlock(k1 + i3, j + 1, i4 + j3);
        }

        float f1 = 0.5F;
        float f2 = 0.5F;

        if (!flag1 && flag2) {
          f1 = 1.0F;
        } else if (flag1 && !flag2) {
          f1 = 0.0F;
        } else if (flag1 && flag2) {
          f2 = 0.0F;
        }

        d8 += (double) ((float) k3 * f1 + f2 * (float) i3);
        d4 += (double) ((float) l3 * f1 + f2 * (float) j3);
        float f3 = 0.0F;
        float f4 = 0.0F;
        float f5 = 0.0F;
        float f6 = 0.0F;

        if (j2 == k2) {
          f3 = 1.0F;
          f4 = 1.0F;
        } else if (j2 == Direction.rotateOpposite[k2]) {
          f3 = -1.0F;
          f4 = -1.0F;
        } else if (j2 == Direction.rotateRight[k2]) {
          f5 = 1.0F;
          f6 = -1.0F;
        } else {
          f5 = -1.0F;
          f6 = 1.0F;
        }

        double d10 = par1Entity.motionX;
        double d11 = par1Entity.motionZ;
        par1Entity.motionX = d10 * (double) f3 + d11 * (double) f6;
        par1Entity.motionZ = d10 * (double) f5 + d11 * (double) f4;
        par1Entity.rotationYaw = par8 - (float) (k2 * 90) + (float) (j2 * 90);
      } else {
        par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
      }

      par1Entity.setLocationAndAngles(d8, d9, d4, par1Entity.rotationYaw, par1Entity.rotationPitch);
      return true;
    } else {
      return false;
    }
  }
  @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;
        }
      }
    }
  }
 public String func_85162_a() {
   return String.valueOf(ChunkCoordIntPair.chunkXZ2Int(this.field_85165_a, this.field_85163_b));
 }
Example #10
0
  private void updateFeet(EntityPlayerSP player, double motionX, double motionZ) {
    GCPlayerStatsClient stats = GCPlayerStatsClient.get(player);
    double motionSqrd = motionX * motionX + motionZ * motionZ;

    // If the player is on the moon, not airbourne and not riding anything
    if (motionSqrd > 0.001
        && player.worldObj != null
        && player.worldObj.provider instanceof WorldProviderMoon
        && player.ridingEntity == null
        && !player.capabilities.isFlying) {
      int iPosX = (int) Math.floor(player.posX);
      int iPosY = (int) Math.floor(player.posY - 1);
      int iPosZ = (int) Math.floor(player.posZ);
      BlockPos pos1 = new BlockPos(iPosX, iPosY, iPosZ);
      IBlockState state = player.worldObj.getBlockState(pos1);

      // If the block below is the moon block
      if (state.getBlock() == GCBlocks.blockMoon) {
        // And is the correct metadata (moon turf)
        if (state.getBlock().getMetaFromState(state) == 5) {
          // If it has been long enough since the last step
          if (stats.distanceSinceLastStep > 0.35) {
            Vector3 pos = new Vector3(player);
            // Set the footprint position to the block below and add random number to stop
            // z-fighting
            pos.y = MathHelper.floor_double(player.posY) + player.getRNG().nextFloat() / 100.0F;

            // Adjust footprint to left or right depending on step count
            switch (stats.lastStep) {
              case 0:
                pos.translate(
                    new Vector3(
                        Math.sin(Math.toRadians(-player.rotationYaw + 90)) * 0.25,
                        0,
                        Math.cos(Math.toRadians(-player.rotationYaw + 90)) * 0.25));
                break;
              case 1:
                pos.translate(
                    new Vector3(
                        Math.sin(Math.toRadians(-player.rotationYaw - 90)) * 0.25,
                        0,
                        Math.cos(Math.toRadians(-player.rotationYaw - 90)) * 0.25));
                break;
            }

            pos =
                WorldUtil.getFootprintPosition(
                    player.worldObj, player.rotationYaw - 180, pos, new BlockVec3(player));

            long chunkKey = ChunkCoordIntPair.chunkXZ2Int(pos.intX() >> 4, pos.intZ() >> 4);
            ClientProxyCore.footprintRenderer.addFootprint(
                chunkKey,
                player.worldObj.provider.getDimensionId(),
                pos,
                player.rotationYaw,
                player.getName());

            // Increment and cap step counter at 1
            stats.lastStep++;
            stats.lastStep %= 2;
            stats.distanceSinceLastStep = 0;
          } else {
            stats.distanceSinceLastStep += motionSqrd;
          }
        }
      }
    }
  }