Skip to content

Commit a23e8b8

Browse files
committed
Initial port to 1.21.3
- Still waiting for SpruceUI to update, only use the advanced config in the meantime
1 parent 1aa449b commit a23e8b8

20 files changed

Lines changed: 115 additions & 87 deletions

common/src/main/java/eu/midnightdust/midnightcontrols/client/MidnightReacharound.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public boolean isReacharoundAvailable() {
7777
}
7878

7979
public static float getPlayerRange(@NotNull MinecraftClient client) {
80-
return client.player != null ? Double.valueOf(client.player.getAttributeValue(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE)).floatValue() : 0.f;
80+
return client.player != null ? Double.valueOf(client.player.getAttributeValue(EntityAttributes.BLOCK_INTERACTION_RANGE)).floatValue() : 0.f;
8181
}
8282

8383
/**

common/src/main/java/eu/midnightdust/midnightcontrols/client/controller/InputHandlers.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public static PressAction handleHotbar(boolean next) {
6060
// When in-game
6161
if (client.currentScreen == null && client.player != null) {
6262
if (!client.player.isSpectator()) {
63+
var inv = client.player.getInventory();
6364
if (next)
64-
client.player.getInventory().scrollInHotbar(-1.0);
65+
inv.setSelectedSlot(inv.selectedSlot < 8 ? inv.selectedSlot + 1 : inv.selectedSlot - 8);
6566
else
66-
client.player.getInventory().scrollInHotbar(1.0);
67+
inv.setSelectedSlot(inv.selectedSlot > 0 ? inv.selectedSlot - 1 : inv.selectedSlot + 8);
6768
}
6869
else {
6970
if (client.inGameHud.getSpectatorHud().isOpen()) {
@@ -79,11 +80,9 @@ public static PressAction handleHotbar(boolean next) {
7980
} else if (client.currentScreen instanceof CreativeInventoryScreenAccessor inventory) {
8081
inventory.midnightcontrols$setSelectedTab(ItemGroupUtil.cycleTab(next, client));
8182
return true;
82-
} else if (client.currentScreen instanceof InventoryScreen || client.currentScreen instanceof CraftingScreen || client.currentScreen instanceof AbstractFurnaceScreen<?>) {
83-
RecipeBookWidget recipeBook;
84-
if (client.currentScreen instanceof InventoryScreen inventoryScreen) recipeBook = inventoryScreen.getRecipeBookWidget();
85-
else if (client.currentScreen instanceof CraftingScreen craftingScreen) recipeBook = craftingScreen.getRecipeBookWidget();
86-
else recipeBook = ((AbstractFurnaceScreen<?>)client.currentScreen).getRecipeBookWidget();
83+
} else if (client.currentScreen instanceof RecipeBookScreen<?> recipeBookScreen) {
84+
RecipeBookWidget<?> recipeBook = ((RecipeBookScreenAccessor) recipeBookScreen).getRecipeBook();
85+
8786
var recipeBookAccessor = (RecipeBookWidgetAccessor) recipeBook;
8887
var tabs = recipeBookAccessor.getTabButtons();
8988
var currentTab = recipeBookAccessor.getCurrentTab();
@@ -98,7 +97,7 @@ else if (nextTab >= tabs.size())
9897
currentTab.setToggled(false);
9998
recipeBookAccessor.setCurrentTab(currentTab = tabs.get(nextTab));
10099
currentTab.setToggled(true);
101-
recipeBookAccessor.midnightcontrols$refreshResults(true);
100+
recipeBookScreen.refreshRecipeBook();
102101
return true;
103102
} else if (client.currentScreen instanceof AdvancementsScreenAccessor screen) {
104103
var tabs = screen.getTabs().values().stream().distinct().toList();

common/src/main/java/eu/midnightdust/midnightcontrols/client/controller/MovementHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ private MovementHandler() {
4848
public void applyMovement(@NotNull ClientPlayerEntity player) {
4949
if (!this.shouldOverrideMovement)
5050
return;
51-
player.input.pressingForward = this.pressingForward;
52-
player.input.pressingBack = this.pressingBack;
53-
player.input.pressingLeft = this.pressingLeft;
54-
player.input.pressingRight = this.pressingRight;
51+
// TODO
52+
// player.input.playerInput.pressingForward = this.pressingForward;
53+
// player.input.pressingBack = this.pressingBack;
54+
// player.input.pressingLeft = this.pressingLeft;
55+
// player.input.pressingRight = this.pressingRight;
5556

5657
polarUtil.calculate(this.movementSideways, this.movementForward, this.slowdownFactor);
5758
player.input.movementForward = polarUtil.polarY;
@@ -81,7 +82,7 @@ else if (button == ButtonBinding.BACK || button == ButtonBinding.RIGHT)
8182
}
8283

8384
this.slowdownFactor = client.player.shouldSlowDown() ? (MathHelper.clamp(
84-
0.3F + (float) client.player.getAttributeValue(EntityAttributes.PLAYER_SNEAKING_SPEED),
85+
0.3F + (float) client.player.getAttributeValue(EntityAttributes.SNEAKING_SPEED),
8586
0.0F,
8687
1.0F
8788
)) : 1.f;

common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/MidnightControlsRenderer.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@
1818
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
1919
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
2020
import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin;
21+
import eu.midnightdust.midnightcontrols.client.mixin.DrawContextAccessor;
2122
import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor;
2223
import net.minecraft.client.MinecraftClient;
2324
import net.minecraft.client.font.TextRenderer;
2425
import net.minecraft.client.gui.DrawContext;
25-
import net.minecraft.client.render.BufferBuilder;
26-
import net.minecraft.client.render.BufferRenderer;
27-
import net.minecraft.client.render.GameRenderer;
28-
import net.minecraft.client.render.Tessellator;
29-
import net.minecraft.client.render.VertexFormat;
30-
import net.minecraft.client.render.VertexFormats;
26+
import net.minecraft.client.render.*;
3127
import net.minecraft.client.resource.language.I18n;
3228
import net.minecraft.client.texture.Sprite;
3329
import net.minecraft.screen.slot.Slot;
3430
import net.minecraft.util.Identifier;
31+
import net.minecraft.util.math.ColorHelper;
3532
import org.jetbrains.annotations.NotNull;
3633
import org.joml.Matrix4f;
3734
import org.lwjgl.glfw.GLFW;
3835

36+
import java.util.function.Function;
37+
3938
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
4039

4140
/**
@@ -175,7 +174,7 @@ else if (button >= 500) {
175174
int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE;
176175

177176
RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f);
178-
context.drawTexture(axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
177+
context.drawTexture(RenderLayer::getGuiTextured, axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
179178
, x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2),
180179
(float) buttonOffset, (float) (controllerType * assetSize),
181180
assetSize, assetSize,
@@ -216,7 +215,7 @@ public static void renderWaylandCursor(@NotNull DrawContext context, @NotNull Mi
216215
if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK)
217216
spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK;
218217
Sprite sprite = client.getGuiAtlasManager().getSprite(spritePath);
219-
drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
218+
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
220219
} catch (IllegalStateException ignored) {}
221220
}
222221

@@ -260,19 +259,20 @@ public static void renderVirtualCursor(@NotNull DrawContext context, @NotNull Mi
260259

261260
try {
262261
Sprite sprite = client.getGuiAtlasManager().getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : "")));
263-
drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
262+
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
264263
} catch (IllegalStateException ignored) {}
265264
}
266-
private static void drawUnalignedTexturedQuad(Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float z, float u1, float u2, float v1, float v2) {
267-
RenderSystem.setShaderTexture(0, texture);
268-
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
265+
private static void drawUnalignedTexturedQuad(Function<Identifier, RenderLayer> renderLayers, Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float z, float u1, float u2, float v1, float v2) {
266+
RenderLayer renderLayer = renderLayers.apply(texture);
267+
//RenderSystem.setShaderTexture(0, texture);
269268
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
270-
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
271-
bufferBuilder.vertex(matrix4f, x1, y1, z).texture(u1, v1);
272-
bufferBuilder.vertex(matrix4f, x1, y2, z).texture(u1, v2);
273-
bufferBuilder.vertex(matrix4f, x2, y2, z).texture(u2, v2);
274-
bufferBuilder.vertex(matrix4f, x2, y1, z).texture(u2, v1);
275-
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
269+
//BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
270+
VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer);
271+
vertexConsumer.vertex(matrix4f, x1, y1, z).texture(u1, v1).color(ColorHelper.getWhite(1.0f));
272+
vertexConsumer.vertex(matrix4f, x1, y2, z).texture(u1, v2).color(ColorHelper.getWhite(1.0f));
273+
vertexConsumer.vertex(matrix4f, x2, y2, z).texture(u2, v2).color(ColorHelper.getWhite(1.0f));
274+
vertexConsumer.vertex(matrix4f, x2, y1, z).texture(u2, v1).color(ColorHelper.getWhite(1.0f));
275+
context.draw();
276276
}
277277

278278
public record ButtonSize(int length, int height) {

common/src/main/java/eu/midnightdust/midnightcontrols/client/gui/MidnightControlsSettingsScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private static void fill(MatrixStack matrixStack, int x2, int y2, int x1, int y1
514514
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
515515
RenderSystem.enableBlend();
516516
RenderSystem.defaultBlendFunc();
517-
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
517+
//RenderSystem.setShader(GameRenderer::getPositionColorProgram);
518518
bufferBuilder.vertex(matrix, (float)x1, (float)y2, 0.0F).color(r, g, b, t);
519519
bufferBuilder.vertex(matrix, (float)x2, (float)y2, 0.0F).color(r, g, b, t);
520520
bufferBuilder.vertex(matrix, (float)x2, (float)y1, 0.0F).color(r, g, b, t);

common/src/main/java/eu/midnightdust/midnightcontrols/client/mixin/ClientPlayerEntityMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public void onTickMovement(CallbackInfo ci) {
8888
if (MidnightControlsConfig.verticalFlyDrifting || !MidnightControls.isExtrasLoaded)
8989
return;
9090
int moving = 0;
91-
if (this.input.sneaking) {
91+
if (this.input.playerInput.sneak()) {
9292
--moving;
9393
}
9494

95-
if (this.input.jumping) {
95+
if (this.input.playerInput.jump()) {
9696
++moving;
9797
}
9898

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
3+
*
4+
* This file is part of midnightcontrols.
5+
*
6+
* Licensed under the MIT license. For more information,
7+
* see the LICENSE file.
8+
*/
9+
10+
package eu.midnightdust.midnightcontrols.client.mixin;
11+
12+
import net.minecraft.client.gui.DrawContext;
13+
import net.minecraft.client.render.VertexConsumerProvider;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.gen.Accessor;
16+
17+
@Mixin(DrawContext.class)
18+
public interface DrawContextAccessor {
19+
@Accessor("vertexConsumers")
20+
VertexConsumerProvider.Immediate getVertexConsumers();
21+
}

