WorldProvider, WorldType, WorldServer, WorldServerMulti

This commit is contained in:
RainWarrior 2015-11-10 20:09:49 +03:00
parent adddfab850
commit df05edaa11
7 changed files with 296 additions and 150 deletions

View File

@ -44,6 +44,22 @@
+ return this.terrainType.getCloudHeight();
}
@SideOnly(Side.CLIENT)
@@ -176,13 +162,13 @@
public int getAverageGroundLevel()
{
- return this.terrainType == WorldType.FLAT ? 4 : this.worldObj.func_181545_F() + 1;
+ return this.terrainType.getMinimumSpawnHeight(this.worldObj);
}
@SideOnly(Side.CLIENT)
public double getVoidFogYFactor()
{
- return this.terrainType == WorldType.FLAT ? 1.0D : 0.03125D;
+ return this.terrainType.voidFadeMagnitude();
}
@SideOnly(Side.CLIENT)
@@ -224,4 +210,319 @@
{

View File

@ -60,7 +60,15 @@
this.theProfiler.endSection();
this.sendQueuedBlockEvents();
}
@@ -269,10 +289,7 @@
@@ -218,6 +238,7 @@
public BiomeGenBase.SpawnListEntry func_175734_a(EnumCreatureType p_175734_1_, BlockPos p_175734_2_)
{
List<BiomeGenBase.SpawnListEntry> list = this.getChunkProvider().func_177458_a(p_175734_1_, p_175734_2_);
+ list = net.minecraftforge.event.ForgeEventFactory.getPotentialSpawns(this, p_175734_1_, p_175734_2_, list);
return list != null && !list.isEmpty() ? (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
}
@@ -269,10 +290,7 @@
private void resetRainAndThunder()
{
@ -72,7 +80,7 @@
}
public boolean areAllPlayersAsleep()
@@ -350,7 +367,7 @@
@@ -350,7 +368,7 @@
chunk.func_150804_b(false);
this.theProfiler.endStartSection("thunder");
@ -81,7 +89,7 @@
{
this.updateLCG = this.updateLCG * 3 + 1013904223;
int i1 = this.updateLCG >> 2;
@@ -364,7 +381,7 @@
@@ -364,7 +382,7 @@
this.theProfiler.endStartSection("iceandsnow");
@ -90,7 +98,17 @@
{
this.updateLCG = this.updateLCG * 3 + 1013904223;
int k2 = this.updateLCG >> 2;
@@ -510,7 +527,7 @@
@@ -458,6 +476,9 @@
if (p_175654_2_.requiresUpdates())
{
i = 8;
+ //Keeping here as a note for future when it may be restored.
+ boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.position.getX() >> 4, nextticklistentry.position.getZ() >> 4));
+ i = isForced ? 0 : 8;
if (this.isAreaLoaded(nextticklistentry.position.add(-i, -i, -i), nextticklistentry.position.add(i, i, i)))
{
@@ -510,7 +531,7 @@
public void updateEntities()
{
@ -99,7 +117,53 @@
{
if (this.updateEntityTick++ >= 1200)
{
@@ -714,6 +731,10 @@
@@ -575,6 +596,9 @@
{
NextTickListEntry nextticklistentry1 = (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;
int k = 0;
if (this.isAreaLoaded(nextticklistentry1.position.add(-k, -k, -k), nextticklistentry1.position.add(k, k, k)))
@@ -698,22 +722,39 @@
{
List<TileEntity> list = Lists.<TileEntity>newArrayList();
- for (int i = 0; i < this.loadedTileEntityList.size(); ++i)
+ //Forge: Optomize this loop to only grab from the chunks it needs
+ for (int x = (p_147486_1_ >> 4); x <= (p_147486_4_ >> 4); x++)
{
- TileEntity tileentity = (TileEntity)this.loadedTileEntityList.get(i);
- BlockPos blockpos = tileentity.getPos();
-
- if (blockpos.getX() >= p_147486_1_ && blockpos.getY() >= p_147486_2_ && blockpos.getZ() >= p_147486_3_ && blockpos.getX() < p_147486_4_ && blockpos.getY() < p_147486_5_ && blockpos.getZ() < p_147486_6_)
+ for (int z = (p_147486_3_ >> 4); z <= (p_147486_6_ >> 4); z++)
{
- list.add(tileentity);
+ Chunk chunk = this.getChunkFromChunkCoords(x, z);
+ if (chunk != null)
+ {
+ for (TileEntity entity : chunk.getTileEntityMap().values())
+ {
+ if (!entity.isInvalid())
+ {
+ BlockPos pos = entity.getPos();
+ if (pos.getX() >= p_147486_1_ && pos.getY() >= p_147486_2_ && pos.getZ() >= p_147486_3_ &&
+ pos.getX() <= p_147486_4_ && pos.getY() <= p_147486_5_ && pos.getZ() <= p_147486_6_)
+ {
+ list.add(entity);
+ }
+
+ }
+ }
+ }
}
}
-
return list;
}
public boolean isBlockModifiable(EntityPlayer player, BlockPos pos)
{
@ -110,7 +174,7 @@
return !this.mcServer.isBlockProtected(this, pos, player) && this.getWorldBorder().contains(pos);
}
@@ -779,6 +800,7 @@
@@ -779,6 +820,7 @@
}
else
{
@ -118,7 +182,7 @@
this.findingSpawnPoint = true;
WorldChunkManager worldchunkmanager = this.provider.getWorldChunkManager();
List<BiomeGenBase> list = worldchunkmanager.getBiomesToSpawnIn();
@@ -824,7 +846,7 @@
@@ -824,7 +866,7 @@
protected void createBonusChest()
{
@ -127,7 +191,15 @@
for (int i = 0; i < 10; ++i)
{
@@ -894,6 +916,7 @@
@@ -861,6 +903,7 @@
}
this.chunkProvider.saveChunks(p_73044_1_, p_73044_2_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Save(this));
for (Chunk chunk : Lists.newArrayList(this.theChunkProviderServer.func_152380_a()))
{
@@ -894,6 +937,7 @@
this.worldInfo.setBorderLerpTime(this.getWorldBorder().getTimeUntilTarget());
this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData());
this.mapStorage.saveAllData();
@ -135,7 +207,7 @@
}
public void onEntityAdded(Entity p_72923_1_)
@@ -949,6 +972,7 @@
@@ -949,6 +993,7 @@
public Explosion newExplosion(Entity p_72885_1_, double p_72885_2_, double p_72885_4_, double p_72885_6_, float p_72885_8_, boolean p_72885_9_, boolean p_72885_10_)
{
Explosion explosion = new Explosion(this, p_72885_1_, p_72885_2_, p_72885_4_, p_72885_6_, p_72885_8_, p_72885_9_, p_72885_10_);
@ -143,7 +215,7 @@
explosion.doExplosionA();
explosion.doExplosionB(false);
@@ -1028,19 +1052,23 @@
@@ -1028,19 +1073,23 @@
this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.getDimensionId());
}
@ -171,3 +243,15 @@
}
}
@@ -1106,6 +1155,11 @@
return this.mcServer.isCallingFromMinecraftThread();
}
+ public java.io.File getChunkSaveLocation()
+ {
+ return ((net.minecraft.world.chunk.storage.AnvilChunkLoader)theChunkProviderServer.chunkLoader).chunkSaveLocation;
+ }
+
static class ServerBlockEventList extends ArrayList<BlockEventData>
{
private static final String __OBFID = "CL_00001439";

View File

@ -16,7 +16,37 @@
{
private static final String __OBFID = "CL_00002273";
public void onSizeChanged(WorldBorder border, double newSize)
@@ -75,4 +76,12 @@
@@ -48,11 +49,13 @@
{
WorldServerMulti.this.getWorldBorder().setDamageBuffer(newSize);
}
- });
+ };
+ this.delegate.getWorldBorder().addListener(this.borderListener);
}
protected void saveLevel() throws MinecraftException
{
+ this.perWorldStorage.saveAllData();
}
public World init()
@@ -60,12 +63,12 @@
this.mapStorage = this.delegate.getMapStorage();
this.worldScoreboard = this.delegate.getScoreboard();
String s = VillageCollection.fileNameForProvider(this.provider);
- VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, s);
+ VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.loadData(VillageCollection.class, s);
if (villagecollection == null)
{
this.villageCollectionObj = new VillageCollection(this);
- this.mapStorage.setData(s, this.villageCollectionObj);
+ this.perWorldStorage.setData(s, this.villageCollectionObj);
}
else
{
@@ -75,4 +78,12 @@
return this;
}

View File

@ -0,0 +1,155 @@
--- ../src-base/minecraft/net/minecraft/world/WorldType.java
+++ ../src-work/minecraft/net/minecraft/world/WorldType.java
@@ -28,6 +28,7 @@
private WorldType(int id, String name, int version)
{
+ if (name.length() > 16 && DEBUG_WORLD != null) throw new IllegalArgumentException("World type names must not be longer then 16: " + name);
this.worldType = name;
this.generatorVersion = version;
this.canBeCreated = true;
@@ -114,4 +115,144 @@
this.hasNotificationData = true;
return this;
}
+
+ public net.minecraft.world.biome.WorldChunkManager getChunkManager(World world)
+ {
+ if (this == FLAT)
+ {
+ net.minecraft.world.gen.FlatGeneratorInfo flatgeneratorinfo = net.minecraft.world.gen.FlatGeneratorInfo.createFlatGeneratorFromString(world.getWorldInfo().getGeneratorOptions());
+ return new net.minecraft.world.biome.WorldChunkManagerHell(net.minecraft.world.biome.BiomeGenBase.getBiomeFromBiomeList(flatgeneratorinfo.getBiome(), net.minecraft.world.biome.BiomeGenBase.field_180279_ad), 0.5F);
+ }
+ else if (this == DEBUG_WORLD)
+ {
+ return new net.minecraft.world.biome.WorldChunkManagerHell(net.minecraft.world.biome.BiomeGenBase.plains, 0.0F);
+ }
+ else
+ {
+ return new net.minecraft.world.biome.WorldChunkManager(world);
+ }
+ }
+
+ public net.minecraft.world.chunk.IChunkProvider getChunkGenerator(World world, String generatorOptions)
+ {
+ if (this == FLAT) return new net.minecraft.world.gen.ChunkProviderFlat(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled(), generatorOptions);
+ if (this == DEBUG_WORLD) return new net.minecraft.world.gen.ChunkProviderDebug(world);
+ return new net.minecraft.world.gen.ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled(), generatorOptions);
+ }
+
+ public int getMinimumSpawnHeight(World world)
+ {
+ return this == FLAT ? 4 : 64;
+ }
+
+ public double getHorizon(World world)
+ {
+ return this == FLAT ? 0.0D : 63.0D;
+ }
+
+ public double voidFadeMagnitude()
+ {
+ return this == FLAT ? 1.0D : 0.03125D;
+ }
+
+ public boolean handleSlimeSpawnReduction(java.util.Random random, World world)
+ {
+ return this == FLAT ? random.nextInt(4) != 1 : false;
+ }
+
+ /*=================================================== FORGE START ======================================*/
+ private static int getNextID()
+ {
+ for (int x = 0; x < worldTypes.length; x++)
+ {
+ if (worldTypes[x] == null)
+ {
+ return x;
+ }
+ }
+
+ int oldLen = worldTypes.length;
+ worldTypes = java.util.Arrays.copyOf(worldTypes, oldLen + 16);
+ return oldLen;
+ }
+
+ /**
+ * Creates a new world type, the ID is hidden and should not be referenced by modders.
+ * It will automatically expand the underlying workdType array if there are no IDs left.
+ * @param name
+ */
+ public WorldType(String name)
+ {
+ this(getNextID(), name);
+ }
+
+ /**
+ * Called when 'Create New World' button is pressed before starting game
+ */
+ public void onGUICreateWorldPress() { }
+
+ /**
+ * Gets the spawn fuzz for players who join the world.
+ * Useful for void world types.
+ * @return Fuzz for entity initial spawn in blocks.
+ */
+ public int getSpawnFuzz()
+ {
+ return Math.max(5, net.minecraft.server.MinecraftServer.getServer().getSpawnProtectionSize() - 6);
+ }
+
+ /**
+ * Called when the 'Customize' button is pressed on world creation GUI
+ * @param mc The Minecraft instance
+ * @param guiCreateWorld the createworld GUI
+ */
+ @SideOnly(Side.CLIENT)
+ public void onCustomizeButton(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.GuiCreateWorld guiCreateWorld)
+ {
+ if (this == WorldType.FLAT)
+ {
+ mc.displayGuiScreen(new net.minecraft.client.gui.GuiCreateFlatWorld(guiCreateWorld, guiCreateWorld.chunkProviderSettingsJson));
+ }
+ else if (this == WorldType.CUSTOMIZED)
+ {
+ mc.displayGuiScreen(new net.minecraft.client.gui.GuiCustomizeWorldScreen(guiCreateWorld, guiCreateWorld.chunkProviderSettingsJson));
+ }
+ }
+
+ /**
+ * Should world creation GUI show 'Customize' button for this world type?
+ * @return if this world type has customization parameters
+ */
+ public boolean isCustomizable()
+ {
+ return this == FLAT || this == WorldType.CUSTOMIZED;
+ }
+
+
+ /**
+ * Get the height to render the clouds for this world type
+ * @return The height to render clouds at
+ */
+ public float getCloudHeight()
+ {
+ return 128.0F;
+ }
+
+ /**
+ * Creates the GenLayerBiome used for generating the world with the specified ChunkProviderSettings JSON String
+ * *IF AND ONLY IF* this WorldType == WorldType.CUSTOMIZED.
+ *
+ *
+ * @param worldSeed The world seed
+ * @param parentLayer The parent layer to feed into any layer you return
+ * @param chunkProviderSettingsJson The JSON string to use when initializing ChunkProviderSettings.Factory
+ * @return A GenLayer that will return ints representing the Biomes to be generated, see GenLayerBiome
+ */
+ public net.minecraft.world.gen.layer.GenLayer getBiomeLayer(long worldSeed, net.minecraft.world.gen.layer.GenLayer parentLayer, String chunkProviderSettingsJson)
+ {
+ net.minecraft.world.gen.layer.GenLayer ret = new net.minecraft.world.gen.layer.GenLayerBiome(200L, parentLayer, this, chunkProviderSettingsJson);
+ ret = net.minecraft.world.gen.layer.GenLayerZoom.magnify(1000L, ret, 2);
+ ret = new net.minecraft.world.gen.layer.GenLayerBiomeEdge(1000L, ret);
+ return ret;
+ }
}

