Skip to content

Commit

Permalink
Merge pull request #124 from Lyzev/123-suggestion-mixin-redirect
Browse files Browse the repository at this point in the history
removed redirect
  • Loading branch information
Lyzev authored Jun 8, 2024
2 parents 5f08768 + 0e34dd0 commit f1f1c48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package dev.lyzev.schizoid.injection.mixins.minecraft.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.lyzev.api.events.EventIsCursorLocked;
import dev.lyzev.api.events.EventMouseClick;
import dev.lyzev.api.events.EventMouseScroll;
Expand All @@ -15,7 +17,6 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
Expand Down Expand Up @@ -49,9 +50,9 @@ private void onMouseButton(long window, int button, int action, int mods, Callba
* @param instance The Mouse instance.
* @return The return value of the event.
*/
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;isCursorLocked()Z"))
private boolean onTick(Mouse instance) {
EventIsCursorLocked event = new EventIsCursorLocked(instance.isCursorLocked());
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;isCursorLocked()Z"))
private boolean onTick(Mouse instance, Operation<Boolean> original) {
EventIsCursorLocked event = new EventIsCursorLocked(original.call(instance));
event.fire();
return event.isCursorLocked();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

package dev.lyzev.schizoid.injection.mixins.minecraft.client.input;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.lyzev.api.events.EventIsMovementKeyPressed;
import net.minecraft.client.input.KeyboardInput;
import net.minecraft.client.option.KeyBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

/**
* This class provides a mixin for the KeyboardInput class in the Minecraft client input package.
Expand All @@ -27,8 +28,8 @@ public class MixinKeyboardInput {
* @param instance The key binding that was pressed.
* @return The return value of the event.
*/
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
private boolean onTick(KeyBinding instance) {
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
private boolean onTick(KeyBinding instance, Operation<Boolean> original) {
EventIsMovementKeyPressed event = new EventIsMovementKeyPressed(instance);
event.fire();
return event.isPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

package dev.lyzev.schizoid.injection.mixins.minecraft.client.network;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.lyzev.api.events.EventClientPlayerEntityTick;
import dev.lyzev.api.events.EventIsMovementKeyPressed;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
Expand Down Expand Up @@ -41,8 +42,8 @@ private void onTick(CallbackInfo ci) {
* @param instance The key binding that is checked.
* @return The return value of the event.
*/
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
private boolean onTickMovement(KeyBinding instance) {
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
private boolean onTickMovement(KeyBinding instance, Operation<Boolean> original) {
EventIsMovementKeyPressed event = new EventIsMovementKeyPressed(instance);
event.fire();
return event.isPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package dev.lyzev.schizoid.injection.mixins.minecraft.client.render.entity;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import dev.lyzev.api.events.EventRenderModel;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

/**
* This class provides a mixin for the LivingEntityRenderer class in the Minecraft client render entity package.
Expand All @@ -26,20 +26,22 @@ public class MixinLivingEntityRenderer {
* It creates and fires an EventRenderModel event when the model is rendered.
* The parameters of the render method are then replaced by the parameters of the event.
*
* @param instance The instance of the EntityModel class.
* @param matrixStack The matrix stack used for transformations.
* @param instance The instance of the EntityModel class.
* @param matrixStack The matrix stack used for transformations.
* @param vertexConsumer The vertex consumer used for rendering.
* @param light The light level for the render.
* @param overlay The overlay level for the render.
* @param red The red color component for the render.
* @param green The green color component for the render.
* @param blue The blue color component for the render.
* @param alpha The alpha component for the render.
* @param light The light level for the render.
* @param overlay The overlay level for the render.
* @param red The red color component for the render.
* @param green The green color component for the render.
* @param blue The blue color component for the render.
* @param alpha The alpha component for the render.
* @return
*/
@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/EntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V"))
private void onRenderModel(EntityModel instance, MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
@WrapWithCondition(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/EntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V"))
private boolean onRenderModel(EntityModel instance, MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
EventRenderModel event = new EventRenderModel(instance, matrixStack, vertexConsumer, light, overlay, red, green, blue, alpha);
event.fire();
instance.render(event.getMatrixStack(), event.getVertexConsumer(), event.getLight(), event.getOverlay(), event.getRed(), event.getGreen(), event.getBlue(), event.getAlpha());
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@

import dev.lyzev.api.events.EventGlfwInit;
import dev.lyzev.api.events.EventSwapBuffers;
import net.minecraft.client.WindowEventHandler;
import net.minecraft.client.WindowSettings;
import net.minecraft.client.util.MonitorTracker;
import net.minecraft.client.util.Window;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL44;
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 static org.lwjgl.glfw.GLFW.GLFW_SAMPLES;

/**
* This class provides a mixin for the Window class in the Minecraft client util package.
* It modifies the behavior of the setPhase method of the Window class.
Expand Down

0 comments on commit f1f1c48

Please sign in to comment.