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,6 +1,6 @@
--- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java
@@ -140,6 +140,36 @@
@@ -140,6 +140,33 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -10,10 +10,9 @@
+import net.minecraft.world.food.FoodMetaData;
+import net.minecraft.world.item.enchantment.EnchantmentManager;
+import net.minecraft.world.level.block.BlockChest;
+import net.minecraft.world.level.dimension.DimensionManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+import net.minecraft.world.scores.Scoreboard;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.CraftWorld;
@@ -22,11 +21,9 @@
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.CraftDimensionUtil;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.PlayerBedLeaveEvent;
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerGameModeChangeEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
@@ -37,7 +34,7 @@
public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogManager.getLogger();
@@ -194,6 +224,20 @@
@@ -194,6 +221,20 @@
public int latency;
public boolean wonGame;
@@ -58,7 +55,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL;
@@ -256,12 +300,56 @@
@@ -256,12 +297,56 @@
this.advancements = minecraftserver.getPlayerList().getPlayerAdvancements(this);
this.maxUpStep = 1.0F;
this.fudgeSpawnLocation(worldserver);
@@ -116,7 +113,7 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
@@ -319,11 +407,20 @@
@@ -319,11 +404,20 @@
if (nbttagcompound.contains("recipeBook", 10)) {
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
}
@@ -137,7 +134,7 @@
if (nbttagcompound.contains("SpawnX", 99) && nbttagcompound.contains("SpawnY", 99) && nbttagcompound.contains("SpawnZ", 99)) {
this.respawnPosition = new BlockPosition(nbttagcompound.getInt("SpawnX"), nbttagcompound.getInt("SpawnY"), nbttagcompound.getInt("SpawnZ"));
this.respawnForced = nbttagcompound.getBoolean("SpawnForced");
@@ -356,7 +453,20 @@
@@ -356,7 +450,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@@ -159,7 +156,7 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -374,7 +484,7 @@
@@ -374,7 +481,7 @@
nbttagcompound.putInt("SpawnZ", this.respawnPosition.getZ());
nbttagcompound.putBoolean("SpawnForced", this.respawnForced);
nbttagcompound.putFloat("SpawnAngle", this.respawnAngle);
@@ -168,7 +165,7 @@
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -382,9 +492,33 @@
@@ -382,9 +489,33 @@
nbttagcompound.put("SpawnDimension", nbtbase);
});
}
@@ -202,7 +199,7 @@
public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f;
@@ -443,6 +577,11 @@
@@ -443,6 +574,11 @@
@Override
public void tick() {
@@ -214,7 +211,7 @@
this.gameMode.tick();
--this.spawnInvulnerableTime;
if (this.invulnerableTime > 0) {
@@ -498,7 +637,7 @@
@@ -498,7 +634,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@@ -223,7 +220,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -529,6 +668,12 @@
@@ -529,6 +665,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
}
@@ -236,7 +233,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
@@ -543,6 +688,16 @@
@@ -543,6 +685,16 @@
CriterionTriggers.LOCATION.trigger(this);
}
@@ -253,7 +250,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -585,7 +740,8 @@
@@ -585,7 +737,8 @@
}
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@@ -263,7 +260,7 @@
scoreboardscore.setScore(i);
});
}
@@ -593,9 +749,47 @@
@@ -593,9 +746,47 @@
@Override
public void die(DamageSource damagesource) {
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@@ -313,7 +310,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), (future) -> {
if (!future.isSuccess()) {
@@ -629,12 +823,18 @@
@@ -629,12 +820,18 @@
if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
@@ -336,7 +333,7 @@
EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -671,10 +871,12 @@
@@ -671,10 +868,12 @@
String s = this.getScoreboardName();
String s1 = entity.getScoreboardName();
@@ -351,7 +348,7 @@
} else {
this.awardStat(StatisticList.MOB_KILLS);
}
@@ -692,7 +894,8 @@
@@ -692,7 +891,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@@ -361,7 +358,7 @@
}
}
@@ -736,18 +939,20 @@
@@ -736,18 +936,20 @@
}
private boolean isPvpAllowed() {
@@ -377,7 +374,7 @@
+ worldserver = (shapedetectorshape == null) ? worldserver : shapedetectorshape.world; // CraftBukkit
- if (shapedetectorshape != null && this.level.dimension() == World.OVERWORLD && worldserver.dimension() == World.END) {
+ if (shapedetectorshape != null && this.level.getTypeKey() == DimensionManager.OVERWORLD_LOCATION && worldserver != null && worldserver.getTypeKey() == DimensionManager.END_LOCATION) { // CraftBukkit
+ if (shapedetectorshape != null && this.level.getTypeKey() == WorldDimension.OVERWORLD && worldserver != null && worldserver.getTypeKey() == WorldDimension.END) { // CraftBukkit
Vec3D vec3d = shapedetectorshape.pos.add(0.0D, -1.0D, 0.0D);
- return new ShapeDetectorShape(vec3d, Vec3D.ZERO, 90.0F, 0.0F);
@@ -385,7 +382,7 @@
} else {
return shapedetectorshape;
}
@@ -756,11 +961,20 @@
@@ -756,11 +958,20 @@
@Nullable
@Override
public Entity changeDimension(WorldServer worldserver) {
@@ -401,15 +398,15 @@
+ // this.isChangingDimension = true; // CraftBukkit - Moved down and into PlayerList#changeDimension
WorldServer worldserver1 = this.getLevel();
- ResourceKey<World> resourcekey = worldserver1.dimension();
+ ResourceKey<DimensionManager> resourcekey = worldserver1.getTypeKey(); // CraftBukkit
+ ResourceKey<WorldDimension> resourcekey = worldserver1.getTypeKey(); // CraftBukkit
- if (resourcekey == World.END && worldserver.dimension() == World.OVERWORLD) {
+ if (resourcekey == DimensionManager.END_LOCATION && worldserver != null && worldserver.getTypeKey() == DimensionManager.OVERWORLD_LOCATION) { // CraftBukkit
+ if (resourcekey == WorldDimension.END && worldserver != null && worldserver.getTypeKey() == WorldDimension.OVERWORLD) { // CraftBukkit
+ this.isChangingDimension = true; // CraftBukkit - Moved down from above
this.unRide();
this.getLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
if (!this.wonGame) {
@@ -771,6 +985,8 @@
@@ -771,6 +982,8 @@
return this;
} else {
@@ -418,7 +415,7 @@
WorldData worlddata = worldserver.getLevelData();
this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionType(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
@@ -780,22 +996,52 @@
@@ -780,22 +993,52 @@
playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved();
@@ -431,10 +428,10 @@
- if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) {
+ worldserver = shapedetectorshape.world; // CraftBukkit
+ if (worldserver == null) { } else // CraftBukkit - empty to fall through to null to event
+ if (resourcekey == DimensionManager.OVERWORLD_LOCATION && worldserver.getTypeKey() == DimensionManager.NETHER_LOCATION) { // CraftBukkit
+ if (resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit
this.enteredNetherPosition = this.position();
- } else if (worldserver.dimension() == World.END) {
+ } else if (worldserver.getTypeKey() == DimensionManager.END_LOCATION && shapedetectorshape.portalEventInfo != null && shapedetectorshape.portalEventInfo.getCanCreatePortal()) { // CraftBukkit
+ } else if (worldserver.getTypeKey() == WorldDimension.END && shapedetectorshape.portalEventInfo != null && shapedetectorshape.portalEventInfo.getCanCreatePortal()) { // CraftBukkit
this.createEndPlatform(worldserver, new BlockPosition(shapedetectorshape.pos));
}
+ // CraftBukkit start
@@ -477,7 +474,7 @@
worldserver1.getProfiler().pop();
this.triggerDimensionChangeTriggers(worldserver1);
this.connection.send(new PacketPlayOutAbilities(this.getAbilities()));
@@ -813,12 +1059,31 @@
@@ -813,12 +1056,31 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -509,7 +506,7 @@
private void createEndPlatform(WorldServer worldserver, BlockPosition blockposition) {
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable();
@@ -835,17 +1100,17 @@
@@ -835,17 +1097,17 @@
}
@Override
@@ -532,7 +529,7 @@
}
return optional1;
@@ -855,13 +1120,21 @@
@@ -855,13 +1117,21 @@
public void triggerDimensionChangeTriggers(WorldServer worldserver) {
ResourceKey<World> resourcekey = worldserver.dimension();
ResourceKey<World> resourcekey1 = this.level.dimension();
@@ -557,7 +554,7 @@
this.enteredNetherPosition = null;
}
@@ -878,12 +1151,10 @@
@@ -878,12 +1148,10 @@
this.containerMenu.broadcastChanges();
}
@@ -573,7 +570,7 @@
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
} else if (!this.bedInRange(blockposition, enumdirection)) {
return Either.left(EntityHuman.EnumBedResult.TOO_FAR_AWAY);
@@ -907,7 +1178,36 @@
@@ -907,7 +1175,36 @@
}
}
@@ -611,7 +608,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -920,9 +1220,8 @@
@@ -920,9 +1217,8 @@
return either;
}
}
@@ -622,7 +619,7 @@
}
@Override
@@ -949,6 +1248,24 @@
@@ -949,6 +1245,24 @@
@Override
public void stopSleepInBed(boolean flag, boolean flag1) {
@@ -647,7 +644,7 @@
if (this.isSleeping()) {
this.getLevel().getChunkSource().broadcastAndSend(this, new PacketPlayOutAnimation(this, 2));
}
@@ -1030,8 +1347,9 @@
@@ -1030,8 +1344,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos()));
}
@@ -658,7 +655,7 @@
}
@Override
@@ -1039,13 +1357,35 @@
@@ -1039,13 +1354,35 @@
if (itileinventory == null) {
return OptionalInt.empty();
} else {
@@ -694,7 +691,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage((new ChatMessage("container.spectatorCantOpen")).withStyle(EnumChatFormat.RED), true);
@@ -1053,9 +1393,11 @@
@@ -1053,9 +1390,11 @@
return OptionalInt.empty();
} else {
@@ -708,7 +705,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1068,13 +1410,24 @@
@@ -1068,13 +1407,24 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@@ -735,7 +732,7 @@
this.initMenu(this.containerMenu);
}
@@ -1097,6 +1450,7 @@
@@ -1097,6 +1447,7 @@
@Override
public void closeContainer() {
@@ -743,7 +740,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1126,7 +1480,7 @@
@@ -1126,7 +1477,7 @@
@Override
public void awardStat(Statistic<?> statistic, int i) {
this.stats.increment(this, statistic, i);
@@ -752,7 +749,7 @@
scoreboardscore.add(i);
});
}
@@ -1134,7 +1488,7 @@
@@ -1134,7 +1485,7 @@
@Override
public void resetStat(Statistic<?> statistic) {
this.stats.setValue(this, statistic, 0);
@@ -761,7 +758,7 @@
}
@Override
@@ -1150,7 +1504,7 @@
@@ -1150,7 +1501,7 @@
for (int j = 0; j < i; ++j) {
MinecraftKey minecraftkey = aminecraftkey1[j];
@@ -770,7 +767,7 @@
Objects.requireNonNull(list);
optional.ifPresent(list::add);
@@ -1185,8 +1539,17 @@
@@ -1185,8 +1536,17 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -788,7 +785,7 @@
@Override
public void displayClientMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.sendMessage(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT, SystemUtils.NIL_UUID);
@@ -1240,7 +1603,7 @@
@@ -1240,7 +1600,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -797,7 +794,7 @@
this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft());
@@ -1367,7 +1730,20 @@
@@ -1367,7 +1727,20 @@
return s;
}
@@ -818,7 +815,7 @@
this.chatVisibility = packetplayinsettings.chatVisibility();
this.canChatColor = packetplayinsettings.chatColors();
this.textFilteringEnabled = packetplayinsettings.textFilteringEnabled();
@@ -1438,7 +1814,7 @@
@@ -1438,7 +1811,7 @@
this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) {
this.connection.send(new PacketPlayOutCamera(this.camera));
@@ -827,7 +824,7 @@
}
}
@@ -1467,7 +1843,7 @@
@@ -1467,7 +1840,7 @@
@Nullable
public IChatBaseComponent getTabListDisplayName() {
@@ -836,7 +833,7 @@
}
@Override
@@ -1488,9 +1864,16 @@
@@ -1488,9 +1861,16 @@
return this.advancements;
}
@@ -853,7 +850,7 @@
if (worldserver == this.level) {
this.connection.teleport(d0, d1, d2, f, f1);
} else {
@@ -1510,6 +1893,9 @@
@@ -1510,6 +1890,9 @@
this.server.getPlayerList().sendLevelInfo(this, worldserver);
this.server.getPlayerList().sendAllPlayerInfo(this);
}
@@ -863,7 +860,7 @@
}
@@ -1668,4 +2054,145 @@
@@ -1668,4 +2051,145 @@
public boolean allowsListing() {
return this.allowsListing;
}