Improve multi-dimension code

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-11-23 18:39:43 +11:00
parent 820ad30036
commit 3e7bd2643c
10 changed files with 157 additions and 167 deletions

View File

@@ -1,11 +1,12 @@
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
@@ -147,6 +147,19 @@
@@ -147,6 +147,20 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.entity.monster.EntityDrowned;
+import net.minecraft.world.level.dimension.WorldDimension;
+import net.minecraft.world.level.storage.WorldDataServer;
+import org.bukkit.Bukkit;
+import org.bukkit.WeatherType;
@@ -20,7 +21,7 @@
public class WorldServer extends World implements GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
@@ -164,7 +177,7 @@
@@ -164,7 +178,7 @@
final List<EntityPlayer> players;
private final ChunkProviderServer chunkSource;
private final MinecraftServer server;
@@ -29,7 +30,7 @@
final EntityTickList entityTickList;
public final PersistentEntitySectionManager<Entity> entityManager;
public boolean noSave;
@@ -186,9 +199,24 @@
@@ -186,9 +200,29 @@
private final StructureCheck structureCheck;
private final boolean tickTime;
@@ -46,6 +47,11 @@
+ return this.chunkSource.getChunk(x, z, false);
+ }
+
+ @Override
+ public ResourceKey<WorldDimension> getTypeKey() {
+ return convertable.dimensionType;
+ }
+
+ // Add env and gen to constructor, WorldData -> WorldDataServer
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey<World> resourcekey, DimensionManager dimensionmanager, WorldLoadListener worldloadlistener, ChunkGenerator chunkgenerator, boolean flag, long i, List<MobSpawner> list, boolean flag1, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
@@ -57,7 +63,7 @@
this.players = Lists.newArrayList();
this.entityTickList = new EntityTickList();
this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
@@ -200,7 +228,13 @@
@@ -200,7 +234,13 @@
this.tickTime = flag1;
this.server = minecraftserver;
this.customSpawners = list;
@@ -72,7 +78,7 @@
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(this, convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, minecraftserver);
@@ -231,14 +265,15 @@
@@ -231,14 +271,15 @@
long l = minecraftserver.getWorldData().worldGenSettings().seed();
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this, chunkgenerator.getBiomeSource(), l, datafixer);
@@ -90,7 +96,7 @@
}
public void setWeatherParameters(int i, int j, boolean flag, boolean flag1) {
@@ -270,12 +305,20 @@
@@ -270,12 +311,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
@@ -114,7 +120,7 @@
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -301,7 +344,7 @@
@@ -301,7 +350,7 @@
this.runBlockEvents();
this.handlingTick = false;
gameprofilerfiller.pop();
@@ -123,7 +129,7 @@
if (flag) {
this.resetEmptyTime();
@@ -317,7 +360,7 @@
@@ -317,7 +366,7 @@
this.entityTickList.forEach((entity) -> {
if (!entity.isRemoved()) {
@@ -132,7 +138,7 @@
entity.discard();
} else {
gameprofilerfiller.push("checkDespawn");
@@ -389,7 +432,7 @@
@@ -389,7 +438,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
@@ -141,7 +147,7 @@
entityplayer.stopSleepInBed(false, false);
});
}
@@ -416,14 +459,14 @@
@@ -416,14 +465,14 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -158,7 +164,7 @@
}
}
@@ -434,12 +477,12 @@
@@ -434,12 +483,12 @@
BiomeBase biomebase = this.getBiome(blockposition);
if (biomebase.shouldFreeze(this, blockposition1)) {
@@ -173,7 +179,7 @@
}
IBlockData iblockdata = this.getBlockState(blockposition1);
@@ -635,6 +678,7 @@
@@ -635,6 +684,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
@@ -181,7 +187,7 @@
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
@@ -653,14 +697,47 @@
@@ -653,14 +703,47 @@
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
}
@@ -231,7 +237,7 @@
}
public void resetEmptyTime() {
@@ -695,6 +772,7 @@
@@ -695,6 +778,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
@@ -239,7 +245,7 @@
this.getProfiler().pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -718,6 +796,7 @@
@@ -718,6 +802,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
@@ -247,7 +253,7 @@
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
@@ -742,6 +821,7 @@
@@ -742,6 +827,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
@@ -255,7 +261,7 @@
if (iprogressupdate != null) {
iprogressupdate.progressStartNoAbort(new ChatMessage("menu.savingLevel"));
}
@@ -759,11 +839,19 @@
@@ -759,11 +845,19 @@
}
}
@@ -276,7 +282,7 @@
}
this.getChunkSource().getDataStorage().save();
@@ -809,15 +897,34 @@
@@ -809,15 +903,34 @@
@Override
public boolean addFreshEntity(Entity entity) {
@@ -314,7 +320,7 @@
}
public void addDuringCommandTeleport(EntityPlayer entityplayer) {
@@ -848,24 +955,36 @@
@@ -848,24 +961,36 @@
this.entityManager.addNewEntity(entityplayer);
}
@@ -355,7 +361,7 @@
return true;
}
}
@@ -879,10 +998,32 @@
@@ -879,10 +1004,32 @@
entityplayer.remove(entity_removalreason);
}
@@ -388,7 +394,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -891,6 +1032,12 @@
@@ -891,6 +1038,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
@@ -401,7 +407,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
@@ -938,7 +1085,18 @@
@@ -938,7 +1091,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -421,7 +427,7 @@
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (!navigationabstract.hasDelayedRecomputation()) {
@@ -961,10 +1119,20 @@
@@ -961,10 +1125,20 @@
@Override
public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
@@ -442,7 +448,7 @@
if (explosion_effect == Explosion.Effect.NONE) {
explosion.clearToBlow();
}
@@ -1045,13 +1213,20 @@
@@ -1045,13 +1219,20 @@
}
public <T extends ParticleParam> int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
@@ -465,7 +471,7 @@
++j;
}
}
@@ -1101,7 +1276,7 @@
@@ -1101,7 +1282,7 @@
@Nullable
public BlockPosition findNearestMapFeature(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
@@ -474,7 +480,7 @@
}
@Nullable
@@ -1138,11 +1313,21 @@
@@ -1138,11 +1319,21 @@
@Nullable
@Override
public WorldMap getMapData(String s) {
@@ -497,7 +503,7 @@
this.getServer().overworld().getDataStorage().set(s, worldmap);
}
@@ -1454,6 +1639,11 @@
@@ -1454,6 +1645,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
@@ -509,7 +515,7 @@
this.updateNeighborsAt(blockposition, block);
}
@@ -1473,12 +1663,12 @@
@@ -1473,12 +1669,12 @@
}
public boolean isFlat() {
@@ -524,7 +530,7 @@
}
@Nullable
@@ -1506,7 +1696,7 @@
@@ -1506,7 +1702,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@@ -533,7 +539,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1515,7 +1705,7 @@
@@ -1515,7 +1711,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -542,7 +548,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1526,17 +1716,33 @@
@@ -1526,17 +1722,33 @@
}
public static void makeObsidianPlatform(WorldServer worldserver) {
@@ -578,7 +584,7 @@
}
@Override
@@ -1629,6 +1835,7 @@
@@ -1629,6 +1841,7 @@
}
}
@@ -586,7 +592,7 @@
}
public void onTrackingEnd(Entity entity) {
@@ -1661,6 +1868,7 @@
@@ -1661,6 +1874,7 @@
gameeventlistenerregistrar.onListenerRemoved(entity.level);
}