Files
MinecraftForge/patches/minecraft/net/minecraft/world/WorldServer.java.patch
T

248 lines
9.9 KiB
Diff

--- ../src_base/minecraft/net/minecraft/world/WorldServer.java
+++ ../src_work/minecraft/net/minecraft/world/WorldServer.java
@@ -2,6 +2,8 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+
+import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -47,11 +49,19 @@
import net.minecraft.world.biome.WorldChunkManager;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
+import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.WorldGeneratorBonusChest;
import net.minecraft.world.storage.ISaveHandler;
+
+import net.minecraftforge.common.ChestGenHooks;
+import static net.minecraftforge.common.ChestGenHooks.*;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.ForgeEventFactory;
+import net.minecraftforge.event.world.WorldEvent;
public class WorldServer extends World
{
@@ -88,6 +98,10 @@
/** An IntHashMap of entity IDs (integers) to their Entity objects. */
private IntHashMap entityIdMap;
+ /** Stores the recently processed (lighting) chunks */
+ protected Set<ChunkCoordIntPair> doneChunks = new HashSet<ChunkCoordIntPair>();
+ public List<Teleporter> customTeleporters = new ArrayList<Teleporter>();
+
public WorldServer(MinecraftServer par1MinecraftServer, ISaveHandler par2ISaveHandler, String par3Str, int par4, WorldSettings par5WorldSettings, Profiler par6Profiler, ILogAgent par7ILogAgent)
{
super(par2ISaveHandler, par3Str, par5WorldSettings, WorldProvider.getProviderForDimension(par4), par6Profiler, par7ILogAgent);
@@ -120,8 +134,12 @@
this.mapStorage.setData("scoreboard", scoreboardsavedata);
}
- scoreboardsavedata.func_96499_a(this.worldScoreboard);
+ if (!(this instanceof WorldServerMulti)) //Forge: We fix the global mapStorage, which causes us to share scoreboards early. So don't associate the save data with the temporary scoreboard
+ {
+ scoreboardsavedata.func_96499_a(this.worldScoreboard);
+ }
((ServerScoreboard)this.worldScoreboard).func_96547_a(scoreboardsavedata);
+ DimensionManager.setWorld(par4, this);
}
/**
@@ -184,6 +202,10 @@
this.villageSiegeObj.tick();
this.theProfiler.endStartSection("portalForcer");
this.field_85177_Q.func_85189_a(this.getTotalWorldTime());
+ for (Teleporter tele : customTeleporters)
+ {
+ tele.func_85189_a(getTotalWorldTime());
+ }
this.theProfiler.endSection();
this.sendAndApplyBlockEvents();
}
@@ -194,6 +216,7 @@
public SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
{
List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4);
+ list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list);
return list != null && !list.isEmpty() ? (SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
}
@@ -237,10 +260,7 @@
private void resetRainAndThunder()
{
- this.worldInfo.setRainTime(0);
- this.worldInfo.setRaining(false);
- this.worldInfo.setThunderTime(0);
- this.worldInfo.setThundering(false);
+ provider.resetRainAndThunder();
}
public boolean areAllPlayersAsleep()
@@ -311,6 +331,14 @@
int i = 0;
int j = 0;
Iterator iterator = this.activeChunkSet.iterator();
+
+ doneChunks.retainAll(activeChunkSet);
+ if (doneChunks.size() == activeChunkSet.size())
+ {
+ doneChunks.clear();
+ }
+
+ final long startTime = System.nanoTime();
while (iterator.hasNext())
{
@@ -321,14 +349,18 @@
Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
this.moodSoundAndLightCheck(k, l, chunk);
this.theProfiler.endStartSection("tickChunk");
- chunk.updateSkylight();
+ //Limits and evenly distributes the lighting update time
+ if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(chunkcoordintpair))
+ {
+ chunk.updateSkylight();
+ }
this.theProfiler.endStartSection("thunder");
int i1;
int j1;
int k1;
int l1;
- if (this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering())
+ if (provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering())
{
this.updateLCG = this.updateLCG * 3 + 1013904223;
i1 = this.updateLCG >> 2;
@@ -345,7 +377,7 @@
this.theProfiler.endStartSection("iceandsnow");
int i2;
- if (this.rand.nextInt(16) == 0)
+ if (provider.canDoRainSnowIce(chunk) && this.rand.nextInt(16) == 0)
{
this.updateLCG = this.updateLCG * 3 + 1013904223;
i1 = this.updateLCG >> 2;
@@ -433,6 +465,9 @@
public void func_82740_a(int par1, int par2, int par3, int par4, int par5, int par6)
{
NextTickListEntry nextticklistentry = new NextTickListEntry(par1, par2, par3, par4);
+ //Keeping here as a note for future when it may be restored.
+ //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.xCoord >> 4, nextticklistentry.zCoord >> 4));
+ //byte b0 = isForced ? 0 : 8;
byte b0 = 0;
if (this.scheduledUpdatesAreImmediate && par4 > 0)
@@ -496,7 +531,7 @@
*/
public void updateEntities()
{
- if (this.playerEntities.isEmpty())
+ if (this.playerEntities.isEmpty() && getPersistentChunks().isEmpty())
{
if (this.updateEntityTick++ >= 1200)
{
@@ -562,6 +597,9 @@
{
nextticklistentry = (NextTickListEntry)iterator.next();
iterator.remove();
+ //Keeping here as a note for future when it may be restored.
+ //boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.xCoord >> 4, nextticklistentry.zCoord >> 4));
+ //byte b0 = isForced ? 0 : 8;
byte b0 = 0;
if (this.checkChunksExist(nextticklistentry.xCoord - b0, nextticklistentry.yCoord - b0, nextticklistentry.zCoord - b0, nextticklistentry.xCoord + b0, nextticklistentry.yCoord + b0, nextticklistentry.zCoord + b0))
@@ -705,16 +743,28 @@
{
ArrayList arraylist = new ArrayList();
- for (int k1 = 0; k1 < this.loadedTileEntityList.size(); ++k1)
- {
- TileEntity tileentity = (TileEntity)this.loadedTileEntityList.get(k1);
-
- if (tileentity.xCoord >= par1 && tileentity.yCoord >= par2 && tileentity.zCoord >= par3 && tileentity.xCoord < par4 && tileentity.yCoord < par5 && tileentity.zCoord < par6)
- {
- arraylist.add(tileentity);
- }
- }
-
+ for(int x = (par1 >> 4); x <= (par4 >> 4); x++)
+ {
+ for(int z = (par3 >> 4); z <= (par6 >> 4); z++)
+ {
+ Chunk chunk = getChunkFromChunkCoords(x, z);
+ if (chunk != null)
+ {
+ for(Object obj : chunk.chunkTileEntityMap.values())
+ {
+ TileEntity entity = (TileEntity)obj;
+ if (!entity.isInvalid())
+ {
+ if (entity.xCoord >= par1 && entity.yCoord >= par2 && entity.zCoord >= par3 &&
+ entity.xCoord <= par4 && entity.yCoord <= par5 && entity.zCoord <= par6)
+ {
+ arraylist.add(entity);
+ }
+ }
+ }
+ }
+ }
+ }
return arraylist;
}
@@ -722,6 +772,11 @@
* Called when checking if a certain block can be mined or not. The 'spawn safe zone' check is located here.
*/
public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4)
+ {
+ return super.canMineBlock(par1EntityPlayer, par2, par3, par4);
+ }
+
+ public boolean canMineBlockBody(EntityPlayer par1EntityPlayer, int par2, int par3, int par4)
{
return !this.mcServer.func_96290_a(this, par2, par3, par4, par1EntityPlayer);
}
@@ -806,7 +861,7 @@
*/
protected void createBonusChest()
{
- WorldGeneratorBonusChest worldgeneratorbonuschest = new WorldGeneratorBonusChest(bonusChestContent, 10);
+ WorldGeneratorBonusChest worldgeneratorbonuschest = new WorldGeneratorBonusChest(ChestGenHooks.getItems(BONUS_CHEST, rand), ChestGenHooks.getCount(BONUS_CHEST, rand));
for (int i = 0; i < 10; ++i)
{
@@ -849,6 +904,7 @@
}
this.chunkProvider.saveChunks(par1, par2IProgressUpdate);
+ MinecraftForge.EVENT_BUS.post(new WorldEvent.Save(this));
}
}
@@ -860,6 +916,7 @@
this.checkSessionLock();
this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData());
this.mapStorage.saveAllData();
+ this.perWorldStorage.saveAllData();
}
/**
@@ -1073,4 +1130,9 @@
{
return this.field_85177_Q;
}
+
+ public File getChunkSaveLocation()
+ {
+ return ((AnvilChunkLoader)theChunkProviderServer.currentChunkLoader).chunkSaveLocation;
+ }
}