ForgePatch/patches/minecraft/net/minecraft/world/WorldServer.java.patch

258 lines
14 KiB
Diff

--- a/net/minecraft/world/WorldServer.java
+++ b/net/minecraft/world/WorldServer.java
@@ -85,7 +85,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public class WorldServer extends World implements IThreadListener {
+public class WorldServer extends World implements IThreadListener, net.minecraftforge.common.extensions.IForgeWorldServer {
private static final Logger field_147491_a = LogManager.getLogger();
private final MinecraftServer field_73061_a;
private final EntityTracker field_73062_L;
@@ -105,27 +105,36 @@
protected final VillageSiege field_175740_d = new VillageSiege(this);
ObjectLinkedOpenHashSet<BlockEventData> field_147490_S = new ObjectLinkedOpenHashSet<BlockEventData>();
private boolean field_211159_Q;
+
+ /** Stores the recently processed (lighting) chunks */
+ protected java.util.Set<ChunkPos> doneChunks = new java.util.HashSet<ChunkPos>();
+ public List<Teleporter> customTeleporters = new java.util.ArrayList<Teleporter>();
public WorldServer(MinecraftServer p_i45921_1_, ISaveHandler p_i45921_2_, WorldInfo p_i45921_3_, int p_i45921_4_, Profiler p_i45921_5_) {
- super(p_i45921_2_, p_i45921_3_, DimensionType.func_186069_a(p_i45921_4_).func_186070_d(), p_i45921_5_, false);
+ super(p_i45921_2_, p_i45921_3_,net.minecraftforge.common.DimensionManager.createProviderFor(p_i45921_4_), p_i45921_5_, false);
this.field_73061_a = p_i45921_1_;
this.field_73062_L = new EntityTracker(this);
this.field_73063_M = new PlayerChunkMap(this);
+ // Guarantee the dimension ID was not reset by the provider
+ int providerDim = this.field_73011_w.getId();
this.field_73011_w.func_76558_a(this);
+ this.field_73011_w.setId(providerDim);
this.field_73020_y = this.func_72970_h();
+ perWorldStorage = new WorldSavedDataStorage(new net.minecraftforge.common.WorldSpecificSaveHandler((WorldServer)this, p_i45921_2_));
this.field_85177_Q = new Teleporter(this);
this.func_72966_v();
this.func_72947_a();
this.func_175723_af().func_177725_a(p_i45921_1_.func_175580_aG());
+ net.minecraftforge.common.DimensionManager.setWorld(p_i45921_4_, this, p_i45921_1_);
}
public IWorld func_175643_b() {
this.field_72988_C = new WorldSavedDataStorage(this.field_73019_z);
String s = VillageCollection.func_176062_a(this.field_73011_w);
- VillageCollection villagecollection = (VillageCollection)this.field_72988_C.func_201067_a(VillageCollection::new, s);
+ VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.func_201067_a(VillageCollection::new, s);
if (villagecollection == null) {
this.field_72982_D = new VillageCollection(this);
- this.field_72988_C.func_75745_a(s, this.field_72982_D);
+ this.perWorldStorage.func_75745_a(s, this.field_72982_D);
} else {
this.field_72982_D = villagecollection;
this.field_72982_D.func_82566_a(this);
@@ -150,6 +159,7 @@
this.func_175723_af().func_177750_a(this.field_72986_A.func_176137_E());
}
+ this.initCapabilities();
return this;
}
@@ -163,8 +173,8 @@
this.field_73020_y.func_201711_g().func_202090_b().func_73660_a();
if (this.func_73056_e()) {
if (this.func_82736_K().func_82766_b("doDaylightCycle")) {
- long i = this.field_72986_A.func_76073_f() + 24000L;
- this.field_72986_A.func_76068_b(i - i % 24000L);
+ long i = this.func_72820_D() + 24000L;
+ this.func_72877_b(i - i % 24000L);
}
this.func_73053_d();
@@ -185,7 +195,7 @@
this.field_72986_A.func_82572_b(this.field_72986_A.func_82573_f() + 1L);
if (this.func_82736_K().func_82766_b("doDaylightCycle")) {
- this.field_72986_A.func_76068_b(this.field_72986_A.func_76073_f() + 1L);
+ this.field_72986_A.func_76068_b(this.func_72820_D() + 1L);
}
this.field_72984_F.func_76318_c("tickPending");
@@ -199,6 +209,10 @@
this.field_175740_d.func_75528_a();
this.field_72984_F.func_76318_c("portalForcer");
this.field_85177_Q.func_85189_a(this.func_82737_E());
+ for (Teleporter tele : customTeleporters)
+ {
+ tele.func_85189_a(func_82737_E());
+ }
this.field_72984_F.func_76319_b();
this.func_147488_Z();
this.field_211159_Q = false;
@@ -211,11 +225,13 @@
@Nullable
public Biome.SpawnListEntry func_175734_a(EnumCreatureType p_175734_1_, BlockPos p_175734_2_) {
List<Biome.SpawnListEntry> list = this.func_72863_F().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.isEmpty() ? null : (Biome.SpawnListEntry)WeightedRandom.func_76271_a(this.field_73012_v, list);
}
public boolean func_175732_a(EnumCreatureType p_175732_1_, Biome.SpawnListEntry p_175732_2_, BlockPos p_175732_3_) {
List<Biome.SpawnListEntry> list = this.func_72863_F().func_177458_a(p_175732_1_, p_175732_3_);
+ list = net.minecraftforge.event.ForgeEventFactory.getPotentialSpawns(this, p_175732_1_, p_175732_3_, list);
return list != null && !list.isEmpty() ? list.contains(p_175732_2_) : false;
}
@@ -256,10 +272,7 @@
}
private void func_73051_P() {
- this.field_72986_A.func_76080_g(0);
- this.field_72986_A.func_76084_b(false);
- this.field_72986_A.func_76090_f(0);
- this.field_72986_A.func_76069_a(false);
+ this.field_73011_w.resetRainAndThunder();
}
public boolean func_73056_e() {
@@ -346,7 +359,7 @@
this.field_72984_F.func_76318_c("tickChunk");
chunk.func_150804_b(false);
this.field_72984_F.func_76318_c("thunder");
- if (flag && flag1 && this.field_73012_v.nextInt(100000) == 0) {
+ if (this.field_73011_w.canDoLightning(chunk) && flag && flag1 && this.field_73012_v.nextInt(100000) == 0) {
this.field_73005_l = this.field_73005_l * 3 + 1013904223;
int l = this.field_73005_l >> 2;
BlockPos blockpos = this.func_175736_a(new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
@@ -366,12 +379,13 @@
}
this.field_72984_F.func_76318_c("iceandsnow");
- if (this.field_73012_v.nextInt(16) == 0) {
+ if (this.field_73011_w.canDoRainSnowIce(chunk) && this.field_73012_v.nextInt(16) == 0) {
this.field_73005_l = this.field_73005_l * 3 + 1013904223;
int j2 = this.field_73005_l >> 2;
BlockPos blockpos1 = this.func_205770_a(Heightmap.Type.MOTION_BLOCKING, new BlockPos(j + (j2 & 15), 0, k + (j2 >> 8 & 15)));
BlockPos blockpos2 = blockpos1.func_177977_b();
Biome biome = this.func_180494_b(blockpos1);
+ if (this.func_175648_a(blockpos2, 1, false)) // Forge: check area to avoid loading neighbors in unloaded chunks
if (biome.func_201848_a(this, blockpos2)) {
this.func_175656_a(blockpos2, Blocks.field_150432_aD.func_176223_P());
}
@@ -545,6 +559,11 @@
}
public boolean func_175660_a(EntityPlayer p_175660_1_, BlockPos p_175660_2_) {
+ return super.func_175660_a(p_175660_1_, p_175660_2_);
+ }
+
+ public boolean canMineBlockBody(EntityPlayer p_175660_1_, BlockPos p_175660_2_)
+ {
return !this.field_73061_a.func_175579_a(this, p_175660_2_, p_175660_1_) && this.func_175723_af().func_177746_a(p_175660_2_);
}
@@ -594,6 +613,7 @@
} else if (this.field_72986_A.func_76067_t() == WorldType.field_180272_g) {
this.field_72986_A.func_176143_a(BlockPos.field_177992_a.func_177984_a());
} else {
+ if (net.minecraftforge.event.ForgeEventFactory.onCreateWorldSpawn(this, p_73052_1_)) return;
BiomeProvider biomeprovider = this.field_73020_y.func_201711_g().func_202090_b();
List<Biome> list = biomeprovider.func_76932_a();
Random random = new Random(this.func_72905_C());
@@ -676,6 +696,7 @@
p_73044_2_.func_200209_c(new TextComponentTranslation("menu.savingChunks", new Object[0]));
}
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Save(this));
chunkproviderserver.func_186027_a(p_73044_1_);
for(Chunk chunk : Lists.newArrayList(chunkproviderserver.func_189548_a())) {
@@ -715,6 +736,7 @@
this.field_72986_A.func_201356_c(this.field_73061_a.func_201300_aS().func_201380_c());
this.field_73019_z.func_75755_a(this.field_72986_A, this.field_73061_a.func_184103_al().func_72378_q());
this.field_72988_C.func_75744_a();
+ this.perWorldStorage.func_75744_a();
}
public boolean func_72838_d(Entity p_72838_1_) {
@@ -723,7 +745,7 @@
public void func_175650_b(Collection<Entity> p_175650_1_) {
for(Entity entity : Lists.newArrayList(p_175650_1_)) {
- if (this.func_184165_i(entity)) {
+ if (this.func_184165_i(entity) && !net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityJoinWorldEvent(entity, this))) {
this.field_72996_f.add(entity);
this.func_72923_a(entity);
}
@@ -785,7 +807,7 @@
public boolean func_72942_c(Entity p_72942_1_) {
if (super.func_72942_c(p_72942_1_)) {
- this.field_73061_a.func_184103_al().func_148543_a((EntityPlayer)null, p_72942_1_.field_70165_t, p_72942_1_.field_70163_u, p_72942_1_.field_70161_v, 512.0D, this.field_73011_w.func_186058_p().func_186068_a(), new SPacketSpawnGlobalEntity(p_72942_1_));
+ this.field_73061_a.func_184103_al().func_148543_a((EntityPlayer)null, p_72942_1_.field_70165_t, p_72942_1_.field_70163_u, p_72942_1_.field_70161_v, 512.0D, this.field_73011_w.getId(), new SPacketSpawnGlobalEntity(p_72942_1_));
return true;
} else {
return false;
@@ -802,6 +824,7 @@
public Explosion func_211529_a(@Nullable Entity p_211529_1_, DamageSource p_211529_2_, double p_211529_3_, double p_211529_5_, double p_211529_7_, float p_211529_9_, boolean p_211529_10_, boolean p_211529_11_) {
Explosion explosion = new Explosion(this, p_211529_1_, p_211529_3_, p_211529_5_, p_211529_7_, p_211529_9_, p_211529_10_, p_211529_11_);
+ if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this, explosion)) return explosion;
if (p_211529_2_ != null) {
explosion.func_199592_a(p_211529_2_);
}
@@ -829,7 +852,7 @@
while(!this.field_147490_S.isEmpty()) {
BlockEventData blockeventdata = this.field_147490_S.removeFirst();
if (this.func_147485_a(blockeventdata)) {
- this.field_73061_a.func_184103_al().func_148543_a((EntityPlayer)null, (double)blockeventdata.func_180328_a().func_177958_n(), (double)blockeventdata.func_180328_a().func_177956_o(), (double)blockeventdata.func_180328_a().func_177952_p(), 64.0D, this.field_73011_w.func_186058_p().func_186068_a(), new SPacketBlockAction(blockeventdata.func_180328_a(), blockeventdata.func_151337_f(), blockeventdata.func_151339_d(), blockeventdata.func_151338_e()));
+ this.field_73061_a.func_184103_al().func_148543_a((EntityPlayer)null, (double)blockeventdata.func_180328_a().func_177958_n(), (double)blockeventdata.func_180328_a().func_177956_o(), (double)blockeventdata.func_180328_a().func_177952_p(), 64.0D, this.field_73011_w.getId(), new SPacketBlockAction(blockeventdata.func_180328_a(), blockeventdata.func_151337_f(), blockeventdata.func_151339_d(), blockeventdata.func_151338_e()));
}
}
@@ -849,22 +872,26 @@
boolean flag = this.func_72896_J();
super.func_72979_l();
if (this.field_73003_n != this.field_73004_o) {
- this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(7, this.field_73004_o), this.field_73011_w.func_186058_p().func_186068_a());
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(7, this.field_73004_o), this.field_73011_w.getId());
}
if (this.field_73018_p != this.field_73017_q) {
- this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(8, this.field_73017_q), this.field_73011_w.func_186058_p().func_186068_a());
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(8, this.field_73017_q), this.field_73011_w.getId());
}
+ /* The function in use here has been replaced in order to only send the weather info to players in the correct dimension,
+ * rather than to all players on the server. This is what causes the client-side rain, as the
+ * client believes that it has started raining locally, rather than in another dimension.
+ */
if (flag != this.func_72896_J()) {
if (flag) {
- this.field_73061_a.func_184103_al().func_148540_a(new SPacketChangeGameState(2, 0.0F));
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(2, 0.0F), this.field_73011_w.getId());
} else {
- this.field_73061_a.func_184103_al().func_148540_a(new SPacketChangeGameState(1, 0.0F));
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(1, 0.0F), this.field_73011_w.getId());
}
- this.field_73061_a.func_184103_al().func_148540_a(new SPacketChangeGameState(7, this.field_73004_o));
- this.field_73061_a.func_184103_al().func_148540_a(new SPacketChangeGameState(8, this.field_73017_q));
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(7, this.field_73004_o), this.field_73011_w.getId());
+ this.field_73061_a.func_184103_al().func_148537_a(new SPacketChangeGameState(8, this.field_73017_q), this.field_73011_w.getId());
}
}
@@ -957,4 +984,12 @@
public NetworkTagManager func_205772_D() {
return this.field_73061_a.func_199731_aO();
}
+
+ private long[] tickTime = new long[100];
+ public void setTickTime(int tick, long time) {
+ this.tickTime[tick % 100] = time;
+ }
+ public long[] getTickTimes() {
+ return this.tickTime;
+ }
}