Java源码示例:net.minecraft.world.ChunkCoordIntPair
示例1
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));
}
示例2
@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);
}
示例3
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()));
}
}
示例4
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();
}
示例5
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;
}
示例6
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);
}
}
示例7
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();
}
示例8
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();
}
示例9
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();
}
示例10
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);
}
示例11
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);
}
}
}
示例12
@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);
}
示例13
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));
}
示例14
@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;
}
示例15
@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;
}
示例16
@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;
}
示例17
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;
}
示例18
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);
}
}
示例19
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);
}
}
示例20
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);
}
示例21
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();
}
示例22
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;
}
示例23
@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);
}
}
示例24
public TicketChange(Ticket ticket, ChunkCoordIntPair chunk, boolean force)
{
this.ticket = ticket;
this.dimension = CommonUtils.getDimension(ticket.world);
this.chunk = chunk;
this.force = force;
}
示例25
@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);
}
}
示例26
@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);
}
示例27
@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));
}
示例28
@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);
}
}
}
}
示例29
/**
* 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);
}
}
}
}
示例30
public void run() {
int xCenter = this.getVeinCenterCoordinate(this.mX >> 4);
int zCenter = this.getVeinCenterCoordinate(this.mZ >> 4);
Random random = this.getRandom(xCenter, zCenter);
xCenter <<= 4;
zCenter <<= 4;
ChunkCoordIntPair centerChunk = new ChunkCoordIntPair(xCenter, zCenter);
if (!BW_WordGenerator.WorldGenContainer.mGenerated.contains(centerChunk) && this.surroundingChunksLoaded(xCenter, zCenter)) {
BW_WordGenerator.WorldGenContainer.mGenerated.add(centerChunk);
if ((BW_OreLayer.sWeight > 0) && (BW_OreLayer.sList.size() > 0)) {
boolean temp = true;
int tRandomWeight;
for (int i = 0; (i < 256) && (temp); i++) {
tRandomWeight = random.nextInt(BW_OreLayer.sWeight);
for (BW_OreLayer tWorldGen : BW_OreLayer.sList) {
if (!tWorldGen.isGenerationAllowed(this.mWorld, this.mDimensionType, this.mDimensionType))
continue;
tRandomWeight -= tWorldGen.mWeight;
if (tRandomWeight <= 0) {
try {
boolean placed;
int attempts = 0;
do {
placed = tWorldGen.executeWorldgen(this.mWorld, random, "", this.mDimensionType, xCenter, zCenter, this.mChunkGenerator, this.mChunkProvider);
++attempts;
}
while ((!placed) && attempts < 25);
temp = false;
break;
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
}
}
}
}
}
Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ);
if (tChunk != null) {
tChunk.isModified = true;
}
}