common/src/main/java/eu/midnightdust/midnightcontrols/client/mixin/GameOptionsScreenMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected GameOptionsScreenMixin(Text title) {
4848
}
4949
}
5050

51-
@Inject(method = "initTabNavigation", at = @At("TAIL"))
51+
@Inject(method = "refreshWidgetPositions", at = @At("TAIL"))
5252
public void midnightcontrols$onResize(CallbackInfo ci) {
5353
this.midnightcontrols$setButtonPos();
5454
}

common/src/main/java/eu/midnightdust/midnightcontrols/client/mixin/MinecraftClientMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ private void onItemUse(CallbackInfo ci, @Local Hand hand, @Local ItemStack stack
127127
int previousStackCount = stackInHand.getCount();
128128
var result = this.interactionManager.interactBlock(this.player, hand, hitResult);
129129
if (result.isAccepted()) {
130-
if (result.shouldSwingHand()) {
130+
//if (result.shouldSwingHand()) {
131131
this.player.swingHand(hand);
132132
if (!stackInHand.isEmpty() && (stackInHand.getCount() != previousStackCount || this.interactionManager.hasCreativeInventory())) {
133133
this.gameRenderer.firstPersonRenderer.resetEquipProgress(hand);
134134
}
135-
}
135+
//}
136136

137137
ci.cancel();
138138
}

common/src/main/java/eu/midnightdust/midnightcontrols/client/mixin/MouseMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import net.minecraft.client.util.GlfwUtil;
2121
import net.minecraft.item.ItemStack;
2222
import net.minecraft.item.ThrowablePotionItem;
23-
import net.minecraft.util.UseAction;
23+
import net.minecraft.item.consume.UseAction;
2424
import net.minecraft.util.math.Smoother;
2525
import org.lwjgl.glfw.GLFW;
2626
import org.spongepowered.asm.mixin.Final;

0 commit comments

Comments
 (0)