Skip to content

Commit

Permalink
Port to Fabric 1.20.6, 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed May 22, 2024
1 parent 18df05a commit d5c3265
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 71 deletions.
16 changes: 5 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Item> SPYGLASSES = QuiltTagKey.of(
Registries.ITEM, new ResourceLocation("libzoomer", "spyglasses"), TagType.CLIENT_FALLBACK
public static final TagKey<Item> SPYGLASSES = TagKey.create(
Registries.ITEM, new ResourceLocation("libzoomer", "spyglasses")
);
}
4 changes: 2 additions & 2 deletions src/main/java/io/github/ennuil/libzoomer/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
import io.github.ennuil.libzoomer.api.ZoomRegistry;

@Mixin(MouseHandler.class)
public abstract class MouseMixin {
public abstract class MouseHandlerMixin {
@Inject(
method = "turnPlayer",
at = @At(
value = "INVOKE",
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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/libzoomer/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tag.item.libzoomer.spyglasses": "Spyglasses"
}
29 changes: 29 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/libzoomer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"GameRendererMixin",
"GuiMixin",
"ItemPropertiesMixin",
"MouseMixin",
"PlayerHeldItemFeatureRendererMixin"
"MouseHandlerMixin",
"PlayerItemInHandMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
17 changes: 7 additions & 10 deletions src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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(
Expand All @@ -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());
});
}
}
5 changes: 2 additions & 3 deletions src/testmod/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit d5c3265

Please sign in to comment.