#1010: Add PDC to World

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2022-02-15 09:36:00 +11:00
parent 80e9699ccf
commit 77b8e4803a
4 changed files with 64 additions and 14 deletions

View file

@ -70,7 +70,7 @@
- this.serverLevelData = iworlddataserver;
+ // CraftBukkit start
+ this.serverLevelData = (WorldDataServer) iworlddataserver;
+ serverLevelData.world = this;
+ serverLevelData.setWorld(this);
+ if (gen != null) {
+ chunkgenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkgenerator, gen);
+ }

View file

@ -11,7 +11,20 @@
public class Convertable {
static final Logger LOGGER = LogManager.getLogger();
@@ -277,9 +281,23 @@
@@ -216,7 +220,11 @@
LevelVersion levelversion = LevelVersion.parse(dynamic);
WorldSettings worldsettings = WorldSettings.parse(dynamic, datapackconfiguration);
- return WorldDataServer.parse(dynamic, datafixer, i, nbttagcompound2, worldsettings, levelversion, (GeneratorSettings) pair.getFirst(), (Lifecycle) pair.getSecond());
+ // CraftBukkit start - Add PDC to world
+ WorldDataServer worldDataServer = WorldDataServer.parse(dynamic, datafixer, i, nbttagcompound2, worldsettings, levelversion, (GeneratorSettings) pair.getFirst(), (Lifecycle) pair.getSecond());
+ worldDataServer.pdc = nbttagcompound1.get("BukkitValues");
+ return worldDataServer;
+ // CraftBukkit end
} catch (Exception exception) {
Convertable.LOGGER.error("Exception reading {}", file, exception);
return null;
@@ -277,9 +285,23 @@
return this.backupDir;
}
@ -37,7 +50,7 @@
public class ConversionSession implements AutoCloseable {
@@ -287,8 +305,12 @@
@@ -287,8 +309,12 @@
public final Path levelPath;
private final String levelId;
private final Map<SavedFile, Path> resources = Maps.newHashMap();
@ -51,7 +64,7 @@
this.levelId = s;
this.levelPath = Convertable.this.baseDir.resolve(s);
this.lock = SessionLock.create(this.levelPath);
@@ -305,7 +327,7 @@
@@ -305,7 +331,7 @@
}
public Path getDimensionPath(ResourceKey<World> resourcekey) {

View file

@ -16,15 +16,27 @@
public class WorldDataServer implements IWorldDataServer, SaveData {
private static final Logger LOGGER = LogManager.getLogger();
@@ -78,6 +87,7 @@
@@ -78,6 +87,19 @@
private final Set<String> knownServerBrands;
private boolean wasModded;
private final CustomFunctionCallbackTimerQueue<MinecraftServer> scheduledEvents;
+ public WorldServer world; // CraftBukkit
+ // CraftBukkit start - Add world and pdc
+ private WorldServer world;
+ protected NBTBase pdc;
+
+ public void setWorld(WorldServer world) {
+ if (this.world != null) {
+ return;
+ }
+ this.world = world;
+ world.getWorld().readBukkitValues(pdc);
+ pdc = null;
+ }
+ // CraftBukkit end
private WorldDataServer(@Nullable DataFixer datafixer, int i, @Nullable NBTTagCompound nbttagcompound, boolean flag, int j, int k, int l, float f, long i1, long j1, int k1, int l1, int i2, boolean flag1, int j2, boolean flag2, boolean flag3, boolean flag4, WorldBorder.c worldborder_c, int k2, int l2, @Nullable UUID uuid, Set<String> set, CustomFunctionCallbackTimerQueue<MinecraftServer> customfunctioncallbacktimerqueue, @Nullable NBTTagCompound nbttagcompound1, NBTTagCompound nbttagcompound2, WorldSettings worldsettings, GeneratorSettings generatorsettings, Lifecycle lifecycle) {
this.fixerUpper = datafixer;
@@ -121,7 +131,8 @@
@@ -121,7 +143,8 @@
return (NBTBase) dynamic.get("DimensionData").get("1").get("DragonFight").orElseEmptyMap().getValue();
});
@ -34,7 +46,7 @@
return SystemUtils.toStream(dynamic1.asString().result());
}).collect(Collectors.toCollection(Sets::newLinkedHashSet)), new CustomFunctionCallbackTimerQueue<>(CustomFunctionCallbackTimers.SERVER_CALLBACKS, dynamic.get("ScheduledEvents").asStream()), (NBTTagCompound) dynamic.get("CustomBossEvents").orElseEmptyMap().getValue(), nbttagcompound1, worldsettings, generatorsettings, lifecycle);
}
@@ -141,7 +152,7 @@
@@ -141,7 +164,7 @@
private void setTagData(IRegistryCustom iregistrycustom, NBTTagCompound nbttagcompound, @Nullable NBTTagCompound nbttagcompound1) {
NBTTagList nbttaglist = new NBTTagList();
@ -43,7 +55,7 @@
Objects.requireNonNull(nbttaglist);
stream.forEach(nbttaglist::add);
@@ -156,7 +167,7 @@
@@ -156,7 +179,7 @@
nbttagcompound.put("Version", nbttagcompound2);
nbttagcompound.putInt("DataVersion", SharedConstants.getCurrentVersion().getWorldVersion());
RegistryWriteOps<NBTBase> registrywriteops = RegistryWriteOps.create(DynamicOpsNBT.INSTANCE, iregistrycustom);
@ -52,15 +64,16 @@
Logger logger = WorldDataServer.LOGGER;
Objects.requireNonNull(logger);
@@ -204,6 +215,7 @@
@@ -204,6 +227,8 @@
nbttagcompound.putUUID("WanderingTraderId", this.wanderingTraderId);
}
+ nbttagcompound.putString("Bukkit.Version", Bukkit.getName() + "/" + Bukkit.getVersion() + "/" + Bukkit.getBukkitVersion()); // CraftBukkit
+ world.getWorld().storeBukkitValues(nbttagcompound); // CraftBukkit - add pdc
}
@Override
@@ -321,6 +333,20 @@
@@ -321,6 +346,20 @@
@Override
public void setThundering(boolean flag) {
@ -81,7 +94,7 @@
this.thundering = flag;
}
@@ -341,6 +367,20 @@
@@ -341,6 +380,20 @@
@Override
public void setRaining(boolean flag) {
@ -102,7 +115,7 @@
this.raining = flag;
}
@@ -407,6 +447,12 @@
@@ -407,6 +460,12 @@
@Override
public void setDifficulty(EnumDifficulty enumdifficulty) {
this.settings = this.settings.withDifficulty(enumdifficulty);
@ -115,7 +128,7 @@
}
@Override
@@ -527,4 +573,12 @@
@@ -527,4 +586,12 @@
public WorldSettings getLevelSettings() {
return this.settings.copy();
}

