diff --git a/build-logic/src/main/groovy/qsl.module.gradle b/build-logic/src/main/groovy/qsl.module.gradle index 8f7ef9db6e..11c5cf6db5 100644 --- a/build-logic/src/main/groovy/qsl.module.gradle +++ b/build-logic/src/main/groovy/qsl.module.gradle @@ -15,7 +15,6 @@ import qsl.internal.Git import qsl.internal.Versions -import qsl.internal.extension.QslLibraryExtension import qsl.internal.extension.QslModuleExtension import qsl.internal.extension.QslModuleExtensionImpl @@ -104,6 +103,11 @@ sourceSets { compileClasspath += sourceSets.main.compileClasspath runtimeClasspath += sourceSets.main.runtimeClasspath } + + test { + compileClasspath += sourceSets.testmod.compileClasspath + runtimeClasspath += sourceSets.testmod.runtimeClasspath + } } processTestmodResources { @@ -126,6 +130,14 @@ processTestmodResources { dependencies { // testmod sourceSet should depend on everything in the main source set. testmodImplementation sourceSets.main.output + + testImplementation "org.quiltmc:quilt-loader-junit:${Versions.LOADER_VERSION}" + testImplementation sourceSets.testmod.output + testImplementation 'org.mockito:mockito-core:5.4.0' +} + +test { + useJUnitPlatform() } loom { @@ -174,7 +186,7 @@ javadoc { "https://asm.ow2.io/javadoc/", "https://docs.oracle.com/en/java/javase/17/docs/api/", "https://jenkins.liteloader.com/job/Mixin/javadoc/", - "https://logging.apache.org/log4j/2.x/log4j-api/apidocs/" + "https://logging.apache.org/log4j/2.x/javadoc/log4j-api/" ) // Disable the overzealous doclint tool in Java 8 diff --git a/build-logic/src/main/java/qsl/internal/Versions.java b/build-logic/src/main/java/qsl/internal/Versions.java index 6aec07c01e..f45b2ea46b 100644 --- a/build-logic/src/main/java/qsl/internal/Versions.java +++ b/build-logic/src/main/java/qsl/internal/Versions.java @@ -23,7 +23,7 @@ public final class Versions { /** * The QSL version */ - public static final String QSL_VERSION = "7.0.0-alpha.1"; + public static final String QSL_VERSION = "7.0.0-alpha.8"; /** * The target Minecraft version. @@ -38,12 +38,12 @@ public final class Versions { /** * The target Quilt Mappings build. */ - public static final int MAPPINGS_BUILD = 2; + public static final int MAPPINGS_BUILD = 3; /** * The version of Quilt Loader to use. */ - public static final String LOADER_VERSION = "0.20.2"; + public static final String LOADER_VERSION = "0.23.0"; /** * The target Java version. diff --git a/library/core/networking/build.gradle b/library/core/networking/build.gradle index 7d1d9ab287..30956541bf 100644 --- a/library/core/networking/build.gradle +++ b/library/core/networking/build.gradle @@ -18,10 +18,17 @@ qslModule { } entrypoints { init { - values = ["org.quiltmc.qsl.networking.impl.NetworkingImpl::init"] + values = [ + "org.quiltmc.qsl.networking.impl.NetworkingImpl::init", + "org.quiltmc.qsl.networking.impl.common.CommonPacketsImpl::init" + ] } client_init { values = ["org.quiltmc.qsl.networking.impl.client.ClientNetworkingImpl::clientInit"] } } + + injectedInterface("net/minecraft/class_8610") { + values = ["org/quiltmc/qsl/networking/api/ServerConfigurationTaskManager"] + } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationConnectionEvents.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationConnectionEvents.java index d69acfee1a..c316b4985f 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationConnectionEvents.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationConnectionEvents.java @@ -27,6 +27,7 @@ /** * Offers access to events related to the connection to a client on a logical server while a client is in game. */ +// TODO: Double check these events with fabric. Also make sure that the add tasks event is invoked or fold it into the ready event. public final class ServerConfigurationConnectionEvents { /** * Event indicating a connection entered the CONFIGURATION state, ready for registering channel handlers. @@ -61,6 +62,16 @@ public final class ServerConfigurationConnectionEvents { } }); + /** + * An event for adding tasks to a server configuration network handler. + * Called once per connection when the optional tasks are also added. + */ + public static final Event ADD_TASKS = Event.create(AddTasks.class, callbacks -> (handler, server) -> { + for (AddTasks callback : callbacks) { + callback.onAddTasks(handler, server); + } + }); + private ServerConfigurationConnectionEvents() { } @@ -87,4 +98,12 @@ public interface Join extends EventAwareListener { public interface Disconnect extends EventAwareListener { void onConfigurationDisconnect(ServerConfigurationPacketHandler handler, MinecraftServer server); } + + /** + * @see #ADD_TASKS + */ + @FunctionalInterface + public interface AddTasks extends EventAwareListener { + void onAddTasks(ServerConfigurationPacketHandler handler, MinecraftServer server); + } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationTaskManager.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationTaskManager.java new file mode 100644 index 0000000000..212e6bb2ba --- /dev/null +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerConfigurationTaskManager.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.networking.api; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.network.ServerConfigurationPacketHandler; +import net.minecraft.network.configuration.ConfigurationTask; + +import org.quiltmc.qsl.base.api.util.InjectedInterface; + +/** + * An injected interface for {@link net.minecraft.network.ServerConfigurationPacketHandler} that exposes the task system. + */ +@InjectedInterface(ServerConfigurationPacketHandler.class) +public interface ServerConfigurationTaskManager { + /** + * Adds a task to the handler that must complete before joining. + * + * @param task the task to add + */ + void addTask(ConfigurationTask task); + + /** + * Finishes the task of the specified type. Will throw an error if a different or no task is running. + * + * @param type the type to finish + */ + void finishTask(ConfigurationTask.Type type); + + /** + * Gets the currently running task for the configuration handler. + * + * @return the current task + */ + @Nullable ConfigurationTask getCurrentTask(); +} diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerPlayNetworking.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerPlayNetworking.java index 69e2572092..a445c6fbd6 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerPlayNetworking.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/api/ServerPlayNetworking.java @@ -380,6 +380,7 @@ public interface CustomChannelReceiver { /** * This functional interface should only be used when sending a raw {@link PacketByteBuf} is necessary. + * * @deprecated use {@link CustomChannelReceiver} */ @Deprecated diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/AbstractChanneledNetworkAddon.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/AbstractChanneledNetworkAddon.java index 805d647330..1749db51af 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/AbstractChanneledNetworkAddon.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/AbstractChanneledNetworkAddon.java @@ -1,4 +1,5 @@ /* + * Copyright 2016, 2017, 2018, 2019 FabricMC * Copyright 2022 The Quilt Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +36,8 @@ import net.minecraft.util.Identifier; import org.quiltmc.qsl.networking.api.PacketSender; +import org.quiltmc.qsl.networking.impl.common.CommonPacketHandler; +import org.quiltmc.qsl.networking.impl.common.CommonRegisterPayload; import org.quiltmc.qsl.networking.impl.payload.ChannelPayload; /** @@ -43,7 +46,7 @@ * @param the channel handler type */ @ApiStatus.Internal -public abstract class AbstractChanneledNetworkAddon extends AbstractNetworkAddon implements PacketSender { +public abstract class AbstractChanneledNetworkAddon extends AbstractNetworkAddon implements PacketSender, CommonPacketHandler { protected final ClientConnection connection; protected final GlobalReceiverRegistry receiver; protected final Set sendableChannels; @@ -157,4 +160,65 @@ public void sendPacket(Packet packet, PacketSendListener callback) { public Set getSendableChannels() { return Collections.unmodifiableSet(this.sendableChannels); } + + /* Common Packet Handling */ + protected int commonVersion = -1; + + @Override + public void onCommonVersionPacket(int negotiatedVersion) { + assert negotiatedVersion == 1; // We only support version 1 for now + + this.commonVersion = negotiatedVersion; + this.logger.debug("Negotiated common packet version {}", this.commonVersion); + } + + @Override + public void onCommonRegisterPacket(CommonRegisterPayload payload) { + if (payload.version() != this.getNegotiatedVersion()) { + throw new IllegalStateException("Negotiated common packet version: %d but received packet with version: %d".formatted(this.commonVersion, payload.version())); + } + + final String currentPhase = this.getPhase(); + + if (currentPhase == null) { + // We don't support receiving the register packet during this phase. See getPhase() for supported phases. + // The normal case where the play channels are sent during configuration is handled in the client/common configuration packet handlers. + logger.warn("Received common register packet for phase {} in network state: {}", payload.phase(), this.receiver.getState()); + return; + } + + if (!payload.phase().equals(currentPhase)) { + // We need to handle receiving the play phase during configuration! + throw new IllegalStateException("Register packet received for phase (%s) on handler for phase(%s)".formatted(payload.phase(), currentPhase)); + } + + this.register(new ArrayList<>(payload.channels())); + } + + @Override + public CommonRegisterPayload createRegisterPayload() { + return new CommonRegisterPayload(this.getNegotiatedVersion(), this.getPhase(), this.getReceivableChannels()); + } + + @Override + public int getNegotiatedVersion() { + if (this.commonVersion == -1) { + throw new IllegalStateException("Not yet negotiated common packet version"); + } + + return this.commonVersion; + } + + @Nullable + private String getPhase() { + return switch (this.receiver.getState()) { + case PLAY -> CommonRegisterPayload.PLAY_PHASE; + case CONFIGURATION -> CommonRegisterPayload.CONFIGURATION_PHASE; + default -> null; // We don't support receiving this packet on any other phase + }; + } + + public ChannelInfoHolder getChannelInfoHolder() { + return ((ChannelInfoHolder) this.connection); + } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/client/ClientNetworkingImpl.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/client/ClientNetworkingImpl.java index 48e4b8cd40..9258d5fd5e 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/client/ClientNetworkingImpl.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/client/ClientNetworkingImpl.java @@ -1,4 +1,5 @@ /* + * Copyright 2016, 2017, 2018, 2019 FabricMC * Copyright 2022 The Quilt Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,7 +42,9 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.minecraft.ClientOnly; +import org.quiltmc.qsl.networking.api.CustomPayloads; import org.quiltmc.qsl.networking.api.PacketByteBufs; +import org.quiltmc.qsl.networking.api.PacketSender; import org.quiltmc.qsl.networking.api.client.ClientConfigurationConnectionEvents; import org.quiltmc.qsl.networking.api.client.ClientConfigurationNetworking; import org.quiltmc.qsl.networking.api.client.ClientLoginNetworking; @@ -51,6 +54,9 @@ import org.quiltmc.qsl.networking.impl.GlobalReceiverRegistry; import org.quiltmc.qsl.networking.impl.NetworkHandlerExtensions; import org.quiltmc.qsl.networking.impl.NetworkingImpl; +import org.quiltmc.qsl.networking.impl.common.CommonPacketsImpl; +import org.quiltmc.qsl.networking.impl.common.CommonRegisterPayload; +import org.quiltmc.qsl.networking.impl.common.CommonVersionPayload; import org.quiltmc.qsl.networking.impl.payload.PacketByteBufPayload; import org.quiltmc.qsl.networking.mixin.accessor.ClientLoginNetworkHandlerAccessor; import org.quiltmc.qsl.networking.mixin.accessor.ConnectScreenAccessor; @@ -148,6 +154,34 @@ public static void clientInit(ModContainer mod) { // Register a login query handler for early channel registration. ClientLoginNetworking.registerGlobalReceiver(NetworkingImpl.EARLY_REGISTRATION_CHANNEL, ClientNetworkingImpl::receiveEarlyRegistration); ClientLoginNetworking.registerGlobalReceiver(NetworkingImpl.EARLY_REGISTRATION_CHANNEL_FABRIC, ClientNetworkingImpl::receiveEarlyRegistration); + + CustomPayloads.registerS2CPayload(CommonVersionPayload.PACKET_ID, CommonVersionPayload::new); + CustomPayloads.registerS2CPayload(CommonRegisterPayload.PACKET_ID, CommonRegisterPayload::new); + + ClientConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.PACKET_ID, ClientNetworkingImpl::handleCommonVersion); + ClientConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.PACKET_ID, ClientNetworkingImpl::handleCommonRegister); + } + + private static void handleCommonVersion(MinecraftClient client, ClientConfigurationNetworkHandler handler, CommonVersionPayload payload, PacketSender sender) { + int negotiatedVersion = handleVersionPacket(payload, sender); + ClientNetworkingImpl.getAddon(handler).onCommonVersionPacket(negotiatedVersion); + } + + private static void handleCommonRegister(MinecraftClient client, ClientConfigurationNetworkHandler handler, CommonRegisterPayload payload, PacketSender sender) { + ClientConfigurationNetworkAddon addon = ClientNetworkingImpl.getAddon(handler); + + if (CommonRegisterPayload.PLAY_PHASE.equals(payload.phase())) { + if (payload.version() != addon.getNegotiatedVersion()) { + throw new IllegalStateException("Negotiated common packet version: %d but received packet with version: %d".formatted(addon.getNegotiatedVersion(), payload.version())); + } + + addon.getChannelInfoHolder().getPendingChannelsNames(NetworkState.PLAY).addAll(payload.channels()); + NetworkingImpl.LOGGER.debug("Received accepted channels from the server"); + sender.sendPayload(new CommonRegisterPayload(addon.getNegotiatedVersion(), CommonRegisterPayload.PLAY_PHASE, ClientPlayNetworking.getGlobalReceivers())); + } else { + addon.onCommonRegisterPacket(payload); + sender.sendPayload(addon.createRegisterPayload()); + } } private static CompletableFuture receiveEarlyRegistration( @@ -174,5 +208,19 @@ private static CompletableFuture receiveEarlyRegistration( NetworkingImpl.LOGGER.debug("Sent accepted channels to the server"); return CompletableFuture.completedFuture(response); } + + // Disconnect if there are no commonly supported versions. + // Client responds with the intersection of supported versions. + // Return the highest supported version + private static int handleVersionPacket(CommonVersionPayload payload, PacketSender packetSender) { + int version = CommonPacketsImpl.getHighestCommonVersion(payload.versions(), CommonPacketsImpl.SUPPORTED_COMMON_PACKET_VERSIONS); + + if (version <= 0) { + throw new UnsupportedOperationException("Client does not support any requested versions from server"); + } + + packetSender.sendPayload(new CommonVersionPayload(new int[]{version})); + return version; + } } diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SyncTaskHolder.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketHandler.java similarity index 61% rename from library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SyncTaskHolder.java rename to library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketHandler.java index 7a3fe1c87c..0f650d1f8a 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SyncTaskHolder.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketHandler.java @@ -1,5 +1,6 @@ /* - * Copyright 2023 The Quilt Project + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2024 The Quilt Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +15,14 @@ * limitations under the License. */ -package org.quiltmc.qsl.registry.impl.sync.server; +package org.quiltmc.qsl.networking.impl.common; -public interface SyncTaskHolder { - QuiltSyncTask qsl$getQuiltSyncTask(); - void qsl$finishQuiltSyncTask(); +public interface CommonPacketHandler { + void onCommonVersionPacket(int negotiatedVersion); - void qsl$finishFabricSyncTask(); + void onCommonRegisterPacket(CommonRegisterPayload payload); + + CommonRegisterPayload createRegisterPayload(); + + int getNegotiatedVersion(); } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketsImpl.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketsImpl.java new file mode 100644 index 0000000000..74961bad4e --- /dev/null +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonPacketsImpl.java @@ -0,0 +1,154 @@ +/* + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.networking.impl.common; + +import java.util.Arrays; +import java.util.function.Consumer; + +import net.minecraft.network.NetworkState; +import net.minecraft.network.ServerConfigurationPacketHandler; +import net.minecraft.network.configuration.ConfigurationTask; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.payload.CustomPayload; +import net.minecraft.server.MinecraftServer; + +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.networking.api.CustomPayloads; +import org.quiltmc.qsl.networking.api.PacketSender; +import org.quiltmc.qsl.networking.api.ServerConfigurationConnectionEvents; +import org.quiltmc.qsl.networking.api.ServerConfigurationNetworking; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; +import org.quiltmc.qsl.networking.impl.NetworkingImpl; +import org.quiltmc.qsl.networking.impl.server.ServerConfigurationNetworkAddon; +import org.quiltmc.qsl.networking.impl.server.ServerNetworkingImpl; + +public class CommonPacketsImpl { + public static final int PACKET_VERSION_1 = 1; + public static final int[] SUPPORTED_COMMON_PACKET_VERSIONS = new int[]{PACKET_VERSION_1}; + + public static void init(ModContainer mod) { + CustomPayloads.registerC2SPayload(CommonVersionPayload.PACKET_ID, CommonVersionPayload::new); + CustomPayloads.registerC2SPayload(CommonRegisterPayload.PACKET_ID, CommonRegisterPayload::new); + + ServerConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.PACKET_ID, CommonPacketsImpl::handleCommonVersion); + ServerConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.PACKET_ID, CommonPacketsImpl::handleCommonRegister); + + // Create a configuration task to send and receive the common packets + ServerConfigurationConnectionEvents.ADD_TASKS.register((handler, server) -> { + final ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(handler); + + if (ServerConfigurationNetworking.canSend(handler, CommonVersionPayload.PACKET_ID)) { + // Tasks are processed in order. + ((ServerConfigurationTaskManager) handler).addTask(new CommonVersionConfigurationTask(addon)); + + if (ServerConfigurationNetworking.canSend(handler, CommonRegisterPayload.PACKET_ID)) { + ((ServerConfigurationTaskManager) handler).addTask(new CommonRegisterConfigurationTask(addon)); + } + } + }); + } + + private static void handleCommonVersion(MinecraftServer server, ServerConfigurationPacketHandler handler, CommonVersionPayload payload, PacketSender responseSender) { + ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(handler); + addon.onCommonVersionPacket(getNegotiatedVersion(payload)); + ((ServerConfigurationTaskManager) handler).finishTask(CommonVersionConfigurationTask.KEY); + } + + private static void handleCommonRegister(MinecraftServer server, ServerConfigurationPacketHandler handler, CommonRegisterPayload payload, PacketSender responseSender) { + ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(handler); + + if (CommonRegisterPayload.PLAY_PHASE.equals(payload.phase())) { + if (payload.version() != addon.getNegotiatedVersion()) { + throw new IllegalStateException("Negotiated common packet version: %d but received packet with version: %d".formatted(addon.getNegotiatedVersion(), payload.version())); + } + + // Play phase hasnt started yet, add them to the pending names. + addon.getChannelInfoHolder().getPendingChannelsNames(NetworkState.PLAY).addAll(payload.channels()); + NetworkingImpl.LOGGER.debug("Received accepted channels from the client for play phase"); + } else { + addon.onCommonRegisterPacket(payload); + } + + ((ServerConfigurationTaskManager) handler).finishTask(CommonRegisterConfigurationTask.KEY); + } + + // A configuration phase task to send and receive the version packets. + private record CommonVersionConfigurationTask(ServerConfigurationNetworkAddon addon) implements ConfigurationTask { + public static final Type KEY = new Type(CommonVersionPayload.PACKET_ID.toString()); + + @Override + public void start(Consumer> sender) { + this.addon.sendPayload(new CommonVersionPayload(SUPPORTED_COMMON_PACKET_VERSIONS)); + } + + @Override + public Type getType() { + return KEY; + } + } + + // A configuration phase task to send and receive the registration packets. + private record CommonRegisterConfigurationTask(ServerConfigurationNetworkAddon addon) implements ConfigurationTask { + public static final Type KEY = new Type(CommonRegisterPayload.PACKET_ID.toString()); + + @Override + public void start(Consumer> sender) { + this.addon.sendPayload(this.addon.createRegisterPayload()); + } + + @Override + public Type getType() { + return KEY; + } + } + + private static int getNegotiatedVersion(CommonVersionPayload payload) { + int version = getHighestCommonVersion(payload.versions(), SUPPORTED_COMMON_PACKET_VERSIONS); + + if (version <= 0) { + throw new UnsupportedOperationException("Server does not support any requested versions from client"); + } + + return version; + } + + public static int getHighestCommonVersion(int[] a, int[] b) { + int[] as = a.clone(); + int[] bs = b.clone(); + + Arrays.sort(as); + Arrays.sort(bs); + + int ap = as.length - 1; + int bp = bs.length - 1; + + while (ap >= 0 && bp >= 0) { + if (as[ap] == bs[bp]) { + return as[ap]; + } + + if (as[ap] > bs[bp]) { + ap--; + } else { + bp--; + } + } + + return -1; + } +} diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonRegisterPayload.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonRegisterPayload.java new file mode 100644 index 0000000000..a0bd0716ce --- /dev/null +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonRegisterPayload.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.networking.impl.common; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.payload.CustomPayload; +import net.minecraft.util.Identifier; + +public record CommonRegisterPayload(int version, String phase, Set channels) implements CustomPayload { + public static final Identifier PACKET_ID = new Identifier("c", "register"); + + public static final String PLAY_PHASE = "play"; + public static final String CONFIGURATION_PHASE = "configuration"; + + public CommonRegisterPayload(PacketByteBuf buf) { + this( + buf.readVarInt(), + buf.readString(), + buf.readCollection(HashSet::new, PacketByteBuf::readIdentifier) + ); + } + + @Override + public void write(PacketByteBuf buf) { + buf.writeVarInt(this.version); + buf.writeString(this.phase); + buf.writeCollection(this.channels, PacketByteBuf::writeIdentifier); + } + + @Override + public Identifier id() { + return PACKET_ID; + } +} diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonVersionPayload.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonVersionPayload.java new file mode 100644 index 0000000000..faeb44c766 --- /dev/null +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/common/CommonVersionPayload.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.networking.impl.common; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.payload.CustomPayload; +import net.minecraft.util.Identifier; + +public record CommonVersionPayload(int[] versions) implements CustomPayload { + public static final Identifier PACKET_ID = new Identifier("c", "version"); + + public CommonVersionPayload(PacketByteBuf buf) { + this(buf.readIntArray()); + } + + @Override + public void write(PacketByteBuf buf) { + buf.writeIntArray(this.versions); + } + + @Override + public Identifier id() { + return PACKET_ID; + } +} diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/SendChannelsTask.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/SendChannelsTask.java index e69e31dcde..b4a59c808c 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/SendChannelsTask.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/SendChannelsTask.java @@ -23,10 +23,15 @@ public class SendChannelsTask implements ConfigurationTask { public static final ConfigurationTask.Type TYPE = new ConfigurationTask.Type("qsl:send_channels"); + private final ServerConfigurationNetworkAddon addon; + + public SendChannelsTask(ServerConfigurationNetworkAddon addon) { + this.addon = addon; + } @Override public void start(Consumer> task) { - // Do Nothing. This just has us wait for the response from the client. + this.addon.onConfigureReady(); } @Override diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerConfigurationNetworkAddon.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerConfigurationNetworkAddon.java index fc9bdd3275..1f197a039a 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerConfigurationNetworkAddon.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerConfigurationNetworkAddon.java @@ -78,7 +78,6 @@ public void onConfigureReady() { public boolean handle(T payload) { boolean handled = super.handle(payload); if (handled && payload.id().equals(NetworkingImpl.REGISTER_CHANNEL)) { - this.onConfigureReady(); ((ServerConfigurationPacketHandlerAccessor) this.handler).invokeFinishCurrentTask(SendChannelsTask.TYPE); } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerLoginNetworkAddon.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerLoginNetworkAddon.java index eac4f88d75..9343f3d13b 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerLoginNetworkAddon.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/impl/server/ServerLoginNetworkAddon.java @@ -34,6 +34,7 @@ import net.minecraft.network.PacketSendListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; +import net.minecraft.network.packet.c2s.login.payload.DiscardedLoginQueryResponsePayload; import net.minecraft.network.packet.s2c.login.LoginCompressionS2CPacket; import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; import net.minecraft.network.packet.s2c.login.payload.CustomQueryPayload; @@ -130,8 +131,20 @@ private void sendCompressionPacket() { * @return true if the packet was handled */ public boolean handle(LoginQueryResponseC2SPacket packet) { - var payload = (PacketByteBufLoginQueryResponsePayload) packet.payload(); - return this.handle(packet.transactionId(), (payload == null) ? null : payload.data()); + if (packet.payload() instanceof PacketByteBufLoginQueryResponsePayload payload) { + return this.handle(packet.transactionId(), payload.data()); + } else if (packet.payload() instanceof DiscardedLoginQueryResponsePayload) { + Identifier channel = this.channels.remove(packet.transactionId()); + if (channel == null) { + this.logger.warn("Query ID {} was received but no query has been associated in {}!", packet.transactionId(), this.connection); + return false; + } + + this.logger.warn("Known channel {} response was received but not handled by {}!", channel, this.connection); + return true; + } + + return false; } private boolean handle(int queryId, @Nullable PacketByteBuf originalBuf) { diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ClientConnectionMixin.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ClientConnectionMixin.java index b843f1e0eb..086192b55d 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ClientConnectionMixin.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ClientConnectionMixin.java @@ -18,6 +18,8 @@ import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; @@ -55,11 +57,11 @@ abstract class ClientConnectionMixin implements ChannelInfoHolder { public abstract void disconnect(Text disconnectReason); @Unique - private Collection playChannels; + private Map> playChannels; @Inject(method = "", at = @At("RETURN")) private void initAddedFields(NetworkSide side, CallbackInfo ci) { - this.playChannels = Collections.newSetFromMap(new ConcurrentHashMap<>()); + this.playChannels = new HashMap<>(); } // Must be fully qualified due to mixin not working in production without it @@ -101,6 +103,6 @@ private void handleDisconnect(ChannelHandlerContext channelHandlerContext, Callb @Override public Collection getPendingChannelsNames(NetworkState state) { - return this.playChannels; + return this.playChannels.computeIfAbsent(state, (s) -> Collections.newSetFromMap(new ConcurrentHashMap<>())); } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadC2SPacketMixin.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadC2SPacketMixin.java index 0580f60c52..f137b5533a 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadC2SPacketMixin.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadC2SPacketMixin.java @@ -33,6 +33,7 @@ import net.minecraft.network.packet.payload.CustomPayload; import net.minecraft.util.Identifier; +import org.quiltmc.qsl.networking.api.PacketByteBufs; import org.quiltmc.qsl.networking.impl.payload.PacketByteBufPayload; @Mixin(CustomPayloadC2SPacket.class) @@ -49,6 +50,8 @@ private static void makeMutable(CallbackInfo ci) { @Inject(method = "readPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/c2s/common/CustomPayloadC2SPacket;readUnknownPayload(Lnet/minecraft/util/Identifier;Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/network/packet/payload/DiscardedCustomPayload;"), cancellable = true) private static void inject(Identifier id, PacketByteBuf buf, CallbackInfoReturnable cir) { - cir.setReturnValue(new PacketByteBufPayload(id, buf)); + PacketByteBuf copied = PacketByteBufs.copy(buf); + cir.setReturnValue(new PacketByteBufPayload(id, copied)); + buf.skipBytes(buf.readableBytes()); } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadS2CPacketMixin.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadS2CPacketMixin.java index 5451647a63..f3534498da 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadS2CPacketMixin.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/CustomPayloadS2CPacketMixin.java @@ -33,6 +33,7 @@ import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; import net.minecraft.util.Identifier; +import org.quiltmc.qsl.networking.api.PacketByteBufs; import org.quiltmc.qsl.networking.impl.payload.PacketByteBufPayload; @Mixin(CustomPayloadS2CPacket.class) @@ -49,6 +50,8 @@ private static void makeMutable(CallbackInfo ci) { @Inject(method = "readPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;readUnknownPayload(Lnet/minecraft/util/Identifier;Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/network/packet/payload/DiscardedCustomPayload;"), cancellable = true) private static void inject(Identifier id, PacketByteBuf buf, CallbackInfoReturnable cir) { - cir.setReturnValue(new PacketByteBufPayload(id, buf)); + PacketByteBuf copied = PacketByteBufs.copy(buf); + cir.setReturnValue(new PacketByteBufPayload(id, copied)); + buf.skipBytes(buf.readableBytes()); } } diff --git a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ServerConfigurationPacketHandlerMixin.java b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ServerConfigurationPacketHandlerMixin.java index f7c1610c25..7eb253607a 100644 --- a/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ServerConfigurationPacketHandlerMixin.java +++ b/library/core/networking/src/main/java/org/quiltmc/qsl/networking/mixin/ServerConfigurationPacketHandlerMixin.java @@ -18,6 +18,7 @@ import java.util.Queue; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -36,6 +37,7 @@ import net.minecraft.text.Text; import net.minecraft.unmapped.C_eyqfalbd; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; import org.quiltmc.qsl.networking.impl.DisconnectPacketSource; import org.quiltmc.qsl.networking.impl.NetworkHandlerExtensions; import org.quiltmc.qsl.networking.impl.server.SendChannelsTask; @@ -43,10 +45,17 @@ // We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues @Mixin(value = ServerConfigurationPacketHandler.class, priority = 999) -abstract class ServerConfigurationPacketHandlerMixin extends AbstractServerPacketHandler implements NetworkHandlerExtensions, DisconnectPacketSource { +abstract class ServerConfigurationPacketHandlerMixin extends AbstractServerPacketHandler implements NetworkHandlerExtensions, DisconnectPacketSource, ServerConfigurationTaskManager { @Shadow @Final private Queue tasks; + @Shadow + @Nullable + private ConfigurationTask currentTask; + + @Shadow + protected abstract void finishCurrentTask(ConfigurationTask.Type taskType); + @Unique private ServerConfigurationNetworkAddon addon; @@ -63,7 +72,7 @@ private void initAddon(CallbackInfo ci) { @Inject(method = "startConfiguration", at = @At("HEAD")) private void start(CallbackInfo ci) { - this.tasks.add(new SendChannelsTask()); + this.tasks.add(new SendChannelsTask(this.addon)); } @Inject(method = "onDisconnected", at = @At("HEAD")) @@ -80,4 +89,20 @@ public ServerConfigurationNetworkAddon getAddon() { public Packet createDisconnectPacket(Text message) { return new DisconnectS2CPacket(message); } + + @Override + public void addTask(ConfigurationTask task) { + this.tasks.add(task); + } + + @Override + public void finishTask(ConfigurationTask.Type type) { + this.finishCurrentTask(type); + } + + @Nullable + @Override + public ConfigurationTask getCurrentTask() { + return this.currentTask; + } } diff --git a/library/core/networking/src/test/java/org/quiltmc/qsl/networking/test/CommonPacketTests.java b/library/core/networking/src/test/java/org/quiltmc/qsl/networking/test/CommonPacketTests.java new file mode 100644 index 0000000000..b979fb681b --- /dev/null +++ b/library/core/networking/src/test/java/org/quiltmc/qsl/networking/test/CommonPacketTests.java @@ -0,0 +1,316 @@ +/* + * Copyright 2016, 2017, 2018, 2019 FabricMC + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.networking.test; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import net.minecraft.client.network.ClientConfigurationNetworkHandler; +import net.minecraft.network.NetworkState; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.ServerConfigurationPacketHandler; +import net.minecraft.network.packet.payload.CustomPayload; +import net.minecraft.util.Identifier; + +import org.quiltmc.qsl.networking.api.PacketByteBufs; +import org.quiltmc.qsl.networking.api.PacketSender; +import org.quiltmc.qsl.networking.api.ServerConfigurationNetworking; +import org.quiltmc.qsl.networking.api.client.ClientConfigurationNetworking; +import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; +import org.quiltmc.qsl.networking.impl.ChannelInfoHolder; +import org.quiltmc.qsl.networking.impl.client.ClientConfigurationNetworkAddon; +import org.quiltmc.qsl.networking.impl.client.ClientNetworkingImpl; +import org.quiltmc.qsl.networking.impl.common.CommonPacketHandler; +import org.quiltmc.qsl.networking.impl.common.CommonPacketsImpl; +import org.quiltmc.qsl.networking.impl.common.CommonRegisterPayload; +import org.quiltmc.qsl.networking.impl.common.CommonVersionPayload; +import org.quiltmc.qsl.networking.impl.server.ServerConfigurationNetworkAddon; +import org.quiltmc.qsl.networking.impl.server.ServerNetworkingImpl; + +@SuppressWarnings("unchecked") +public class CommonPacketTests { + private PacketSender packetSender; + private ChannelInfoHolder channelInfoHolder; + + private ClientConfigurationNetworkHandler clientNetworkHandler; + private ClientConfigurationNetworkAddon clientAddon; + + private ServerConfigurationPacketHandler serverNetworkHandler; + private ServerConfigurationNetworkAddon serverAddon; + + private static final Identifier CLIENT_RECEIVE = new Identifier("quilt", "global_client"); + private static final Identifier CLIENT_RECEIVE_CONFIGURATION = new Identifier("quilt", "global_configuration_client"); + private static final Identifier SERVER_RECEIVE = new Identifier("quilt", "test"); + + @BeforeAll + static void beforeAll() { + CommonPacketsImpl.init(null); + ClientNetworkingImpl.clientInit(null); + + // Register a receiver to send in the play registry response + ClientPlayNetworking.registerGlobalReceiver(CLIENT_RECEIVE, (client, handler, buf, responseSender) -> { + }); + } + + @BeforeEach + void setUp() { + packetSender = mock(PacketSender.class); + channelInfoHolder = new MockChannelInfoHolder(); + + clientNetworkHandler = mock(ClientConfigurationNetworkHandler.class); + clientAddon = mock(ClientConfigurationNetworkAddon.class); + when(ClientNetworkingImpl.getAddon(clientNetworkHandler)).thenReturn(clientAddon); + when(clientAddon.getChannelInfoHolder()).thenReturn(channelInfoHolder); + + serverNetworkHandler = mock(ServerConfigurationPacketHandler.class); + serverAddon = mock(ServerConfigurationNetworkAddon.class); + when(ServerNetworkingImpl.getAddon(serverNetworkHandler)).thenReturn(serverAddon); + when(serverAddon.getChannelInfoHolder()).thenReturn(channelInfoHolder); + } + + // Test handling the version packet on the client + @Test + void handleVersionPacketClient() { + var packetHandler = ((ClientConfigurationNetworking.CustomChannelReceiver) ClientNetworkingImpl.CONFIGURATION.getReceiver(CommonVersionPayload.PACKET_ID)); + assertNotNull(packetHandler); + + // Receive a packet from the server + CommonVersionPayload payload = new CommonVersionPayload(new int[]{1, 2, 3}); + + packetHandler.receive(null, clientNetworkHandler, payload, packetSender); + + // Check the response we are sending back to the server + PacketByteBuf response = readResponse(packetSender); + assertArrayEquals(new int[]{1}, response.readIntArray()); + assertEquals(0, response.readableBytes()); + + assertEquals(1, getNegotiatedVersion(clientAddon)); + } + + // Test handling the version packet on the client, when the server sends unsupported versions + @Test + void handleVersionPacketClientUnsupported() { + var packetHandler = ((ClientConfigurationNetworking.CustomChannelReceiver) ClientNetworkingImpl.CONFIGURATION.getReceiver(CommonVersionPayload.PACKET_ID)); + assertNotNull(packetHandler); + + // Receive a packet from the server + CommonVersionPayload payload = new CommonVersionPayload(new int[]{2, 3}); // We only support version 1 + + assertThrows(UnsupportedOperationException.class, () -> { + packetHandler.receive(null, clientNetworkHandler, payload, packetSender); + }); + } + + // Test handling the version packet on the server + @Test + void handleVersionPacketServer() { + var packetHandler = ((ServerConfigurationNetworking.CustomChannelReceiver) ServerNetworkingImpl.CONFIGURATION.getReceiver(CommonVersionPayload.PACKET_ID)); + assertNotNull(packetHandler); + + // Receive a packet from the client + CommonVersionPayload payload = new CommonVersionPayload(new int[]{1, 2, 3}); + + packetHandler.receive(null, serverNetworkHandler, payload, null); + + assertEquals(1, getNegotiatedVersion(serverAddon)); + } + + // Test handling the version packet on the server unsupported version + @Test + void handleVersionPacketServerUnsupported() { + var packetHandler = ((ServerConfigurationNetworking.CustomChannelReceiver) ServerNetworkingImpl.CONFIGURATION.getReceiver(CommonVersionPayload.PACKET_ID)); + assertNotNull(packetHandler); + + // Receive a packet from the client + CommonVersionPayload payload = new CommonVersionPayload(new int[]{3}); // Server only supports version 1 + + assertThrows(UnsupportedOperationException.class, () -> { + packetHandler.receive(null, serverNetworkHandler, payload, packetSender); + }); + } + + // Test handing the play registry packet on the client configuration handler + @Test + void handlePlayRegistryClient() { + var packetHandler = ((ClientConfigurationNetworking.CustomChannelReceiver) ClientNetworkingImpl.CONFIGURATION.getReceiver(CommonRegisterPayload.PACKET_ID)); + assertNotNull(packetHandler); + + when(clientAddon.getNegotiatedVersion()).thenReturn(1); + + // Receive a packet from the server + CommonRegisterPayload payload = new CommonRegisterPayload( + 1, + "play", + Set.of(SERVER_RECEIVE) + ); + + packetHandler.receive(null, clientNetworkHandler, payload, packetSender); + + assertIterableEquals(List.of(SERVER_RECEIVE), channelInfoHolder.getPendingChannelsNames(NetworkState.PLAY)); + + // Check the response we are sending back to the server + PacketByteBuf response = readResponse(packetSender); + assertEquals(1, response.readVarInt()); + assertEquals("play", response.readString()); + assertIterableEquals(List.of(CLIENT_RECEIVE), response.readCollection(HashSet::new, PacketByteBuf::readIdentifier)); + assertEquals(0, response.readableBytes()); + } + + // Test handling the configuration registry packet on the client configuration handler + @Test + void handleConfigurationRegistryClient() { + var packetHandler = ((ClientConfigurationNetworking.CustomChannelReceiver) ClientNetworkingImpl.CONFIGURATION.getReceiver(CommonRegisterPayload.PACKET_ID)); + assertNotNull(packetHandler); + + when(clientAddon.getNegotiatedVersion()).thenReturn(1); + when(clientAddon.createRegisterPayload()).thenAnswer(i -> new CommonRegisterPayload(1, "configuration", Set.of(CLIENT_RECEIVE_CONFIGURATION))); + + // Receive a packet from the server + CommonRegisterPayload payload = new CommonRegisterPayload( + 1, + "configuration", + Set.of(SERVER_RECEIVE) + ); + + packetHandler.receive(null, clientNetworkHandler, payload, packetSender); + + verify(clientAddon, times(1)).onCommonRegisterPacket(any()); + + // Check the response we are sending back to the server + PacketByteBuf response = readResponse(packetSender); + assertEquals(1, response.readVarInt()); + assertEquals("configuration", response.readString()); + assertIterableEquals(List.of(CLIENT_RECEIVE_CONFIGURATION), response.readCollection(HashSet::new, PacketByteBuf::readIdentifier)); + assertEquals(0, response.readableBytes()); + } + + // Test handing the play registry packet on the server configuration handler + @Test + void handlePlayRegistryServer() { + var packetHandler = ((ServerConfigurationNetworking.CustomChannelReceiver) ServerNetworkingImpl.CONFIGURATION.getReceiver(CommonRegisterPayload.PACKET_ID)); + assertNotNull(packetHandler); + + when(serverAddon.getNegotiatedVersion()).thenReturn(1); + + // Receive a packet from the client + CommonRegisterPayload payload = new CommonRegisterPayload( + 1, + "play", + Set.of(SERVER_RECEIVE) + ); + + packetHandler.receive(null, serverNetworkHandler, payload, packetSender); + + // Assert the entire packet was read + assertIterableEquals(List.of(SERVER_RECEIVE), channelInfoHolder.getPendingChannelsNames(NetworkState.PLAY)); + } + + // Test handing the configuration registry packet on the server configuration handler + @Test + void handleConfigurationRegistryServer() { + var packetHandler = ((ServerConfigurationNetworking.CustomChannelReceiver) ServerNetworkingImpl.CONFIGURATION.getReceiver(CommonRegisterPayload.PACKET_ID)); + assertNotNull(packetHandler); + + when(serverAddon.getNegotiatedVersion()).thenReturn(1); + + // Receive a packet from the client + CommonRegisterPayload payload = new CommonRegisterPayload( + 1, + "configuration", + Set.of(SERVER_RECEIVE) + ); + + packetHandler.receive(null, serverNetworkHandler, payload, packetSender); + + // Assert the entire packet was read + verify(serverAddon, times(1)).onCommonRegisterPacket(any()); + } + + @Test + public void testHighestCommonVersionWithCommonElement() { + int[] a = {1, 2, 3}; + int[] b = {1, 2}; + assertEquals(2, CommonPacketsImpl.getHighestCommonVersion(a, b)); + } + + @Test + public void testHighestCommonVersionWithoutCommonElement() { + int[] a = {1, 3, 5}; + int[] b = {2, 4, 6}; + assertEquals(-1, CommonPacketsImpl.getHighestCommonVersion(a, b)); + } + + @Test + public void testHighestCommonVersionWithOneEmptyArray() { + int[] a = {1, 3, 5}; + int[] b = {}; + assertEquals(-1, CommonPacketsImpl.getHighestCommonVersion(a, b)); + } + + @Test + public void testHighestCommonVersionWithBothEmptyArrays() { + int[] a = {}; + int[] b = {}; + assertEquals(-1, CommonPacketsImpl.getHighestCommonVersion(a, b)); + } + + @Test + public void testHighestCommonVersionWithIdenticalArrays() { + int[] a = {1, 2, 3}; + int[] b = {1, 2, 3}; + assertEquals(3, CommonPacketsImpl.getHighestCommonVersion(a, b)); + } + + private static PacketByteBuf readResponse(PacketSender packetSender) { + ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(CustomPayload.class); + verify(packetSender, times(1)).sendPayload(responseCaptor.capture()); + + PacketByteBuf buf = PacketByteBufs.create(); + responseCaptor.getValue().write(buf); + + return buf; + } + + private static int getNegotiatedVersion(CommonPacketHandler packetHandler) { + ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(Integer.class); + verify(packetHandler, times(1)).onCommonVersionPacket(responseCaptor.capture()); + return responseCaptor.getValue(); + } + + private static class MockChannelInfoHolder implements ChannelInfoHolder { + private final Map> playChannels = new ConcurrentHashMap<>(); + + @Override + public Collection getPendingChannelsNames(NetworkState state) { + return this.playChannels.computeIfAbsent(state, (key) -> Collections.newSetFromMap(new ConcurrentHashMap<>())); + } + } +} diff --git a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelList.java b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelList.java index 1de4e6c099..3f68405591 100644 --- a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelList.java +++ b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelList.java @@ -19,7 +19,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.EntryListWidget; +import net.minecraft.client.gui.widget.list.EntryListWidget; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; diff --git a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelScreen.java b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelScreen.java index 5118dc5166..1ca9db7474 100644 --- a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelScreen.java +++ b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/channeltest/ChannelScreen.java @@ -19,7 +19,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.button.ButtonWidget; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -37,15 +37,15 @@ final class ChannelScreen extends Screen { @Override protected void init() { - this.s2cButton = this.addDrawableChild(ButtonWidget.builder(Text.literal("S2C"), this::toS2C) + this.s2cButton = this.addDrawableSelectableElement(ButtonWidget.builder(Text.literal("S2C"), this::toS2C) .positionAndSize(this.width / 2 - 55, 5, 50, 20) .tooltip(Tooltip.create(Text.literal("Packets this client can receive"))) .build()); - this.c2sButton = this.addDrawableChild(ButtonWidget.builder(Text.literal("C2S"), this::toC2S) + this.c2sButton = this.addDrawableSelectableElement(ButtonWidget.builder(Text.literal("C2S"), this::toC2S) .positionAndSize(this.width / 2 + 5, 5, 50, 20) .tooltip(Tooltip.create(Text.literal("Packets the server can receive"))) .build()); - this.addDrawableChild(ButtonWidget.builder(Text.literal("Close"), button -> this.closeScreen()) + this.addDrawableSelectableElement(ButtonWidget.builder(Text.literal("Close"), button -> this.closeScreen()) .positionAndSize(this.width / 2 - 60, this.height - 25, 120, 20) .build()); this.channelList = this.addDrawable(new ChannelList(this.client, this.width, this.height - 60, 30, this.height - 30, this.textRenderer.fontHeight + 2)); diff --git a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/play/NetworkingPlayPacketTest.java b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/play/NetworkingPlayPacketTest.java index d3fcb5e379..86d3f80cb2 100644 --- a/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/play/NetworkingPlayPacketTest.java +++ b/library/core/networking/src/testmod/java/org/quiltmc/qsl/networking/test/play/NetworkingPlayPacketTest.java @@ -68,8 +68,8 @@ public static void registerCommand(CommandDispatcher dispat bufB.writeText(Text.literal("Bundled #2")); var packet = new PacketBundleS2CPacket(List.of( - (Packet) (Object) ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, bufA), - (Packet) (Object) ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, bufB) + (Packet) (Object) ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, bufA), + (Packet) (Object) ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, bufB) )); ctx.getSource().getPlayer().networkHandler.send(packet); return Command.SINGLE_SUCCESS; diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/RegistryConfig.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/RegistryConfig.java index 632e50da90..4197890d5c 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/RegistryConfig.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/RegistryConfig.java @@ -33,11 +33,11 @@ public class RegistryConfig extends ReflectiveConfig { public static class RegistrySync extends Section { @Comment(""" - Mod protocol is a feature allowing you to prevent clients with mismatched settings to join. - Client with mismatched values won't be able to connect to servers having this enabled. - It should be used only for non-vanilla compatible modpacks! - Protocol version. Needs to be the same on client and server. If it has value of -1, it won't be required by servers. - """) + Mod protocol is a feature allowing you to prevent clients with mismatched settings to join. + Client with mismatched values won't be able to connect to servers having this enabled. + It should be used only for non-vanilla compatible modpacks! + Protocol version. Needs to be the same on client and server. If it has value of -1, it won't be required by servers. + """) public final TrackedValue mod_protocol_version = value(-1); @Comment("Protocol id. It should be different for every modpack, to prevent joining with mismatched mods.") public final TrackedValue mod_protocol_id = value("my_quilt_modpack"); diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncInitializer.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncInitializer.java index f46b220304..547d5dd00f 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncInitializer.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncInitializer.java @@ -23,9 +23,12 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.networking.api.CustomPayloads; +import org.quiltmc.qsl.networking.api.ServerConfigurationConnectionEvents; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; import org.quiltmc.qsl.registry.impl.sync.mod_protocol.ModProtocolImpl; import org.quiltmc.qsl.registry.impl.sync.registry.SynchronizedRegistry; import org.quiltmc.qsl.registry.impl.sync.server.ServerRegistrySync; +import org.quiltmc.qsl.registry.impl.sync.server.SetupSyncTask; @ApiStatus.Internal public class RegistrySyncInitializer implements ModInitializer { @@ -55,6 +58,10 @@ public void onInitialize(ModContainer mod) { Registries.VILLAGER_PROFESSION ); + ServerConfigurationConnectionEvents.ADD_TASKS.register((handler, server) -> { + ((ServerConfigurationTaskManager) handler).addTask(new SetupSyncTask(handler)); + }); + ServerRegistrySync.registerHandlers(); CustomPayloads.registerS2CPayload(ServerPackets.Handshake.ID, ServerPackets.Handshake::new); CustomPayloads.registerS2CPayload(ServerPackets.End.ID, ServerPackets.End::new); diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncText.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncText.java index 9199ca03c0..5805c9bc61 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncText.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/RegistrySyncText.java @@ -91,7 +91,7 @@ private static MutableText entryList(List namespacesList, Function unsupported, ModProtocolDef missingPrioritized) { diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/ScrollableMultiTextWidget.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/ScrollableMultiTextWidget.java index 1b98fad43a..40c9e0eac0 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/ScrollableMultiTextWidget.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/ScrollableMultiTextWidget.java @@ -25,11 +25,11 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.GridWidget; -import net.minecraft.client.gui.widget.MultilineTextWidget; import net.minecraft.client.gui.widget.ScrollableWidget; import net.minecraft.client.gui.widget.SpacerWidget; -import net.minecraft.client.gui.widget.container.LayoutSettings; +import net.minecraft.client.gui.widget.layout.GridWidget; +import net.minecraft.client.gui.widget.layout.LayoutSettings; +import net.minecraft.client.gui.widget.text.MultilineTextWidget; import net.minecraft.text.MutableText; import net.minecraft.text.Text; diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/SyncLogScreen.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/SyncLogScreen.java index 665476a3bd..73bf531be4 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/SyncLogScreen.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/client/screen/SyncLogScreen.java @@ -22,7 +22,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.button.ButtonWidget; import net.minecraft.text.CommonTexts; import net.minecraft.text.Text; @@ -47,20 +47,20 @@ public SyncLogScreen(Screen parent, List text) { protected void init() { super.init(); this.scrollableText = new ScrollableMultiTextWidget(this.client, 40, 40, this.width - 80, this.height - 90, this.text, this.currentScroll, (s) -> this.currentScroll = s); - this.addDrawableChild(this.scrollableText); + this.addDrawableSelectableElement(this.scrollableText); int y = this.height - 40; { int x = this.width / 2 - 5 - 120; - this.addDrawableChild(ButtonWidget.builder(Text.translatable("chat.copy"), (button) -> { + this.addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("chat.copy"), (button) -> { this.client.keyboard.setClipboard(LogBuilder.stringify(this.text)); }).positionAndSize(x, y, 120, 20).build()); } { int x = this.width / 2 + 5; - this.addDrawableChild(ButtonWidget.builder(CommonTexts.BACK, (button) -> { + this.addDrawableSelectableElement(ButtonWidget.builder(CommonTexts.BACK, (button) -> { this.client.setScreen(this.parent); }).positionAndSize(x, y, 120, 20).build()); } diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/FabricSyncTask.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/FabricSyncTask.java index 1b1a556648..6705e0c2c0 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/FabricSyncTask.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/FabricSyncTask.java @@ -22,6 +22,8 @@ import net.minecraft.network.configuration.ConfigurationTask; import net.minecraft.network.packet.Packet; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; + public class FabricSyncTask implements ConfigurationTask { public static final Type TYPE = new Type("fabric:registry_sync"); private final ServerConfigurationPacketHandler packetHandler; @@ -42,6 +44,6 @@ public Type getType() { } public void handleComplete() { - ((SyncTaskHolder) this.packetHandler).qsl$finishFabricSyncTask(); + ((ServerConfigurationTaskManager) this.packetHandler).finishTask(TYPE); } } diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/QuiltSyncTask.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/QuiltSyncTask.java index 1532ead26a..72a9a05b45 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/QuiltSyncTask.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/QuiltSyncTask.java @@ -27,6 +27,7 @@ import net.minecraft.network.packet.Packet; import net.minecraft.registry.Registries; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; import org.quiltmc.qsl.registry.impl.sync.ClientPackets; import org.quiltmc.qsl.registry.impl.sync.ProtocolVersions; @@ -88,7 +89,7 @@ public void handleEnd(ClientPackets.End end) { if (this.syncVersion == ProtocolVersions.NO_PROTOCOL && ServerRegistrySync.requiresSync()) { this.packetHandler.disconnect(ServerRegistrySync.noRegistrySyncMessage); } else { - ((SyncTaskHolder) this.packetHandler).qsl$finishQuiltSyncTask(); + ((ServerConfigurationTaskManager) this.packetHandler).finishTask(TYPE); } } } diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/ServerRegistrySync.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/ServerRegistrySync.java index 63019c405e..99be9d8039 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/ServerRegistrySync.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/ServerRegistrySync.java @@ -48,6 +48,7 @@ import org.quiltmc.loader.api.QuiltLoader; import org.quiltmc.qsl.networking.api.PacketSender; import org.quiltmc.qsl.networking.api.ServerConfigurationNetworking; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; import org.quiltmc.qsl.registry.api.sync.RegistrySynchronization; import org.quiltmc.qsl.registry.impl.RegistryConfig; import org.quiltmc.qsl.registry.impl.sync.ClientPackets; @@ -80,23 +81,23 @@ public static void registerHandlers() { } public static void handleHandshake(MinecraftServer server, ServerConfigurationPacketHandler handler, ClientPackets.Handshake handshake, PacketSender responseSender) { - ((SyncTaskHolder) handler).qsl$getQuiltSyncTask().handleHandshake(handshake); + ((QuiltSyncTask) ((ServerConfigurationTaskManager) handler).getCurrentTask()).handleHandshake(handshake); } public static void handleSyncFailed(MinecraftServer server, ServerConfigurationPacketHandler handler, ClientPackets.SyncFailed syncFailed, PacketSender responseSender) { - ((SyncTaskHolder) handler).qsl$getQuiltSyncTask().handleSyncFailed(syncFailed); + ((QuiltSyncTask) ((ServerConfigurationTaskManager) handler).getCurrentTask()).handleSyncFailed(syncFailed); } public static void handleModProtocol(MinecraftServer server, ServerConfigurationPacketHandler handler, ClientPackets.ModProtocol modProtocol, PacketSender responseSender) { - ((SyncTaskHolder) handler).qsl$getQuiltSyncTask().handleModProtocol(modProtocol); + ((QuiltSyncTask) ((ServerConfigurationTaskManager) handler).getCurrentTask()).handleModProtocol(modProtocol); } public static void handleUnknownEntry(MinecraftServer server, ServerConfigurationPacketHandler handler, ClientPackets.UnknownEntry unknownEntry, PacketSender responseSender) { - ((SyncTaskHolder) handler).qsl$getQuiltSyncTask().handleUnknownEntry(unknownEntry); + ((QuiltSyncTask) ((ServerConfigurationTaskManager) handler).getCurrentTask()).handleUnknownEntry(unknownEntry); } public static void handleEnd(MinecraftServer server, ServerConfigurationPacketHandler handler, ClientPackets.End end, PacketSender responseSender) { - ((SyncTaskHolder) handler).qsl$getQuiltSyncTask().handleEnd(end); + ((QuiltSyncTask) ((ServerConfigurationTaskManager) handler).getCurrentTask()).handleEnd(end); } public static void readConfig() { diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SetupSyncTask.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SetupSyncTask.java index 70d21a49c8..51465c4002 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SetupSyncTask.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/impl/sync/server/SetupSyncTask.java @@ -23,9 +23,9 @@ import net.minecraft.network.packet.Packet; import org.quiltmc.qsl.networking.api.ServerConfigurationNetworking; +import org.quiltmc.qsl.networking.api.ServerConfigurationTaskManager; import org.quiltmc.qsl.registry.impl.sync.ServerPackets; import org.quiltmc.qsl.registry.mixin.AbstractServerPacketHandlerAccessor; -import org.quiltmc.qsl.registry.mixin.ServerConfigurationPacketHandlerAccessor; public record SetupSyncTask(ServerConfigurationPacketHandler handler) implements ConfigurationTask { public static final ConfigurationTask.Type TYPE = new Type("qsl:configure_sync"); @@ -34,16 +34,16 @@ public record SetupSyncTask(ServerConfigurationPacketHandler handler) implements public void start(Consumer> task) { // First check if Quilt sync is available if (ServerConfigurationNetworking.getSendable(this.handler).contains(ServerPackets.Handshake.ID)) { - ((ServerConfigurationPacketHandlerAccessor) this.handler).getTasks().add(new QuiltSyncTask(this.handler, ((AbstractServerPacketHandlerAccessor) this.handler).getConnection())); + ((ServerConfigurationTaskManager) this.handler).addTask(new QuiltSyncTask(this.handler, ((AbstractServerPacketHandlerAccessor) this.handler).getConnection())); } else if (ServerRegistrySync.forceFabricFallback || (ServerRegistrySync.supportFabric && ServerConfigurationNetworking.getSendable(this.handler).contains(ServerFabricRegistrySync.ID))) { FabricSyncTask fabricSyncTask = new FabricSyncTask(this.handler); ServerConfigurationNetworking.registerReceiver(this.handler, ServerFabricRegistrySync.SYNC_COMPLETE_ID, (server, handler, buf, responseSender) -> fabricSyncTask.handleComplete()); - ((ServerConfigurationPacketHandlerAccessor) this.handler).getTasks().add(fabricSyncTask); + ((ServerConfigurationTaskManager) this.handler).addTask(fabricSyncTask); } else { ((AbstractServerPacketHandlerAccessor) this.handler).getConnection().disconnect(ServerRegistrySync.noRegistrySyncMessage); } - ((org.quiltmc.qsl.networking.mixin.accessor.ServerConfigurationPacketHandlerAccessor) this.handler).invokeFinishCurrentTask(TYPE); + ((ServerConfigurationTaskManager) this.handler).finishTask(TYPE); } @Override diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/ServerConfigurationPacketHandlerMixin.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/ServerConfigurationPacketHandlerMixin.java deleted file mode 100644 index c61481254e..0000000000 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/ServerConfigurationPacketHandlerMixin.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2023 The Quilt Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.quiltmc.qsl.registry.mixin; - -import java.util.Queue; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.network.ServerConfigurationPacketHandler; -import net.minecraft.network.configuration.ConfigurationTask; - -import org.quiltmc.qsl.registry.impl.sync.server.FabricSyncTask; -import org.quiltmc.qsl.registry.impl.sync.server.QuiltSyncTask; -import org.quiltmc.qsl.registry.impl.sync.server.SetupSyncTask; -import org.quiltmc.qsl.registry.impl.sync.server.SyncTaskHolder; -import org.quiltmc.qsl.registry.impl.sync.server.ServerRegistrySync; - -@Mixin(ServerConfigurationPacketHandler.class) -public abstract class ServerConfigurationPacketHandlerMixin implements AbstractServerPacketHandlerAccessor, SyncTaskHolder { - @Shadow - @Final - private Queue tasks; - - @Shadow - @Nullable - private ConfigurationTask currentTask; - - @Shadow - protected abstract void finishCurrentTask(ConfigurationTask.Type taskType); - - @SuppressWarnings("deprecated") - @Inject(method = "addOptionalTasks", at = @At("TAIL")) - private void quilt$addSyncTask(CallbackInfo ci) { - if (ServerRegistrySync.shouldSync()) { - this.tasks.add(new SetupSyncTask((ServerConfigurationPacketHandler) (Object) this)); - } - } - - @Override - public @Nullable QuiltSyncTask qsl$getQuiltSyncTask() { - if (this.currentTask instanceof QuiltSyncTask task) return task; - throw new IllegalStateException("Not currently in QuiltSyncTask!"); - } - - @Override - public void qsl$finishQuiltSyncTask() { - this.finishCurrentTask(QuiltSyncTask.TYPE); - } - - @Override - public void qsl$finishFabricSyncTask() { - this.finishCurrentTask(FabricSyncTask.TYPE); - } -} diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/DisconnectedScreenMixin.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/DisconnectedScreenMixin.java index 89fa3f7779..9d212c4238 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/DisconnectedScreenMixin.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/DisconnectedScreenMixin.java @@ -27,8 +27,8 @@ import net.minecraft.client.gui.screen.DisconnectedScreen; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.LinearLayoutWidget; +import net.minecraft.client.gui.widget.button.ButtonWidget; +import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; import net.minecraft.text.Text; import org.quiltmc.loader.api.minecraft.ClientOnly; diff --git a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/MultiplayerServerListWidgetServerEntryMixin.java b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/MultiplayerServerListWidgetServerEntryMixin.java index e449497213..e85a9ae304 100644 --- a/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/MultiplayerServerListWidgetServerEntryMixin.java +++ b/library/core/registry/src/main/java/org/quiltmc/qsl/registry/mixin/client/MultiplayerServerListWidgetServerEntryMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget; +import net.minecraft.client.gui.widget.list.multiplayer.ServerEntryListWidget; import net.minecraft.client.network.ServerInfo; import org.quiltmc.loader.api.minecraft.ClientOnly; @@ -32,7 +32,7 @@ import org.quiltmc.qsl.registry.impl.sync.mod_protocol.ModProtocolImpl; @ClientOnly -@Mixin(MultiplayerServerListWidget.ServerEntry.class) +@Mixin(ServerEntryListWidget.ServerEntry.class) public class MultiplayerServerListWidgetServerEntryMixin { @Shadow @Final diff --git a/library/core/registry/src/main/resources/quilt_registry.mixins.json b/library/core/registry/src/main/resources/quilt_registry.mixins.json index a69da809ec..ad520c58d3 100644 --- a/library/core/registry/src/main/resources/quilt_registry.mixins.json +++ b/library/core/registry/src/main/resources/quilt_registry.mixins.json @@ -16,7 +16,6 @@ "RegistriesMixin", "RegistryLoaderMixin", "ServerConfigurationPacketHandlerAccessor", - "ServerConfigurationPacketHandlerMixin", "ServerMetadataVersionMixin", "SimpleRegistryMixin", "TagManagerLoaderMixin" diff --git a/library/core/resource_loader/build.gradle b/library/core/resource_loader/build.gradle index cb892226bd..f6f17a80f1 100644 --- a/library/core/resource_loader/build.gradle +++ b/library/core/resource_loader/build.gradle @@ -15,9 +15,9 @@ qslModule { } accessWidener() injectedInterface("net/minecraft/class_3262") { - values = ["org/quiltmc/qsl/resource/loader/api/QuiltResourcePack"] + values = ["org/quiltmc/qsl/resource/loader/api/QuiltPack"] } injectedInterface("net/minecraft/class_3288") { - values = ["org/quiltmc/qsl/resource/loader/api/QuiltResourcePackProfile"] + values = ["org/quiltmc/qsl/resource/loader/api/QuiltPackProfile"] } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupResourcePack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupPack.java similarity index 95% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupResourcePack.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupPack.java index 59f0aa23af..e0e134c98c 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupResourcePack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/GroupPack.java @@ -48,13 +48,13 @@ *
  • etc.
  • * */ -public abstract class GroupResourcePack implements ResourcePack { +public abstract class GroupPack implements ResourcePack { protected final ResourceType type; protected final List packs; protected final Map> namespacedPacks = new Object2ObjectOpenHashMap<>(); private boolean builtin; - public GroupResourcePack(@NotNull ResourceType type, @NotNull List packs) { + public GroupPack(@NotNull ResourceType type, @NotNull List packs) { this.type = type; this.packs = packs; this.recompute(); @@ -87,7 +87,7 @@ public GroupResourcePack(@NotNull ResourceType type, @NotNull List streamPacks() { return this.packs.stream().mapMulti((pack, consumer) -> { - if (pack instanceof GroupResourcePack grouped) { + if (pack instanceof GroupPack grouped) { grouped.streamPacks().forEach(consumer); } else { consumer.accept(pack); @@ -159,7 +159,7 @@ public void close() { /** * Represents a group resource pack which wraps a "base" resource pack. */ - public static class Wrapped extends GroupResourcePack { + public static class Wrapped extends GroupPack { private final ResourcePack basePack; /** diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryResourcePack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryPack.java similarity index 96% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryResourcePack.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryPack.java index 24dddcfa9e..a60c32b7b1 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryResourcePack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/InMemoryPack.java @@ -59,7 +59,7 @@ *

    * The resources of this pack are stored in memory instead of it being on-disk. */ -public abstract class InMemoryResourcePack implements MutableResourcePack { +public abstract class InMemoryPack implements MutablePack { private static final Logger LOGGER = LogUtils.getLogger(); private static final ExecutorService EXECUTOR_SERVICE; private static final boolean DUMP = TriState.fromProperty("quilt.resource_loader.debug.pack.dump_from_in_memory") @@ -224,9 +224,9 @@ public void dumpTo(@NotNull Path path) { this.root.forEach((p, resource) -> this.dumpResource(path, p, resource.get())); this.assets.forEach((p, resource) -> - this.dumpResource(path, QuiltResourcePack.getResourcePath(ResourceType.CLIENT_RESOURCES, p), resource.get())); + this.dumpResource(path, QuiltPack.getResourcePath(ResourceType.CLIENT_RESOURCES, p), resource.get())); this.data.forEach((p, resource) -> - this.dumpResource(path, QuiltResourcePack.getResourcePath(ResourceType.SERVER_DATA, p), resource.get())); + this.dumpResource(path, QuiltPack.getResourcePath(ResourceType.SERVER_DATA, p), resource.get())); } catch (IOException e) { LOGGER.error("Failed to write resource pack dump from pack {} to {}.", this.getName(), path, e); } @@ -275,7 +275,7 @@ private Map> getResourceMap(ResourceType type) { /** * Represents an in-memory resource pack with a static name. */ - public static class Named extends InMemoryResourcePack { + public static class Named extends InMemoryPack { private final String name; public Named(String name) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutableResourcePack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutablePack.java similarity index 99% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutableResourcePack.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutablePack.java index 8507ce71ad..5a7aee3ef9 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutableResourcePack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/MutablePack.java @@ -35,7 +35,7 @@ /** * Represents a resource pack whose resources are mutable. */ -public interface MutableResourcePack extends ResourcePack { +public interface MutablePack extends ResourcePack { /** * Puts a resource into the resource pack's root. * diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackActivationType.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackActivationType.java similarity index 96% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackActivationType.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackActivationType.java index 9845d63106..a1ab744191 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackActivationType.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackActivationType.java @@ -19,7 +19,7 @@ /** * Represents the resource pack activation type. */ -public enum ResourcePackActivationType { +public enum PackActivationType { /** * Normal activation. The user has full control over the activation of the resource pack. */ diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackRegistrationContext.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackRegistrationContext.java similarity index 80% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackRegistrationContext.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackRegistrationContext.java index 44598a90dd..877fd12cd0 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourcePackRegistrationContext.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/PackRegistrationContext.java @@ -25,10 +25,10 @@ /** * Represents a context to register resource packs at will invisibly from the user. * - * @see ResourceLoader#getRegisterDefaultResourcePackEvent() - * @see ResourceLoader#getRegisterTopResourcePackEvent() + * @see ResourceLoader#getRegisterDefaultPackEvent() + * @see ResourceLoader#getRegisterTopPackEvent() */ -public interface ResourcePackRegistrationContext { +public interface PackRegistrationContext { /** * {@return the resource manager that contains the currently existing resource packs} */ @@ -45,8 +45,8 @@ public interface ResourcePackRegistrationContext { void addResourcePack(@NotNull ResourcePack pack); /** - * Functional interface to be implemented on callbacks for {@link ResourceLoader#getRegisterDefaultResourcePackEvent()} - * and {@link ResourceLoader#getRegisterTopResourcePackEvent()}. + * Functional interface to be implemented on callbacks for {@link ResourceLoader#getRegisterDefaultPackEvent()} + * and {@link ResourceLoader#getRegisterTopPackEvent()}. */ @FunctionalInterface interface Callback { @@ -55,6 +55,6 @@ interface Callback { * * @param context the context */ - void onRegisterPack(@NotNull ResourcePackRegistrationContext context); + void onRegisterPack(@NotNull PackRegistrationContext context); } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPack.java similarity index 91% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePack.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPack.java index 875ceda232..e4eadf419d 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPack.java @@ -30,7 +30,7 @@ * Represents a resource pack with extended metadata, injected into {@link net.minecraft.resource.pack.ResourcePack}. */ @InjectedInterface(ResourcePack.class) -public interface QuiltResourcePack { +public interface QuiltPack { /** * {@return a display name for this resource pack} */ @@ -42,13 +42,13 @@ public interface QuiltResourcePack { /** * Gets the activation type of this resource pack. *

    - * This only serves as a hint as ultimately the {@link net.minecraft.resource.pack.ResourcePackProfile} + * This only serves as a hint as ultimately the {@link net.minecraft.resource.pack.PackProfile} * has the last word. * * @return the activation type of this resource pack */ - default @NotNull ResourcePackActivationType getActivationType() { - return ResourcePackActivationType.NORMAL; + default @NotNull PackActivationType getActivationType() { + return PackActivationType.NORMAL; } /** diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePackProfile.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPackProfile.java similarity index 56% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePackProfile.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPackProfile.java index ee5f6ea082..7d422cb811 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltResourcePackProfile.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/QuiltPackProfile.java @@ -18,31 +18,31 @@ import org.jetbrains.annotations.NotNull; -import net.minecraft.resource.pack.BuiltinResourcePackProvider; +import net.minecraft.resource.pack.BuiltinPackProvider; +import net.minecraft.resource.pack.PackProfile; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProfile; import org.quiltmc.qsl.base.api.util.InjectedInterface; /** - * Represents a resource pack profile with extended metadata, injected into {@link ResourcePackProfile}. + * Represents a resource pack profile with extended metadata, injected into {@link PackProfile}. */ -@InjectedInterface(ResourcePackProfile.class) -public interface QuiltResourcePackProfile { +@InjectedInterface(PackProfile.class) +public interface QuiltPackProfile { /** * Gets the activation type of this resource pack. *

    - * This may be influenced by a {@link QuiltResourcePack#getActivationType() resource pack's activation type}, - * but this should return {@link ResourcePackActivationType#ALWAYS_ENABLED}, - * if {@link ResourcePackProfile#isAlwaysEnabled()} returns {@code true}. + * This may be influenced by a {@link QuiltPack#getActivationType() resource pack's activation type}, + * but this should return {@link PackActivationType#ALWAYS_ENABLED}, + * if {@link PackProfile#isAlwaysEnabled()} returns {@code true}. * * @return the activation type of this resource pack */ - default @NotNull ResourcePackActivationType getActivationType() { - return ResourcePackActivationType.NORMAL; + default @NotNull PackActivationType getActivationType() { + return PackActivationType.NORMAL; } - static ResourcePackProfile.ResourcePackFactory wrapToFactory(ResourcePack pack) { - return BuiltinResourcePackProvider.wrapToFactory(pack); + static PackProfile.PackFactory wrapToFactory(ResourcePack pack) { + return BuiltinPackProvider.wrapToFactory(pack); } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourceLoader.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourceLoader.java index 95070eae72..4f8ba4799a 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourceLoader.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/ResourceLoader.java @@ -23,8 +23,8 @@ import org.jetbrains.annotations.NotNull; import net.minecraft.resource.ResourceType; +import net.minecraft.resource.pack.PackProvider; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProvider; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -74,33 +74,33 @@ public interface ResourceLoader { void addReloaderOrdering(@NotNull Identifier firstReloader, @NotNull Identifier secondReloader); /** - * Registers a resource pack profile provider. + * Registers a pack profile provider. *

    - * A resource pack profile means any provided resource packs will show up in the resource pack selection screen. - * Always fired after the built-in resource pack providers. + * A pack profile means any provided resource packs will show up in the resource pack selection screen. + * Always fired after the built-in pack providers. * * @param provider the provider */ - void registerResourcePackProfileProvider(@NotNull ResourcePackProvider provider); + void registerPackProfileProvider(@NotNull PackProvider provider); /** - * {@return the registration of default resource packs event} + * {@return the registration of default packs event} *

    - * This event is triggered when the default resources are created and allow to register additional resource packs - * that are displayed to the user as the {@code "Default"} resource pack. - * Added packs are added before mod resource packs, meaning mod resources will override added packs' resources. + * This event is triggered when the default resources are created and allow to register additional packs + * that are displayed to the user as the {@code "Default"} pack. + * Added packs are added before mod packs, meaning mod resources will override added packs' resources. */ @Contract(pure = true) - @NotNull Event getRegisterDefaultResourcePackEvent(); + @NotNull Event getRegisterDefaultPackEvent(); /** - * {@return the registration of top resource packs event} + * {@return the registration of top packs event} *

    - * This event is triggered once all default and user resource packs are added. - * It allows to add additional resource packs that can override any other resource packs. + * This event is triggered once all default and user packs are added. + * It allows to add additional packs that can override any other packs. */ @Contract(pure = true) - @NotNull Event getRegisterTopResourcePackEvent(); + @NotNull Event getRegisterTopPackEvent(); /** * Creates a new resource pack based on a {@link Path} as its root. @@ -111,13 +111,13 @@ public interface ResourceLoader { * @param rootPath the root path of this resource pack * @param activationType the activation type hint of this resource pack * @return a new resource pack instance - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType, Text) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType, Text) + * @see #newFileSystemPack(Identifier, Path, PackActivationType, Text) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType, Text) */ - default @NotNull ResourcePack newFileSystemResourcePack(@NotNull Identifier id, @NotNull Path rootPath, - ResourcePackActivationType activationType) { - return this.newFileSystemResourcePack(id, rootPath, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); + default @NotNull ResourcePack newFileSystemPack(@NotNull Identifier id, @NotNull Path rootPath, + PackActivationType activationType) { + return this.newFileSystemPack(id, rootPath, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); } /** @@ -130,16 +130,16 @@ public interface ResourceLoader { * @param activationType the activation type hint of this resource pack * @param displayName the display name of the resource pack * @return a new resource pack instance - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType, Text) + * @see #newFileSystemPack(Identifier, Path, PackActivationType) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType, Text) */ - default @NotNull ResourcePack newFileSystemResourcePack(@NotNull Identifier id, @NotNull Path rootPath, - ResourcePackActivationType activationType, @NotNull Text displayName) { + default @NotNull ResourcePack newFileSystemPack(@NotNull Identifier id, @NotNull Path rootPath, + PackActivationType activationType, @NotNull Text displayName) { var container = QuiltLoader.getModContainer(id.getNamespace()) .orElseThrow(() -> new IllegalArgumentException("No mod with ID '" + id.getNamespace() + "' could be found")); - return this.newFileSystemResourcePack(id, container, rootPath, activationType, displayName); + return this.newFileSystemPack(id, container, rootPath, activationType, displayName); } /** @@ -152,13 +152,13 @@ public interface ResourceLoader { * @param rootPath the root path of this resource pack * @param activationType the activation type hint of this resource pack * @return a new resource pack instance - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType) - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType, Text) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType, Text) + * @see #newFileSystemPack(Identifier, Path, PackActivationType) + * @see #newFileSystemPack(Identifier, Path, PackActivationType, Text) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType, Text) */ - default @NotNull ResourcePack newFileSystemResourcePack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, - ResourcePackActivationType activationType) { - return this.newFileSystemResourcePack(id, owner, rootPath, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); + default @NotNull ResourcePack newFileSystemPack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, + PackActivationType activationType) { + return this.newFileSystemPack(id, owner, rootPath, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); } /** @@ -172,12 +172,12 @@ public interface ResourceLoader { * @param activationType the activation type hint of this resource pack * @param displayName the display name of the resource pack * @return a new resource pack instance - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType) - * @see #newFileSystemResourcePack(Identifier, Path, ResourcePackActivationType, Text) - * @see #newFileSystemResourcePack(Identifier, ModContainer, Path, ResourcePackActivationType) + * @see #newFileSystemPack(Identifier, Path, PackActivationType) + * @see #newFileSystemPack(Identifier, Path, PackActivationType, Text) + * @see #newFileSystemPack(Identifier, ModContainer, Path, PackActivationType) */ - @NotNull ResourcePack newFileSystemResourcePack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, - ResourcePackActivationType activationType, @NotNull Text displayName); + @NotNull ResourcePack newFileSystemPack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, + PackActivationType activationType, @NotNull Text displayName); /** * Registers a built-in resource pack. @@ -197,12 +197,12 @@ public interface ResourceLoader { * @param activationType the activation type of the resource pack * @return {@code true} if the resource pack was successfully registered, or {@code false} otherwise * @throws IllegalArgumentException if a mod with the corresponding namespace given in id cannot be found - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType, Text) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType, Text) + * @see #registerBuiltinPack(Identifier, PackActivationType, Text) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType, Text) */ - static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull ResourcePackActivationType activationType) { - return registerBuiltinResourcePack(id, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); + static boolean registerBuiltinPack(@NotNull Identifier id, @NotNull PackActivationType activationType) { + return registerBuiltinPack(id, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); } /** @@ -224,15 +224,15 @@ static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull Reso * @param displayName the display name of the resource pack * @return {@code true} if the resource pack was successfully registered, or {@code false} otherwise * @throws IllegalArgumentException if a mod with the corresponding namespace given in id cannot be found - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType, Text) + * @see #registerBuiltinPack(Identifier, PackActivationType) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType, Text) */ - static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull ResourcePackActivationType activationType, Text displayName) { + static boolean registerBuiltinPack(@NotNull Identifier id, @NotNull PackActivationType activationType, Text displayName) { var container = QuiltLoader.getModContainer(id.getNamespace()) .orElseThrow(() -> new IllegalArgumentException("No mod with mod id " + id.getNamespace() + " could be found")); - return registerBuiltinResourcePack(id, container, activationType, displayName); + return registerBuiltinPack(id, container, activationType, displayName); } /** @@ -251,13 +251,13 @@ static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull Reso * @param container the mod container * @param activationType the activation type of the resource pack * @return {@code true} if the resource pack was successfully registered, or {@code false} otherwise - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType) - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType, Text) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType, Text) + * @see #registerBuiltinPack(Identifier, PackActivationType) + * @see #registerBuiltinPack(Identifier, PackActivationType, Text) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType, Text) */ - static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull ModContainer container, - @NotNull ResourcePackActivationType activationType) { - return registerBuiltinResourcePack(id, container, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); + static boolean registerBuiltinPack(@NotNull Identifier id, @NotNull ModContainer container, + @NotNull PackActivationType activationType) { + return registerBuiltinPack(id, container, activationType, ResourceLoaderImpl.getBuiltinPackDisplayNameFromId(id)); } /** @@ -277,13 +277,13 @@ static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull ModC * @param activationType the activation type of the resource pack * @param displayName the display name of the resource pack * @return {@code true} if the resource pack was successfully registered, or {@code false} otherwise - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType) - * @see #registerBuiltinResourcePack(Identifier, ResourcePackActivationType, Text) - * @see #registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType) + * @see #registerBuiltinPack(Identifier, PackActivationType) + * @see #registerBuiltinPack(Identifier, PackActivationType, Text) + * @see #registerBuiltinPack(Identifier, ModContainer, PackActivationType) */ - static boolean registerBuiltinResourcePack(@NotNull Identifier id, @NotNull ModContainer container, - @NotNull ResourcePackActivationType activationType, Text displayName) { - return ResourceLoaderImpl.registerBuiltinResourcePack(id, "resourcepacks/" + id.getPath(), container, + static boolean registerBuiltinPack(@NotNull Identifier id, @NotNull ModContainer container, + @NotNull PackActivationType activationType, Text displayName) { + return ResourceLoaderImpl.registerBuiltinPack(id, "resourcepacks/" + id.getPath(), container, activationType, displayName); } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/client/ClientResourceLoaderEvents.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/client/ClientResourceLoaderEvents.java index 05bcc865d9..d626538e74 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/client/ClientResourceLoaderEvents.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/client/ClientResourceLoaderEvents.java @@ -44,10 +44,10 @@ private ClientResourceLoaderEvents() { *

    * This event should not be used to load resources, use {@link ResourceLoader#registerReloader(IdentifiableResourceReloader)} instead. */ - public static final Event START_RESOURCE_PACK_RELOAD = Event.create(StartResourcePackReload.class, + public static final Event START_PACK_RELOAD = Event.create(StartPackReload.class, callbacks -> context -> { for (var callback : callbacks) { - callback.onStartResourcePackReload(context); + callback.onStartPackReload(context); } }); @@ -56,26 +56,26 @@ private ClientResourceLoaderEvents() { *

    * This event should not be used to load resources, use {@link ResourceLoader#registerReloader(IdentifiableResourceReloader)} instead. */ - public static final Event END_RESOURCE_PACK_RELOAD = Event.create(EndResourcePackReload.class, + public static final Event END_PACK_RELOAD = Event.create(EndPackReload.class, callbacks -> context -> { for (var callback : callbacks) { - callback.onEndResourcePackReload(context); + callback.onEndPackReload(context); } }); /** - * Functional interface to be implemented on callbacks for {@link #START_RESOURCE_PACK_RELOAD}. + * Functional interface to be implemented on callbacks for {@link #START_PACK_RELOAD}. * - * @see #START_RESOURCE_PACK_RELOAD + * @see #START_PACK_RELOAD */ @FunctionalInterface - public interface StartResourcePackReload extends ClientEventAwareListener { + public interface StartPackReload extends ClientEventAwareListener { /** * Called before resource packs on the Minecraft client have been reloaded. * * @param context the resource reload context */ - void onStartResourcePackReload(Context context); + void onStartPackReload(Context context); @ApiStatus.NonExtendable interface Context { @@ -104,12 +104,12 @@ default MinecraftClient client() { } /** - * Functional interface to be implemented on callbacks for {@link #END_RESOURCE_PACK_RELOAD}. + * Functional interface to be implemented on callbacks for {@link #END_PACK_RELOAD}. * - * @see #END_RESOURCE_PACK_RELOAD + * @see #END_PACK_RELOAD */ @FunctionalInterface - public interface EndResourcePackReload extends ClientEventAwareListener { + public interface EndPackReload extends ClientEventAwareListener { /** * Called after resource packs on the Minecraft client have been reloaded. *

    @@ -117,10 +117,10 @@ public interface EndResourcePackReload extends ClientEventAwareListener { * * @param context the resource reload context */ - void onEndResourcePackReload(Context context); + void onEndPackReload(Context context); @ApiStatus.NonExtendable - interface Context extends StartResourcePackReload.Context { + interface Context extends StartPackReload.Context { /** * {@return present if the resource pack reload failed, or {@linkplain Optional#empty() empty} otherwise} */ diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/package-info.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/package-info.java index acc0ae86ce..5f1b48283f 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/package-info.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/api/package-info.java @@ -20,13 +20,13 @@ *

    *

    Quick note about vocabulary in Resource Loader and Minecraft:

    *
      - *
    • Resource Pack refers to both client-sided resource pack and data pack.
    • - *
    • Virtual Resource Pack refers to a resource pack that may be generated at runtime, or simply doesn't exist directly on disk.
    • - *
    • Group Resource Pack refers to a virtual resource pack that groups multiple resource packs together.
    • + *
    • (Resource) Pack refers to both client-sided resource pack and data pack.
    • + *
    • Virtual Pack refers to a resource pack that may be generated at runtime, or simply doesn't exist directly on disk.
    • + *
    • Group Pack refers to a virtual resource pack that groups multiple resource packs together.
    • *
    * *

    - *

    Modded Resource Pack Handling

    + *

    Modded Pack Handling

    * The Resource Loader will create a resource pack for each mod that provides resources in {@code assets} or {@code data} * top-level directories of the mod. * Those mod resource packs are grouped into the default resource pack. @@ -36,14 +36,14 @@ *

    *

    Built-in Mod Resource Pack

    * The Resource Loader adds manually registered mod resource packs. Those resource packs are registered with - * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#registerBuiltinResourcePack(Identifier, ResourcePackActivationType)}, or - * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#registerBuiltinResourcePack(Identifier, org.quiltmc.loader.api.ModContainer, ResourcePackActivationType)} + * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#registerBuiltinPack(Identifier, PackActivationType)}, or + * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#registerBuiltinPack(Identifier, org.quiltmc.loader.api.ModContainer, PackActivationType)} * *

    *

    Resource Pack Injection

    *

    - *

    Resource Pack Profile Provider
    - * The Resource Loader gives a method to register {@link net.minecraft.resource.pack.ResourcePackProvider ResourcePackProviders}, + *
    Pack Profile Provider
    + * The Resource Loader gives a method to register {@link net.minecraft.resource.pack.PackProvider PackProviders}, * which may be used to add new resource packs that are visible to the player in the resource pack selection screens or the {@code datapack} command. * *

    @@ -52,16 +52,16 @@ * The Resource Loader provides utilities to work with such kind of resource packs: *

      *
    • - * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#getRegisterDefaultResourcePackEvent()} + * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#getRegisterDefaultPackEvent()} * - an event to register resource packs that are injected into the default resource pack. *
    • *
    • - * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#getRegisterTopResourcePackEvent()} + * {@link org.quiltmc.qsl.resource.loader.api.ResourceLoader#getRegisterTopPackEvent()} * - an event to register resource packs that are on the top of the resource pack hierarchy, those resource packs are invisible to the player. *
    • - *
    • {@link org.quiltmc.qsl.resource.loader.api.InMemoryResourcePack} - a resource pack implementation whose resources are stored in the live memory.
    • + *
    • {@link org.quiltmc.qsl.resource.loader.api.InMemoryPack} - a resource pack implementation whose resources are stored in the live memory.
    • *
    • - * {@link org.quiltmc.qsl.resource.loader.api.GroupResourcePack} - a resource pack implementation which can be used to group multiple resource packs into one. + * {@link org.quiltmc.qsl.resource.loader.api.GroupPack} - a resource pack implementation which can be used to group multiple resource packs into one. *
    • *
    * diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java index cc5564a6e8..ef34fee218 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java @@ -16,21 +16,21 @@ package org.quiltmc.qsl.resource.loader.impl; -import net.minecraft.resource.pack.ResourcePackSource; +import net.minecraft.resource.pack.PackSource; import net.minecraft.text.Text; import net.minecraft.util.Formatting; /** * Represents a built-in resource pack source. - * Similar to {@link ResourcePackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too. + * Similar to {@link PackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too. */ -public class BuiltinResourcePackSource implements ResourcePackSource { +public class BuiltinResourcePackSource implements PackSource { private static final Text SOURCE_BUILTIN_TEXT = Text.translatable("pack.source.builtin"); - private final ModNioResourcePack pack; + private final ModNioPack pack; private final Text text; private final Text tooltip; - BuiltinResourcePackSource(ModNioResourcePack pack) { + BuiltinResourcePackSource(ModNioPack pack) { String modName = pack.modInfo.name(); if (modName == null) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioResourcePack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java similarity index 86% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioResourcePack.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java index 87a4c2b43f..2d28a825ee 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioResourcePack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java @@ -44,8 +44,8 @@ import org.quiltmc.loader.api.CachedFileSystem; import org.quiltmc.loader.api.ModMetadata; import org.quiltmc.qsl.base.api.util.TriState; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePack; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.QuiltPack; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; import org.quiltmc.qsl.resource.loader.impl.cache.EntryType; import org.quiltmc.qsl.resource.loader.impl.cache.ResourceAccess; import org.quiltmc.qsl.resource.loader.impl.cache.ResourceTreeCache; @@ -54,7 +54,7 @@ * A NIO implementation of a mod resource pack. */ @ApiStatus.Internal -public class ModNioResourcePack extends AbstractFileResourcePack implements QuiltResourcePack { +public class ModNioPack extends AbstractFileResourcePack implements QuiltPack { private static final Logger LOGGER = LogUtils.getLogger(); private static final FileSystem DEFAULT_FILESYSTEM = FileSystems.getDefault(); private static final boolean DISABLE_CACHING = TriState.fromProperty("quilt.resource_loader.disable_caching").toBooleanOrElse(false); @@ -62,7 +62,7 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements Quil private final String name; private final Text displayName; final ModMetadata modInfo; - private final ResourcePackActivationType activationType; + private final PackActivationType activationType; /* Resource Stuff */ private final ModIoOps io; final ResourceType type; @@ -70,19 +70,19 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements Quil /* Caches */ private final ResourceAccess cache; - static ModNioResourcePack ofMod(ModMetadata modInfo, Path path, ResourceType type) { - return new ModNioResourcePack( - null, modInfo, null, ResourcePackActivationType.ALWAYS_ENABLED, + static ModNioPack ofMod(ModMetadata modInfo, Path path, ResourceType type) { + return new ModNioPack( + null, modInfo, null, PackActivationType.ALWAYS_ENABLED, path, type, null ); } - public ModNioResourcePack(@Nullable String name, ModMetadata modInfo, @Nullable Text displayName, ResourcePackActivationType activationType, - Path path, ResourceType type, @Nullable AutoCloseable closer) { + public ModNioPack(@Nullable String name, ModMetadata modInfo, @Nullable Text displayName, PackActivationType activationType, + Path path, ResourceType type, @Nullable AutoCloseable closer) { super(null, true); /* Metadata */ - this.name = name == null ? ModResourcePackUtil.getName(modInfo) : name; + this.name = name == null ? ModPackUtil.getName(modInfo) : name; this.displayName = displayName == null ? Text.of(name) : displayName; this.modInfo = modInfo; this.activationType = activationType; @@ -116,7 +116,7 @@ public ModNioResourcePack(@Nullable String name, ModMetadata modInfo, @Nullable @Override public @Nullable ResourceIoSupplier open(ResourceType type, Identifier id) { - return this.open(QuiltResourcePack.getResourcePath(type, id)); + return this.open(QuiltPack.getResourcePath(type, id)); } protected ResourceIoSupplier open(String filePath) { @@ -126,7 +126,7 @@ protected ResourceIoSupplier open(String filePath) { return ResourceIoSupplier.create(entry.path()); } - return ModResourcePackUtil.openDefault(this.modInfo, this.type, filePath); + return ModPackUtil.openDefault(this.modInfo, this.type, filePath); } @Override @@ -209,7 +209,7 @@ public boolean isBuiltin() { } @Override - public @NotNull ResourcePackActivationType getActivationType() { + public @NotNull PackActivationType getActivationType() { return this.activationType; } //endregion diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackProvider.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackProvider.java similarity index 69% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackProvider.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackProvider.java index bd9df3b8a2..b5dcb4d241 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackProvider.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackProvider.java @@ -22,25 +22,25 @@ import org.jetbrains.annotations.ApiStatus; import net.minecraft.resource.ResourceType; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackProvider; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackProvider; /** * Represents a resource pack provider for built-in mods resource packs and low-priority virtual resource packs. */ @ApiStatus.Internal -public final class ModResourcePackProvider implements ResourcePackProvider { - public static final ModResourcePackProvider CLIENT_RESOURCE_PACK_PROVIDER = new ModResourcePackProvider(ResourceType.CLIENT_RESOURCES); - public static final ModResourcePackProvider SERVER_RESOURCE_PACK_PROVIDER = new ModResourcePackProvider(ResourceType.SERVER_DATA); +public final class ModPackProvider implements PackProvider { + public static final ModPackProvider CLIENT_RESOURCE_PACK_PROVIDER = new ModPackProvider(ResourceType.CLIENT_RESOURCES); + public static final ModPackProvider SERVER_RESOURCE_PACK_PROVIDER = new ModPackProvider(ResourceType.SERVER_DATA); private final ResourceType type; - public ModResourcePackProvider(ResourceType type) { + public ModPackProvider(ResourceType type) { this.type = type; } @Override - public void register(Consumer profileAdder) { + public void register(Consumer profileAdder) { /* Register order rule in this provider: 1. Mod built-in resource packs @@ -52,7 +52,7 @@ public void register(Consumer profileAdder) { 5. (Invisible) High-priority virtual resource packs */ - ResourceLoaderImpl.registerBuiltinResourcePacks(this.type, profileAdder); + ResourceLoaderImpl.registerBuiltinPacks(this.type, profileAdder); for (var provider : ResourceLoaderImpl.get(this.type).resourcePackProfileProviders) { provider.register(profileAdder); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackUtil.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackUtil.java similarity index 78% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackUtil.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackUtil.java index 856ec3e1e2..b50227fd94 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModResourcePackUtil.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModPackUtil.java @@ -31,15 +31,15 @@ import net.minecraft.resource.ResourceIoSupplier; import net.minecraft.resource.ResourceType; import net.minecraft.resource.pack.DataPackSettings; +import net.minecraft.resource.pack.PackProfile; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProfile; import org.quiltmc.loader.api.ModMetadata; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; @ApiStatus.Internal -public final class ModResourcePackUtil { +public final class ModPackUtil { /** * Represents the default data-pack settings, including the default-enabled built-in data-packs. */ @@ -79,8 +79,8 @@ public static String getName(ModMetadata info) { } public static DataPackSettings createDefaultDataPackSettings(DataPackSettings source) { - var moddedResourcePacks = new ArrayList(); - ModResourcePackProvider.SERVER_RESOURCE_PACK_PROVIDER.register(moddedResourcePacks::add); + var moddedResourcePacks = new ArrayList(); + ModPackProvider.SERVER_RESOURCE_PACK_PROVIDER.register(moddedResourcePacks::add); var enabled = new ArrayList<>(source.getEnabled()); var disabled = new ArrayList<>(source.getDisabled()); @@ -88,7 +88,7 @@ public static DataPackSettings createDefaultDataPackSettings(DataPackSettings so // This ensure that any built-in registered data packs by mods which needs to be enabled by default are // as the data pack screen automatically put any data pack as disabled except the Default data pack. for (var profile : moddedResourcePacks) { - ResourcePack pack = profile.createResourcePack(); + ResourcePack pack = profile.createPack(); if (pack.getActivationType().isEnabledByDefault()) { enabled.add(profile.getName()); @@ -100,22 +100,22 @@ public static DataPackSettings createDefaultDataPackSettings(DataPackSettings so return new DataPackSettings(enabled, disabled); } - public static ResourcePackProfile makeBuiltinPackProfile(ModNioResourcePack pack, ResourcePackProfile.Info info) { - return ResourcePackProfile.of( + public static PackProfile makeBuiltinPackProfile(ModNioPack pack, PackProfile.Info info) { + return PackProfile.of( pack.getName(), pack.getDisplayName(), - pack.getActivationType() == ResourcePackActivationType.ALWAYS_ENABLED, - QuiltResourcePackProfile.wrapToFactory(pack), + pack.getActivationType() == PackActivationType.ALWAYS_ENABLED, + QuiltPackProfile.wrapToFactory(pack), info, - ResourcePackProfile.InsertionPosition.TOP, + PackProfile.InsertionPosition.TOP, false, new BuiltinResourcePackSource(pack) ); } - static @Nullable ResourcePackProfile makeBuiltinPackProfile(ModNioResourcePack pack) { + static @Nullable PackProfile makeBuiltinPackProfile(ModNioPack pack) { // I think the resource version really shouldn't matter here, but we'll go for the latest asset version just in case - ResourcePackProfile.Info info = ResourcePackProfile.readInfoFromPack(pack.getName(), QuiltResourcePackProfile.wrapToFactory(pack), + PackProfile.Info info = PackProfile.readInfoFromPack(pack.getName(), QuiltPackProfile.wrapToFactory(pack), SharedConstants.getGameVersion().getResourceVersion(ResourceType.CLIENT_RESOURCES)); if (info == null) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourcePackRegistrationContextImpl.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/PackRegistrationContextImpl.java similarity index 79% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourcePackRegistrationContextImpl.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/PackRegistrationContextImpl.java index 136c5ba107..f9ee6a8a78 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourcePackRegistrationContextImpl.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/PackRegistrationContextImpl.java @@ -27,19 +27,19 @@ import net.minecraft.resource.ResourceType; import net.minecraft.resource.pack.ResourcePack; -import org.quiltmc.qsl.resource.loader.api.ResourcePackRegistrationContext; +import org.quiltmc.qsl.resource.loader.api.PackRegistrationContext; @ApiStatus.Internal -final class ResourcePackRegistrationContextImpl implements ResourcePackRegistrationContext { +final class PackRegistrationContextImpl implements PackRegistrationContext { private final MultiPackResourceManager resourceManager; private final Consumer packConsumer; - ResourcePackRegistrationContextImpl(MultiPackResourceManager resourceManager, Consumer packConsumer) { + PackRegistrationContextImpl(MultiPackResourceManager resourceManager, Consumer packConsumer) { this.resourceManager = resourceManager; this.packConsumer = packConsumer; } - ResourcePackRegistrationContextImpl(ResourceType type, List packs, Consumer packConsumer) { + PackRegistrationContextImpl(ResourceType type, List packs, Consumer packConsumer) { this(new MultiPackResourceManager(type, packs), packConsumer); } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinResourcePackProfile.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java similarity index 62% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinResourcePackProfile.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java index 520662903b..f704276903 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinResourcePackProfile.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java @@ -23,69 +23,69 @@ import org.slf4j.Logger; import net.minecraft.SharedConstants; +import net.minecraft.resource.pack.PackCompatibility; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackCompatibility; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; @ApiStatus.Internal -public final class QuiltBuiltinResourcePackProfile extends ResourcePackProfile { +public final class QuiltBuiltinPackProfile extends PackProfile { private static final Logger LOGGER = LogUtils.getLogger(); private final ResourcePack pack; - static @Nullable QuiltBuiltinResourcePackProfile of(ModNioResourcePack pack) { + static @Nullable QuiltBuiltinPackProfile of(ModNioPack pack) { int version = SharedConstants.getGameVersion().getResourceVersion(pack.type); - Info info = readInfoFromPack(pack.getName(), QuiltResourcePackProfile.wrapToFactory(pack), version); + Info info = readInfoFromPack(pack.getName(), QuiltPackProfile.wrapToFactory(pack), version); if (info == null) { LOGGER.warn("Couldn't find pack meta for pack {}.", pack.getName()); return null; } - return new QuiltBuiltinResourcePackProfile(pack, info); + return new QuiltBuiltinPackProfile(pack, info); } - private QuiltBuiltinResourcePackProfile(ModNioResourcePack pack, Info info) { + private QuiltBuiltinPackProfile(ModNioPack pack, Info info) { super( pack.getName(), - pack.getActivationType() == ResourcePackActivationType.ALWAYS_ENABLED, - QuiltResourcePackProfile.wrapToFactory(pack), + pack.getActivationType() == PackActivationType.ALWAYS_ENABLED, + QuiltPackProfile.wrapToFactory(pack), pack.getDisplayName(), info, - ResourcePackProfile.InsertionPosition.TOP, + PackProfile.InsertionPosition.TOP, false, - new BuiltinResourcePackSource(pack) + new BuiltinPackSource(pack) ); this.pack = pack; } @Override - public ResourcePackCompatibility getCompatibility() { + public PackCompatibility getCompatibility() { // This is to ease multi-version mods whose built-in packs actually work across versions. - return ResourcePackCompatibility.COMPATIBLE; + return PackCompatibility.COMPATIBLE; } @Override - public @NotNull ResourcePackActivationType getActivationType() { + public @NotNull PackActivationType getActivationType() { return this.pack.getActivationType(); } /** - * Represents a built-in resource pack source. - * Similar to {@link ResourcePackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too. + * Represents a built-in pack source. + * Similar to {@link PackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too. */ - public static class BuiltinResourcePackSource implements ResourcePackSource { + public static class BuiltinPackSource implements PackSource { private static final Text SOURCE_BUILTIN_TEXT = Text.translatable("pack.source.builtin"); - private final ModNioResourcePack pack; + private final ModNioPack pack; private final Text text; private final Text tooltip; - BuiltinResourcePackSource(ModNioResourcePack pack) { + BuiltinPackSource(ModNioPack pack) { String modName = pack.modInfo.name(); if (modName == null) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltMultiPackResourceManagerHooks.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltMultiPackResourceManagerHooks.java index dd8f0ec866..bdc1d72eb0 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltMultiPackResourceManagerHooks.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltMultiPackResourceManagerHooks.java @@ -26,7 +26,7 @@ @ApiStatus.Internal public interface QuiltMultiPackResourceManagerHooks { /** - * Appends the top resource packs that have been registered from {@link ResourceLoader#getRegisterTopResourcePackEvent()}. + * Appends the top resource packs that have been registered from {@link ResourceLoader#getRegisterTopPackEvent()}. */ void quilt$appendTopPacks(); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java index 9c90c0822b..98436bf695 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java @@ -50,9 +50,9 @@ import net.minecraft.resource.MultiPackResourceManager; import net.minecraft.resource.ResourceReloader; import net.minecraft.resource.ResourceType; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackProvider; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackProvider; import net.minecraft.resource.pack.metadata.ResourceMetadataSectionReader; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -68,10 +68,10 @@ import org.quiltmc.qsl.base.api.phase.PhaseData; import org.quiltmc.qsl.base.api.phase.PhaseSorting; import org.quiltmc.qsl.base.api.util.TriState; -import org.quiltmc.qsl.resource.loader.api.GroupResourcePack; +import org.quiltmc.qsl.resource.loader.api.GroupPack; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; -import org.quiltmc.qsl.resource.loader.api.ResourcePackRegistrationContext; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; +import org.quiltmc.qsl.resource.loader.api.PackRegistrationContext; import org.quiltmc.qsl.resource.loader.api.reloader.IdentifiableResourceReloader; import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys; import org.quiltmc.qsl.resource.loader.mixin.VanillaDataPackProviderAccessor; @@ -85,13 +85,13 @@ public final class ResourceLoaderImpl implements ResourceLoader { /** * Represents a cache of the client mod resource packs so resource packs that can cache don't lose their cache. */ - private static final Map> CLIENT_MOD_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); + private static final Map> CLIENT_MOD_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); /** * Represents a cache of the server mod data packs so resource packs that can cache don't lose their cache. */ - private static final Map> SERVER_MOD_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); - private static final Map CLIENT_BUILTIN_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); - private static final Map SERVER_BUILTIN_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); + private static final Map> SERVER_MOD_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); + private static final Map CLIENT_BUILTIN_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); + private static final Map SERVER_BUILTIN_RESOURCE_PACKS = new Object2ObjectOpenHashMap<>(); private static final Logger LOGGER = LoggerFactory.getLogger("ResourceLoader"); private static final boolean DEBUG_RELOADERS_IDENTITY = TriState.fromProperty("quilt.resource_loader.debug.reloaders_identity") @@ -103,13 +103,13 @@ public final class ResourceLoaderImpl implements ResourceLoader { private final Set addedReloaderIds = new ObjectOpenHashSet<>(); private final Set addedReloaders = new LinkedHashSet<>(); private final Set> reloadersOrdering = new LinkedHashSet<>(); - final Set resourcePackProfileProviders = new ObjectOpenHashSet<>(); + final Set resourcePackProfileProviders = new ObjectOpenHashSet<>(); - private final Event defaultResourcePackRegistrationEvent = createResourcePackRegistrationEvent(); - private final Event topResourcePackRegistrationEvent = createResourcePackRegistrationEvent(); + private final Event defaultResourcePackRegistrationEvent = createResourcePackRegistrationEvent(); + private final Event topResourcePackRegistrationEvent = createResourcePackRegistrationEvent(); - private static Event createResourcePackRegistrationEvent() { - return Event.create(ResourcePackRegistrationContext.Callback.class, callbacks -> context -> { + private static Event createResourcePackRegistrationEvent() { + return Event.create(PackRegistrationContext.Callback.class, callbacks -> context -> { for (var callback : callbacks) { callback.onRegisterPack(context); } @@ -182,7 +182,7 @@ public void addReloaderOrdering(@NotNull Identifier firstReloader, @NotNull Iden } @Override - public void registerResourcePackProfileProvider(@NotNull ResourcePackProvider provider) { + public void registerPackProfileProvider(@NotNull PackProvider provider) { if (!this.resourcePackProfileProviders.add(provider)) { throw new IllegalStateException( "Tried to register a resource pack profile provider twice!" @@ -191,20 +191,20 @@ public void registerResourcePackProfileProvider(@NotNull ResourcePackProvider pr } @Override - public @NotNull Event getRegisterDefaultResourcePackEvent() { + public @NotNull Event getRegisterDefaultPackEvent() { return this.defaultResourcePackRegistrationEvent; } @Override - public @NotNull Event getRegisterTopResourcePackEvent() { + public @NotNull Event getRegisterTopPackEvent() { return this.topResourcePackRegistrationEvent; } @Override - public @NotNull ResourcePack newFileSystemResourcePack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, - ResourcePackActivationType activationType, @NotNull Text displayName) { + public @NotNull ResourcePack newFileSystemPack(@NotNull Identifier id, @NotNull ModContainer owner, @NotNull Path rootPath, + PackActivationType activationType, @NotNull Text displayName) { String name = id.getNamespace() + '/' + id.getPath(); - return new ModNioResourcePack(name, owner.metadata(), displayName, activationType, rootPath, this.type, null); + return new ModNioPack(name, owner.metadata(), displayName, activationType, rootPath, this.type, null); } /** @@ -216,7 +216,7 @@ public void registerResourcePackProfileProvider(@NotNull ResourcePackProvider pr * @param consumer the resource pack consumer */ public static void flattenPacks(ResourcePack pack, Consumer consumer) { - if (pack instanceof GroupResourcePack grouped) { + if (pack instanceof GroupPack grouped) { grouped.streamPacks().forEach(p -> flattenPacks(p, consumer)); } else { consumer.accept(pack); @@ -224,7 +224,7 @@ public static void flattenPacks(ResourcePack pack, Consumer consum } public void appendTopPacks(MultiPackResourceManager resourceManager, Consumer resourcePackAdder) { - this.topResourcePackRegistrationEvent.invoker().onRegisterPack(new ResourcePackRegistrationContextImpl(resourceManager, resourcePackAdder)); + this.topResourcePackRegistrationEvent.invoker().onRegisterPack(new PackRegistrationContextImpl(resourceManager, resourcePackAdder)); } /** @@ -349,11 +349,11 @@ private void sort(List reloaders) { * @param type the type of resource * @param subPath the resource pack sub path directory in mods, may be {@code null} */ - public static void appendModResourcePacks(List packs, ResourceType type, @Nullable String subPath) { + public static void appendModPacks(List packs, ResourceType type, @Nullable String subPath) { var modResourcePacks = type == ResourceType.CLIENT_RESOURCES ? CLIENT_MOD_RESOURCE_PACKS : SERVER_MOD_RESOURCE_PACKS; var existingList = modResourcePacks.get(subPath); - var byMod = new Reference2ObjectOpenHashMap(); + var byMod = new Reference2ObjectOpenHashMap(); if (existingList != null) { for (var pack : existingList) { @@ -382,10 +382,10 @@ public static void appendModResourcePacks(List packs, ResourceType path = childPath; } - byMod.put(container.metadata(), ModNioResourcePack.ofMod(container.metadata(), path, type)); + byMod.put(container.metadata(), ModNioPack.ofMod(container.metadata(), path, type)); } - List packList = byMod.values().stream() + List packList = byMod.values().stream() .filter(pack -> !pack.getNamespaces(type).isEmpty()) .toList(); @@ -395,30 +395,30 @@ public static void appendModResourcePacks(List packs, ResourceType packs.addAll(packList); } - public static GroupResourcePack.Wrapped buildMinecraftResourcePack(ResourceType type, ResourcePack vanillaPack) { + public static GroupPack.Wrapped buildMinecraftPack(ResourceType type, ResourcePack vanillaPack) { // Build a list of mod resource packs. var packs = new ArrayList(); - appendModResourcePacks(packs, type, null); + appendModPacks(packs, type, null); - var pack = new GroupResourcePack.Wrapped(type, vanillaPack, packs, false); + var pack = new GroupPack.Wrapped(type, vanillaPack, packs, false); int[] lastExtraPackIndex = new int[] {1}; - var context = new ResourcePackRegistrationContextImpl(type, List.of(pack), p -> { + var context = new PackRegistrationContextImpl(type, List.of(pack), p -> { packs.add(lastExtraPackIndex[0]++, p); pack.recompute(); }); - get(type).getRegisterDefaultResourcePackEvent().invoker().onRegisterPack(context); + get(type).getRegisterDefaultPackEvent().invoker().onRegisterPack(context); return pack; } - public static GroupResourcePack.Wrapped buildVanillaBuiltinResourcePack(ResourcePack vanillaPack, ResourceType type, String packName) { + public static GroupPack.Wrapped buildVanillaBuiltinPack(ResourcePack vanillaPack, ResourceType type, String packName) { // Build a list of mod resource packs. var packs = new ArrayList(); - appendModResourcePacks(packs, type, packName); + appendModPacks(packs, type, packName); - return new GroupResourcePack.Wrapped(type, vanillaPack, packs, false); + return new GroupPack.Wrapped(type, vanillaPack, packs, false); } /* Built-in resource packs */ @@ -436,10 +436,10 @@ public static Text getBuiltinPackDisplayNameFromId(Identifier id) { * @param activationType the activation type of the resource pack * @param displayName the display name of the resource pack * @return {@code true} if successfully registered the resource pack, or {@code false} otherwise - * @see ResourceLoader#registerBuiltinResourcePack(Identifier, ModContainer, ResourcePackActivationType, Text) + * @see ResourceLoader#registerBuiltinPack(Identifier, ModContainer, PackActivationType, Text) */ - public static boolean registerBuiltinResourcePack(Identifier id, String subPath, ModContainer container, - ResourcePackActivationType activationType, Text displayName) { + public static boolean registerBuiltinPack(Identifier id, String subPath, ModContainer container, + PackActivationType activationType, Text displayName) { Path resourcePackPath = container.getPath(subPath).toAbsolutePath().normalize(); if (!Files.exists(resourcePackPath)) { @@ -450,19 +450,19 @@ public static boolean registerBuiltinResourcePack(Identifier id, String subPath, boolean result = false; if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT) { - result = registerBuiltinResourcePack(ResourceType.CLIENT_RESOURCES, - newBuiltinResourcePack(container, name, displayName, resourcePackPath, ResourceType.CLIENT_RESOURCES, activationType) + result = registerBuiltinPack(ResourceType.CLIENT_RESOURCES, + newBuiltinPack(container, name, displayName, resourcePackPath, ResourceType.CLIENT_RESOURCES, activationType) ); } - result |= registerBuiltinResourcePack(ResourceType.SERVER_DATA, - newBuiltinResourcePack(container, name, displayName, resourcePackPath, ResourceType.SERVER_DATA, activationType) + result |= registerBuiltinPack(ResourceType.SERVER_DATA, + newBuiltinPack(container, name, displayName, resourcePackPath, ResourceType.SERVER_DATA, activationType) ); return result; } - private static boolean registerBuiltinResourcePack(ResourceType type, ModNioResourcePack pack) { + private static boolean registerBuiltinPack(ResourceType type, ModNioPack pack) { if (QuiltLoader.isDevelopmentEnvironment() || !pack.getNamespaces(type).isEmpty()) { var builtinResourcePacks = type == ResourceType.CLIENT_RESOURCES ? CLIENT_BUILTIN_RESOURCE_PACKS : SERVER_BUILTIN_RESOURCE_PACKS; @@ -472,23 +472,23 @@ private static boolean registerBuiltinResourcePack(ResourceType type, ModNioReso return false; } - private static ModNioResourcePack newBuiltinResourcePack(ModContainer container, String name, Text displayName, - Path resourcePackPath, ResourceType type, ResourcePackActivationType activationType) { - return new ModNioResourcePack(name, container.metadata(), displayName, activationType, resourcePackPath, type, null); + private static ModNioPack newBuiltinPack(ModContainer container, String name, Text displayName, + Path resourcePackPath, ResourceType type, PackActivationType activationType) { + return new ModNioPack(name, container.metadata(), displayName, activationType, resourcePackPath, type, null); } - public static void registerBuiltinResourcePacks(ResourceType type, Consumer profileAdder) { + public static void registerBuiltinPacks(ResourceType type, Consumer profileAdder) { var builtinPacks = type == ResourceType.CLIENT_RESOURCES ? CLIENT_BUILTIN_RESOURCE_PACKS : SERVER_BUILTIN_RESOURCE_PACKS; // Loop through each registered built-in resource packs and add them if valid. for (var entry : builtinPacks.entrySet()) { - ModNioResourcePack pack = entry.getValue(); + ModNioPack pack = entry.getValue(); // Add the built-in pack only if namespaces for the specified resource type are present. if (!pack.getNamespaces(type).isEmpty()) { // Make the resource pack profile for built-in pack, should never be always enabled. - var profile = ModResourcePackUtil.makeBuiltinPackProfile(pack); + var profile = ModPackUtil.makeBuiltinPackProfile(pack); if (profile != null) { profileAdder.accept(profile); @@ -505,8 +505,8 @@ public static void registerBuiltinResourcePacks(ResourceType type, Consumer map) { - var pack = ResourceLoaderImpl.buildMinecraftResourcePack(ResourceType.CLIENT_RESOURCES, - VanillaDataPackProviderAccessor.invokeCreateVanillaResourcePack() + var pack = ResourceLoaderImpl.buildMinecraftPack(ResourceType.CLIENT_RESOURCES, + VanillaDataPackProviderAccessor.invokeDefaultPackBuilder() ); try (var manager = new MultiPackResourceManager(ResourceType.CLIENT_RESOURCES, List.of(pack))) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/ClientResourceLoaderEventContextsImpl.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/ClientResourceLoaderEventContextsImpl.java index 613c93a4ac..1348e4005c 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/ClientResourceLoaderEventContextsImpl.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/ClientResourceLoaderEventContextsImpl.java @@ -27,7 +27,7 @@ @ClientOnly @ApiStatus.Internal -public class ClientResourceLoaderEventContextsImpl implements ClientResourceLoaderEvents.StartResourcePackReload.Context { +public class ClientResourceLoaderEventContextsImpl implements ClientResourceLoaderEvents.StartPackReload.Context { private final ResourceManager resourceManager; private final boolean first; @@ -47,7 +47,7 @@ public boolean isFirst() { } public static final class ReloadEndContext extends ClientResourceLoaderEventContextsImpl - implements ClientResourceLoaderEvents.EndResourcePackReload.Context { + implements ClientResourceLoaderEvents.EndPackReload.Context { private final Optional error; public ReloadEndContext(ResourceManager resourceManager, boolean first, Optional error) { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinResourcePackProviderMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinPackProviderMixin.java similarity index 72% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinResourcePackProviderMixin.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinPackProviderMixin.java index 20018e946b..f019f358fd 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinResourcePackProviderMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/BuiltinPackProviderMixin.java @@ -23,20 +23,20 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.resource.pack.BuiltinResourcePackProvider; -import net.minecraft.resource.pack.ResourcePackProfile; +import net.minecraft.resource.pack.BuiltinPackProvider; +import net.minecraft.resource.pack.PackProfile; import net.minecraft.resource.pack.VanillaDataPackProvider; -import org.quiltmc.qsl.resource.loader.impl.ModResourcePackProvider; +import org.quiltmc.qsl.resource.loader.impl.ModPackProvider; -@Mixin(BuiltinResourcePackProvider.class) -public class BuiltinResourcePackProviderMixin { +@Mixin(BuiltinPackProvider.class) +public class BuiltinPackProviderMixin { @SuppressWarnings("ConstantConditions") @Inject(method = "registerAdditionalPacks", at = @At("RETURN")) - private void onRegisterAdditionalPacks(Consumer profileAdder, CallbackInfo ci) { + private void onRegisterAdditionalPacks(Consumer profileAdder, CallbackInfo ci) { // Register built-in resource packs after vanilla built-in resource packs are registered. if (((Object) this) instanceof VanillaDataPackProvider) { - ModResourcePackProvider.SERVER_RESOURCE_PACK_PROVIDER.register(profileAdder); + ModPackProvider.SERVER_RESOURCE_PACK_PROVIDER.register(profileAdder); } } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackMixin.java similarity index 88% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackMixin.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackMixin.java index 6b416cea1a..ea13e1a207 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackMixin.java @@ -23,10 +23,10 @@ import net.minecraft.resource.pack.ResourcePack; import net.minecraft.text.Text; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePack; +import org.quiltmc.qsl.resource.loader.api.QuiltPack; @Mixin(ResourcePack.class) -public interface ResourcePackMixin extends QuiltResourcePack { +public interface PackMixin extends QuiltPack { @Shadow String getName(); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackProfileMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackProfileMixin.java similarity index 62% rename from library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackProfileMixin.java rename to library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackProfileMixin.java index 05f45c2176..bc9de8a885 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ResourcePackProfileMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/PackProfileMixin.java @@ -23,21 +23,21 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.text.Text; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; -@Mixin(ResourcePackProfile.class) -public class ResourcePackProfileMixin implements QuiltResourcePackProfile { +@Mixin(PackProfile.class) +public class PackProfileMixin implements QuiltPackProfile { @Unique - private ResourcePackActivationType quilt$activationType; + private PackActivationType quilt$activationType; @Inject(method = "", at = @At("RETURN")) - private void quilt$onInit(String name, boolean alwaysEnabled, ResourcePackProfile.ResourcePackFactory packFactory, Text displayName, - ResourcePackProfile.Info info, ResourcePackProfile.InsertionPosition position, boolean pinned, ResourcePackSource source, + private void quilt$onInit(String name, boolean alwaysEnabled, PackProfile.PackFactory packFactory, Text displayName, + PackProfile.Info info, PackProfile.InsertionPosition position, boolean pinned, PackSource source, CallbackInfo ci) { try (var pack = packFactory.open(name, info)) { this.quilt$activationType = pack.getActivationType(); @@ -45,7 +45,7 @@ public class ResourcePackProfileMixin implements QuiltResourcePackProfile { } @Override - public @NotNull ResourcePackActivationType getActivationType() { + public @NotNull PackActivationType getActivationType() { return this.quilt$activationType; } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ReloadableResourceManagerMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ReloadableResourceManagerMixin.java index 1e65ef6e39..a345526e6f 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ReloadableResourceManagerMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/ReloadableResourceManagerMixin.java @@ -38,7 +38,7 @@ import net.minecraft.resource.pack.ResourcePack; import net.minecraft.util.Unit; -import org.quiltmc.qsl.resource.loader.api.GroupResourcePack; +import org.quiltmc.qsl.resource.loader.api.GroupPack; import org.quiltmc.qsl.resource.loader.impl.QuiltMultiPackResourceManagerHooks; import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderImpl; @@ -79,8 +79,8 @@ private void reload(Executor prepareExecutor, Executor applyExecutor, Completabl @Inject(method = "method_29491(Ljava/util/List;)Ljava/lang/Object;", at = @At("HEAD"), cancellable = true) private static void getResourcePackNames(List packs, CallbackInfoReturnable cir) { cir.setReturnValue(packs.stream().map(pack -> { - if (pack instanceof GroupResourcePack groupResourcePack) { - return groupResourcePack.getFullName(); + if (pack instanceof GroupPack groupPack) { + return groupPack.getFullName(); } else { return pack.getName(); } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/TestServerMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/TestServerMixin.java index 52598846f8..a5cb6efda5 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/TestServerMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/TestServerMixin.java @@ -28,7 +28,7 @@ import net.minecraft.test.TestServer; import org.quiltmc.qsl.resource.loader.api.ResourceLoaderEvents; -import org.quiltmc.qsl.resource.loader.impl.ModResourcePackUtil; +import org.quiltmc.qsl.resource.loader.impl.ModPackUtil; import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderEventContextsImpl; @Mixin(TestServer.class) @@ -42,7 +42,7 @@ public class TestServerMixin { index = 0 ) private static DataPackSettings replaceDefaultDataPackSettings(DataPackSettings initialDataPacks) { - return ModResourcePackUtil.DEFAULT_SETTINGS; + return ModPackUtil.DEFAULT_SETTINGS; } @ModifyVariable(method = "create", at = @At(value = "STORE")) diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderAccessor.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderAccessor.java index 5e9615b79f..60556c117e 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderAccessor.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderAccessor.java @@ -19,13 +19,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -import net.minecraft.resource.pack.DefaultResourcePack; +import net.minecraft.resource.pack.DefaultPack; import net.minecraft.resource.pack.VanillaDataPackProvider; @Mixin(VanillaDataPackProvider.class) public interface VanillaDataPackProviderAccessor { @Invoker - static DefaultResourcePack invokeCreateVanillaResourcePack() { + static DefaultPack invokeDefaultPackBuilder() { throw new IllegalStateException("Mixin injection failed."); } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderMixin.java index b7ec037fb9..f13e7195a0 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/VanillaDataPackProviderMixin.java @@ -23,14 +23,14 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import net.minecraft.resource.ResourceType; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; import net.minecraft.resource.pack.VanillaDataPackProvider; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderImpl; @Mixin(VanillaDataPackProvider.class) @@ -40,29 +40,29 @@ public class VanillaDataPackProviderMixin { private static Identifier DATA_PACKS_DIR; @ModifyArg( - method = "createBuiltinResourcePackProfile(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/ResourcePackProfile;", + method = "createBuiltinPackProfile(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/PackProfile;", at = @At( value = "INVOKE", - target = "Lnet/minecraft/resource/pack/VanillaDataPackProvider;wrapToFactory(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;" + target = "Lnet/minecraft/resource/pack/VanillaDataPackProvider;wrapToFactory(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/PackProfile$PackFactory;" ), index = 0 ) private ResourcePack onPackGet(ResourcePack pack) { - return ResourceLoaderImpl.buildMinecraftResourcePack(ResourceType.SERVER_DATA, pack); + return ResourceLoaderImpl.buildMinecraftPack(ResourceType.SERVER_DATA, pack); } @ModifyArg( - method = "createBuiltinResourcePackProfile(Ljava/lang/String;Lnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;Lnet/minecraft/text/Text;)Lnet/minecraft/resource/pack/ResourcePackProfile;", + method = "createBuiltinPackProfile(Ljava/lang/String;Lnet/minecraft/resource/pack/PackProfile$PackFactory;Lnet/minecraft/text/Text;)Lnet/minecraft/resource/pack/PackProfile;", at = @At( value = "INVOKE", - target = "Lnet/minecraft/resource/pack/ResourcePackProfile;of(Ljava/lang/String;Lnet/minecraft/text/Text;ZLnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;Lnet/minecraft/resource/ResourceType;Lnet/minecraft/resource/pack/ResourcePackProfile$InsertionPosition;Lnet/minecraft/resource/pack/ResourcePackSource;)Lnet/minecraft/resource/pack/ResourcePackProfile;" + target = "Lnet/minecraft/resource/pack/PackProfile;of(Ljava/lang/String;Lnet/minecraft/text/Text;ZLnet/minecraft/resource/pack/PackProfile$PackFactory;Lnet/minecraft/resource/ResourceType;Lnet/minecraft/resource/pack/PackProfile$InsertionPosition;Lnet/minecraft/resource/pack/PackSource;)Lnet/minecraft/resource/pack/PackProfile;" ), index = 3 ) - private ResourcePackProfile.ResourcePackFactory onCreateBuiltinResourcePackProfile(String name, Text displayName, boolean alwaysEnabled, - ResourcePackProfile.ResourcePackFactory factory, ResourceType type, ResourcePackProfile.InsertionPosition insertionPosition, - ResourcePackSource source) { - return QuiltResourcePackProfile.wrapToFactory(ResourceLoaderImpl.buildVanillaBuiltinResourcePack(factory.openPrimary(name), ResourceType.SERVER_DATA, + private PackProfile.PackFactory onCreateBuiltinResourcePackProfile(String name, Text displayName, boolean alwaysEnabled, + PackProfile.PackFactory factory, ResourceType type, PackProfile.InsertionPosition insertionPosition, + PackSource source) { + return QuiltPackProfile.wrapToFactory(ResourceLoaderImpl.buildVanillaBuiltinPack(factory.openPrimary(name), ResourceType.SERVER_DATA, "data/" + DATA_PACKS_DIR.getNamespace() + '/' + DATA_PACKS_DIR.getPath() + '/' + name )); } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ClientBuiltinResourcePackProviderMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ClientBuiltinResourcePackProviderMixin.java index 0795c00a77..6ec17a4d0f 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ClientBuiltinResourcePackProviderMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ClientBuiltinResourcePackProviderMixin.java @@ -29,15 +29,15 @@ import net.minecraft.client.resource.ClientBuiltinResourcePackProvider; import net.minecraft.resource.ResourceType; -import net.minecraft.resource.pack.BuiltinResourcePackProvider; +import net.minecraft.resource.pack.BuiltinPackProvider; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; import net.minecraft.text.Text; import org.quiltmc.loader.api.minecraft.ClientOnly; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; -import org.quiltmc.qsl.resource.loader.impl.ModResourcePackProvider; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; +import org.quiltmc.qsl.resource.loader.impl.ModPackProvider; import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderImpl; @ClientOnly @@ -48,44 +48,44 @@ public abstract class ClientBuiltinResourcePackProviderMixin { private static Map BUILTIN_PACK_DISPLAY_NAMES; @ModifyArg( - method = "createBuiltinResourcePackProfile(Ljava/lang/String;Lnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;Lnet/minecraft/text/Text;)Lnet/minecraft/resource/pack/ResourcePackProfile;", + method = "createBuiltinPackProfile(Ljava/lang/String;Lnet/minecraft/resource/pack/PackProfile$PackFactory;Lnet/minecraft/text/Text;)Lnet/minecraft/resource/pack/PackProfile;", at = @At( value = "INVOKE", - target = "Lnet/minecraft/resource/pack/ResourcePackProfile;of(Ljava/lang/String;Lnet/minecraft/text/Text;ZLnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;Lnet/minecraft/resource/ResourceType;Lnet/minecraft/resource/pack/ResourcePackProfile$InsertionPosition;Lnet/minecraft/resource/pack/ResourcePackSource;)Lnet/minecraft/resource/pack/ResourcePackProfile;" + target = "Lnet/minecraft/resource/pack/PackProfile;of(Ljava/lang/String;Lnet/minecraft/text/Text;ZLnet/minecraft/resource/pack/PackProfile$PackFactory;Lnet/minecraft/resource/ResourceType;Lnet/minecraft/resource/pack/PackProfile$InsertionPosition;Lnet/minecraft/resource/pack/PackSource;)Lnet/minecraft/resource/pack/PackProfile;" ), index = 3 ) - private ResourcePackProfile.ResourcePackFactory onCreateBuiltinResourcePackProfile(String name, Text displayName, boolean alwaysEnabled, - ResourcePackProfile.ResourcePackFactory factory, ResourceType type, ResourcePackProfile.InsertionPosition insertionPosition, - ResourcePackSource source) { + private PackProfile.PackFactory onCreateBuiltinResourcePackProfile(String name, Text displayName, boolean alwaysEnabled, + PackProfile.PackFactory factory, ResourceType type, PackProfile.InsertionPosition insertionPosition, + PackSource source) { if (BUILTIN_PACK_DISPLAY_NAMES.containsKey(name)) { - return QuiltResourcePackProfile.wrapToFactory(ResourceLoaderImpl.buildVanillaBuiltinResourcePack(factory.openPrimary(name), ResourceType.CLIENT_RESOURCES, name)); + return QuiltPackProfile.wrapToFactory(ResourceLoaderImpl.buildVanillaBuiltinPack(factory.openPrimary(name), ResourceType.CLIENT_RESOURCES, name)); } return factory; } @ModifyArg( - method = "createBuiltinResourcePackProfile(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/ResourcePackProfile;", + method = "createBuiltinPackProfile(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/PackProfile;", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/resource/ClientBuiltinResourcePackProvider;wrapToFactory(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;" + target = "Lnet/minecraft/client/resource/ClientBuiltinResourcePackProvider;wrapToFactory(Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/PackProfile$PackFactory;" ), index = 0 ) private ResourcePack onPackGet(ResourcePack pack) { - return ResourceLoaderImpl.buildMinecraftResourcePack(ResourceType.CLIENT_RESOURCES, pack); + return ResourceLoaderImpl.buildMinecraftPack(ResourceType.CLIENT_RESOURCES, pack); } @ClientOnly - @Mixin(BuiltinResourcePackProvider.class) + @Mixin(BuiltinPackProvider.class) public static class Parent { @SuppressWarnings("ConstantConditions") @Inject(method = "registerAdditionalPacks", at = @At("RETURN")) - private void addBuiltinResourcePacks(Consumer profileAdder, CallbackInfo ci) { + private void addBuiltinResourcePacks(Consumer profileAdder, CallbackInfo ci) { // Register built-in resource packs after vanilla built-in resource packs are registered. if (((Object) this) instanceof ClientBuiltinResourcePackProvider) { - ModResourcePackProvider.CLIENT_RESOURCE_PACK_PROVIDER.register(profileAdder); + ModPackProvider.CLIENT_RESOURCE_PACK_PROVIDER.register(profileAdder); } } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/GameOptionsMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/GameOptionsMixin.java index 6000bf5819..a908890bf5 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/GameOptionsMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/GameOptionsMixin.java @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.client.option.GameOptions; -import net.minecraft.resource.pack.ResourcePackManager; +import net.minecraft.resource.pack.PackManager; import org.quiltmc.loader.api.minecraft.ClientOnly; @@ -62,7 +62,7 @@ private void onAccept(GameOptions.Visitor visitor, CallbackInfo ci) { } @Inject(method = "addResourcePackProfilesToManager", at = @At("HEAD")) - private void onAddResourcePackProfilesToManager(ResourcePackManager manager, CallbackInfo ci) { + private void onAddResourcePackProfilesToManager(PackManager manager, CallbackInfo ci) { var toEnable = new ArrayList(); // Remove all resource packs that cannot be found from the available resource packs list. diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/IntegratedServerLoaderMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/IntegratedServerLoaderMixin.java index 0393713b5c..90f52ccb9b 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/IntegratedServerLoaderMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/IntegratedServerLoaderMixin.java @@ -37,7 +37,7 @@ import net.minecraft.client.gui.screen.world.CreateWorldScreen; import net.minecraft.registry.LayeredRegistryManager; import net.minecraft.resource.AutoCloseableResourceManager; -import net.minecraft.resource.pack.ResourcePackManager; +import net.minecraft.resource.pack.PackManager; import net.minecraft.server.ServerReloadableResources; import net.minecraft.server.WorldLoader; import net.minecraft.server.WorldStem; @@ -108,7 +108,7 @@ private Throwable onFailedDataPackLoad(Throwable exception) { cancellable = true ) private void onBackupExperimentalWarning(Screen parentScreen, String worldName, boolean safeMode, boolean requireBackup, CallbackInfo ci, - WorldSaveStorage.Session session, ResourcePackManager resourcePackManager, WorldStem worldStem) { + WorldSaveStorage.Session session, PackManager resourcePackManager, WorldStem worldStem) { if (EXPERIMENTAL_SCREEN_OVERRIDE.toBooleanOrElse(true) && !worldStem.saveProperties().getGeneratorOptions().hasLegacyCustomOptions()) { worldStem.close(); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/MinecraftClientMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/MinecraftClientMixin.java index f7d16dd9c2..438e1a0c0f 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/MinecraftClientMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/MinecraftClientMixin.java @@ -60,7 +60,7 @@ private void onFirstReloadResources(RunArgs runArgs, CallbackInfo ci) { @SuppressWarnings("target") @Inject(method = "method_53522", at = @At("HEAD")) private void onFirstEndReloadResources(MinecraftClient.C_vfwwgdbg c_vfwwgdbg, Optional error, CallbackInfo ci) { - ClientResourceLoaderEvents.END_RESOURCE_PACK_RELOAD.invoker().onEndResourcePackReload( + ClientResourceLoaderEvents.END_PACK_RELOAD.invoker().onEndPackReload( new ClientResourceLoaderEventContextsImpl.ReloadEndContext(this.resourceManager, true, error) ); } @@ -81,7 +81,7 @@ private void onStartReloadResources(boolean bl, @Nullable MinecraftClient.C_vfww @SuppressWarnings("target") @Inject(method = "method_24228", at = @At(value = "HEAD")) private void onEndReloadResources(boolean force, MinecraftClient.C_vfwwgdbg c_vfwwgdbg, CompletableFuture completableFuture, Optional error, CallbackInfo ci) { - ClientResourceLoaderEvents.END_RESOURCE_PACK_RELOAD.invoker().onEndResourcePackReload( + ClientResourceLoaderEvents.END_PACK_RELOAD.invoker().onEndPackReload( new ClientResourceLoaderEventContextsImpl.ReloadEndContext(this.resourceManager, false, error) ); } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/PackScreenMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/PackScreenMixin.java index 210e676bc5..1246ea68e8 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/PackScreenMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/PackScreenMixin.java @@ -24,9 +24,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.pack.PackListWidget; -import net.minecraft.client.gui.screen.pack.PackListWidget.ResourcePackEntry; import net.minecraft.client.gui.screen.pack.PackScreen; +import net.minecraft.client.gui.widget.list.pack.PackEntryListWidget; import net.minecraft.text.Text; import org.quiltmc.loader.api.minecraft.ClientOnly; @@ -36,10 +35,10 @@ @Mixin(PackScreen.class) public abstract class PackScreenMixin extends Screen { @Shadow - private PackListWidget availablePackList; + private PackEntryListWidget availablePackList; @Shadow - private PackListWidget selectedPackList; + private PackEntryListWidget selectedPackList; private PackScreenMixin(Text text) { super(text); @@ -48,14 +47,14 @@ private PackScreenMixin(Text text) { @SuppressWarnings("unchecked") @Inject(method = "render", at = @At("TAIL")) private void renderTooltips(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) { - ResourcePackEntry availableEntry = this.availablePackList.getHoveredEntry(); + PackEntryListWidget.PackEntry availableEntry = this.availablePackList.getHoveredEntry(); if (availableEntry != null) { if (((ResourcePackEntryAccessor) availableEntry).getPack().getSource() instanceof BuiltinResourcePackSource source) { graphics.drawTooltip(this.textRenderer, source.getTooltip(), mouseX, mouseY); } } - ResourcePackEntry selectedEntry = this.selectedPackList.getHoveredEntry(); + PackEntryListWidget.PackEntry selectedEntry = this.selectedPackList.getHoveredEntry(); if (selectedEntry != null) { if (((ResourcePackEntryAccessor) selectedEntry).getPack().getSource() instanceof BuiltinResourcePackSource source) { graphics.drawTooltip(this.textRenderer, source.getTooltip(), mouseX, mouseY); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ReloadableResourceManagerMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ReloadableResourceManagerMixin.java index 4c533c4b96..a85b321e7e 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ReloadableResourceManagerMixin.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ReloadableResourceManagerMixin.java @@ -52,7 +52,7 @@ private void reload(Executor prepareExecutor, Executor applyExecutor, Completabl if (firstReload != null) { try { - ClientResourceLoaderEvents.START_RESOURCE_PACK_RELOAD.invoker().onStartResourcePackReload( + ClientResourceLoaderEvents.START_PACK_RELOAD.invoker().onStartPackReload( new ClientResourceLoaderEventContextsImpl(this, firstReload) ); } finally { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ResourcePackEntryAccessor.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ResourcePackEntryAccessor.java index 8878047d3a..482d9326d7 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ResourcePackEntryAccessor.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/client/ResourcePackEntryAccessor.java @@ -19,13 +19,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import net.minecraft.client.gui.screen.pack.PackListWidget.ResourcePackEntry; import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer; +import net.minecraft.client.gui.widget.list.pack.PackEntryListWidget; import org.quiltmc.loader.api.minecraft.ClientOnly; @ClientOnly -@Mixin(ResourcePackEntry.class) +@Mixin(PackEntryListWidget.PackEntry.class) public interface ResourcePackEntryAccessor { @Accessor ResourcePackOrganizer.Pack getPack(); diff --git a/library/core/resource_loader/src/main/resources/quilt_resource_loader.accesswidener b/library/core/resource_loader/src/main/resources/quilt_resource_loader.accesswidener index e7ec9744a3..4f9d929796 100644 --- a/library/core/resource_loader/src/main/resources/quilt_resource_loader.accesswidener +++ b/library/core/resource_loader/src/main/resources/quilt_resource_loader.accesswidener @@ -4,6 +4,6 @@ accessible class net/minecraft/client/option/GameOptions$Visitor accessible class net/minecraft/resource/NamespaceResourceManager$ResourceEntry accessible class net/minecraft/client/MinecraftClient$C_vfwwgdbg -accessible method net/minecraft/resource/pack/ResourcePackProfile (Ljava/lang/String;ZLnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory;Lnet/minecraft/text/Text;Lnet/minecraft/resource/pack/ResourcePackProfile$Info;Lnet/minecraft/resource/pack/ResourcePackProfile$InsertionPosition;ZLnet/minecraft/resource/pack/ResourcePackSource;)V -accessible method net/minecraft/resource/pack/BuiltinResourcePackProvider wrapToFactory (Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/ResourcePackProfile$ResourcePackFactory; -accessible method net/minecraft/client/gui/widget/EntryListWidget getHoveredEntry ()Lnet/minecraft/client/gui/widget/EntryListWidget$Entry; +accessible method net/minecraft/resource/pack/PackProfile (Ljava/lang/String;ZLnet/minecraft/resource/pack/PackProfile$PackFactory;Lnet/minecraft/text/Text;Lnet/minecraft/resource/pack/PackProfile$Info;Lnet/minecraft/resource/pack/PackProfile$InsertionPosition;ZLnet/minecraft/resource/pack/PackSource;)V +accessible method net/minecraft/resource/pack/BuiltinPackProvider wrapToFactory (Lnet/minecraft/resource/pack/ResourcePack;)Lnet/minecraft/resource/pack/PackProfile$PackFactory; +accessible method net/minecraft/client/gui/widget/list/EntryListWidget getHoveredEntry ()Lnet/minecraft/client/gui/widget/list/EntryListWidget$Entry; diff --git a/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json b/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json index 3675947a99..963db8891c 100644 --- a/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json +++ b/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json @@ -3,14 +3,14 @@ "package": "org.quiltmc.qsl.resource.loader.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "BuiltinResourcePackProviderMixin", + "BuiltinPackProviderMixin", "IdentifierAccessor", "KeyedResourceReloaderMixin", "MinecraftServerMixin", "MultiPackResourceManagerMixin", "ReloadableResourceManagerMixin", - "ResourcePackMixin", - "ResourcePackProfileMixin", + "PackMixin", + "PackProfileMixin", "ServerReloadableResourcesMixin", "TestServerMixin", "VanillaDataPackProviderAccessor", diff --git a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/BuiltinResourcePackTestMod.java b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/BuiltinResourcePackTestMod.java index 77fffae415..4c214f45fe 100644 --- a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/BuiltinResourcePackTestMod.java +++ b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/BuiltinResourcePackTestMod.java @@ -29,13 +29,13 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; -import org.quiltmc.qsl.resource.loader.impl.ModResourcePackUtil; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; +import org.quiltmc.qsl.resource.loader.impl.ModPackUtil; public class BuiltinResourcePackTestMod implements ModInitializer { @Override public void onInitialize(ModContainer mod) { - if (!ResourceLoader.registerBuiltinResourcePack(id("test"), mod, ResourcePackActivationType.DEFAULT_ENABLED, + if (!ResourceLoader.registerBuiltinPack(id("test"), mod, PackActivationType.DEFAULT_ENABLED, Text.literal("Test built-in resource pack").formatted(Formatting.GOLD))) { throw new RuntimeException("Could not register built-in resource pack."); } @@ -44,7 +44,7 @@ public void onInitialize(ModContainer mod) { } /** - * Tests {@link ModResourcePackUtil#getPackMeta(String, ResourceType)} so it generates a perfectly valid JSON. + * Tests {@link ModPackUtil#getPackMeta(String, ResourceType)} so it generates a perfectly valid JSON. */ private void testPackMetaGenerations() { this.testPackMetaGeneration(null); @@ -56,7 +56,7 @@ private void testPackMetaGenerations() { } private void testPackMetaGeneration(String name) { - String pack = ModResourcePackUtil.getPackMeta(name, ResourceType.CLIENT_RESOURCES); + String pack = ModPackUtil.getPackMeta(name, ResourceType.CLIENT_RESOURCES); JsonObject obj; try { diff --git a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/VirtualResourcePackTestMod.java b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/VirtualResourcePackTestMod.java index 264f9f8a06..0ebfc3edd7 100644 --- a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/VirtualResourcePackTestMod.java +++ b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/VirtualResourcePackTestMod.java @@ -27,8 +27,8 @@ import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; import net.minecraft.resource.ResourceType; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -36,13 +36,13 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.lifecycle.api.event.ServerLifecycleEvents; -import org.quiltmc.qsl.resource.loader.api.InMemoryResourcePack; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; +import org.quiltmc.qsl.resource.loader.api.InMemoryPack; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; -import org.quiltmc.qsl.resource.loader.api.ResourcePackRegistrationContext; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; +import org.quiltmc.qsl.resource.loader.api.PackRegistrationContext; -public class VirtualResourcePackTestMod implements ModInitializer, ResourcePackRegistrationContext.Callback, ServerLifecycleEvents.Ready { +public class VirtualResourcePackTestMod implements ModInitializer, PackRegistrationContext.Callback, ServerLifecycleEvents.Ready { private static final TagKey TEST_TAG = TagKey.of(RegistryKeys.BLOCK, ResourceLoaderTestMod.id("test_virtual_tag")); private static final TagKey TEST_TAG2 = TagKey.of(RegistryKeys.BLOCK, ResourceLoaderTestMod.id("test_stackable_tag")); private static final Identifier TAG_FILE = new Identifier( @@ -54,27 +54,27 @@ public class VirtualResourcePackTestMod implements ModInitializer, ResourcePackR @Override public void onInitialize(ModContainer mod) { - ResourceLoader.get(ResourceType.CLIENT_RESOURCES).getRegisterDefaultResourcePackEvent().register(this); - ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterDefaultResourcePackEvent().register(this); + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).getRegisterDefaultPackEvent().register(this); + ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterDefaultPackEvent().register(this); - ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterDefaultResourcePackEvent() + ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterDefaultPackEvent() .register(this.createBasicTagBasedResourcePack("Virtual Tag Default", Blocks.DIAMOND_BLOCK)); - ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterTopResourcePackEvent() + ResourceLoader.get(ResourceType.SERVER_DATA).getRegisterTopPackEvent() .register(this.createBasicTagBasedResourcePack("Virtual Tag Top", Blocks.MOSS_BLOCK)); ResourceLoader.get(ResourceType.CLIENT_RESOURCES) - .registerResourcePackProfileProvider(profileAdder -> this.providePacks(profileAdder, ResourceType.CLIENT_RESOURCES)); + .registerPackProfileProvider(profileAdder -> this.providePacks(profileAdder, ResourceType.CLIENT_RESOURCES)); ResourceLoader.get(ResourceType.SERVER_DATA) - .registerResourcePackProfileProvider(profileAdder -> this.providePacks(profileAdder, ResourceType.SERVER_DATA)); + .registerPackProfileProvider(profileAdder -> this.providePacks(profileAdder, ResourceType.SERVER_DATA)); ServerLifecycleEvents.READY.register(this); } - private void providePacks(Consumer profileAdder, ResourceType type) { - var pack = new InMemoryResourcePack.Named("activation_test") { + private void providePacks(Consumer profileAdder, ResourceType type) { + var pack = new InMemoryPack.Named("activation_test") { @Override - public @NotNull ResourcePackActivationType getActivationType() { - return ResourcePackActivationType.DEFAULT_ENABLED; + public @NotNull PackActivationType getActivationType() { + return PackActivationType.DEFAULT_ENABLED; } }; @@ -112,13 +112,13 @@ private void providePacks(Consumer profileAdder, ResourceTy } """); - profileAdder.accept(ResourcePackProfile.of("activation_test", Text.literal("Activation Test"), false, - QuiltResourcePackProfile.wrapToFactory(pack), type, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_BUILTIN)); + profileAdder.accept(PackProfile.of("activation_test", Text.literal("Activation Test"), false, + QuiltPackProfile.wrapToFactory(pack), type, PackProfile.InsertionPosition.BOTTOM, PackSource.PACK_SOURCE_BUILTIN)); } @Override - public void onRegisterPack(@NotNull ResourcePackRegistrationContext context) { - var pack = new InMemoryResourcePack.Named("Test Virtual Resource Pack"); + public void onRegisterPack(@NotNull PackRegistrationContext context) { + var pack = new InMemoryPack.Named("Test Virtual Resource Pack"); pack.putText(ResourceType.CLIENT_RESOURCES, new Identifier("models/block/poppy.json"), """ { "parent": "minecraft:block/cube_all", @@ -158,9 +158,9 @@ public void readyServer(MinecraftServer server) { assert Blocks.MOSS_BLOCK.getDefaultState().isIn(TEST_TAG); } - private ResourcePackRegistrationContext.Callback createBasicTagBasedResourcePack(String name, Block block) { + private PackRegistrationContext.Callback createBasicTagBasedResourcePack(String name, Block block) { return context -> { - var pack = new InMemoryResourcePack.Named(name); + var pack = new InMemoryPack.Named(name); pack.putTextAsync(ResourceType.SERVER_DATA, TAG_FILE, file -> """ { "replace": true, diff --git a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientResourceLoaderEventsTestMod.java b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientLoaderEventsTestMod.java similarity index 79% rename from library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientResourceLoaderEventsTestMod.java rename to library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientLoaderEventsTestMod.java index ec7c6e7908..bb83d779b4 100644 --- a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientResourceLoaderEventsTestMod.java +++ b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ClientLoaderEventsTestMod.java @@ -22,13 +22,13 @@ import org.quiltmc.qsl.resource.loader.api.client.ClientResourceLoaderEvents; import org.quiltmc.qsl.resource.loader.test.ResourceLoaderTestMod; -public class ClientResourceLoaderEventsTestMod implements ClientResourceLoaderEvents.StartResourcePackReload, - ClientResourceLoaderEvents.EndResourcePackReload { - private static final Logger LOGGER = LoggerFactory.getLogger(ClientResourceLoaderEventsTestMod.class); +public class ClientLoaderEventsTestMod implements ClientResourceLoaderEvents.StartPackReload, + ClientResourceLoaderEvents.EndPackReload { + private static final Logger LOGGER = LoggerFactory.getLogger(ClientLoaderEventsTestMod.class); private long start; @Override - public void onStartResourcePackReload(ClientResourceLoaderEvents.StartResourcePackReload.Context context) { + public void onStartPackReload(ClientResourceLoaderEvents.StartPackReload.Context context) { LOGGER.info("Preparing for resource pack reload, resource manager: {}. Is it the first time?: {}", context.resourceManager(), context.isFirst()); @@ -37,7 +37,7 @@ public void onStartResourcePackReload(ClientResourceLoaderEvents.StartResourcePa } @Override - public void onEndResourcePackReload(ClientResourceLoaderEvents.EndResourcePackReload.Context context) { + public void onEndPackReload(ClientResourceLoaderEvents.EndPackReload.Context context) { LOGGER.info("Took {}ms to perform resource pack reload.", (System.currentTimeMillis() - this.start)); context.error().ifPresentOrElse( diff --git a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ResourcePackProfileProviderTestMod.java b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ResourcePackProfileProviderTestMod.java index 926706deff..c571469bfe 100644 --- a/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ResourcePackProfileProviderTestMod.java +++ b/library/core/resource_loader/src/testmod/java/org/quiltmc/qsl/resource/loader/test/client/ResourcePackProfileProviderTestMod.java @@ -24,16 +24,16 @@ import net.minecraft.SharedConstants; import net.minecraft.resource.ResourceType; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; -import org.quiltmc.qsl.resource.loader.api.InMemoryResourcePack; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; +import org.quiltmc.qsl.resource.loader.api.InMemoryPack; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; public class ResourcePackProfileProviderTestMod implements ClientModInitializer { @@ -41,12 +41,12 @@ public class ResourcePackProfileProviderTestMod implements ClientModInitializer @Override public void onInitializeClient(ModContainer mod) { - ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerResourcePackProfileProvider((profileAdder) -> { + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerPackProfileProvider((profileAdder) -> { var pack = new TestPack(); - profileAdder.accept(ResourcePackProfile.of( - PACK_NAME, pack.getDisplayName(), false, QuiltResourcePackProfile.wrapToFactory(pack), ResourceType.CLIENT_RESOURCES, - ResourcePackProfile.InsertionPosition.TOP, - new ResourcePackSource() { + profileAdder.accept(PackProfile.of( + PACK_NAME, pack.getDisplayName(), false, QuiltPackProfile.wrapToFactory(pack), ResourceType.CLIENT_RESOURCES, + PackProfile.InsertionPosition.TOP, + new PackSource() { @Override public Text decorate(Text name) { return name.copy().append(Text.literal(" (Virtual Provider)").formatted(Formatting.DARK_GRAY)); @@ -60,7 +60,7 @@ public boolean shouldAddAutomatically() { }); } - static class TestPack extends InMemoryResourcePack { + static class TestPack extends InMemoryPack { private static final Identifier DIRT_IDENTIFIER = new Identifier("textures/block/dirt.png"); private final Random random = new Random(); diff --git a/library/core/testing/src/main/java/org/quiltmc/qsl/testing/impl/game/QuiltGameTestImpl.java b/library/core/testing/src/main/java/org/quiltmc/qsl/testing/impl/game/QuiltGameTestImpl.java index d54120c058..9a32c4f5e2 100644 --- a/library/core/testing/src/main/java/org/quiltmc/qsl/testing/impl/game/QuiltGameTestImpl.java +++ b/library/core/testing/src/main/java/org/quiltmc/qsl/testing/impl/game/QuiltGameTestImpl.java @@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; -import net.minecraft.resource.pack.ResourcePackManager; +import net.minecraft.resource.pack.PackManager; import net.minecraft.test.GameTest; import net.minecraft.test.GameTestBatch; import net.minecraft.test.StructureTestUtil; @@ -72,7 +72,7 @@ public final class QuiltGameTestImpl implements ModInitializer { * @param storageSession the storage session * @param resourcePackManager the resource pack manager */ - public static void runHeadlessServer(WorldSaveStorage.Session storageSession, ResourcePackManager resourcePackManager) { + public static void runHeadlessServer(WorldSaveStorage.Session storageSession, PackManager resourcePackManager) { LOGGER.info("Starting test server..."); LOGGER.info("By starting a Minecraft server you agree to its EULA."); diff --git a/library/core/testing/src/main/java/org/quiltmc/qsl/testing/mixin/server/MainMixin.java b/library/core/testing/src/main/java/org/quiltmc/qsl/testing/mixin/server/MainMixin.java index ef7353cdac..710629bcaf 100644 --- a/library/core/testing/src/main/java/org/quiltmc/qsl/testing/mixin/server/MainMixin.java +++ b/library/core/testing/src/main/java/org/quiltmc/qsl/testing/mixin/server/MainMixin.java @@ -30,7 +30,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import net.minecraft.resource.pack.ResourcePackManager; +import net.minecraft.resource.pack.PackManager; import net.minecraft.server.Main; import net.minecraft.server.Services; import net.minecraft.server.dedicated.EulaReader; @@ -53,7 +53,7 @@ private static boolean isEulaAgreedTo(EulaReader reader) { method = "main", at = @At( value = "INVOKE", - target = "Lnet/minecraft/resource/pack/VanillaDataPackProvider;createDataPackManager(Lnet/minecraft/world/storage/WorldSaveStorage$Session;)Lnet/minecraft/resource/pack/ResourcePackManager;", + target = "Lnet/minecraft/resource/pack/VanillaDataPackProvider;createPackManager(Lnet/minecraft/world/storage/WorldSaveStorage$Session;)Lnet/minecraft/resource/pack/PackManager;", shift = At.Shift.BY, by = 2, remap = true @@ -69,7 +69,7 @@ private static void onStart(String[] strings, CallbackInfo ci, OptionSpec optionSpec11, OptionSpec optionSpec12, OptionSpec optionSpec13, OptionSpec optionSpec14, OptionSpec optionSpec15, OptionSet optionSet, Path path, Path path2, ServerPropertiesLoader serverPropertiesLoader, Path path3, EulaReader eulaReader, File file, Services services, String string, WorldSaveStorage worldSaveStorage, - WorldSaveStorage.Session session, WorldSaveSummary worldSaveSummary, boolean bl, ResourcePackManager resourcePackManager) { + WorldSaveStorage.Session session, WorldSaveSummary worldSaveSummary, boolean bl, PackManager resourcePackManager) { if (QuiltGameTestImpl.ENABLED) { QuiltGameTestImpl.runHeadlessServer(session, resourcePackManager); ci.cancel(); // Do not progress in starting the normal dedicated server. diff --git a/library/core/testing/src/testmod/java/org/quiltmc/qsl/testing/test/ExampleTestSuite.java b/library/core/testing/src/testmod/java/org/quiltmc/qsl/testing/test/ExampleTestSuite.java index d9b332aa4f..b37402077f 100644 --- a/library/core/testing/src/testmod/java/org/quiltmc/qsl/testing/test/ExampleTestSuite.java +++ b/library/core/testing/src/testmod/java/org/quiltmc/qsl/testing/test/ExampleTestSuite.java @@ -33,9 +33,9 @@ public void noStructure(QuiltTestContext context) { context.succeedWhen(() -> context.checkBlock( - new BlockPos(0, 2, 0), - (block) -> block == Blocks.DIAMOND_BLOCK, - "Expected block to be diamond" + new BlockPos(0, 2, 0), + (block) -> block == Blocks.DIAMOND_BLOCK, + "Expected block to be diamond" ) ); } diff --git a/library/data/advancement/src/main/java/org/quiltmc/qsl/advancement/mixin/CriteriaAccessor.java b/library/data/advancement/src/main/java/org/quiltmc/qsl/advancement/mixin/CriteriaAccessor.java index 2904d2d056..054846c8ef 100644 --- a/library/data/advancement/src/main/java/org/quiltmc/qsl/advancement/mixin/CriteriaAccessor.java +++ b/library/data/advancement/src/main/java/org/quiltmc/qsl/advancement/mixin/CriteriaAccessor.java @@ -16,7 +16,6 @@ package org.quiltmc.qsl.advancement.mixin; - import com.google.common.collect.BiMap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/library/data/registry_entry_attachment/src/testmod/java/org/quiltmc/qsl/registry/attachment/test/mixin/client/DebugHudMixin.java b/library/data/registry_entry_attachment/src/testmod/java/org/quiltmc/qsl/registry/attachment/test/mixin/client/DebugHudMixin.java index 178472a6ab..11d8a91abe 100644 --- a/library/data/registry_entry_attachment/src/testmod/java/org/quiltmc/qsl/registry/attachment/test/mixin/client/DebugHudMixin.java +++ b/library/data/registry_entry_attachment/src/testmod/java/org/quiltmc/qsl/registry/attachment/test/mixin/client/DebugHudMixin.java @@ -25,7 +25,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import net.minecraft.block.BlockState; -import net.minecraft.client.gui.hud.DebugHud; +import net.minecraft.client.gui.hud.debug.DebugHud; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; diff --git a/library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/client/ClientDefaultTagManagerReloader.java b/library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/client/ClientDefaultTagManagerReloader.java index e4893d4d2b..9c465a1a7d 100644 --- a/library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/client/ClientDefaultTagManagerReloader.java +++ b/library/data/tags/src/main/java/org/quiltmc/qsl/tag/impl/client/ClientDefaultTagManagerReloader.java @@ -28,16 +28,16 @@ import net.minecraft.resource.MultiPackResourceManager; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceType; -import net.minecraft.resource.pack.DefaultResourcePack; -import net.minecraft.resource.pack.ResourcePackManager; -import net.minecraft.resource.pack.ResourcePackProfile; -import net.minecraft.resource.pack.ResourcePackSource; +import net.minecraft.resource.pack.DefaultPack; +import net.minecraft.resource.pack.PackManager; +import net.minecraft.resource.pack.PackProfile; +import net.minecraft.resource.pack.PackSource; import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; import org.quiltmc.loader.api.minecraft.ClientOnly; -import org.quiltmc.qsl.resource.loader.api.QuiltResourcePackProfile; -import org.quiltmc.qsl.resource.loader.impl.ModResourcePackProvider; +import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; +import org.quiltmc.qsl.resource.loader.impl.ModPackProvider; import org.quiltmc.qsl.resource.loader.impl.QuiltMultiPackResourceManagerHooks; import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderImpl; @@ -45,17 +45,17 @@ @ApiStatus.Internal final class ClientDefaultTagManagerReloader extends ClientOnlyTagManagerReloader { private static final Identifier ID = new Identifier(ClientQuiltTagsMod.NAMESPACE, "client_default_tags"); - private final ResourcePackManager resourcePackManager; + private final PackManager resourcePackManager; ClientDefaultTagManagerReloader() { - DefaultResourcePack defaultPack = MinecraftClient.getInstance().getDefaultResourcePack(); + DefaultPack defaultPack = MinecraftClient.getInstance().getDefaultResourcePack(); - var pack = ResourceLoaderImpl.buildMinecraftResourcePack(ResourceType.SERVER_DATA, defaultPack); - this.resourcePackManager = new ResourcePackManager((profileAdder) -> { - profileAdder.accept(ResourcePackProfile.of("vanilla", pack.getDisplayName(), true, QuiltResourcePackProfile.wrapToFactory(pack), - ResourceType.SERVER_DATA, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_BUILTIN + var pack = ResourceLoaderImpl.buildMinecraftPack(ResourceType.SERVER_DATA, defaultPack); + this.resourcePackManager = new PackManager((profileAdder) -> { + profileAdder.accept(PackProfile.of("vanilla", pack.getDisplayName(), true, QuiltPackProfile.wrapToFactory(pack), + ResourceType.SERVER_DATA, PackProfile.InsertionPosition.BOTTOM, PackSource.PACK_SOURCE_BUILTIN )); - }, ModResourcePackProvider.SERVER_RESOURCE_PACK_PROVIDER); + }, ModPackProvider.SERVER_RESOURCE_PACK_PROVIDER); } @Override diff --git a/library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java b/library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java index 1202bb2406..d3eea118af 100644 --- a/library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java +++ b/library/data/tags/src/testmod/java/org/quiltmc/qsl/tag/test/client/ClientTagsTestMod.java @@ -33,7 +33,7 @@ import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; import org.quiltmc.qsl.command.api.client.ClientCommandRegistrationCallback; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; import org.quiltmc.qsl.tag.api.QuiltTagKey; import org.quiltmc.qsl.tag.api.TagType; import org.quiltmc.qsl.tag.test.TagsTestMod; @@ -48,7 +48,7 @@ public final class ClientTagsTestMod implements ClientModInitializer { @Override public void onInitializeClient(ModContainer mod) { - ResourceLoader.registerBuiltinResourcePack(TagsTestMod.id("defaulted_test_pack"), ResourcePackActivationType.NORMAL); + ResourceLoader.registerBuiltinPack(TagsTestMod.id("defaulted_test_pack"), PackActivationType.NORMAL); ClientCommandRegistrationCallback.EVENT.register((dispatcher, buildContext, environment) -> { dispatcher.register(literal("client_tag_test") diff --git a/library/entity/entity_extensions/src/main/resources/quilt_entity_extensions.mixins.json b/library/entity/entity_extensions/src/main/resources/quilt_entity_extensions.mixins.json index efa5fde106..933216ceb0 100644 --- a/library/entity/entity_extensions/src/main/resources/quilt_entity_extensions.mixins.json +++ b/library/entity/entity_extensions/src/main/resources/quilt_entity_extensions.mixins.json @@ -10,7 +10,7 @@ "PointOfInterestTypesAccessor", "TypeAwareBuyForOneEmeraldFactoryMixin", "networking.EntityMixin", - "networking.TrackedDataHandlerRegistryMixin", + "networking.TrackedDataHandlerRegistryMixin" ], "injectors": { "defaultRequire": 1 diff --git a/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/api/StatusEffectUtils.java b/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/api/StatusEffectUtils.java index e70992c4a0..18215a4cb9 100644 --- a/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/api/StatusEffectUtils.java +++ b/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/api/StatusEffectUtils.java @@ -21,8 +21,10 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffectType; import org.quiltmc.qsl.base.api.util.TriState; +import org.quiltmc.qsl.entity.effect.mixin.StatusEffectAccessor; /** * Utilities for dealing with status effects. @@ -50,4 +52,15 @@ public static boolean shouldRemove(@NotNull LivingEntity entity, @NotNull Status return eventResult.toBooleanOrElse(false); } } + + /** + * Creates a new status effect by calling {@link StatusEffect#StatusEffect(StatusEffectType, int)}. + * + * @param type the type for the effect + * @param color the color for the effect + * @return the new effect + */ + public static StatusEffect createEffect(StatusEffectType type, int color) { + return StatusEffectAccessor.invokeNew(type, color); + } } diff --git a/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/mixin/StatusEffectAccessor.java b/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/mixin/StatusEffectAccessor.java new file mode 100644 index 0000000000..10ad5f9602 --- /dev/null +++ b/library/entity/status_effect/src/main/java/org/quiltmc/qsl/entity/effect/mixin/StatusEffectAccessor.java @@ -0,0 +1,31 @@ +/* + * Copyright 2024 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.entity.effect.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectType; + +@Mixin(StatusEffect.class) +public interface StatusEffectAccessor { + @Invoker("") + static StatusEffect invokeNew(StatusEffectType type, int color) { + throw new UnsupportedOperationException("Mixin not applied"); + } +} diff --git a/library/entity/status_effect/src/main/resources/quilt_status_effect.mixins.json b/library/entity/status_effect/src/main/resources/quilt_status_effect.mixins.json index 5da95f5464..3f1eebfc04 100644 --- a/library/entity/status_effect/src/main/resources/quilt_status_effect.mixins.json +++ b/library/entity/status_effect/src/main/resources/quilt_status_effect.mixins.json @@ -6,6 +6,7 @@ "EffectCommandMixin", "LivingEntityMixin", "MilkBucketItemMixin", + "StatusEffectAccessor", "StatusEffectMixin" ], "injectors": { diff --git a/library/gui/screen/src/testmod/java/org/quiltmc/qsl/screen/test/client/ScreenTests.java b/library/gui/screen/src/testmod/java/org/quiltmc/qsl/screen/test/client/ScreenTests.java index 51219ddaef..51e06cb49b 100644 --- a/library/gui/screen/src/testmod/java/org/quiltmc/qsl/screen/test/client/ScreenTests.java +++ b/library/gui/screen/src/testmod/java/org/quiltmc/qsl/screen/test/client/ScreenTests.java @@ -26,8 +26,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ClickableWidget; +import net.minecraft.client.gui.widget.button.ButtonWidget; import net.minecraft.text.Text; import net.minecraft.util.Identifier; diff --git a/library/worldgen/biome/src/testmod/java/org/quiltmc/qsl/worldgen/biome/QuiltBiomeTest.java b/library/worldgen/biome/src/testmod/java/org/quiltmc/qsl/worldgen/biome/QuiltBiomeTest.java index 54b3254fd8..c93c157ed4 100644 --- a/library/worldgen/biome/src/testmod/java/org/quiltmc/qsl/worldgen/biome/QuiltBiomeTest.java +++ b/library/worldgen/biome/src/testmod/java/org/quiltmc/qsl/worldgen/biome/QuiltBiomeTest.java @@ -61,7 +61,7 @@ import org.quiltmc.qsl.registry.api.event.DynamicRegistryManagerSetupContext; import org.quiltmc.qsl.registry.api.event.RegistryEvents; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.ResourcePackActivationType; +import org.quiltmc.qsl.resource.loader.api.PackActivationType; import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectors; import org.quiltmc.qsl.worldgen.biome.api.ModificationPhase; @@ -94,7 +94,7 @@ public class QuiltBiomeTest implements ModInitializer { @Override public void onInitialize(ModContainer mod) { - ResourceLoader.registerBuiltinResourcePack(id("registry_entry_existence_test"), mod, ResourcePackActivationType.NORMAL); + ResourceLoader.registerBuiltinPack(id("registry_entry_existence_test"), mod, PackActivationType.NORMAL); Preconditions.checkArgument(NetherBiomes.canGenerateInNether(Biomes.NETHER_WASTES)); Preconditions.checkArgument(!NetherBiomes.canGenerateInNether(Biomes.END_HIGHLANDS));