net.minecraft.world.ChunkCoordIntPair Java Examples
The following examples show how to use
net.minecraft.world.ChunkCoordIntPair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BREventHandler.java From BigReactors with MIT License | 6 votes |
@SubscribeEvent public void chunkLoad(ChunkDataEvent.Load loadEvent) { if(!BigReactors.enableWorldRegeneration || !BigReactors.enableWorldGen) { return; } NBTTagCompound loadData = loadEvent.getData(); if(loadData.getInteger("BigReactorsWorldGen") == BRConfig.WORLDGEN_VERSION && loadData.getInteger("BigReactorsUserWorldGen") == BigReactors.userWorldGenVersion) { return; } if(!StaticUtils.WorldGen.shouldGenerateInDimension(loadEvent.world.provider.dimensionId)) { return; } ChunkCoordIntPair coordPair = loadEvent.getChunk().getChunkCoordIntPair(); BigReactors.tickHandler.addRegenChunk(loadEvent.world.provider.dimensionId, coordPair); }
Example #2
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 6 votes |
public void loadDimension(PacketCustom packet, WorldClient world) { synchronized(dimensionChunks) { DimensionChunkInfo dimInfo = new DimensionChunkInfo(packet.readInt()); int numChunks = packet.readInt(); for(int i = 0; i < numChunks; i++) dimInfo.allchunks.add(new ChunkCoordIntPair(packet.readInt(), packet.readInt())); int numTickets = packet.readInt(); for(int i = 0; i < numTickets; i++) { TicketInfo ticket = new TicketInfo(packet, world); dimInfo.tickets.put(ticket.ID, ticket); } dimensionChunks.put(dimInfo.dimension, dimInfo); } }
Example #3
Source File: BigReactorsTickHandler.java From BigReactors with MIT License | 6 votes |
public void addRegenChunk(int dimensionId, ChunkCoordIntPair chunkCoord) { if(chunkRegenMap == null) { chunkRegenMap = new HashMap<Integer, Queue<ChunkCoordIntPair>>(); } if(!chunkRegenMap.containsKey(dimensionId)) { LinkedList<ChunkCoordIntPair> list = new LinkedList<ChunkCoordIntPair>(); list.add(chunkCoord); chunkRegenMap.put(dimensionId, list); } else { if(!chunkRegenMap.get(dimensionId).contains(chunkCoord)) { chunkRegenMap.get(dimensionId).add(chunkCoord); } } }
Example #4
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 6 votes |
public LinkedList<TicketInfo> getTicketsUnderMouse(DimensionChunkInfo dimInfo, Point mouse) { LinkedList<TicketInfo> mouseOverTickets = new LinkedList<TicketInfo>(); for(TicketInfo ticket : dimInfo.tickets.values()) { for(ChunkCoordIntPair coord : ticket.chunkSet) { Point pos = getChunkRenderPosition(coord.chunkXPos, coord.chunkZPos); if(new Rectangle(pos.x, pos.y, 4, 4).contains(mouse)) { mouseOverTickets.add(ticket); } } } return mouseOverTickets; }
Example #5
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 6 votes |
public void update() { TicketInfo ticket = tickets.get(ticketComboBox.getSelectedIndex()); String info = "<span style=\"font-family:Tahoma; font-size:10px\">"; info += "Mod: " + ticket.modId; if(ticket.player != null) info += "<br>Player: " + ticket.player; info += "<br>Type: " + ticket.type.name(); if(ticket.entity != null) info += "<br>Entity: " + EntityList.classToStringMapping.get(ticket.entity) + "#" + ticket.entity.getEntityId() + " (" + String.format("%.2f", ticket.entity.posX) + ", " + String.format("%.2f", ticket.entity.posY) + ", " + String.format("%.2f", ticket.entity.posZ) + ")"; info+="</span><p style=\"text-align:center; font-family:Tahoma; font-size:10px\">ForcedChunks</p>"; String chunks = "<span style=\"font-family:Tahoma; font-size:10px\">"; for(ChunkCoordIntPair coord : ticket.chunkSet) chunks += coord.chunkXPos + ", " + coord.chunkZPos + "<br>"; chunks += "</span>"; infoPane.setText(info); chunkPane.setText(chunks); repaint(); }
Example #6
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 6 votes |
public TicketInfo(PacketCustom packet, WorldClient world) { ID = packet.readInt(); modId = packet.readString(); if(packet.readBoolean()) player = packet.readString(); type = net.minecraftforge.common.ForgeChunkManager.Type.values()[packet.readUByte()]; if(type == net.minecraftforge.common.ForgeChunkManager.Type.ENTITY) entity = world.getEntityByID(packet.readInt()); int chunks = packet.readUShort(); chunkSet = new HashSet<ChunkCoordIntPair>(chunks); for(int i = 0; i < chunks; i++) { chunkSet.add(new ChunkCoordIntPair(packet.readInt(), packet.readInt())); } }
Example #7
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
public void addChunkLoader(IChickenChunkLoader loader) { if (reviving) return; int dim = CommonUtils.getDimension(loader.getWorld()); if (dormant) { HashSet<BlockCoord> coords = dormantLoaders.get(dim); if (coords == null) dormantLoaders.put(dim, coords = new HashSet<BlockCoord>()); coords.add(loader.getPosition()); } else { forcedChunksByLoader.put(loader, new HashSet<ChunkCoordIntPair>()); forceChunks(loader, dim, loader.getChunks()); } setDirty(); }
Example #8
Source File: PlayerChunkViewerTracker.java From ChickenChunks with MIT License | 6 votes |
@SuppressWarnings("unchecked") public void loadDimension(WorldServer world) { PacketCustom packet = new PacketCustom(channel, 2).compress(); int dim = CommonUtils.getDimension(world); packet.writeInt(dim); List<Chunk> allchunks = world.theChunkProviderServer.loadedChunks; packet.writeInt(allchunks.size()); for(Chunk chunk : allchunks) { packet.writeInt(chunk.xPosition); packet.writeInt(chunk.zPosition); } Map<Ticket, Collection<ChunkCoordIntPair>> tickets = ForgeChunkManager.getPersistentChunksFor(world).inverse().asMap(); packet.writeInt(tickets.size()); for(Entry<Ticket, Collection<ChunkCoordIntPair>> entry : tickets.entrySet()) writeTicketToPacket(packet, entry.getKey(), entry.getValue()); packet.sendToPlayer(owner); }
Example #9
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
public void updateChunkLoader(IChickenChunkLoader loader) { HashSet<ChunkCoordIntPair> loaderChunks = forcedChunksByLoader.get(loader); if (loaderChunks == null) { addChunkLoader(loader); return; } HashSet<ChunkCoordIntPair> oldChunks = new HashSet<ChunkCoordIntPair>(loaderChunks); HashSet<ChunkCoordIntPair> newChunks = new HashSet<ChunkCoordIntPair>(); for (ChunkCoordIntPair chunk : loader.getChunks()) if (!oldChunks.remove(chunk)) newChunks.add(chunk); int dim = CommonUtils.getDimension(loader.getWorld()); if (!oldChunks.isEmpty()) unforceChunks(loader, dim, oldChunks, false); if (!newChunks.isEmpty()) forceChunks(loader, dim, newChunks); }
Example #10
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
private void forceChunks(IChickenChunkLoader loader, int dim, Collection<ChunkCoordIntPair> chunks) { for (ChunkCoordIntPair coord : chunks) { DimChunkCoord dimCoord = new DimChunkCoord(dim, coord); LinkedList<IChickenChunkLoader> loaders = forcedChunksByChunk.get(dimCoord); if (loaders == null) forcedChunksByChunk.put(dimCoord, loaders = new LinkedList<IChickenChunkLoader>()); if (loaders.isEmpty()) { timedUnloadQueue.remove(dimCoord); addChunk(dimCoord); } if (!loaders.contains(loader)) loaders.add(loader); } forcedChunksByLoader.get(loader).addAll(chunks); setDirty(); }
Example #11
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
private void unforceChunks(IChickenChunkLoader loader, int dim, Collection<ChunkCoordIntPair> chunks, boolean remLoader) { for (ChunkCoordIntPair coord : chunks) { DimChunkCoord dimCoord = new DimChunkCoord(dim, coord); LinkedList<IChickenChunkLoader> loaders = forcedChunksByChunk.get(dimCoord); if (loaders == null || !loaders.remove(loader)) continue; if (loaders.isEmpty()) { forcedChunksByChunk.remove(dimCoord); timedUnloadQueue.put(dimCoord, 100); } } if (!remLoader) forcedChunksByLoader.get(loader).removeAll(chunks); setDirty(); }
Example #12
Source File: PlayerChunkViewerTracker.java From ChickenChunks with MIT License | 6 votes |
public void writeTicketToPacket(PacketCustom packet, Ticket ticket, Collection<ChunkCoordIntPair> chunkSet) { packet.writeInt(manager.ticketIDs.get(ticket)); packet.writeString(ticket.getModId()); String player = ticket.getPlayerName(); packet.writeBoolean(player != null); if(player != null) packet.writeString(player); packet.writeByte(ticket.getType().ordinal()); Entity entity = ticket.getEntity(); if(entity != null) packet.writeInt(entity.getEntityId()); packet.writeShort(chunkSet.size()); for(ChunkCoordIntPair chunk : chunkSet) { packet.writeInt(chunk.chunkXPos); packet.writeInt(chunk.chunkZPos); } knownTickets.add(manager.ticketIDs.get(ticket)); }
Example #13
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public boolean canForceNewChunks(int dimension, Collection<ChunkCoordIntPair> chunks) { if (dormant) return true; int required = 0; for (ChunkCoordIntPair coord : chunks) { LinkedList<IChickenChunkLoader> loaders = forcedChunksByChunk.get(new DimChunkCoord(dimension, coord)); if (loaders == null || loaders.isEmpty()) required++; } return canForceNewChunks(required, dimension); }
Example #14
Source File: VanillaChunkHashMap.java From Thermos with GNU General Public License v3.0 | 5 votes |
private long V2B(long key) { if(notRealFace) { return key; } else { return ChunkCoordIntPair.chunkXZ2Int(LongHash.msw(key) , LongHash.lsw(key)); } //return LongHash.toLong((int) (key & 0xFFFFFFFFL), (int) (key >>> 32)); }
Example #15
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public void remChunkLoader(IChickenChunkLoader loader) { int dim = CommonUtils.getDimension(loader.getWorld()); if (dormant) { HashSet<BlockCoord> coords = dormantLoaders.get(dim); if(coords != null) coords.remove(loader.getPosition()); } else { HashSet<ChunkCoordIntPair> chunks = forcedChunksByLoader.remove(loader); if (chunks == null) return; unforceChunks(loader, dim, chunks, true); } setDirty(); }
Example #16
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public static boolean canLoaderAdd(IChickenChunkLoader loader, Collection<ChunkCoordIntPair> chunks) { String owner = loader.getOwner(); int dim = CommonUtils.getDimension(loader.getWorld()); if (owner != null) return getPlayerOrganiser(owner).canForceNewChunks(dim, chunks); return false; }
Example #17
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
@SuppressWarnings("unchecked") public static void cleanChunks(WorldServer world) { int dim = CommonUtils.getDimension(world); int viewdist = ServerUtils.mc().getConfigurationManager().getViewDistance(); HashSet<ChunkCoordIntPair> loadedChunks = new HashSet<ChunkCoordIntPair>(); for (EntityPlayer player : ServerUtils.getPlayersInDimension(dim)) { int playerChunkX = (int) player.posX >> 4; int playerChunkZ = (int) player.posZ >> 4; for (int cx = playerChunkX - viewdist; cx <= playerChunkX + viewdist; cx++) for (int cz = playerChunkZ - viewdist; cz <= playerChunkZ + viewdist; cz++) loadedChunks.add(new ChunkCoordIntPair(cx, cz)); } ImmutableSetMultimap<ChunkCoordIntPair, Ticket> persistantChunks = world.getPersistentChunks(); PlayerManager manager = world.getPlayerManager(); for (Chunk chunk : (List<Chunk>) world.theChunkProviderServer.loadedChunks) { ChunkCoordIntPair coord = chunk.getChunkCoordIntPair(); if (!loadedChunks.contains(coord) && !persistantChunks.containsKey(coord) && world.theChunkProviderServer.chunkExists(coord.chunkXPos, coord.chunkZPos)) { PlayerInstance instance = manager.getOrCreateChunkWatcher(coord.chunkXPos, coord.chunkZPos, false); if (instance == null) { world.theChunkProviderServer.unloadChunksIfNotNearSpawn(coord.chunkXPos, coord.chunkZPos); } else { while (instance.playersWatchingChunk.size() > 0) instance.removePlayer((EntityPlayerMP) instance.playersWatchingChunk.get(0)); } } } if (ServerUtils.getPlayersInDimension(dim).isEmpty() && world.getPersistentChunks().isEmpty() && !DimensionManager.shouldLoadSpawn(dim)) { DimensionManager.unloadWorld(dim); } }
Example #18
Source File: PlayerChunkViewerManager.java From ChickenChunks with MIT License | 5 votes |
public TicketChange(Ticket ticket, ChunkCoordIntPair chunk, boolean force) { this.ticket = ticket; this.dimension = CommonUtils.getDimension(ticket.world); this.chunk = chunk; this.force = force; }
Example #19
Source File: PlayerChunkViewerManager.java From ChickenChunks with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void updateChunkChangeMap() { for(WorldServer world : DimensionManager.getWorlds()) { HashSet<ChunkCoordIntPair> allChunks = new HashSet<ChunkCoordIntPair>(); ArrayList<Chunk> loadedChunkCopy = new ArrayList<Chunk>(world.theChunkProviderServer.loadedChunks); for(Chunk chunk : loadedChunkCopy) allChunks.add(chunk.getChunkCoordIntPair()); lastLoadedChunkMap.put(CommonUtils.getDimension(world), allChunks); } }
Example #20
Source File: MyTownLoadingCallback.java From MyTown2 with The Unlicense | 5 votes |
@Override public void ticketsLoaded(List<ForgeChunkManager.Ticket> tickets, World world) { for (ForgeChunkManager.Ticket ticket : tickets) { NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound chunkNBT = list.getCompoundTagAt(i); ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkNBT.getInteger("x"), chunkNBT.getInteger("z"))); } } MyTownLoadingCallback.tickets.addAll(tickets); }
Example #21
Source File: ChunkExtension.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public boolean equals(Object o) { return (o instanceof ChunkExtension && ((ChunkExtension)o).coord.equals(coord)) || (o instanceof ChunkCoordIntPair && coord.equals(o)) || (o instanceof Long && (Long)o == (((long)coord.chunkXPos)<<32 | coord.chunkZPos)); }
Example #22
Source File: BigReactorsTickHandler.java From BigReactors with MIT License | 5 votes |
@SubscribeEvent public void onWorldTick(TickEvent.WorldTickEvent event) { if(event.side == Side.SERVER && event.phase == TickEvent.Phase.END) { if(chunkRegenMap == null) { return; } if(event.world.isRemote) { return; } int dimensionId = event.world.provider.dimensionId; if(chunkRegenMap.containsKey(dimensionId)) { // Split up regen so it takes at most 16 millisec per frame to allow for ~55-60 FPS Queue<ChunkCoordIntPair> chunksToGen = chunkRegenMap.get(dimensionId); long startTime = System.nanoTime(); while(System.nanoTime() - startTime < maximumDeltaTimeNanoSecs && !chunksToGen.isEmpty()) { // Regenerate chunk ChunkCoordIntPair nextChunk = chunksToGen.poll(); if(nextChunk == null) { break; } Random fmlRandom = new Random(event.world.getSeed()); long xSeed = fmlRandom.nextLong() >> 2 + 1L; long zSeed = fmlRandom.nextLong() >> 2 + 1L; fmlRandom.setSeed((xSeed * nextChunk.chunkXPos + zSeed * nextChunk.chunkZPos) ^ event.world.getSeed()); BigReactors.worldGenerator.generateChunk(fmlRandom, nextChunk.chunkXPos, nextChunk.chunkZPos, event.world); } if(chunksToGen.isEmpty()) { chunkRegenMap.remove(dimensionId); } } } }
Example #23
Source File: MultiblockWorldRegistry.java From BeefCore with MIT License | 5 votes |
/** * Called when a chunk has finished loading. Adds all of the parts which are awaiting * load to the list of parts which are orphans and therefore will be added to machines * after the next world tick. * * @param chunkX Chunk X coordinate (world coordate >> 4) of the chunk that was loaded * @param chunkZ Chunk Z coordinate (world coordate >> 4) of the chunk that was loaded */ public void onChunkLoaded(int chunkX, int chunkZ) { long chunkHash = ChunkCoordIntPair.chunkXZ2Int(chunkX, chunkZ); if(partsAwaitingChunkLoad.containsKey(chunkHash)) { synchronized(partsAwaitingChunkLoadMutex) { if(partsAwaitingChunkLoad.containsKey(chunkHash)) { addAllOrphanedPartsThreadsafe(partsAwaitingChunkLoad.get(chunkHash)); partsAwaitingChunkLoad.remove(chunkHash); } } } }
Example #24
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 5 votes |
public void handleTicketChange(int dimension, int ticketID, ChunkCoordIntPair coord, boolean force) { synchronized(dimensionChunks) { DimensionChunkInfo dimInfo = dimensionChunks.get(dimension); TicketInfo ticket = dimInfo.tickets.get(ticketID); if(force) ticket.chunkSet.add(coord); else ticket.chunkSet.remove(coord); } }
Example #25
Source File: PlayerChunkViewer.java From ChickenChunks with MIT License | 5 votes |
public void handleChunkChange(int dimension, ChunkCoordIntPair coord, boolean add) { synchronized(dimensionChunks) { if(add) dimensionChunks.get(dimension).allchunks.add(coord); else dimensionChunks.get(dimension).allchunks.remove(coord); } }
Example #26
Source File: ForgeQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public ExtendedBlockStorage[] getCachedSections(World world, int cx, int cz) { Chunk chunk = ((ChunkProviderServer)world.getChunkProvider()).id2ChunkMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(cx, cz)); if (chunk != null) { return chunk.getBlockStorageArray(); } return null; }
Example #27
Source File: ForgeQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) { IChunkProvider provider = world.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; long pos = ChunkCoordIntPair.chunkXZ2Int(x, z); Chunk mcChunk; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); 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 = chunkProvider.provideChunk(x, z); chunkServer.id2ChunkMap.add(pos, mcChunk); chunkServer.loadedChunks.add(mcChunk); if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkProvider, chunkProvider, x, z); } return true; }
Example #28
Source File: ForgeQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public ExtendedBlockStorage[] getCachedSections(World world, int cx, int cz) { Chunk chunk = (Chunk) ((ChunkProviderServer)world.getChunkProvider()).loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(cx, cz)); if (chunk != null) { return chunk.getBlockStorageArray(); } return null; }
Example #29
Source File: TileChunkLoader.java From ChickenChunks with MIT License | 5 votes |
public boolean setShapeAndRadius(ChunkLoaderShape newShape, int newRadius) { if(worldObj.isRemote) { radius = newRadius; shape = newShape; return true; } Collection<ChunkCoordIntPair> chunks = getContainedChunks(newShape, xCoord, zCoord, newRadius); if(chunks.size() > ChunkLoaderManager.maxChunksPerLoader()) { return false; } else if(powered) { radius = newRadius; shape = newShape; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return true; } else if(ChunkLoaderManager.canLoaderAdd(this, chunks)) { radius = newRadius; shape = newShape; ChunkLoaderManager.updateLoader(this); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return true; } return false; }
Example #30
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
public DimChunkCoord(int dim, ChunkCoordIntPair coord) { this(dim, coord.chunkXPos, coord.chunkZPos); }