Skip to content

Commit

Permalink
Fixed screen batching on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 6, 2023
1 parent 468db9d commit 1f4e34a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,20 @@
package net.raphimc.immediatelyfast.injection.mixins.screen_batching;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.raphimc.immediatelyfast.feature.batching.BatchingBuffers;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = HandledScreen.class, priority = 500)
public abstract class MixinHandledScreen {

@Shadow
public static void drawSlotHighlight(MatrixStack matrices, int x, int y, int z) {
}

@Inject(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;focusedSlot:Lnet/minecraft/screen/slot/Slot;", ordinal = 0))
private void beginBatching(CallbackInfo ci) {
BatchingBuffers.beginHudBatching();
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawSlotHighlight(Lnet/minecraft/client/util/math/MatrixStack;III)V"))
private void drawSlotHightlightOnTop(MatrixStack matrices, int x, int y, int z) {
BatchingBuffers.beginItemOverlayRendering();
drawSlotHighlight(matrices, x, y, z);
BatchingBuffers.endItemOverlayRendering();
}

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/util/math/MatrixStack;II)V", shift = At.Shift.BEFORE))
private void endBatching(CallbackInfo ci) {
BatchingBuffers.endHudBatching();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of ImmediatelyFast - https://github.com/RaphiMC/ImmediatelyFast
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.immediatelyfast.fabric.injection.mixins.screen_batching;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.raphimc.immediatelyfast.feature.batching.BatchingBuffers;
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.Redirect;

@Mixin(value = HandledScreen.class, priority = 500)
public abstract class MixinHandledScreen {

@Shadow
public static void drawSlotHighlight(MatrixStack matrices, int x, int y, int z) {
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawSlotHighlight(Lnet/minecraft/client/util/math/MatrixStack;III)V"))
private void drawSlotHightlightOnTop(MatrixStack matrices, int x, int y, int z) {
BatchingBuffers.beginItemOverlayRendering();
drawSlotHighlight(matrices, x, y, z);
BatchingBuffers.endItemOverlayRendering();
}

}
3 changes: 2 additions & 1 deletion fabric/src/main/resources/immediatelyfast-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"client": [
"core.MixinRenderLayer",
"hud_batching.MixinInGameHud",
"hud_batching.compat.appleskin.MixinAppleSkin_HUDOverlayHandler"
"hud_batching.compat.appleskin.MixinAppleSkin_HUDOverlayHandler",
"screen_batching.MixinHandledScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of ImmediatelyFast - https://github.com/RaphiMC/ImmediatelyFast
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.immediatelyfast.forge.injection.mixins.screen_batching;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.raphimc.immediatelyfast.feature.batching.BatchingBuffers;
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.Redirect;

@Mixin(value = HandledScreen.class, priority = 500)
public abstract class MixinHandledScreen {

@Shadow
public static void renderSlotHighlight(MatrixStack matrices, int x, int y, int z, int slotColor) {
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;renderSlotHighlight(Lnet/minecraft/client/util/math/MatrixStack;IIII)V"))
private void drawSlotHightlightOnTop(MatrixStack matrices, int x, int y, int z, int slotColor) {
BatchingBuffers.beginItemOverlayRendering();
renderSlotHighlight(matrices, x, y, z, slotColor);
BatchingBuffers.endItemOverlayRendering();
}

}
3 changes: 2 additions & 1 deletion forge/src/main/resources/immediatelyfast-forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"client": [
"core.MixinForgeRenderTypes",
"hud_batching.MixinForgeGui",
"hud_batching.compat.appleskin.MixinAppleSkin_HUDOverlayHandler"
"hud_batching.compat.appleskin.MixinAppleSkin_HUDOverlayHandler",
"screen_batching.MixinHandledScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 1f4e34a

Please sign in to comment.