From 7df0d6776f5137fe7991943c1397f2934ccaf830 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sun, 21 Jul 2024 02:16:55 -0700 Subject: [PATCH] Fix a license and clean up some other code --- .../impl/BuiltinResourcePackSource.java | 58 ------------------- .../qsl/resource/loader/impl/ModNioPack.java | 2 +- .../loader/impl/QuiltBuiltinPackProfile.java | 13 +++-- .../impl/client/PackScreenTooltips.java | 22 ++++++- 4 files changed, 27 insertions(+), 68 deletions(-) delete mode 100644 library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java 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 deleted file mode 100644 index ef34fee218..0000000000 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/BuiltinResourcePackSource.java +++ /dev/null @@ -1,58 +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.resource.loader.impl; - -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 PackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too. - */ -public class BuiltinResourcePackSource implements PackSource { - private static final Text SOURCE_BUILTIN_TEXT = Text.translatable("pack.source.builtin"); - private final ModNioPack pack; - private final Text text; - private final Text tooltip; - - BuiltinResourcePackSource(ModNioPack pack) { - String modName = pack.modInfo.name(); - - if (modName == null) { - modName = pack.modInfo.id(); - } - - this.pack = pack; - this.text = SOURCE_BUILTIN_TEXT; - this.tooltip = Text.translatable("options.generic_value", SOURCE_BUILTIN_TEXT, modName); - } - - @Override - public Text decorate(Text description) { - return Text.translatable("pack.nameAndSource", description, this.text).formatted(Formatting.GRAY); - } - - @Override - public boolean shouldAddAutomatically() { - return this.pack.getActivationType().isEnabledByDefault(); - } - - public Text getTooltip() { - return this.tooltip; - } -} diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java index b8e9959479..cd249fd309 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ModNioPack.java @@ -86,7 +86,7 @@ public ModNioPack(@Nullable String name, ModMetadata modInfo, @Nullable Text dis super(new PackLocationInfo( name, displayName, - PackSource.PACK_SOURCE_BUILTIN, + new QuiltBuiltinPackProfile.BuiltinPackSource(modInfo, activationType), Optional.empty() )); diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java index 26a80a45d0..720087c2cd 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/QuiltBuiltinPackProfile.java @@ -31,6 +31,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import org.quiltmc.loader.api.ModMetadata; import org.quiltmc.qsl.resource.loader.api.QuiltPackProfile; import org.quiltmc.qsl.resource.loader.api.PackActivationType; @@ -82,20 +83,20 @@ public PackCompatibility getCompatibility() { */ public static class BuiltinPackSource implements PackSource { private static final Text SOURCE_BUILTIN_TEXT = Text.translatable("pack.source.builtin"); - private final ModNioPack pack; private final Text text; private final Text tooltip; + private final PackActivationType activationType; - BuiltinPackSource(ModNioPack pack) { - String modName = pack.modInfo.name(); + BuiltinPackSource(ModMetadata modInfo, PackActivationType activationType) { + String modName = modInfo.name(); if (modName == null) { - modName = pack.modInfo.id(); + modName = modInfo.id(); } - this.pack = pack; this.text = SOURCE_BUILTIN_TEXT; this.tooltip = Text.translatable("options.generic_value", SOURCE_BUILTIN_TEXT, modName); + this.activationType = activationType; } @Override @@ -105,7 +106,7 @@ public Text decorate(Text description) { @Override public boolean shouldAddAutomatically() { - return this.pack.getActivationType().isEnabledByDefault(); + return this.activationType.isEnabledByDefault(); } public Text getTooltip() { diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/PackScreenTooltips.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/PackScreenTooltips.java index b4d2cbd065..2968e7e849 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/PackScreenTooltips.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/client/PackScreenTooltips.java @@ -1,3 +1,19 @@ +/* + * 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.resource.loader.impl.client; import net.minecraft.client.gui.GuiGraphics; @@ -5,7 +21,7 @@ import net.minecraft.client.gui.screen.pack.PackScreen; import net.minecraft.client.gui.widget.list.pack.PackEntryListWidget; -import org.quiltmc.qsl.resource.loader.impl.BuiltinResourcePackSource; +import org.quiltmc.qsl.resource.loader.impl.QuiltBuiltinPackProfile; import org.quiltmc.qsl.resource.loader.mixin.client.PackScreenAccessor; import org.quiltmc.qsl.resource.loader.mixin.client.ResourcePackEntryAccessor; import org.quiltmc.qsl.screen.api.client.QuiltScreen; @@ -17,14 +33,14 @@ public void afterRender(Screen screen, GuiGraphics graphics, int mouseX, int mou if (screen instanceof PackScreen packScreen) { PackEntryListWidget.PackEntry availableEntry = ((PackScreenAccessor) packScreen).getAvailablePackList().getHoveredEntry(); if (availableEntry != null) { - if (((ResourcePackEntryAccessor) availableEntry).getPack().getSource() instanceof BuiltinResourcePackSource source) { + if (((ResourcePackEntryAccessor) availableEntry).getPack().getSource() instanceof QuiltBuiltinPackProfile.BuiltinPackSource source) { graphics.drawTooltip(((QuiltScreen) packScreen).getTextRenderer(), source.getTooltip(), mouseX, mouseY); } } PackEntryListWidget.PackEntry selectedEntry = ((PackScreenAccessor) packScreen).getSelectedPackList().getHoveredEntry(); if (selectedEntry != null) { - if (((ResourcePackEntryAccessor) selectedEntry).getPack().getSource() instanceof BuiltinResourcePackSource source) { + if (((ResourcePackEntryAccessor) selectedEntry).getPack().getSource() instanceof QuiltBuiltinPackProfile.BuiltinPackSource source) { graphics.drawTooltip(((QuiltScreen) packScreen).getTextRenderer(), source.getTooltip(), mouseX, mouseY); } }