diff --git a/src/main/java/net/minecraft/client/multiplayer/WorldClient.java b/src/main/java/net/minecraft/client/multiplayer/WorldClient.java index 9b8dd95..adae0a4 100644 --- a/src/main/java/net/minecraft/client/multiplayer/WorldClient.java +++ b/src/main/java/net/minecraft/client/multiplayer/WorldClient.java @@ -2,11 +2,17 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.set.hash.TIntHashSet; + import java.util.HashSet; import java.util.Iterator; import java.util.Random; import java.util.Set; import java.util.concurrent.Callable; + +import org.ultramine.server.chunk.ChunkHash; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; @@ -33,7 +39,6 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.storage.SaveHandlerMP; - import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; @@ -46,7 +51,7 @@ private Set entityList = new HashSet(); private Set entitySpawnQueue = new HashSet(); private final Minecraft mc = Minecraft.getMinecraft(); - private final Set previousActiveChunkSet = new HashSet(); + private final TIntHashSet previousActiveChunkSet = new TIntHashSet(512); private static final String __OBFID = "CL_00000882"; public WorldClient(NetHandlerPlayClient p_i45063_1_, WorldSettings p_i45063_2_, int p_i45063_3_, EnumDifficulty p_i45063_4_, Profiler p_i45063_5_) @@ -104,7 +109,7 @@ protected void func_147456_g() { super.func_147456_g(); - this.previousActiveChunkSet.retainAll(this.activeChunkSet); + this.previousActiveChunkSet.retainAll(this.activeChunkSet.keySet()); if (this.previousActiveChunkSet.size() == this.activeChunkSet.size()) { @@ -112,21 +117,22 @@ } int i = 0; - Iterator iterator = this.activeChunkSet.iterator(); - - while (iterator.hasNext()) + for (TIntIterator iter = activeChunkSet.keySet().iterator(); iter.hasNext();) { - ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next(); + int chunkCoord = iter.next(); - if (!this.previousActiveChunkSet.contains(chunkcoordintpair)) + if (!this.previousActiveChunkSet.contains(chunkCoord)) { - int j = chunkcoordintpair.chunkXPos * 16; - int k = chunkcoordintpair.chunkZPos * 16; + int chunkX = ChunkHash.keyToX(chunkCoord); + int chunkZ = ChunkHash.keyToZ(chunkCoord); + + int j = chunkX << 4; + int k = chunkZ << 4; this.theProfiler.startSection("getChunk"); - Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos); + Chunk chunk = this.getChunkFromChunkCoords(chunkX, chunkZ); this.func_147467_a(j, k, chunk); this.theProfiler.endSection(); - this.previousActiveChunkSet.add(chunkcoordintpair); + this.previousActiveChunkSet.add(chunkCoord); ++i; if (i >= 10) diff --git a/src/main/java/net/minecraft/world/World.java b/src/main/java/net/minecraft/world/World.java index ce3e84b..73a53ec 100644 --- a/src/main/java/net/minecraft/world/World.java +++ b/src/main/java/net/minecraft/world/World.java @@ -2,6 +2,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.map.TIntByteMap; +import gnu.trove.map.hash.TIntByteHashMap; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -11,6 +14,10 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.Callable; + +import org.ultramine.server.ConfigurationHandler; +import org.ultramine.server.chunk.ChunkHash; + import net.minecraft.block.Block; import net.minecraft.block.BlockHopper; import net.minecraft.block.BlockLiquid; @@ -51,7 +58,6 @@ import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.MapStorage; import net.minecraft.world.storage.WorldInfo; - import cpw.mods.fml.common.FMLLog; import com.google.common.collect.ImmutableSetMultimap; @@ -114,7 +120,7 @@ private final Calendar theCalendar = Calendar.getInstance(); protected Scoreboard worldScoreboard = new Scoreboard(); public boolean isRemote; - protected Set activeChunkSet = new HashSet(); + protected TIntByteMap activeChunkSet = new TIntByteHashMap(512, 0.75F, 0, Byte.MAX_VALUE);//XXX private int ambientTickCountdown; protected boolean spawnHostileMobs; protected boolean spawnPeacefulMobs; @@ -1881,7 +1887,7 @@ { TileEntity tileentity = (TileEntity)iterator.next(); - if (!tileentity.isInvalid() && tileentity.hasWorldObj() && this.blockExists(tileentity.xCoord, tileentity.yCoord, tileentity.zCoord)) + if (!tileentity.isInvalid() && tileentity.hasWorldObj() && activeChunkSet.containsKey(ChunkHash.chunkToKey(tileentity.xCoord >> 4, tileentity.zCoord >> 4))) { try { @@ -1987,16 +1993,17 @@ { int i = MathHelper.floor_double(par1Entity.posX); int j = MathHelper.floor_double(par1Entity.posZ); - boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4)); - byte b0 = isForced ? (byte)0 : 32; - boolean canUpdate = !par2 || this.checkChunksExist(i - b0, 0, j - b0, i + b0, 0, j + b0); - - if (!canUpdate) - { - EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(par1Entity); - MinecraftForge.EVENT_BUS.post(event); - canUpdate = event.canUpdate; - } + //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4)); + //byte b0 = isForced ? (byte)0 : 32; + //boolean canUpdate = !par2 || this.checkChunksExist(i - b0, 0, j - b0, i + b0, 0, j + b0); + boolean canUpdate = activeChunkSet.containsKey(ChunkHash.chunkToKey(i >> 4, j >> 4)); + + //if (!canUpdate) + //{ + // EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(par1Entity); + // MinecraftForge.EVENT_BUS.post(event); + // canUpdate = event.canUpdate; + //} if (canUpdate) { @@ -2718,7 +2725,8 @@ { this.activeChunkSet.clear(); this.theProfiler.startSection("buildList"); - this.activeChunkSet.addAll(getPersistentChunks().keySet()); + if(ConfigurationHandler.getServerConfig().enableChunkLoaders) + for(ChunkCoordIntPair c : getPersistentChunks().keySet()) activeChunkSet.put(ChunkHash.chunkToKey(c.chunkXPos, c.chunkZPos), (byte)100); int i; EntityPlayer entityplayer; int j; @@ -2729,13 +2737,22 @@ entityplayer = (EntityPlayer)this.playerEntities.get(i); j = MathHelper.floor_double(entityplayer.posX / 16.0D); k = MathHelper.floor_double(entityplayer.posZ / 16.0D); - byte b0 = 7; + int b0 = ConfigurationHandler.getServerConfig().chunkUpdateRadius; for (int l = -b0; l <= b0; ++l) { for (int i1 = -b0; i1 <= b0; ++i1) { - this.activeChunkSet.add(new ChunkCoordIntPair(l + j, i1 + k)); + int cx = l + j; + int cy = i1 + k; + if(chunkExists(cx, cy)) + { + int key = ChunkHash.chunkToKey(cx, cy); + int priority = Math.max(Math.abs(l), Math.abs(i1)); + //Chunk chunk = this.chunkProvider.provideChunk(cx, cy); + //if(priority > 1) priority -= Math.min(priority-2, (int)(this.getTotalWorldTime() - chunk.lastActiveOrBindTick)/20); + activeChunkSet.put(key, (byte)Math.min(priority, activeChunkSet.get(key))); + } } } } diff --git a/src/main/java/net/minecraft/world/WorldServer.java b/src/main/java/net/minecraft/world/WorldServer.java index 2cc38e0..fdac4da 100644 --- a/src/main/java/net/minecraft/world/WorldServer.java +++ b/src/main/java/net/minecraft/world/WorldServer.java @@ -2,6 +2,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gnu.trove.iterator.TIntByteIterator; +import gnu.trove.set.TIntSet; +import gnu.trove.set.hash.TIntHashSet; + import java.io.File; import java.util.ArrayList; import java.util.HashSet; @@ -10,6 +14,7 @@ import java.util.Random; import java.util.Set; import java.util.TreeSet; + import net.minecraft.block.Block; import net.minecraft.block.BlockEventData; import net.minecraft.block.material.Material; @@ -65,6 +70,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.ultramine.server.chunk.ChunkHash; public class WorldServer extends World { @@ -88,7 +94,7 @@ private static final String __OBFID = "CL_00001437"; /** Stores the recently processed (lighting) chunks */ - protected Set doneChunks = new HashSet(); + protected TIntSet doneChunks = new TIntHashSet(512); public List customTeleporters = new ArrayList(); public WorldServer(MinecraftServer p_i45284_1_, ISaveHandler p_i45284_2_, String p_i45284_3_, int p_i45284_4_, WorldSettings p_i45284_5_, Profiler p_i45284_6_) @@ -301,9 +307,8 @@ super.func_147456_g(); int i = 0; int j = 0; - Iterator iterator = this.activeChunkSet.iterator(); - doneChunks.retainAll(activeChunkSet); + doneChunks.retainAll(activeChunkSet.keySet()); if (doneChunks.size() == activeChunkSet.size()) { doneChunks.clear(); @@ -311,17 +316,21 @@ final long startTime = System.nanoTime(); - while (iterator.hasNext()) + for (TIntByteIterator iter = activeChunkSet.iterator(); iter.hasNext();) { - ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair)iterator.next(); - int k = chunkcoordintpair.chunkXPos * 16; - int l = chunkcoordintpair.chunkZPos * 16; + iter.advance(); + int chunkCoord = iter.key(); + int chunkX = ChunkHash.keyToX(chunkCoord); + int chunkZ = ChunkHash.keyToZ(chunkCoord); + int k = chunkX << 4; + int l = chunkZ << 4; + this.theProfiler.startSection("getChunk"); - Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos); + Chunk chunk = this.getChunkFromChunkCoords(chunkX, chunkZ); this.func_147467_a(k, l, chunk); this.theProfiler.endStartSection("tickChunk"); //Limits and evenly distributes the lighting update time - if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(chunkcoordintpair)) + if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(chunkCoord)) { chunk.func_150804_b(false); } @@ -534,7 +543,14 @@ this.pendingTickListEntriesTreeSet.remove(nextticklistentry); this.pendingTickListEntriesHashSet.remove(nextticklistentry); - this.pendingTickListEntriesThisTick.add(nextticklistentry); + if(activeChunkSet.containsKey(ChunkHash.chunkToKey(nextticklistentry.xCoord >> 4, nextticklistentry.zCoord >> 4))) + { + this.pendingTickListEntriesThisTick.add(nextticklistentry); + } + else + { + i = Math.min(i+1, pendingTickListEntriesTreeSet.size()); + } } this.theProfiler.endSection(); diff --git a/src/main/java/org/ultramine/server/UltramineServerConfig.java b/src/main/java/org/ultramine/server/UltramineServerConfig.java index 4c7d5ee..e6de13c 100644 --- a/src/main/java/org/ultramine/server/UltramineServerConfig.java +++ b/src/main/java/org/ultramine/server/UltramineServerConfig.java @@ -7,6 +7,8 @@ { public WatchdogThreadConfig watchdogThread = new WatchdogThreadConfig(); public VanillaConfig vanilla = new VanillaConfig(); + public boolean enableChunkLoaders = true; + public int chunkUpdateRadius = 7; public static class WatchdogThreadConfig { @@ -14,6 +16,8 @@ public boolean restart = true; } + + public static class VanillaConfig { public String generatorSettings = "";