-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
343 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,9 @@ loom { | |
} | ||
} | ||
|
||
// Mixin plugin needs this | ||
mixin { | ||
useLegacyMixinAp = false | ||
useLegacyMixinAp = true | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/io/github/ennuil/ok_zoomer/OkZoomerMixinPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.ennuil.ok_zoomer; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
// TODO - Demolish this mixin plugin by doing a real port! | ||
public class OkZoomerMixinPlugin implements IMixinConfigPlugin { | ||
private static final Logger LOGGER = LoggerFactory.getLogger("Ok Zoomer Mixins"); | ||
private static String mixinPackage; | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) { | ||
OkZoomerMixinPlugin.mixinPackage = mixinPackage; | ||
} | ||
|
||
@Override | ||
public String getRefMapperConfig() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
if (mixinClassName.startsWith(mixinPackage)) { | ||
var id = mixinClassName.substring(mixinPackage.length()); | ||
id = id.substring(1, id.indexOf('.', 1)); | ||
|
||
boolean connectorLoaded = FabricLoader.getInstance().isModLoaded("connector"); | ||
if (id.equals("sintyra") && connectorLoaded) { | ||
LOGGER.warn("Loaded Sintyra-specific mixins!"); | ||
return true; | ||
} else if (id.equals("fabric")) { | ||
return !connectorLoaded; | ||
} | ||
|
||
return id.equals("common"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {} | ||
|
||
@Override | ||
public List<String> getMixins() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/io/github/ennuil/ok_zoomer/config/screen/components/LabelledEditBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
src/main/java/io/github/ennuil/ok_zoomer/mixin/GuiMixin.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...omer/mixin/AbstractClientPlayerMixin.java → ...xin/common/AbstractClientPlayerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nuil/ok_zoomer/mixin/EditBoxAccessor.java → ..._zoomer/mixin/common/EditBoxAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../ennuil/ok_zoomer/mixin/EditBoxMixin.java → .../ok_zoomer/mixin/common/EditBoxMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/io/github/ennuil/ok_zoomer/mixin/common/GuiMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package io.github.ennuil.ok_zoomer.mixin.common; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.sugar.Share; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager; | ||
import io.github.ennuil.ok_zoomer.zoom.Zoom; | ||
import net.minecraft.client.DeltaTracker; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import org.quiltmc.loader.api.minecraft.ClientOnly; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@ClientOnly | ||
@Mixin(Gui.class) | ||
public abstract class GuiMixin { | ||
@Unique | ||
private boolean hideCrossbar = false; | ||
|
||
@Shadow | ||
protected abstract void renderCrosshair(GuiGraphics guiGraphics, DeltaTracker deltaTracker); | ||
|
||
@Inject( | ||
method = "renderCameraOverlays", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/DeltaTracker;getGameTimeDeltaTicks()F" | ||
) | ||
) | ||
private void injectZoomOverlay(GuiGraphics graphics, DeltaTracker deltaTracker, CallbackInfo ci, @Share("cancelOverlay") LocalBooleanRef cancelOverlay) { | ||
cancelOverlay.set(false); | ||
if (Zoom.getZoomOverlay() != null) { | ||
var overlay = Zoom.getZoomOverlay(); | ||
overlay.tickBeforeRender(deltaTracker); | ||
if (overlay.getActive()) { | ||
cancelOverlay.set(overlay.cancelOverlayRendering()); | ||
overlay.renderOverlay(graphics, deltaTracker, Zoom.getTransitionMode()); | ||
} | ||
} | ||
} | ||
|
||
// Cancel the cancellable overlays | ||
@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(); | ||
} | ||
|
||
@ModifyExpressionValue( | ||
method = "renderCameraOverlays", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isScoping()Z") | ||
) | ||
private boolean activateSpyglassOverlay(boolean isScoping) { | ||
if (switch (OkZoomerConfigManager.CONFIG.features.spyglassMode.value()) { | ||
case REPLACE_ZOOM, BOTH -> true; | ||
default -> false; | ||
}) { | ||
return false; | ||
} | ||
|
||
return isScoping; | ||
} | ||
|
||
@WrapMethod(method = "render") | ||
private void zoomGui(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<Void> original) { | ||
if (OkZoomerConfigManager.CONFIG.features.persistentInterface.value() || !Zoom.getTransitionMode().getActive()) { | ||
original.call(graphics, deltaTracker); | ||
} else { | ||
hideCrossbar = false; | ||
if (!OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value()) { | ||
graphics.pose().pushPose(); | ||
graphics.pose().translate(0.0F, 0.0F, 200.0F); | ||
this.renderCrosshair(graphics, deltaTracker); | ||
graphics.pose().popPose(); | ||
hideCrossbar = true; | ||
} | ||
double fov = Zoom.getTransitionMode().applyZoom(1.0F, deltaTracker.getGameTimeDeltaPartialTick(true)); | ||
float divisor = (float) (1.0D / fov); | ||
double translation = 2.0D / ((1.0D / fov) - 1); | ||
graphics.pose().pushPose(); | ||
graphics.pose().translate(-(graphics.guiWidth() / (translation)), -(graphics.guiHeight() / (translation)), 0.0F); | ||
graphics.pose().scale(divisor, divisor, divisor); | ||
original.call(graphics, deltaTracker); | ||
graphics.pose().popPose(); | ||
} | ||
} | ||
|
||
@WrapMethod(method = "renderCrosshair") | ||
private void hideCrosshair(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<Void> original) { | ||
if (!hideCrossbar) { | ||
if (!OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value() || !Zoom.getTransitionMode().getActive()) { | ||
original.call(graphics, deltaTracker); | ||
} else { | ||
float fade = 1.0F - (float) Zoom.getTransitionMode().getFade(deltaTracker.getGameTimeDeltaPartialTick(true)); | ||
RenderSystem.setShaderColor(fade, fade, fade, 1.0F); | ||
original.call(graphics, deltaTracker); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
} | ||
} else { | ||
hideCrossbar = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.