Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SpongeCommon.server().registryAccess() -> SpongeCommon.vanillaRegistryAccess() #4145

Open
wants to merge 1 commit into
base: api-13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeChatTypeTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeChatTypeTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -173,7 +173,7 @@ public Builder reset() {
@Override
public Builder fromDataPack(final DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
final ChatType chatType = SpongeChatTypeTemplate.decode(json, SpongeCommon.server().registryAccess());
final ChatType chatType = SpongeChatTypeTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
this.fromValue((org.spongepowered.api.adventure.ChatType) (Object) chatType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void register(final DataProviderRegistrator registrator) {
.setAnd((h, v) -> {
if (!h.level().isClientSide) {
final Holder<PaintingVariant> oldArt = h.getVariant();
var newArt = SpongeCommon.server().registryAccess().lookupOrThrow(Registries.PAINTING_VARIANT).wrapAsHolder((PaintingVariant) (Object) v);
var newArt = SpongeCommon.vanillaRegistry(Registries.PAINTING_VARIANT).wrapAsHolder((PaintingVariant) (Object) v);
h.setVariant(newArt);
((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
if (!h.survives()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static boolean set(final ItemStack holder, final List<Enchantment> value
if (value.isEmpty()) {
return BookPagesItemStackData.delete(holder, component);
}
final var registry = SpongeCommon.server().registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
final var registry = SpongeCommon.vanillaRegistry(Registries.ENCHANTMENT);
holder.update(component, ItemEnchantments.EMPTY, ench -> {
final ItemEnchantments.Mutable mutable = new ItemEnchantments.Mutable(ench);
mutable.keySet().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeArtTypeTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeArtTypeTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -116,7 +116,7 @@ public Builder fromValue(final ArtType value) {
@Override
public Builder fromDataPack(final DataView dataView) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(dataView));
final var damageType = SpongeArtTypeTemplate.decode(json, SpongeCommon.server().registryAccess());
final var damageType = SpongeArtTypeTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
this.fromValue((ArtType) (Object) damageType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String fileEnding() {

@Override
public void serializeObject(final SpongeDataPack<JsonElement, T> pack, final Path packDir, final T packEntry) throws IOException {
final JsonElement serialized = this.encoder.encode(packEntry, SpongeCommon.server().registryAccess());
final JsonElement serialized = this.encoder.encode(packEntry, SpongeCommon.vanillaRegistryAccess());
final Path file = this.packEntryFile(pack.type(), packEntry.key(), packDir);
final JsonElement finalJson = this.transformSerialized(file, packEntry, serialized);
Files.createDirectories(file.getParent());
Expand Down Expand Up @@ -82,7 +82,7 @@ public T deserialize(final SpongeDataPack<JsonElement, T> pack, final InputStrea

if (this.decoder != null) {
// TODO this is actually blocking
return this.decoder.decode(pack, key, element, SpongeCommon.server().registryAccess());
return this.decoder.decode(pack, key, element, SpongeCommon.vanillaRegistryAccess());
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String fileEnding() {

@Override
public void serializeObject(final SpongeDataPack<CompoundTag, T> pack, final Path packDir, final T packEntry) throws IOException {
final CompoundTag serialized = this.encoder.encode(packEntry, SpongeCommon.server().registryAccess());
final CompoundTag serialized = this.encoder.encode(packEntry, SpongeCommon.vanillaRegistryAccess());
final Path file = this.packEntryFile(pack.type(), packEntry.key(), packDir);
Files.createDirectories(file.getParent());
NbtDataPackSerializer.writeFile(file, serialized);
Expand All @@ -73,7 +73,7 @@ public T deserialize(final SpongeDataPack<CompoundTag, T> pack, final InputStrea
final CompoundTag element = NbtIo.readCompressed(dis, NbtAccounter.unlimitedHeap());
if (this.decoder != null) {
// TODO this is actually blocking
return this.decoder.decode(pack, key, element, SpongeCommon.server().registryAccess());
return this.decoder.decode(pack, key, element, SpongeCommon.vanillaRegistryAccess());
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private SpongeUserData loadEnderInventory() {
this.enderChest = new SpongeUserInventoryEnderchest(this);
if (this.compound.contains(Constants.Entity.Player.ENDERCHEST_INVENTORY, 9)) {
final ListTag nbttaglist1 = this.compound.getList(Constants.Entity.Player.ENDERCHEST_INVENTORY, 10);
this.enderChest.fromTag(nbttaglist1, SpongeCommon.server().registryAccess());
this.enderChest.fromTag(nbttaglist1, SpongeCommon.vanillaRegistryAccess());
}
}
return this;
Expand Down Expand Up @@ -244,7 +244,7 @@ public void writeCompound(final CompoundTag compound) {
this.loadEnderInventory();

compound.put(Constants.Entity.Player.INVENTORY, this.inventory.writeList(new ListTag()));
compound.put(Constants.Entity.Player.ENDERCHEST_INVENTORY, this.enderChest.createTag(SpongeCommon.server().registryAccess()));
compound.put(Constants.Entity.Player.ENDERCHEST_INVENTORY, this.enderChest.createTag(SpongeCommon.vanillaRegistryAccess()));
compound.putInt(Constants.Entity.Player.SELECTED_ITEM_SLOT, this.inventory.currentItem);

compound.put(Constants.Entity.ENTITY_POSITION, Constants.NBT.newDoubleNBTList(this.x, this.y, this.z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public ListTag writeList(final ListTag nbtTagListIn) {
if (!this.mainInventory.get(i).isEmpty()) {
final CompoundTag nbttagcompound = new CompoundTag();
nbttagcompound.putByte("Slot", (byte) i);
this.mainInventory.get(i).save(SpongeCommon.server().registryAccess(), nbttagcompound);
this.mainInventory.get(i).save(SpongeCommon.vanillaRegistryAccess(), nbttagcompound);
nbtTagListIn.add(nbttagcompound);
}
}
Expand All @@ -148,7 +148,7 @@ public ListTag writeList(final ListTag nbtTagListIn) {
if (!this.armorInventory.get(j).isEmpty()) {
final CompoundTag nbttagcompound1 = new CompoundTag();
nbttagcompound1.putByte("Slot", (byte) (j + 100));
this.armorInventory.get(j).save(SpongeCommon.server().registryAccess(), nbttagcompound1);
this.armorInventory.get(j).save(SpongeCommon.vanillaRegistryAccess(), nbttagcompound1);
nbtTagListIn.add(nbttagcompound1);
}
}
Expand All @@ -157,7 +157,7 @@ public ListTag writeList(final ListTag nbtTagListIn) {
if (!this.offHandInventory.get(k).isEmpty()) {
final CompoundTag nbttagcompound2 = new CompoundTag();
nbttagcompound2.putByte("Slot", (byte) (k + 150));
this.offHandInventory.get(k).save(SpongeCommon.server().registryAccess(), nbttagcompound2);
this.offHandInventory.get(k).save(SpongeCommon.vanillaRegistryAccess(), nbttagcompound2);
nbtTagListIn.add(nbttagcompound2);
}
}
Expand All @@ -178,7 +178,7 @@ public void readList(final ListTag nbtTagListIn) {
for (int i = 0; i < nbtTagListIn.size(); ++i) {
final CompoundTag nbttagcompound = nbtTagListIn.getCompound(i);
final int j = nbttagcompound.getByte("Slot") & 255;
final ItemStack itemstack = ItemStack.parse(SpongeCommon.server().registryAccess(), nbttagcompound).get();
final ItemStack itemstack = ItemStack.parse(SpongeCommon.vanillaRegistryAccess(), nbttagcompound).get();

if (!itemstack.isEmpty()) {
if (j >= 0 && j < this.mainInventory.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public DamageSource build() throws IllegalStateException {

@Override
public DamageSource.Builder type(final DamageType damageType) {
final var registry = SpongeCommon.server().registryAccess().lookupOrThrow(Registries.DAMAGE_TYPE);
final var registry = SpongeCommon.vanillaRegistry(Registries.DAMAGE_TYPE);
this.damageType = registry.wrapAsHolder((net.minecraft.world.damagesource.DamageType) (Object) damageType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeDamageTypeTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeDamageTypeTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public Builder reset() {
@Override
public Builder fromDataPack(final DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
final DamageType damageType = SpongeDamageTypeTemplate.decode(json, SpongeCommon.server().registryAccess());
final DamageType damageType = SpongeDamageTypeTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
this.fromValue((org.spongepowered.api.event.cause.entity.damage.DamageType) (Object) damageType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static DataContainer getDataContainer(final net.minecraft.world.item.Item
SpongeItemStack.cleanupOldCustomData(mcStack);
// Serialize all DataComponents...

var ops = RegistryOps.create(NbtOps.INSTANCE, SpongeCommon.server().registryAccess());
var ops = RegistryOps.create(NbtOps.INSTANCE, SpongeCommon.vanillaRegistryAccess());
var componentsTag = DataComponentPatch.CODEC.encodeStart(ops, mcStack.getComponentsPatch());
var components = NBTTranslator.INSTANCE.translate((CompoundTag) componentsTag.getOrThrow());
container.set(Constants.ItemStack.COMPONENTS, components);
Expand Down Expand Up @@ -352,7 +352,7 @@ public static Optional<ItemStack> createItemStack(final DataView container) {

public static DataComponentPatch patchFromData(final DataView container) {
return container.getView(Constants.ItemStack.COMPONENTS).map(NBTTranslator.INSTANCE::translate).flatMap(compound -> {
var dynamic = new Dynamic<>(RegistryOps.create(NbtOps.INSTANCE, SpongeCommon.server().registryAccess()), compound);
var dynamic = new Dynamic<>(RegistryOps.create(NbtOps.INSTANCE, SpongeCommon.vanillaRegistryAccess()), compound);
return DataComponentPatch.CODEC.decode(dynamic).result().map(Pair::getFirst);
}).orElse(DataComponentPatch.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public List<Enchantment> build() throws IllegalStateException {
if (this.pool == null || this.pool.isEmpty()) {
Objects.requireNonNull(this.item, "The item cannot be null");
this.randomSource.setSeed(this.seed + this.option);
final var registry = SpongeCommon.server().registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
final var registry = SpongeCommon.vanillaRegistry(Registries.ENCHANTMENT);
var stream = registry.listElements().map($$0x -> (Holder<net.minecraft.world.item.enchantment.Enchantment>)$$0x);
enchantments = EnchantmentHelper.selectEnchantment(this.randomSource, ItemStackUtil.toNative(this.item), this.level, stream);
} else {
Expand Down Expand Up @@ -139,7 +139,7 @@ public static List<Enchantment> fromNative(final List<EnchantmentInstance> list)
}

public static List<EnchantmentInstance> toNative(final List<Enchantment> list) {
final var registry = SpongeCommon.server().registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
final var registry = SpongeCommon.vanillaRegistry(Registries.ENCHANTMENT);
return list.stream().map(ench -> {
var mcEnch = registry.wrapAsHolder((net.minecraft.world.item.enchantment.Enchantment) (Object) ench.type());
return new EnchantmentInstance(mcEnch, ench.level());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonObject jsonObject = SpongeTagTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonObject jsonObject = SpongeTagTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
final DataContainer container = DataFormats.JSON.get().read(jsonObject.getAsString());
container.set(DataQuery.of("replace"), this.replace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class SpongeDamageSourceFactory implements DamageSource.Factory {

private DamageSources damageSources() {
if (this.damageSources == null) {
this.damageSources = new DamageSources(SpongeCommon.server().registryAccess());
this.damageSources = new DamageSources(SpongeCommon.vanillaRegistryAccess());
}
return damageSources;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeBiomeTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeBiomeTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public Builder fromValue(final org.spongepowered.api.world.biome.Biome biome) {
@Override
public Builder fromDataPack(final DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
final Biome biome = SpongeBiomeTemplate.decode(json, SpongeCommon.server().registryAccess());
final Biome biome = SpongeBiomeTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
this.fromValue((org.spongepowered.api.world.biome.Biome) (Object) biome);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public ConfigurableChunkGenerator<NoiseGeneratorConfig> theEnd() {
@Override
public ChunkGenerator fromDataPack(DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
return (ChunkGenerator) SpongeWorldTemplate.decodeStem(json, SpongeCommon.server().registryAccess()).generator();
return (ChunkGenerator) SpongeWorldTemplate.decodeStem(json, SpongeCommon.vanillaRegistryAccess()).generator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeCarverTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeCarverTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public Builder fromValue(final Carver carver) {
@Override
public Builder fromDataPack(final DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
final ConfiguredWorldCarver<?> carver = SpongeCarverTemplate.decode(ConfiguredWorldCarver.DIRECT_CODEC, json, SpongeCommon.server().registryAccess());
final ConfiguredWorldCarver<?> carver = SpongeCarverTemplate.decode(ConfiguredWorldCarver.DIRECT_CODEC, json, SpongeCommon.vanillaRegistryAccess());
this.fromValue((Carver) (Object) carver);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeDensityFunctionTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeDensityFunctionTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -104,7 +104,7 @@ public Builder fromValue(final org.spongepowered.api.world.generation.config.noi
@Override
public Builder fromDataPack(final DataView pack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(pack));
this.densityFunction = SpongeDensityFunctionTemplate.decode(json, SpongeCommon.server().registryAccess());
this.densityFunction = SpongeDensityFunctionTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public int contentVersion() {

@Override
public DataContainer toContainer() {
final JsonElement serialized = SpongeNoiseGeneratorConfigTemplate.encode(this, SpongeCommon.server().registryAccess());
final JsonElement serialized = SpongeNoiseGeneratorConfigTemplate.encode(this, SpongeCommon.vanillaRegistryAccess());
try {
return DataFormats.JSON.get().read(serialized.toString());
} catch (IOException e) {
Expand Down Expand Up @@ -210,7 +210,7 @@ public Builder fromValue(final NoiseGeneratorConfig value) {
@Override
public Builder fromDataPack(final DataView datapack) throws IOException {
final JsonElement json = JsonParser.parseString(DataFormats.JSON.get().write(datapack));
final NoiseGeneratorSettings decoded = SpongeNoiseGeneratorConfigTemplate.decode(json, SpongeCommon.server().registryAccess());
final NoiseGeneratorSettings decoded = SpongeNoiseGeneratorConfigTemplate.decode(json, SpongeCommon.vanillaRegistryAccess());
return this.fromValue((NoiseGeneratorConfig) (Object) decoded);
}

Expand Down
Loading
Loading