View File

@ -1,17 +0,0 @@
++++ REJECTED PATCH 3
public int getAverageGroundLevel()
{
- return this.terrainType == WorldType.FLAT ? 4 : 64;
+ return this.terrainType.getMinimumSpawnHeight(this.worldObj);
}
@SideOnly(Side.CLIENT)
public double getVoidFogYFactor()
{
- return this.terrainType == WorldType.FLAT ? 1.0D : 0.03125D;
+ return this.terrainType.voidFadeMagnitude();
}
@SideOnly(Side.CLIENT)
++++ END PATCH

View File

@ -1,90 +0,0 @@
++++ REJECTED PATCH 3
public BiomeGenBase.SpawnListEntry func_175734_a(EnumCreatureType p_175734_1_, BlockPos p_175734_2_)
{
List list = this.getChunkProvider().func_177458_a(p_175734_1_, p_175734_2_);
+ list = net.minecraftforge.event.ForgeEventFactory.getPotentialSpawns(this, p_175734_1_, p_175734_2_, list);
return list != null && !list.isEmpty() ? (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
}
++++ END PATCH
++++ REJECTED PATCH 7
if (p_175654_2_.requiresUpdates())
{
b0 = 8;
+ //Keeping here as a note for future when it may be restored.
+ boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(nextticklistentry.position.getX() >> 4, nextticklistentry.position.getZ() >> 4));
+ b0 = (byte)(isForced ? 0 : 8);
if (this.isAreaLoaded(nextticklistentry.position.add(-b0, -b0, -b0), nextticklistentry.position.add(b0, b0, b0)))
{
++++ END PATCH
++++ REJECTED PATCH 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.isAreaLoaded(nextticklistentry.position.add(-b0, -b0, -b0), nextticklistentry.position.add(b0, b0, b0)))
++++ END PATCH
++++ REJECTED PATCH 10
{
ArrayList arraylist = Lists.newArrayList();
- for (int k1 = 0; k1 < this.loadedTileEntityList.size(); ++k1)
+ //Forge: Optomize this loop to only grab from the chunks it needs
+ for (int x = (p_147486_1_ >> 4); x <= (p_147486_4_ >> 4); x++)
{
- TileEntity tileentity = (TileEntity)this.loadedTileEntityList.get(k1);
- BlockPos blockpos = tileentity.getPos();
-
- if (blockpos.getX() >= p_147486_1_ && blockpos.getY() >= p_147486_2_ && blockpos.getZ() >= p_147486_3_ && blockpos.getX() < p_147486_4_ && blockpos.getY() < p_147486_5_ && blockpos.getZ() < p_147486_6_)
+ for (int z = (p_147486_3_ >> 4); z <= (p_147486_6_ >> 4); z++)
{
- arraylist.add(tileentity);
+ Chunk chunk = this.getChunkFromChunkCoords(x, z);
+ if (chunk != null)
+ {
+ for (Object obj : chunk.getTileEntityMap().values())
+ {
+ TileEntity entity = (TileEntity)obj;
+ if (!entity.isInvalid())
+ {
+ BlockPos pos = entity.getPos();
+ if (pos.getX() >= p_147486_1_ && pos.getY() >= p_147486_2_ && pos.getZ() >= p_147486_3_ &&
+ pos.getX() <= p_147486_4_ && pos.getY() <= p_147486_5_ && pos.getZ() <= p_147486_6_)
+ {
+ arraylist.add(entity);
+ }
+
+ }
+ }
+ }
}
}
++++ END PATCH
++++ REJECTED PATCH 14
}
this.chunkProvider.saveChunks(p_73044_1_, p_73044_2_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Save(this));
List list = this.theChunkProviderServer.func_152380_a();
Iterator iterator = list.iterator();
++++ END PATCH
++++ REJECTED PATCH 18
return this.mcServer.isCallingFromMinecraftThread();
}
+ public java.io.File getChunkSaveLocation()
+ {
+ return ((net.minecraft.world.chunk.storage.AnvilChunkLoader)theChunkProviderServer.chunkLoader).chunkSaveLocation;
+ }
+
static class ServerBlockEventList extends ArrayList
{
private static final String __OBFID = "CL_00001439";
++++ END PATCH

View File

@ -1,32 +0,0 @@
++++ REJECTED PATCH 2
{
WorldServerMulti.this.getWorldBorder().setDamageBuffer(newSize);
}
- });
+ };
+ this.delegate.getWorldBorder().addListener(this.borderListener);
}
- protected void saveLevel() throws MinecraftException {}
+ protected void saveLevel() throws MinecraftException
+ {
+ this.perWorldStorage.saveAllData();
+ }
public World init()
{
this.mapStorage = this.delegate.getMapStorage();
this.worldScoreboard = this.delegate.getScoreboard();
String s = VillageCollection.fileNameForProvider(this.provider);
- VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, s);
+ VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.loadData(VillageCollection.class, s);
if (villagecollection == null)
{
this.villageCollectionObj = new VillageCollection(this);
- this.mapStorage.setData(s, this.villageCollectionObj);
+ this.perWorldStorage.setData(s, this.villageCollectionObj);
}
else
{
++++ END PATCH