diff --git a/build.gradle b/build.gradle index 87bce8e..81bc27c 100644 --- a/build.gradle +++ b/build.gradle @@ -48,9 +48,8 @@ dependencies { }) modImplementation libs.quilt.loader - // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. - // Quilted Fabric API will automatically pull in the correct QSL version. - modImplementation libs.quilted.fabric.api + // Ughhhhhhhhhhh + modImplementation libs.fabric.api afterEvaluate { testmodImplementation sourceSets.main.output @@ -70,22 +69,17 @@ loom { processResources { inputs.property 'version', version - filesMatching('quilt.mod.json') { + filesMatching(['fabric.mod.json', 'quilt.mod.json']) { expand 'version': version } } tasks.withType(JavaCompile).configureEach { - it.options.encoding = 'UTF-8' - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release.set(17) + // Minecraft 1.20.6 (24w14a) upwards uses Java 21. + it.options.release.set(21) } java { - // Still required by IDEs such as Eclipse and Visual Studio Code - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task if it is present. // If you remove this line, sources will not be generated. withSourcesJar() diff --git a/gradle.properties b/gradle.properties index 43a3eb2..05d9abf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx1G org.gradle.parallel = true # Mod Properties -version = 0.8.1 +version = 0.9.0 maven_group = io.github.ennuil archives_base_name = libzoomer diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1846b5e..fb34c04 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,18 +1,18 @@ [versions] -minecraft = "1.20.1" -parchment = "2023.09.03" +minecraft = "1.20.6" +parchment = "2024.05.01" quilt_loom = "1.6.7" quilt_loader = "0.25.0" -quilted_fabric_api = "7.5.0+0.91.0-1.20.1" +fabric_api = "0.99.0+1.20.6" [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } -parchment = { module = "org.parchmentmc.data:parchment-1.20.1", version.ref = "parchment" } +parchment = { module = "org.parchmentmc.data:parchment-1.20.6", version.ref = "parchment" } quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" } -quilted_fabric_api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "quilted_fabric_api" } +fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric_api" } # If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". [bundles] diff --git a/src/main/java/io/github/ennuil/libzoomer/api/overlays/SpyglassZoomOverlay.java b/src/main/java/io/github/ennuil/libzoomer/api/overlays/SpyglassZoomOverlay.java index 122256a..21f9c69 100644 --- a/src/main/java/io/github/ennuil/libzoomer/api/overlays/SpyglassZoomOverlay.java +++ b/src/main/java/io/github/ennuil/libzoomer/api/overlays/SpyglassZoomOverlay.java @@ -1,5 +1,6 @@ package io.github.ennuil.libzoomer.api.overlays; +import com.mojang.blaze3d.systems.RenderSystem; import io.github.ennuil.libzoomer.api.ZoomOverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; @@ -57,7 +58,9 @@ public void renderOverlay(GuiGraphics graphics) { int y = (guiHeight - height) / 2; int borderX = x + width; int borderY = y + height; + RenderSystem.enableBlend(); graphics.blit(textureId, x, y, -90, 0.0F, 0.0F, width, height, width, height); + RenderSystem.disableBlend(); graphics.fill(RenderType.guiOverlay(), 0, borderY, guiWidth, guiHeight, -90, CommonColors.BLACK); graphics.fill(RenderType.guiOverlay(), 0, 0, guiWidth, y, -90, CommonColors.BLACK); graphics.fill(RenderType.guiOverlay(), 0, y, x, borderY, -90, CommonColors.BLACK); diff --git a/src/main/java/io/github/ennuil/libzoomer/impl/SpyglassHelper.java b/src/main/java/io/github/ennuil/libzoomer/impl/SpyglassHelper.java index d4f8c02..eaf480b 100644 --- a/src/main/java/io/github/ennuil/libzoomer/impl/SpyglassHelper.java +++ b/src/main/java/io/github/ennuil/libzoomer/impl/SpyglassHelper.java @@ -4,8 +4,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; -import org.quiltmc.qsl.tag.api.QuiltTagKey; -import org.quiltmc.qsl.tag.api.TagType; /** * An utility class whose sole purpose is to hold the spyglass tag. @@ -14,7 +12,7 @@ public class SpyglassHelper { /** * The spyglass tag, which is used internally in order to unhardcode behavior specific to vanilla spyglasses. */ - public static final TagKey SPYGLASSES = QuiltTagKey.of( - Registries.ITEM, new ResourceLocation("libzoomer", "spyglasses"), TagType.CLIENT_FALLBACK + public static final TagKey SPYGLASSES = TagKey.create( + Registries.ITEM, new ResourceLocation("libzoomer", "spyglasses") ); } diff --git a/src/main/java/io/github/ennuil/libzoomer/mixin/GuiMixin.java b/src/main/java/io/github/ennuil/libzoomer/mixin/GuiMixin.java index 0db63c1..fd003a1 100644 --- a/src/main/java/io/github/ennuil/libzoomer/mixin/GuiMixin.java +++ b/src/main/java/io/github/ennuil/libzoomer/mixin/GuiMixin.java @@ -15,7 +15,7 @@ @Mixin(Gui.class) public class GuiMixin { @Inject( - method = "render(Lnet/minecraft/client/gui/GuiGraphics;F)V", + method = "renderCameraOverlays", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getDeltaFrameTime()F" @@ -36,7 +36,7 @@ private void injectZoomOverlay(GuiGraphics graphics, float tickDelta, CallbackIn } // Cancel the cancellable overlays - @ModifyExpressionValue(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/CameraType;isFirstPerson()Z")) + @ModifyExpressionValue(method = "renderCameraOverlays", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/CameraType;isFirstPerson()Z")) private boolean cancelOverlay(boolean original, @Share("cancelOverlay") LocalBooleanRef cancelOverlay) { return original && !cancelOverlay.get(); } diff --git a/src/main/java/io/github/ennuil/libzoomer/mixin/ItemPropertiesMixin.java b/src/main/java/io/github/ennuil/libzoomer/mixin/ItemPropertiesMixin.java index 6a0cedc..9a6f063 100644 --- a/src/main/java/io/github/ennuil/libzoomer/mixin/ItemPropertiesMixin.java +++ b/src/main/java/io/github/ennuil/libzoomer/mixin/ItemPropertiesMixin.java @@ -1,6 +1,7 @@ package io.github.ennuil.libzoomer.mixin; import io.github.ennuil.libzoomer.impl.SpyglassHelper; +import net.fabricmc.fabric.api.tag.client.v1.ClientTags; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; @@ -16,7 +17,7 @@ private static void addScopingPredicateToModdedSpyglasses(CallbackInfo ci) { entity != null && entity.isUsingItem() && entity.getUseItem() == stack - && entity.getUseItem().is(SpyglassHelper.SPYGLASSES) + && ClientTags.isInWithLocalFallback(SpyglassHelper.SPYGLASSES, entity.getUseItem().getItem()) ? 1.0F : 0.0F ); diff --git a/src/main/java/io/github/ennuil/libzoomer/mixin/MouseMixin.java b/src/main/java/io/github/ennuil/libzoomer/mixin/MouseHandlerMixin.java similarity index 70% rename from src/main/java/io/github/ennuil/libzoomer/mixin/MouseMixin.java rename to src/main/java/io/github/ennuil/libzoomer/mixin/MouseHandlerMixin.java index be44920..5a5d91b 100644 --- a/src/main/java/io/github/ennuil/libzoomer/mixin/MouseMixin.java +++ b/src/main/java/io/github/ennuil/libzoomer/mixin/MouseHandlerMixin.java @@ -12,7 +12,7 @@ import io.github.ennuil.libzoomer.api.ZoomRegistry; @Mixin(MouseHandler.class) -public abstract class MouseMixin { +public abstract class MouseHandlerMixin { @Inject( method = "turnPlayer", at = @At( @@ -20,14 +20,14 @@ public abstract class MouseMixin { target = "Lnet/minecraft/client/Options;invertYMouse()Lnet/minecraft/client/OptionInstance;" ) ) - public void applyZoomChanges(CallbackInfo ci, @Local(ordinal = 1) double e, @Local(ordinal = 2) LocalDoubleRef k, @Local(ordinal = 3) LocalDoubleRef l, @Local(ordinal = 6) double h) { + public void applyZoomChanges(double movementTime, CallbackInfo ci, @Local(ordinal = 1) LocalDoubleRef i, @Local(ordinal = 2) LocalDoubleRef j, @Local(ordinal = 5) double f) { if (ZoomRegistry.shouldIterateModifiers()) { for (ZoomInstance instance : ZoomRegistry.getZoomInstances()) { if (instance.isModifierActive()) { double zoomDivisor = instance.getZoom() ? instance.getZoomDivisor() : 1.0; double transitionDivisor = instance.getTransitionMode().getInternalMultiplier(); - k.set(instance.getMouseModifier().applyXModifier(k.get(), h, e, zoomDivisor, transitionDivisor)); - l.set(instance.getMouseModifier().applyYModifier(l.get(), h, e, zoomDivisor, transitionDivisor)); + i.set(instance.getMouseModifier().applyXModifier(i.get(), f, movementTime, zoomDivisor, transitionDivisor)); + j.set(instance.getMouseModifier().applyYModifier(j.get(), f, movementTime, zoomDivisor, transitionDivisor)); } } } diff --git a/src/main/java/io/github/ennuil/libzoomer/mixin/PlayerHeldItemFeatureRendererMixin.java b/src/main/java/io/github/ennuil/libzoomer/mixin/PlayerItemInHandMixin.java similarity index 84% rename from src/main/java/io/github/ennuil/libzoomer/mixin/PlayerHeldItemFeatureRendererMixin.java rename to src/main/java/io/github/ennuil/libzoomer/mixin/PlayerItemInHandMixin.java index 638e888..ab52383 100644 --- a/src/main/java/io/github/ennuil/libzoomer/mixin/PlayerHeldItemFeatureRendererMixin.java +++ b/src/main/java/io/github/ennuil/libzoomer/mixin/PlayerItemInHandMixin.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import io.github.ennuil.libzoomer.impl.SpyglassHelper; +import net.fabricmc.fabric.api.tag.client.v1.ClientTags; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer; import net.minecraft.world.entity.HumanoidArm; @@ -15,10 +16,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(PlayerItemInHandLayer.class) -public abstract class PlayerHeldItemFeatureRendererMixin { +public abstract class PlayerItemInHandMixin { @Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true) private void renderCustomSpyglassesAsSpyglass(LivingEntity entity, ItemStack stack, ItemDisplayContext displayContext, HumanoidArm arm, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) { - if (stack.is(SpyglassHelper.SPYGLASSES) && entity.getUseItem() == stack && entity.swingTime == 0) { + if (ClientTags.isInWithLocalFallback(SpyglassHelper.SPYGLASSES, stack.getItem()) && entity.getUseItem() == stack && entity.swingTime == 0) { this.renderArmWithSpyglass(entity, stack, arm, poseStack, buffer, packedLight); ci.cancel(); } diff --git a/src/main/resources/assets/libzoomer/lang/en_us.json b/src/main/resources/assets/libzoomer/lang/en_us.json new file mode 100644 index 0000000..9b18106 --- /dev/null +++ b/src/main/resources/assets/libzoomer/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "tag.item.libzoomer.spyglasses": "Spyglasses" +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..302f926 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,29 @@ +{ + "schemaVersion": 1, + "id": "libzoomer", + "version": "${version}", + "name": "LibZoomer", + "description": "A library that allows for easy and powerful zooming.", + "authors": [ + "Ennui Langeweile" + ], + "contact": { + "homepage": "https://modrinth.com/mod/libzoomer", + "issues": "https://github.com/Up-Mods/LibZoomer/issues", + "sources": "https://github.com/Up-Mods/LibZoomer" + }, + "license": "MIT", + "icon": "assets/libzoomer/icon.png", + "environment": "client", + "mixins": ["libzoomer.mixins.json"], + "depends": { + "fabricloader": ">=0.15.10", + "minecraft": ">=1.20.5", + "fabric-api": ">=0.99.0" + }, + "custom": { + "modmenu": { + "badges": ["library"] + } + } +} diff --git a/src/main/resources/libzoomer.mixins.json b/src/main/resources/libzoomer.mixins.json index c0e1855..8b194aa 100644 --- a/src/main/resources/libzoomer.mixins.json +++ b/src/main/resources/libzoomer.mixins.json @@ -6,8 +6,8 @@ "GameRendererMixin", "GuiMixin", "ItemPropertiesMixin", - "MouseMixin", - "PlayerHeldItemFeatureRendererMixin" + "MouseHandlerMixin", + "PlayerItemInHandMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json index 68e7598..a85e8ed 100644 --- a/src/main/resources/quilt.mod.json +++ b/src/main/resources/quilt.mod.json @@ -8,12 +8,13 @@ "name": "LibZoomer", "description": "A library that allows for easy and powerful zooming.", "contributors": { - "Ennui Langeweile": "Owner" + "Ennui Langeweile": "Owner", + "Up": "Developer" }, "contact": { "homepage": "https://modrinth.com/mod/libzoomer", - "issues": "https://github.com/EnnuiL/LibZoomer/issues", - "sources": "https://github.com/EnnuiL/LibZoomer" + "issues": "https://github.com/Up-Mods/LibZoomer/issues", + "sources": "https://github.com/Up-Mods/LibZoomer" }, "license": "MIT", "icon": "assets/libzoomer/icon.png" @@ -22,19 +23,15 @@ "depends": [ { "id": "quilt_loader", - "versions": ">=0.22.0-" + "versions": ">=0.25.0" }, { - "id": "quilted_fabric_api", - "versions": ">=7.0.0-" + "id": "fabric-api", + "versions": ">=0.99.0" }, { "id": "minecraft", "versions": ">=1.20" - }, - { - "id": "mixinextras", - "versions": ">=0.3.0" } ] }, diff --git a/src/testmod/java/io/github/ennuil/libzoomer_test/LibZoomerTestMod.java b/src/testmod/java/io/github/ennuil/libzoomer_test/LibZoomerTestMod.java index aae21e2..3846340 100644 --- a/src/testmod/java/io/github/ennuil/libzoomer_test/LibZoomerTestMod.java +++ b/src/testmod/java/io/github/ennuil/libzoomer_test/LibZoomerTestMod.java @@ -7,22 +7,19 @@ import io.github.ennuil.libzoomer.api.overlays.SpyglassZoomOverlay; import io.github.ennuil.libzoomer.api.transitions.InstantTransitionMode; import io.github.ennuil.libzoomer.api.transitions.SmoothTransitionMode; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.KeyMapping; -import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.SpyglassItem; import org.lwjgl.glfw.GLFW; -import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; -import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; -import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; -import org.quiltmc.qsl.lifecycle.api.client.event.ClientTickEvents; -public class LibZoomerTestMod implements ModInitializer, ClientModInitializer, ClientTickEvents.Start { +public class LibZoomerTestMod implements ModInitializer, ClientModInitializer { // Michael's Zoom Instance private static final ZoomInstance MICHAEL_ZOOM = new ZoomInstance( new ResourceLocation("libzoomer_test:zoom"), @@ -40,7 +37,7 @@ public class LibZoomerTestMod implements ModInitializer, ClientModInitializer, C ); // Michael. He's a reimplementation of the spyglass. Tests if the spyglass can be replicated. - private static final Item MICHAEL_ITEM = new SpyglassItem(new QuiltItemSettings().maxCount(1)); + private static final Item MICHAEL_ITEM = new SpyglassItem(new Item.Properties().stacksTo(1)); // Michelle. She's an implementation of a very simple zoom key. Tests if there are zoom instance conflicts and spyglass-unrelated things. private static final KeyMapping MICHELLE_KEY = new KeyMapping( @@ -50,37 +47,36 @@ public class LibZoomerTestMod implements ModInitializer, ClientModInitializer, C ); @Override - public void onInitialize(ModContainer mod) { + public void onInitialize() { // Register the Michael item Registry.register(BuiltInRegistries.ITEM, new ResourceLocation("libzoomer_test:michael"), MICHAEL_ITEM); } @Override - public void onInitializeClient(ModContainer mod) { + public void onInitializeClient() { // This prints out all zoom instances registered so far and some extra info for (ZoomInstance instance : ZoomRegistry.getZoomInstances()) { System.out.println("Id: " + instance.getInstanceId() + " | Zooming: " + instance.getZoom() + " | Divisor: " + instance.getZoomDivisor()); } KeyBindingHelper.registerKeyBinding(MICHELLE_KEY); - } - // ClientTickEvents.Start is desirable in order to reduce latency issues, since the render tick, which happens later, - // handles the effects of zooming. Setting the zoom after it means a one tick delay for zooming to apply - @Override - public void startClientTick(Minecraft client) { - // This is how you get a spyglass-like zoom working - if (client.player == null) return; + // ClientTickEvents.Start is desirable in order to reduce latency issues, since the render tick, which happens later, + // handles the effects of zooming. Setting the zoom after it means a one tick delay for zooming to apply + ClientTickEvents.START_CLIENT_TICK.register(minecraft -> { + // This is how you get a spyglass-like zoom working + if (minecraft.player == null) return; - MICHAEL_ZOOM.setZoom( - client.options.getCameraType().isFirstPerson() - && ( - client.player.isUsingItem() - && client.player.getUseItem().is(MICHAEL_ITEM) - ) - ); + MICHAEL_ZOOM.setZoom( + minecraft.options.getCameraType().isFirstPerson() + && ( + minecraft.player.isUsingItem() + && minecraft.player.getUseItem().is(MICHAEL_ITEM) + ) + ); - // And this is how you get a simple zoom button working - MICHELLE_ZOOM.setZoom(MICHELLE_KEY.isDown()); + // And this is how you get a simple zoom button working + MICHELLE_ZOOM.setZoom(MICHELLE_KEY.isDown()); + }); } } diff --git a/src/testmod/resources/quilt.mod.json b/src/testmod/resources/quilt.mod.json index c5b4d10..843b9b7 100644 --- a/src/testmod/resources/quilt.mod.json +++ b/src/testmod/resources/quilt.mod.json @@ -14,9 +14,8 @@ }, "intermediate_mappings": "net.fabricmc:intermediary", "entrypoints": { - "init": "io.github.ennuil.libzoomer_test.LibZoomerTestMod", - "client_init": "io.github.ennuil.libzoomer_test.LibZoomerTestMod", - "client_events": "io.github.ennuil.libzoomer_test.LibZoomerTestMod" + "main": "io.github.ennuil.libzoomer_test.LibZoomerTestMod", + "client": "io.github.ennuil.libzoomer_test.LibZoomerTestMod" } } }