View file

@ -23,6 +23,8 @@ import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPosition;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutEntitySound;
@ -91,6 +93,8 @@ import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.metadata.BlockMetadataStore;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
@ -116,6 +120,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.PotionData;
@ -127,6 +132,7 @@ import org.bukkit.util.Vector;
public class CraftWorld extends CraftRegionAccessor implements World {
public static final int CUSTOM_DIMENSION_OFFSET = 10;
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
private final WorldServer world;
private WorldBorder worldBorder;
@ -137,6 +143,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
private static final Random rand = new Random();
@ -1791,4 +1798,21 @@ public class CraftWorld extends CraftRegionAccessor implements World {
public DragonBattle getEnderDragonBattle() {
return (getHandle().dragonFight() == null) ? null : new CraftDragonBattle(getHandle().dragonFight());
}
@Override
public PersistentDataContainer getPersistentDataContainer() {
return persistentDataContainer;
}
public void storeBukkitValues(NBTTagCompound c) {
if (!this.persistentDataContainer.isEmpty()) {
c.put("BukkitValues", this.persistentDataContainer.toTagCompound());
}
}
public void readBukkitValues(NBTBase c) {
if (c instanceof NBTTagCompound) {
this.persistentDataContainer.putAll((NBTTagCompound) c);
}
}
}