Java 类net.minecraft.server.management.PlayerChunkMap 实例源码

项目:CustomWorldGen    文件:WorldServer.java   
public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn)
{
    super(saveHandlerIn, info, net.minecraftforge.common.DimensionManager.createProviderFor(dimensionId), profilerIn, false);
    this.mcServer = server;
    this.theEntityTracker = new EntityTracker(this);
    this.thePlayerManager = new PlayerChunkMap(this);
    // Guarantee the dimension ID was not reset by the provider
    int providerDim = this.provider.getDimension();
    this.provider.registerWorld(this);
    this.provider.setDimension(providerDim);
    this.chunkProvider = this.createChunkProvider();
    perWorldStorage = new MapStorage(new net.minecraftforge.common.WorldSpecificSaveHandler((WorldServer)this, saveHandlerIn));
    this.worldTeleporter = new Teleporter(this);
    this.calculateInitialSkylight();
    this.calculateInitialWeather();
    this.getWorldBorder().setSize(server.getMaxWorldSize());
    net.minecraftforge.common.DimensionManager.setWorld(dimensionId, this, mcServer);
}
项目:CrystalMod    文件:ExplosionMaker.java   
private void removeBlock(BlockPos pos) {
    if(pos.getY() < 0 || pos.getY() >= 256)return;
    Chunk chunk = getChunk(pos);
    IBlockState oldState = chunk.getBlockState(pos);

    if (oldState.getBlock().hasTileEntity(oldState)) {
        serverWorld.setBlockToAir(pos);

        PlayerChunkMap playerChunkMap = serverWorld.getPlayerChunkMap();
        if (playerChunkMap != null) {
            PlayerChunkMapEntry watcher = playerChunkMap.getEntry(pos.getX() >> 4, pos.getZ() >> 4);
            if (watcher != null) {
                watcher.sendPacket(new SPacketBlockChange(serverWorld, pos));
            }
        }
    }

    ExtendedBlockStorage storage = getBlockStorage(pos);
    if(storage !=null){
        storage.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, AIR);
    }
    setChunkModified(pos);
}
项目:CrystalMod    文件:ExplosionMaker.java   
public void finishChunks() {
    PlayerChunkMap playerChunkMap = serverWorld.getPlayerChunkMap();
    if (playerChunkMap == null) {
        return;
    }

    for (Chunk chunk : modifiedChunks) {
        chunk.setModified(true);
        chunk.generateSkylightMap(); //This is where this falls short. It can calculate basic sky lighting for blocks exposed to the sky but thats it.

        PlayerChunkMapEntry watcher = playerChunkMap.getEntry(chunk.xPosition, chunk.zPosition);
        if (watcher != null) {
            watcher.sendPacket(new SPacketChunkData(chunk, 65535));
        }
    }

    modifiedChunks.clear();
}
项目:IvToolkit    文件:IvNetworkHelperServer.java   
public static List<EntityPlayerMP> getPlayersWatchingChunk(World world, int chunkX, int chunkZ)
{
    if (world.isRemote || !(world instanceof WorldServer))
    {
        return Collections.emptyList();
    }

    ArrayList<EntityPlayerMP> playersWatching = new ArrayList<>();

    WorldServer server = (WorldServer) world;
    PlayerChunkMap playerManager = server.getPlayerChunkMap();

    List<EntityPlayer> players = server.playerEntities;
    List<EntityPlayerMP> mpplayers = ((List) players.stream().filter(p -> p instanceof EntityPlayerMP).collect(Collectors.toList()));

    playersWatching.addAll(mpplayers.stream().filter(player -> playerManager.isPlayerWatchingChunk(player, chunkX, chunkZ)).collect(Collectors.toList()));

    return playersWatching;
}
项目:enderutilities    文件:TileEntityEnderUtilities.java   
protected void sendPacketToWatchers(IMessage message)
{
    World world = this.getWorld();

    if (world instanceof WorldServer)
    {
        WorldServer worldServer = (WorldServer) world;
        int chunkX = this.getPos().getX() >> 4;
        int chunkZ = this.getPos().getZ() >> 4;
        PlayerChunkMap map = worldServer.getPlayerChunkMap();

        for (EntityPlayerMP player : worldServer.getPlayers(EntityPlayerMP.class, Predicates.alwaysTrue()))
        {
            if (map.isPlayerWatchingChunk(player, chunkX, chunkZ))
            {
                PacketHandler.INSTANCE.sendTo(message, player);
            }
        }
    }
}
项目:UniversalRemote    文件:WorldServerProxy.java   
@Override
public PlayerChunkMap getPlayerChunkMap() {
    if (m_proxyWorld != null && Util.isPrefixInCallStack(m_modPrefix)) {
        return m_proxyWorld.getPlayerChunkMap();
    } else if (m_realWorld != null) {
        return m_realWorld.getPlayerChunkMap();
    } else {
        return super.getPlayerChunkMap();
    }
}
项目:Backmemed    文件:WorldServer.java   
public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn)
{
    super(saveHandlerIn, info, DimensionType.getById(dimensionId).createDimension(), profilerIn, false);
    this.mcServer = server;
    this.theEntityTracker = new EntityTracker(this);
    this.thePlayerManager = new PlayerChunkMap(this);
    this.provider.registerWorld(this);
    this.chunkProvider = this.createChunkProvider();
    this.worldTeleporter = new Teleporter(this);
    this.calculateInitialSkylight();
    this.calculateInitialWeather();
    this.getWorldBorder().setSize(server.getMaxWorldSize());
}
项目:TheDragonLib    文件:TileTDLBase.java   
public NetworkRegistry.TargetPoint syncRange() {
    if (viewRange == -1 && !world.isRemote) {
        Field f = ReflectionHelper.findField(PlayerChunkMap.class, "playerViewRadius", "field_72698_e");
        f.setAccessible(true);
        try {
            viewRange = f.getInt(((WorldServer) world).getPlayerChunkMap());
        } catch (IllegalAccessException e) {
            LogHelper.error("A THING BROKE!!!!!!!");
            e.printStackTrace();
        }
    } else if (world.isRemote) {
        LogHelper.error("Hay! Someone is doing a bad thing!!! Check your side!!!!!!!");
    }
    return new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), viewRange * 16);
}
项目:EnderIO    文件:PacketDarkSteelSFXPacket.java   
@Override
public IMessage onMessage(PacketDarkSteelSFXPacket message, MessageContext ctx) {
  if (message.upgradeName != null) {
    IDarkSteelUpgrade upgrade = UpgradeRegistry.getUpgrade(message.upgradeName);
    if (upgrade != null) {
      final EntityPlayerMP player = ctx.getServerHandler().player;
      message.uid = player.getUniqueID();
      for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (slot != null) {
          ItemStack stack = player.getItemStackFromSlot(slot);
          if (upgrade.hasUpgrade(stack)) {

            WorldServer worldServer = (WorldServer) player.world;
            PlayerChunkMap playerManager = worldServer.getPlayerChunkMap();

            int chunkX = ((int) player.posX) >> 4;
            int chunkZ = ((int) player.posZ) >> 4;

            for (Object playerObj : worldServer.playerEntities) {
              if (playerObj instanceof EntityPlayerMP && playerObj != player) {
                EntityPlayerMP otherPlayer = (EntityPlayerMP) playerObj;
                if (playerManager.isPlayerWatchingChunk(otherPlayer, chunkX, chunkZ)) {
                  PacketHandler.INSTANCE.sendTo(message, otherPlayer);
                }
              }
            }

            return null;
          }
        }
      }
    }
  }
  return null;
}
项目:Backmemed    文件:WorldServer.java   
/**
 * Gets the player chunk map for this server world.
 */
public PlayerChunkMap getPlayerChunkMap()
{
    return this.thePlayerManager;
}
项目:CustomWorldGen    文件:WorldServer.java   
/**
 * Gets the player chunk map for this server world.
 */
public PlayerChunkMap getPlayerChunkMap()
{
    return this.thePlayerManager;
}
项目:FastAsyncWorldedit    文件:ForgeQueue_All.java   
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }


    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}
项目:FastAsyncWorldedit    文件:SpongeQueue_1_11.java   
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer);
        id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
项目:FastAsyncWorldedit    文件:SpongeQueue_1_12.java   
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer);
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
项目:FastAsyncWorldedit    文件:ForgeQueue_All.java   
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = chunkServer.id2ChunkMap;
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
项目:FastAsyncWorldedit    文件:ForgeQueue_All.java   
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}
项目:FastAsyncWorldedit    文件:ForgeQueue_All.java   
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}