mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-16 16:45:09 +01:00
Compare commits
5 Commits
50103ce4cf
...
architectu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e022fd1827 | ||
|
|
fbecfd5642 | ||
|
|
036be42bec | ||
|
|
4cfee5ba2e | ||
|
|
d753641fa9 |
@@ -13,9 +13,6 @@ repositories {
|
|||||||
maven {
|
maven {
|
||||||
url = "https://api.modrinth.com/maven"
|
url = "https://api.modrinth.com/maven"
|
||||||
}
|
}
|
||||||
flatDir {
|
|
||||||
dirs("localMaven")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
@@ -25,9 +22,6 @@ subprojects {
|
|||||||
url = "https://api.modrinth.com/maven"
|
url = "https://api.modrinth.com/maven"
|
||||||
}
|
}
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
flatDir {
|
|
||||||
dirs("../localMaven")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ dependencies {
|
|||||||
modCompileOnlyApi "org.quiltmc:quilt-json5:1.0.0"
|
modCompileOnlyApi "org.quiltmc:quilt-json5:1.0.0"
|
||||||
modImplementation "maven.modrinth:sodium:${project.sodium_version}-fabric"
|
modImplementation "maven.modrinth:sodium:${project.sodium_version}-fabric"
|
||||||
modCompileOnlyApi "maven.modrinth:emi:${project.emi_version}"
|
modCompileOnlyApi "maven.modrinth:emi:${project.emi_version}"
|
||||||
modImplementation "maven.modrinth:emotecraft:${project.emotecraft_version}"
|
modCompileOnlyApi "maven.modrinth:emotecraft:${project.emotecraft_version}"
|
||||||
modCompileOnlyApi "io.github.kosmx:bendy-lib:${project.bendylib_version}"
|
modCompileOnlyApi "io.github.kosmx:bendy-lib:${project.bendylib_version}"
|
||||||
modCompileOnlyApi "dev.isxander:yet-another-config-lib:${project.yacl_version}"
|
modCompileOnlyApi "dev.isxander:yet-another-config-lib:${project.yacl_version}"
|
||||||
modCompileOnlyApi "maven.modrinth:inventory-tabs-updated:${project.inventorytabs_version}"
|
modCompileOnlyApi "maven.modrinth:inventory-tabs-updated:${project.inventorytabs_version}"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class MidnightControlsClient extends MidnightControls {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (lateInitDone && client.isRunning()) {
|
if (lateInitDone && client.isRunning()) {
|
||||||
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && (client.isWindowFocused() || MidnightControlsConfig.unfocusedInput)) {
|
if (MidnightControlsConfig.controlsMode != ControlsMode.DEFAULT && (client.isWindowFocused() || MidnightControlsConfig.unfocusedInput)) {
|
||||||
input.tickCameraStick();
|
input.tickCameraStick();
|
||||||
input.updateCamera();
|
input.updateCamera();
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,6 @@ public class MidnightControlsClient extends MidnightControls {
|
|||||||
RainbowColor.tick();
|
RainbowColor.tick();
|
||||||
TouchInput.tick();
|
TouchInput.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when opening a screen.
|
* Called when opening a screen.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class MidnightReacharound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getPlayerRange(@NotNull MinecraftClient client) {
|
public static float getPlayerRange(@NotNull MinecraftClient client) {
|
||||||
return client.player != null ? Double.valueOf(client.player.getAttributeValue(EntityAttributes.BLOCK_INTERACTION_RANGE)).floatValue() : 0.f;
|
return client.player != null ? Double.valueOf(client.player.getAttributeValue(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE)).floatValue() : 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,51 +1,36 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.compat;
|
package eu.midnightdust.midnightcontrols.client.compat;
|
||||||
|
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.MouseAccessor;
|
import io.github.kosmx.emotes.arch.gui.EmoteMenuImpl;
|
||||||
import io.github.kosmx.emotes.arch.screen.ingame.FastMenuScreen;
|
import io.github.kosmx.emotes.arch.gui.screen.ingame.FastChosseScreen;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import org.joml.Vector2i;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
public class EmotecraftCompat {
|
public class EmotecraftCompat {
|
||||||
private static final MinecraftClient client = MinecraftClient.getInstance();
|
private static final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
public static void openEmotecraftScreen(Screen parent) {
|
public static void openEmotecraftScreen(Screen parent) {
|
||||||
client.setScreen(new FastMenuScreen(parent));
|
client.setScreen(new EmoteMenuImpl(parent));
|
||||||
}
|
}
|
||||||
public static boolean isEmotecraftScreen(Screen screen) {
|
public static boolean isEmotecraftScreen(Screen screen) {
|
||||||
return screen instanceof FastMenuScreen;
|
return screen instanceof FastChosseScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prevIndex = -1;
|
|
||||||
public static void handleEmoteSelector(int index) {
|
public static void handleEmoteSelector(int index) {
|
||||||
try {
|
if (client.currentScreen instanceof FastChosseScreen) {
|
||||||
if (client.currentScreen instanceof FastMenuScreen) {
|
int x = client.getWindow().getWidth() / 2;
|
||||||
boolean stickReleased = index == -1 && prevIndex != -1;
|
int y = client.getWindow().getHeight() / 2;
|
||||||
var pos = calcMousePos(stickReleased ? prevIndex : index);
|
switch (index) {
|
||||||
InputManager.queueMousePosition(pos.x, pos.y);
|
case 0, 3, 5 -> x -= 200;
|
||||||
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
case 2, 4, 7 -> x += 200;
|
||||||
|
}
|
||||||
|
switch (index) {
|
||||||
|
case 0, 1, 2 -> y -= 200;
|
||||||
|
case 5, 6, 7 -> y += 200;
|
||||||
|
}
|
||||||
|
InputManager.queueMousePosition(x, y);
|
||||||
|
|
||||||
if (stickReleased) {
|
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
||||||
((MouseAccessor) client.mouse).midnightcontrols$onMouseButton(client.getWindow().getHandle(), GLFW.GLFW_MOUSE_BUTTON_LEFT, GLFW.GLFW_PRESS, 0);
|
|
||||||
prevIndex = -1;
|
|
||||||
}
|
|
||||||
else prevIndex = index;
|
|
||||||
} else prevIndex = -1;
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
public static Vector2i calcMousePos(int index) {
|
|
||||||
int x = client.getWindow().getWidth() / 2;
|
|
||||||
int y = client.getWindow().getHeight() / 2;
|
|
||||||
switch (index) {
|
|
||||||
case 0, 3, 5 -> x -= 275;
|
|
||||||
case 2, 4, 7 -> x += 275;
|
|
||||||
}
|
}
|
||||||
switch (index) {
|
|
||||||
case 0, 1, 2 -> y -= 275;
|
|
||||||
case 5, 6, 7 -> y += 275;
|
|
||||||
}
|
|
||||||
return new Vector2i(x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,11 +60,10 @@ public class InputHandlers {
|
|||||||
// When in-game
|
// When in-game
|
||||||
if (client.currentScreen == null && client.player != null) {
|
if (client.currentScreen == null && client.player != null) {
|
||||||
if (!client.player.isSpectator()) {
|
if (!client.player.isSpectator()) {
|
||||||
var inv = client.player.getInventory();
|
|
||||||
if (next)
|
if (next)
|
||||||
inv.setSelectedSlot(inv.selectedSlot < 8 ? inv.selectedSlot + 1 : inv.selectedSlot - 8);
|
client.player.getInventory().scrollInHotbar(-1.0);
|
||||||
else
|
else
|
||||||
inv.setSelectedSlot(inv.selectedSlot > 0 ? inv.selectedSlot - 1 : inv.selectedSlot + 8);
|
client.player.getInventory().scrollInHotbar(1.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (client.inGameHud.getSpectatorHud().isOpen()) {
|
if (client.inGameHud.getSpectatorHud().isOpen()) {
|
||||||
@@ -80,9 +79,11 @@ public class InputHandlers {
|
|||||||
} else if (client.currentScreen instanceof CreativeInventoryScreenAccessor inventory) {
|
} else if (client.currentScreen instanceof CreativeInventoryScreenAccessor inventory) {
|
||||||
inventory.midnightcontrols$setSelectedTab(ItemGroupUtil.cycleTab(next, client));
|
inventory.midnightcontrols$setSelectedTab(ItemGroupUtil.cycleTab(next, client));
|
||||||
return true;
|
return true;
|
||||||
} else if (client.currentScreen instanceof RecipeBookScreen<?> recipeBookScreen) {
|
} else if (client.currentScreen instanceof InventoryScreen || client.currentScreen instanceof CraftingScreen || client.currentScreen instanceof AbstractFurnaceScreen<?>) {
|
||||||
RecipeBookWidget<?> recipeBook = ((RecipeBookScreenAccessor) recipeBookScreen).getRecipeBook();
|
RecipeBookWidget recipeBook;
|
||||||
|
if (client.currentScreen instanceof InventoryScreen inventoryScreen) recipeBook = inventoryScreen.getRecipeBookWidget();
|
||||||
|
else if (client.currentScreen instanceof CraftingScreen craftingScreen) recipeBook = craftingScreen.getRecipeBookWidget();
|
||||||
|
else recipeBook = ((AbstractFurnaceScreen<?>)client.currentScreen).getRecipeBookWidget();
|
||||||
var recipeBookAccessor = (RecipeBookWidgetAccessor) recipeBook;
|
var recipeBookAccessor = (RecipeBookWidgetAccessor) recipeBook;
|
||||||
var tabs = recipeBookAccessor.getTabButtons();
|
var tabs = recipeBookAccessor.getTabButtons();
|
||||||
var currentTab = recipeBookAccessor.getCurrentTab();
|
var currentTab = recipeBookAccessor.getCurrentTab();
|
||||||
@@ -97,7 +98,7 @@ public class InputHandlers {
|
|||||||
currentTab.setToggled(false);
|
currentTab.setToggled(false);
|
||||||
recipeBookAccessor.setCurrentTab(currentTab = tabs.get(nextTab));
|
recipeBookAccessor.setCurrentTab(currentTab = tabs.get(nextTab));
|
||||||
currentTab.setToggled(true);
|
currentTab.setToggled(true);
|
||||||
recipeBookScreen.refreshRecipeBook();
|
recipeBookAccessor.midnightcontrols$refreshResults(true);
|
||||||
return true;
|
return true;
|
||||||
} else if (client.currentScreen instanceof AdvancementsScreenAccessor screen) {
|
} else if (client.currentScreen instanceof AdvancementsScreenAccessor screen) {
|
||||||
var tabs = screen.getTabs().values().stream().distinct().toList();
|
var tabs = screen.getTabs().values().stream().distinct().toList();
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import eu.midnightdust.midnightcontrols.client.util.MathUtil;
|
|||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.util.PlayerInput;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -49,8 +48,10 @@ public final class MovementHandler implements PressAction {
|
|||||||
public void applyMovement(@NotNull ClientPlayerEntity player) {
|
public void applyMovement(@NotNull ClientPlayerEntity player) {
|
||||||
if (!this.shouldOverrideMovement)
|
if (!this.shouldOverrideMovement)
|
||||||
return;
|
return;
|
||||||
player.input.playerInput = new PlayerInput(this.pressingForward, this.pressingBack, this.pressingLeft, this.pressingRight,
|
player.input.pressingForward = this.pressingForward;
|
||||||
player.input.playerInput.jump(), player.input.playerInput.sneak(), player.input.playerInput.sprint());
|
player.input.pressingBack = this.pressingBack;
|
||||||
|
player.input.pressingLeft = this.pressingLeft;
|
||||||
|
player.input.pressingRight = this.pressingRight;
|
||||||
|
|
||||||
polarUtil.calculate(this.movementSideways, this.movementForward, this.slowdownFactor);
|
polarUtil.calculate(this.movementSideways, this.movementForward, this.slowdownFactor);
|
||||||
player.input.movementForward = polarUtil.polarY;
|
player.input.movementForward = polarUtil.polarY;
|
||||||
@@ -80,7 +81,7 @@ public final class MovementHandler implements PressAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.slowdownFactor = client.player.shouldSlowDown() ? (MathHelper.clamp(
|
this.slowdownFactor = client.player.shouldSlowDown() ? (MathHelper.clamp(
|
||||||
0.3F + (float) client.player.getAttributeValue(EntityAttributes.SNEAKING_SPEED),
|
0.3F + (float) client.player.getAttributeValue(EntityAttributes.PLAYER_SNEAKING_SPEED),
|
||||||
0.0F,
|
0.0F,
|
||||||
1.0F
|
1.0F
|
||||||
)) : 1.f;
|
)) : 1.f;
|
||||||
|
|||||||
@@ -18,23 +18,24 @@ import eu.midnightdust.midnightcontrols.client.MidnightInput;
|
|||||||
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
||||||
import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin;
|
import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.DrawContextAccessor;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.render.*;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
|
import net.minecraft.client.render.BufferRenderer;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
import net.minecraft.client.render.Tessellator;
|
||||||
|
import net.minecraft.client.render.VertexFormat;
|
||||||
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.ColorHelper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,7 +175,7 @@ public class MidnightControlsRenderer {
|
|||||||
int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE;
|
int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE;
|
||||||
|
|
||||||
RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f);
|
RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f);
|
||||||
context.drawTexture(RenderLayer::getGuiTextured, axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
|
context.drawTexture(axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
|
||||||
, x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2),
|
, x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2),
|
||||||
(float) buttonOffset, (float) (controllerType * assetSize),
|
(float) buttonOffset, (float) (controllerType * assetSize),
|
||||||
assetSize, assetSize,
|
assetSize, assetSize,
|
||||||
@@ -215,7 +216,7 @@ public class MidnightControlsRenderer {
|
|||||||
if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK)
|
if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK)
|
||||||
spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK;
|
spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK;
|
||||||
Sprite sprite = client.getGuiAtlasManager().getSprite(spritePath);
|
Sprite sprite = client.getGuiAtlasManager().getSprite(spritePath);
|
||||||
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
||||||
} catch (IllegalStateException ignored) {}
|
} catch (IllegalStateException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,20 +260,19 @@ public class MidnightControlsRenderer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Sprite sprite = client.getGuiAtlasManager().getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : "")));
|
Sprite sprite = client.getGuiAtlasManager().getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : "")));
|
||||||
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
||||||
} catch (IllegalStateException ignored) {}
|
} catch (IllegalStateException ignored) {}
|
||||||
}
|
}
|
||||||
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) {
|
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) {
|
||||||
RenderLayer renderLayer = renderLayers.apply(texture);
|
RenderSystem.setShaderTexture(0, texture);
|
||||||
//RenderSystem.setShaderTexture(0, texture);
|
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
|
||||||
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
|
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
|
||||||
//BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
|
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
|
||||||
VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer);
|
bufferBuilder.vertex(matrix4f, x1, y1, z).texture(u1, v1);
|
||||||
vertexConsumer.vertex(matrix4f, x1, y1, z).texture(u1, v1).color(ColorHelper.getWhite(1.0f));
|
bufferBuilder.vertex(matrix4f, x1, y2, z).texture(u1, v2);
|
||||||
vertexConsumer.vertex(matrix4f, x1, y2, z).texture(u1, v2).color(ColorHelper.getWhite(1.0f));
|
bufferBuilder.vertex(matrix4f, x2, y2, z).texture(u2, v2);
|
||||||
vertexConsumer.vertex(matrix4f, x2, y2, z).texture(u2, v2).color(ColorHelper.getWhite(1.0f));
|
bufferBuilder.vertex(matrix4f, x2, y1, z).texture(u2, v1);
|
||||||
vertexConsumer.vertex(matrix4f, x2, y1, z).texture(u2, v1).color(ColorHelper.getWhite(1.0f));
|
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||||
context.draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ButtonSize(int length, int height) {
|
public record ButtonSize(int length, int height) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
|||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.platform.NetworkUtil;
|
import eu.midnightdust.midnightcontrols.client.util.platform.NetworkUtil;
|
||||||
import org.thinkingstudio.obsidianui.background.Background;
|
import org.thinkingstudio.obsidianui.background.Background;
|
||||||
import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor;
|
|
||||||
import org.thinkingstudio.obsidianui.widget.SpruceWidget;
|
import org.thinkingstudio.obsidianui.widget.SpruceWidget;
|
||||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControls;
|
import eu.midnightdust.midnightcontrols.MidnightControls;
|
||||||
@@ -502,24 +501,27 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
|
public void render(DrawContext context, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
|
||||||
fill(context, widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight(), Color.black);
|
fill(context.getMatrices(), widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight(), MidnightColorUtil.hex2Rgb("#000000"));
|
||||||
}
|
}
|
||||||
private static void fill(DrawContext context, int x2, int y2, int x1, int y1, Color color) {
|
private static void fill(MatrixStack matrixStack, int x2, int y2, int x1, int y1, Color color) {
|
||||||
RenderLayer renderLayer = RenderLayer.getGui();
|
matrixStack.push();
|
||||||
VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer);
|
|
||||||
|
|
||||||
|
Matrix4f matrix = matrixStack.peek().getPositionMatrix();
|
||||||
float r = (float)(color.getRed()) / 255.0F;
|
float r = (float)(color.getRed()) / 255.0F;
|
||||||
float g = (float)(color.getGreen()) / 255.0F;
|
float g = (float)(color.getGreen()) / 255.0F;
|
||||||
float b = (float)(color.getBlue()) / 255.0F;
|
float b = (float)(color.getBlue()) / 255.0F;
|
||||||
float t = (float)(transparency) / 255.0F;
|
float t = (float)(transparency) / 255.0F;
|
||||||
|
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.defaultBlendFunc();
|
RenderSystem.defaultBlendFunc();
|
||||||
vertexConsumer.vertex((float)x1, (float)y2, 0.0F).color(r, g, b, t);
|
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
|
||||||
vertexConsumer.vertex((float)x2, (float)y2, 0.0F).color(r, g, b, t);
|
bufferBuilder.vertex(matrix, (float)x1, (float)y2, 0.0F).color(r, g, b, t);
|
||||||
vertexConsumer.vertex((float)x2, (float)y1, 0.0F).color(r, g, b, t);
|
bufferBuilder.vertex(matrix, (float)x2, (float)y2, 0.0F).color(r, g, b, t);
|
||||||
vertexConsumer.vertex((float)x1, (float)y1, 0.0F).color(r, g, b, t);
|
bufferBuilder.vertex(matrix, (float)x2, (float)y1, 0.0F).color(r, g, b, t);
|
||||||
|
bufferBuilder.vertex(matrix, (float)x1, (float)y1, 0.0F).color(r, g, b, t);
|
||||||
|
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||||
RenderSystem.disableBlend();
|
RenderSystem.disableBlend();
|
||||||
context.draw();
|
matrixStack.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.gui;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import org.thinkingstudio.obsidianui.Position;
|
|
||||||
import org.thinkingstudio.obsidianui.SpruceTexts;
|
|
||||||
import org.thinkingstudio.obsidianui.screen.SpruceScreen;
|
|
||||||
import org.thinkingstudio.obsidianui.widget.SpruceButtonWidget;
|
|
||||||
import org.thinkingstudio.obsidianui.widget.container.SpruceContainerWidget;
|
|
||||||
|
|
||||||
public class VirtualKeyboardScreen extends SpruceScreen {
|
|
||||||
private SpruceContainerWidget container;
|
|
||||||
private TextFieldWidget bufferDisplay;
|
|
||||||
private final StringBuilder buffer;
|
|
||||||
private final CloseCallback closeCallback;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface CloseCallback {
|
|
||||||
void onClose(String text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualKeyboardScreen(String initialText, CloseCallback closeCallback) {
|
|
||||||
super(Text.literal("Virtual Keyboard"));
|
|
||||||
|
|
||||||
this.buffer = new StringBuilder(initialText);
|
|
||||||
this.closeCallback = closeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
this.bufferDisplay = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, this.height / 4 - 40, 200, 20, Text.literal(""));
|
|
||||||
this.bufferDisplay.setEditable(false);
|
|
||||||
this.bufferDisplay.setMaxLength(1024);
|
|
||||||
this.bufferDisplay.setText(buffer.toString());
|
|
||||||
this.addDrawableChild(this.bufferDisplay);
|
|
||||||
|
|
||||||
rebuildKeyboard();
|
|
||||||
|
|
||||||
this.addDrawableChild(container);
|
|
||||||
this.addDrawableChild(new SpruceButtonWidget(Position.of(this, this.width / 2 - 50, this.height - 30), 100, 20, SpruceTexts.GUI_DONE, btn -> this.close()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
|
|
||||||
super.render(drawContext, mouseX, mouseY, delta);
|
|
||||||
drawContext.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 10, 0xFFFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void rebuildKeyboard() {
|
|
||||||
this.container = new SpruceContainerWidget(Position.of(0, this.height / 4 - 10), this.width, this.height / 2);
|
|
||||||
|
|
||||||
|
|
||||||
var row1 = new String[]{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"};
|
|
||||||
var row2 = new String[]{"a", "s", "d", "f", "g", "h", "j", "k", "l"};
|
|
||||||
var row3 = new String[]{"z", "x", "c", "v", "b", "n", "m"};
|
|
||||||
|
|
||||||
addKeyRow(0, row1);
|
|
||||||
addKeyRow(1, row2);
|
|
||||||
addKeyRow(2, row3);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addKeyRow(int rowOffset, String... keys) {
|
|
||||||
int keyWidth = 20;
|
|
||||||
int spacing = 2;
|
|
||||||
int totalWidth = (keyWidth + spacing) * keys.length - spacing;
|
|
||||||
int startX = (this.width - totalWidth) / 2;
|
|
||||||
int y = this.height / 4 + rowOffset * 24;
|
|
||||||
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
|
||||||
String key = keys[i];
|
|
||||||
this.container.addChild(new SpruceButtonWidget(Position.of(startX + i * (keyWidth + spacing), y), keyWidth, 20, Text.literal(key), btn -> handleKeyPress(key)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleKeyPress(String key) {
|
|
||||||
if (this.client == null) return;
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
if (key.equals("\b")) {
|
|
||||||
if (!buffer.isEmpty()) {
|
|
||||||
buffer.deleteCharAt(buffer.length() - 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer.append(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.bufferDisplay != null) {
|
|
||||||
this.bufferDisplay.setText(buffer.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldPause() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
super.close();
|
|
||||||
if (closeCallback != null) {
|
|
||||||
closeCallback.onClose(buffer.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.block.entity.SignText;
|
|
||||||
import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(AbstractSignEditScreen.class)
|
|
||||||
public interface AbstractSignEditScreenAccessor {
|
|
||||||
@Accessor("text")
|
|
||||||
SignText midnightcontrols$getText();
|
|
||||||
|
|
||||||
@Accessor("text")
|
|
||||||
void midnightcontrols$setText(SignText text);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
|
||||||
import net.minecraft.client.util.SelectionManager;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
|
||||||
|
|
||||||
@Mixin(BookEditScreen.class)
|
|
||||||
public interface BookEditScreenAccessor {
|
|
||||||
@Accessor("signing")
|
|
||||||
boolean midnightcontrols$isSigning();
|
|
||||||
|
|
||||||
@Accessor("title")
|
|
||||||
String midnightcontrols$getTitle();
|
|
||||||
|
|
||||||
@Accessor("title")
|
|
||||||
void midnightcontrols$setTitle(String title);
|
|
||||||
|
|
||||||
@Accessor("currentPageSelectionManager")
|
|
||||||
SelectionManager midnightcontrols$getCurrentPageSelectionManager();
|
|
||||||
|
|
||||||
@Invoker("getCurrentPageContent")
|
|
||||||
String midnightcontrols$getCurrentPageContent();
|
|
||||||
|
|
||||||
@Invoker("setPageContent")
|
|
||||||
void midnightcontrols$setPageContent(String newContent);
|
|
||||||
}
|
|
||||||
@@ -77,7 +77,7 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V", shift = At.Shift.AFTER))
|
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V", shift = At.Shift.AFTER))
|
||||||
public void onInputUpdate(CallbackInfo ci) {
|
public void onInputUpdate(CallbackInfo ci) {
|
||||||
MovementHandler.HANDLER.applyMovement((ClientPlayerEntity) (Object) this);
|
MovementHandler.HANDLER.applyMovement((ClientPlayerEntity) (Object) this);
|
||||||
}
|
}
|
||||||
@@ -88,11 +88,11 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
|
|||||||
if (MidnightControlsConfig.verticalFlyDrifting || !MidnightControls.isExtrasLoaded)
|
if (MidnightControlsConfig.verticalFlyDrifting || !MidnightControls.isExtrasLoaded)
|
||||||
return;
|
return;
|
||||||
int moving = 0;
|
int moving = 0;
|
||||||
if (this.input.playerInput.sneak()) {
|
if (this.input.sneaking) {
|
||||||
--moving;
|
--moving;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.input.playerInput.jump()) {
|
if (this.input.jumping) {
|
||||||
++moving;
|
++moving;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,4 @@ public interface CreativeInventoryScreenAccessor {
|
|||||||
*/
|
*/
|
||||||
@Invoker("hasScrollbar")
|
@Invoker("hasScrollbar")
|
||||||
boolean midnightcontrols$hasScrollbar();
|
boolean midnightcontrols$hasScrollbar();
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers searching the creative inventory from the current value of the internal {@link net.minecraft.client.gui.widget.TextFieldWidget}
|
|
||||||
*/
|
|
||||||
@Invoker("search")
|
|
||||||
void midnightcontrols$search();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of midnightcontrols.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT license. For more information,
|
|
||||||
* see the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(DrawContext.class)
|
|
||||||
public interface DrawContextAccessor {
|
|
||||||
@Accessor("vertexConsumers")
|
|
||||||
VertexConsumerProvider.Immediate getVertexConsumers();
|
|
||||||
}
|
|
||||||
@@ -33,29 +33,22 @@ import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
|||||||
@Mixin(GameOptionsScreen.class)
|
@Mixin(GameOptionsScreen.class)
|
||||||
public abstract class GameOptionsScreenMixin extends Screen {
|
public abstract class GameOptionsScreenMixin extends Screen {
|
||||||
@Shadow @Nullable protected OptionListWidget body;
|
@Shadow @Nullable protected OptionListWidget body;
|
||||||
@Unique TextIconButtonWidget midnightcontrols$button = TextIconButtonWidget.builder(Text.translatable("midnightcontrols.menu.title.controller"),
|
@Unique TextIconButtonWidget midnightcontrols$button = TextIconButtonWidget.builder(Text.translatable("midnightcontrols.menu.title.controller"), (button -> this.client.setScreen(new MidnightControlsSettingsScreen(this, false))), true)
|
||||||
(button -> this.client.setScreen(new MidnightControlsSettingsScreen(this, false))), true)
|
|
||||||
.dimension(20,20).texture(id("icon/controller"), 20, 20).build();
|
.dimension(20,20).texture(id("icon/controller"), 20, 20).build();
|
||||||
|
|
||||||
protected GameOptionsScreenMixin(Text title) {
|
protected GameOptionsScreenMixin(Text title) {
|
||||||
super(title);
|
super(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "initBody", at = @At("TAIL"))
|
@Inject(method = "init", at = @At("TAIL"))
|
||||||
public void midnightcontrols$addMCButton(CallbackInfo ci) {
|
public void midnightcontrols$addMCButton(CallbackInfo ci) {
|
||||||
if (this.getClass().toString().equals(ControlsOptionsScreen.class.toString())) {
|
if (this.getClass().toString().equals(ControlsOptionsScreen.class.toString())) {
|
||||||
this.midnightcontrols$setButtonPos();
|
this.midnightcontrols$setButtonPos();
|
||||||
this.addSelectableChild(midnightcontrols$button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Inject(method = "init", at = @At("TAIL"))
|
|
||||||
public void midnightcontrols$drawMCButton(CallbackInfo ci) {
|
|
||||||
if (this.getClass().toString().equals(ControlsOptionsScreen.class.toString())) {
|
|
||||||
this.addDrawableChild(midnightcontrols$button);
|
this.addDrawableChild(midnightcontrols$button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "refreshWidgetPositions", at = @At("TAIL"))
|
@Inject(method = "initTabNavigation", at = @At("TAIL"))
|
||||||
public void midnightcontrols$onResize(CallbackInfo ci) {
|
public void midnightcontrols$onResize(CallbackInfo ci) {
|
||||||
this.midnightcontrols$setButtonPos();
|
this.midnightcontrols$setButtonPos();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ public abstract class MinecraftClientMixin {
|
|||||||
int previousStackCount = stackInHand.getCount();
|
int previousStackCount = stackInHand.getCount();
|
||||||
var result = this.interactionManager.interactBlock(this.player, hand, hitResult);
|
var result = this.interactionManager.interactBlock(this.player, hand, hitResult);
|
||||||
if (result.isAccepted()) {
|
if (result.isAccepted()) {
|
||||||
//if (result.shouldSwingHand()) {
|
if (result.shouldSwingHand()) {
|
||||||
this.player.swingHand(hand);
|
this.player.swingHand(hand);
|
||||||
if (!stackInHand.isEmpty() && (stackInHand.getCount() != previousStackCount || this.interactionManager.hasCreativeInventory())) {
|
if (!stackInHand.isEmpty() && (stackInHand.getCount() != previousStackCount || this.interactionManager.hasCreativeInventory())) {
|
||||||
this.gameRenderer.firstPersonRenderer.resetEquipProgress(hand);
|
this.gameRenderer.firstPersonRenderer.resetEquipProgress(hand);
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import net.minecraft.client.Mouse;
|
|||||||
import net.minecraft.client.util.GlfwUtil;
|
import net.minecraft.client.util.GlfwUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ThrowablePotionItem;
|
import net.minecraft.item.ThrowablePotionItem;
|
||||||
import net.minecraft.item.consume.UseAction;
|
import net.minecraft.util.UseAction;
|
||||||
import net.minecraft.util.math.Smoother;
|
import net.minecraft.util.math.Smoother;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of midnightcontrols.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT license. For more information,
|
|
||||||
* see the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.ingame.RecipeBookScreen;
|
|
||||||
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(RecipeBookScreen.class)
|
|
||||||
public interface RecipeBookScreenAccessor {
|
|
||||||
@Accessor("recipeBook")
|
|
||||||
RecipeBookWidget<?> getRecipeBook();
|
|
||||||
}
|
|
||||||
@@ -27,4 +27,7 @@ public interface RecipeBookWidgetAccessor {
|
|||||||
|
|
||||||
@Accessor("currentTab")
|
@Accessor("currentTab")
|
||||||
void setCurrentTab(RecipeGroupButtonWidget currentTab);
|
void setCurrentTab(RecipeGroupButtonWidget currentTab);
|
||||||
|
|
||||||
|
@Invoker("refreshResults")
|
||||||
|
void midnightcontrols$refreshResults(boolean resetCurrentPage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||||
import eu.midnightdust.midnightcontrols.ControlsMode;
|
import eu.midnightdust.midnightcontrols.ControlsMode;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
||||||
import eu.midnightdust.midnightcontrols.client.touch.TouchInput;
|
import eu.midnightdust.midnightcontrols.client.touch.TouchInput;
|
||||||
import eu.midnightdust.midnightcontrols.client.enums.TouchMode;
|
import eu.midnightdust.midnightcontrols.client.enums.TouchMode;
|
||||||
@@ -26,7 +28,8 @@ import net.minecraft.item.ItemUsageContext;
|
|||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.util.math.ColorHelper;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -58,8 +61,12 @@ public abstract class WorldRendererMixin {
|
|||||||
@Final
|
@Final
|
||||||
private BufferBuilderStorage bufferBuilders;
|
private BufferBuilderStorage bufferBuilders;
|
||||||
|
|
||||||
@Redirect(method = "renderTargetBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/BlockHitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"))
|
@Shadow
|
||||||
private HitResult.Type dontRenderOutline(BlockHitResult instance) {
|
private static void drawCuboidShapeOutline(MatrixStack matrices, VertexConsumer vertexConsumer, VoxelShape shape, double offsetX, double offsetY, double offsetZ, float red, float green, float blue, float alpha) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"))
|
||||||
|
private HitResult.Type dontRenderOutline(HitResult instance) {
|
||||||
if (MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN && MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
if (MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN && MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
||||||
return HitResult.Type.MISS;
|
return HitResult.Type.MISS;
|
||||||
}
|
}
|
||||||
@@ -67,10 +74,15 @@ public abstract class WorldRendererMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "renderTargetBlockOutline",
|
method = "render",
|
||||||
at = @At("HEAD")
|
at = @At(
|
||||||
|
value = "FIELD",
|
||||||
|
target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;",
|
||||||
|
ordinal = 1,
|
||||||
|
shift = At.Shift.AFTER
|
||||||
|
)
|
||||||
)
|
)
|
||||||
private void onOutlineRender(Camera camera, VertexConsumerProvider.Immediate vertexConsumers, MatrixStack matrices, boolean translucent, CallbackInfo ci) {
|
private void onOutlineRender(RenderTickCounter tickCounter, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci, @Local MatrixStack matrices) {
|
||||||
if (((MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.touchInControllerMode) || MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN)
|
if (((MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.touchInControllerMode) || MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN)
|
||||||
&& MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
&& MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
||||||
this.midnightcontrols$renderFingerOutline(matrices, camera);
|
this.midnightcontrols$renderFingerOutline(matrices, camera);
|
||||||
@@ -90,8 +102,8 @@ public abstract class WorldRendererMixin {
|
|||||||
var pos = camera.getPos();
|
var pos = camera.getPos();
|
||||||
matrices.push();
|
matrices.push();
|
||||||
var vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines());
|
var vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines());
|
||||||
VertexRendering.drawOutline(matrices, vertexConsumer, outlineShape, blockPos.getX() - pos.getX(), blockPos.getY() - pos.getY(), blockPos.getZ() - pos.getZ(),
|
drawCuboidShapeOutline(matrices, vertexConsumer, outlineShape, blockPos.getX() - pos.getX(), blockPos.getY() - pos.getY(), blockPos.getZ() - pos.getZ(),
|
||||||
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()));
|
rgb.getRed() / 255.f, rgb.getGreen() / 255.f, rgb.getBlue() / 255.f, MidnightControlsConfig.touchOutlineColorAlpha / 255.f);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,8 +134,9 @@ public abstract class WorldRendererMixin {
|
|||||||
if (MidnightControlsConfig.reacharoundOutlineColorHex.isEmpty()) rgb = RainbowColor.radialRainbow(1,1);
|
if (MidnightControlsConfig.reacharoundOutlineColorHex.isEmpty()) rgb = RainbowColor.radialRainbow(1,1);
|
||||||
matrices.push();
|
matrices.push();
|
||||||
var vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines());
|
var vertexConsumer = this.bufferBuilders.getEntityVertexConsumers().getBuffer(RenderLayer.getLines());
|
||||||
VertexRendering.drawOutline(matrices, vertexConsumer, outlineShape, blockPos.getX() - pos.getX(), blockPos.getY() - pos.getY(), blockPos.getZ() - pos.getZ(),
|
drawCuboidShapeOutline(matrices, vertexConsumer, outlineShape,
|
||||||
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()));
|
(double) blockPos.getX() - pos.getX(), (double) blockPos.getY() - pos.getY(), (double) blockPos.getZ() - pos.getZ(),
|
||||||
|
rgb.getRed() / 255.f, rgb.getGreen() / 255.f, rgb.getBlue() / 255.f, MidnightControlsConfig.reacharoundOutlineColorAlpha / 255.f);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,12 +85,12 @@ public class TouchInput {
|
|||||||
int previousStackCount = stackInHand.getCount();
|
int previousStackCount = stackInHand.getCount();
|
||||||
var interaction = client.interactionManager.interactBlock(client.player, client.player.getActiveHand(), blockHit);
|
var interaction = client.interactionManager.interactBlock(client.player, client.player.getActiveHand(), blockHit);
|
||||||
if (interaction.isAccepted()) {
|
if (interaction.isAccepted()) {
|
||||||
//if (interaction.shouldSwingHand()) {
|
if (interaction.shouldSwingHand()) {
|
||||||
client.player.swingHand(client.player.preferredHand);
|
client.player.swingHand(client.player.preferredHand);
|
||||||
if (!stackInHand.isEmpty() && (stackInHand.getCount() != previousStackCount || client.interactionManager.hasCreativeInventory())) {
|
if (!stackInHand.isEmpty() && (stackInHand.getCount() != previousStackCount || client.interactionManager.hasCreativeInventory())) {
|
||||||
client.gameRenderer.firstPersonRenderer.resetEquipProgress(client.player.preferredHand);
|
client.gameRenderer.firstPersonRenderer.resetEquipProgress(client.player.preferredHand);
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.client.render.Camera;
|
import net.minecraft.client.render.Camera;
|
||||||
import net.minecraft.entity.projectile.ProjectileUtil;
|
import net.minecraft.entity.projectile.ProjectileUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.consume.UseAction;
|
import net.minecraft.util.UseAction;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.touch.gui;
|
package eu.midnightdust.midnightcontrols.client.touch.gui;
|
||||||
|
|
||||||
import net.minecraft.item.consume.UseAction;
|
|
||||||
import org.thinkingstudio.obsidianui.Position;
|
import org.thinkingstudio.obsidianui.Position;
|
||||||
import org.thinkingstudio.obsidianui.widget.SpruceButtonWidget;
|
import org.thinkingstudio.obsidianui.widget.SpruceButtonWidget;
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
||||||
import net.minecraft.item.ArmorItem;
|
import net.minecraft.item.ArmorItem;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.UseAction;
|
||||||
|
|
||||||
public class ItemUseButtonWidget extends SpruceButtonWidget {
|
public class ItemUseButtonWidget extends SpruceButtonWidget {
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import net.minecraft.client.gui.screen.ChatScreen;
|
|||||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.item.ArmorItem;
|
import net.minecraft.item.ArmorItem;
|
||||||
import net.minecraft.item.consume.UseAction;
|
|
||||||
import net.minecraft.util.Arm;
|
import net.minecraft.util.Arm;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.UseAction;
|
||||||
import org.thinkingstudio.obsidianui.Position;
|
import org.thinkingstudio.obsidianui.Position;
|
||||||
import org.thinkingstudio.obsidianui.widget.SpruceButtonWidget;
|
import org.thinkingstudio.obsidianui.widget.SpruceButtonWidget;
|
||||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||||
|
|||||||
@@ -3,29 +3,25 @@
|
|||||||
"package": "eu.midnightdust.midnightcontrols.client.mixin",
|
"package": "eu.midnightdust.midnightcontrols.client.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"client": [
|
"client": [
|
||||||
"AdvancementsScreenAccessor",
|
|
||||||
"BookEditScreenAccessor",
|
|
||||||
"ChatScreenMixin",
|
|
||||||
"ClickableWidgetAccessor",
|
"ClickableWidgetAccessor",
|
||||||
|
"AdvancementsScreenAccessor",
|
||||||
"ClientPlayerEntityMixin",
|
"ClientPlayerEntityMixin",
|
||||||
"CreativeInventoryScreenAccessor",
|
|
||||||
"DrawContextAccessor",
|
|
||||||
"GameOptionsScreenMixin",
|
"GameOptionsScreenMixin",
|
||||||
|
"CreativeInventoryScreenAccessor",
|
||||||
"GameRendererMixin",
|
"GameRendererMixin",
|
||||||
"HandledScreenMixin",
|
"HandledScreenMixin",
|
||||||
"InputUtilMixin",
|
|
||||||
"KeyBindingIDAccessor",
|
|
||||||
"KeyBindingMixin",
|
"KeyBindingMixin",
|
||||||
"KeyboardMixin",
|
"InputUtilMixin",
|
||||||
"MinecraftClientMixin",
|
"MinecraftClientMixin",
|
||||||
"MouseAccessor",
|
|
||||||
"MouseMixin",
|
"MouseMixin",
|
||||||
"RecipeBookScreenAccessor",
|
"MouseAccessor",
|
||||||
|
"ChatScreenMixin",
|
||||||
"RecipeBookWidgetAccessor",
|
"RecipeBookWidgetAccessor",
|
||||||
"ScreenMixin",
|
"WorldRendererMixin",
|
||||||
"AbstractSignEditScreenAccessor",
|
"KeyBindingIDAccessor",
|
||||||
"TabNavigationWidgetAccessor",
|
"TabNavigationWidgetAccessor",
|
||||||
"WorldRendererMixin"
|
"ScreenMixin",
|
||||||
|
"KeyboardMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ dependencies {
|
|||||||
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric")
|
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric")
|
||||||
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric") {}
|
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric") {}
|
||||||
include 'org.aperlambda:lambdajcommon:1.8.1'
|
include 'org.aperlambda:lambdajcommon:1.8.1'
|
||||||
modCompileOnly "maven.modrinth:emi:${project.emi_version}"
|
modImplementation "maven.modrinth:emi:${project.emi_version}"
|
||||||
|
|
||||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||||
@@ -92,8 +92,7 @@ unifiedPublishing {
|
|||||||
curseforge {
|
curseforge {
|
||||||
token = CURSEFORGE_TOKEN
|
token = CURSEFORGE_TOKEN
|
||||||
id = rootProject.curseforge_id
|
id = rootProject.curseforge_id
|
||||||
gameVersions.addAll "Java 21", project.minecraft_version
|
gameVersions.addAll "Java 21", project.minecraft_version, project.supported_versions
|
||||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +102,7 @@ unifiedPublishing {
|
|||||||
token = MODRINTH_TOKEN
|
token = MODRINTH_TOKEN
|
||||||
id = rootProject.modrinth_id
|
id = rootProject.modrinth_id
|
||||||
version = "$project.version-$project.name"
|
version = "$project.version-$project.name"
|
||||||
gameVersions.addAll project.minecraft_version
|
gameVersions.addAll project.minecraft_version, project.supported_versions
|
||||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package eu.midnightdust.midnightcontrols.fabric;
|
|||||||
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
||||||
import eu.midnightdust.midnightcontrols.fabric.event.MouseClickListener;
|
|
||||||
import eu.midnightdust.midnightcontrols.packet.ControlsModePayload;
|
import eu.midnightdust.midnightcontrols.packet.ControlsModePayload;
|
||||||
import eu.midnightdust.midnightcontrols.packet.FeaturePayload;
|
import eu.midnightdust.midnightcontrols.packet.FeaturePayload;
|
||||||
import eu.midnightdust.midnightcontrols.packet.HelloPayload;
|
import eu.midnightdust.midnightcontrols.packet.HelloPayload;
|
||||||
@@ -12,12 +11,11 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
|||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
|
||||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents;
|
|
||||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||||
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
|
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
import org.thinkingstudio.obsidianui.fabric.event.OpenScreenCallback;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -53,9 +51,6 @@ public class MidnightControlsClientFabric implements ClientModInitializer {
|
|||||||
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> MidnightControlsClient.onLeave());
|
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> MidnightControlsClient.onLeave());
|
||||||
|
|
||||||
ClientTickEvents.START_CLIENT_TICK.register(MidnightControlsClient::onTick);
|
ClientTickEvents.START_CLIENT_TICK.register(MidnightControlsClient::onTick);
|
||||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
|
||||||
ScreenMouseEvents.allowMouseClick(screen).register(new MouseClickListener(screen));
|
|
||||||
});
|
|
||||||
|
|
||||||
FabricLoader.getInstance().getModContainer(MidnightControlsConstants.NAMESPACE).ifPresent(modContainer -> {
|
FabricLoader.getInstance().getModContainer(MidnightControlsConstants.NAMESPACE).ifPresent(modContainer -> {
|
||||||
ResourceManagerHelper.registerBuiltinResourcePack(id("bedrock"), modContainer, ResourcePackActivationType.NORMAL);
|
ResourceManagerHelper.registerBuiltinResourcePack(id("bedrock"), modContainer, ResourcePackActivationType.NORMAL);
|
||||||
|
|||||||
@@ -1,218 +0,0 @@
|
|||||||
package eu.midnightdust.midnightcontrols.fabric.event;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.gui.VirtualKeyboardScreen;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.AbstractSignEditScreenAccessor;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.BookEditScreenAccessor;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.CreativeInventoryScreenAccessor;
|
|
||||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents;
|
|
||||||
import net.minecraft.block.entity.SignText;
|
|
||||||
import net.minecraft.client.gui.Element;
|
|
||||||
import net.minecraft.client.gui.ParentElement;
|
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
|
||||||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
|
||||||
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
|
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.MidnightControls.logger;
|
|
||||||
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
|
||||||
|
|
||||||
record ScreenLink(Screen screen, List<Integer> elementPath) {}
|
|
||||||
|
|
||||||
public class MouseClickListener implements ScreenMouseEvents.AllowMouseClick {
|
|
||||||
private final Screen screen;
|
|
||||||
|
|
||||||
private ScreenLink link;
|
|
||||||
|
|
||||||
public MouseClickListener(Screen screen) {
|
|
||||||
this.screen = screen;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean allowMouseClick(Screen screen, double mouseX, double mouseY, int button) {
|
|
||||||
interceptMouseClick(screen, mouseX, mouseY);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void interceptMouseClick(Screen screen, double mouseX, double mouseY) {
|
|
||||||
logger.info("In scr: {}", screen.getClass());
|
|
||||||
switch(screen) {
|
|
||||||
case BookEditScreen bookEditScreen -> {
|
|
||||||
if(screen.hoveredElement(mouseX, mouseY).isPresent()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleBookEditScreenClick(bookEditScreen);
|
|
||||||
}
|
|
||||||
case SignEditScreen signEditScreen -> {
|
|
||||||
if(screen.hoveredElement(mouseX, mouseY).isPresent()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleSignEditScreenClick(signEditScreen);
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
var textField = findClickedTextField(screen, mouseX, mouseY);
|
|
||||||
if (textField == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleTextFieldClick(textField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add equals and hashCode to prevent duplicate registrations
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj instanceof MouseClickListener) {
|
|
||||||
return ((MouseClickListener) obj).screen == this.screen;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return screen.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// handlers
|
|
||||||
|
|
||||||
private void handleBookEditScreenClick(BookEditScreen bookEditScreen) {
|
|
||||||
var accessor = (BookEditScreenAccessor) screen;
|
|
||||||
|
|
||||||
VirtualKeyboardScreen virtualKeyboardScreen;
|
|
||||||
if(accessor.midnightcontrols$isSigning()) {
|
|
||||||
virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getTitle(), (text) -> {
|
|
||||||
client.setScreen(bookEditScreen);
|
|
||||||
accessor.midnightcontrols$setTitle(text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getCurrentPageContent(), (text) -> {
|
|
||||||
client.setScreen(bookEditScreen);
|
|
||||||
accessor.midnightcontrols$setPageContent(text);
|
|
||||||
accessor.midnightcontrols$getCurrentPageSelectionManager().putCursorAtEnd();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setScreen(virtualKeyboardScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleSignEditScreenClick(SignEditScreen signEditScreen) {
|
|
||||||
var accessor = (AbstractSignEditScreenAccessor) signEditScreen;
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleTextFieldClick(TextFieldWidget textField) {
|
|
||||||
this.link = new ScreenLink(screen, calculatePathToElement(screen, textField));
|
|
||||||
var virtualKeyboardScreen = new VirtualKeyboardScreen(textField.getText(), this::handleKeyboardClose);
|
|
||||||
client.setScreen(virtualKeyboardScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleKeyboardClose(String newText) {
|
|
||||||
if(this.link == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setScreen(this.link.screen());
|
|
||||||
var txtField = findTextFieldByPath(screen, this.link.elementPath());
|
|
||||||
if (txtField == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
txtField.setText(newText);
|
|
||||||
|
|
||||||
|
|
||||||
switch (this.link.screen()) {
|
|
||||||
case CreativeInventoryScreen creativeInventoryScreen -> {
|
|
||||||
var accessor = (CreativeInventoryScreenAccessor) creativeInventoryScreen;
|
|
||||||
accessor.midnightcontrols$search();
|
|
||||||
}
|
|
||||||
case ChatScreen chatScreen -> {
|
|
||||||
// send the chat message
|
|
||||||
chatScreen.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
|
|
||||||
}
|
|
||||||
default -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// utility
|
|
||||||
|
|
||||||
private TextFieldWidget findClickedTextField(Screen screen, double mouseX, double mouseY) {
|
|
||||||
for (Element element : screen.children()) {
|
|
||||||
if (element instanceof TextFieldWidget textField) {
|
|
||||||
if (textField.isMouseOver(mouseX, mouseY) && textField.isFocused()) {
|
|
||||||
return textField;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// not hovering over a text field
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the path between a parent and a target in the UI hierarchy
|
|
||||||
*/
|
|
||||||
private List<Integer> calculatePathToElement(Element parent, Element target) {
|
|
||||||
if (parent instanceof ParentElement parentElement) {
|
|
||||||
List<? extends Element> children = parentElement.children();
|
|
||||||
|
|
||||||
// check direct children first
|
|
||||||
for (int i = 0; i < children.size(); i++) {
|
|
||||||
if (children.get(i) == target) {
|
|
||||||
// found it, return the path to this element
|
|
||||||
return Collections.singletonList(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check each child's children
|
|
||||||
for (int i = 0; i < children.size(); i++) {
|
|
||||||
if (children.get(i) instanceof ParentElement childParent) {
|
|
||||||
List<Integer> subPath = calculatePathToElement(childParent, target);
|
|
||||||
if (subPath != null) {
|
|
||||||
// found in this subtree, prepend current index
|
|
||||||
List<Integer> fullPath = new ArrayList<>();
|
|
||||||
fullPath.add(i);
|
|
||||||
fullPath.addAll(subPath);
|
|
||||||
return fullPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not found
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TextFieldWidget findTextFieldByPath(Element parent, List<Integer> path) {
|
|
||||||
if (path == null || path.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent instanceof ParentElement parentElement) {
|
|
||||||
List<? extends Element> children = parentElement.children();
|
|
||||||
int index = path.getFirst();
|
|
||||||
|
|
||||||
if (index >= 0 && index < children.size()) {
|
|
||||||
Element child = children.get(index);
|
|
||||||
|
|
||||||
if (path.size() == 1) {
|
|
||||||
// This should be our target
|
|
||||||
return (child instanceof TextFieldWidget) ? (TextFieldWidget) child : null;
|
|
||||||
} else {
|
|
||||||
// Continue traversing
|
|
||||||
if (child instanceof ParentElement) {
|
|
||||||
return findTextFieldByPath(child, path.subList(1, path.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,34 +2,34 @@
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
org.gradle.jvmargs=-Xmx2048M
|
org.gradle.jvmargs=-Xmx2048M
|
||||||
|
|
||||||
minecraft_version=1.21.4
|
minecraft_version=1.21
|
||||||
supported_versions=
|
supported_versions=1.21.1
|
||||||
yarn_mappings=1.21.4+build.1
|
yarn_mappings=1.21+build.2
|
||||||
enabled_platforms=fabric,neoforge
|
enabled_platforms=fabric,neoforge
|
||||||
|
|
||||||
archives_base_name=midnightcontrols
|
archives_base_name=midnightcontrols
|
||||||
mod_version=1.10.5
|
mod_version=1.10.0.1
|
||||||
maven_group=eu.midnightdust
|
maven_group=eu.midnightdust
|
||||||
release_type=release
|
release_type=beta
|
||||||
modrinth_id = bXX9h73M
|
modrinth_id = bXX9h73M
|
||||||
curseforge_id = 621768
|
curseforge_id = 621768
|
||||||
# Configure the IDs here after creating the projects on the websites
|
# Configure the IDs here after creating the projects on the websites
|
||||||
|
|
||||||
midnightlib_version=1.6.8+1.21.4
|
midnightlib_version=1.6.3
|
||||||
|
|
||||||
fabric_loader_version=0.16.9
|
fabric_loader_version=0.15.11
|
||||||
fabric_api_version=0.110.5+1.21.4
|
fabric_api_version=0.100.1+1.21
|
||||||
|
|
||||||
neoforge_version=21.4.9-beta
|
neoforge_version=21.0.14-beta
|
||||||
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
||||||
|
|
||||||
quilt_loader_version=0.19.0-beta.18
|
quilt_loader_version=0.19.0-beta.18
|
||||||
quilt_fabric_api_version=7.0.1+0.83.0-1.20
|
quilt_fabric_api_version=7.0.1+0.83.0-1.20
|
||||||
|
|
||||||
sodium_version=mc1.21-0.6.0-beta.1
|
sodium_version=mc1.21-0.6.0-beta.1
|
||||||
obsidianui_version=0.2.10+mc1.21.3
|
obsidianui_version=0.2.7+mc1.21
|
||||||
modmenu_version=10.0.0-beta.1
|
modmenu_version=10.0.0-beta.1
|
||||||
emotecraft_version=2.5.5+1.21.4-fabric
|
emotecraft_version=2.1.3-SNAPSHOT-build.29-MC1.19-fabric
|
||||||
bendylib_version=2.0.+
|
bendylib_version=2.0.+
|
||||||
emi_version=1.1.10+1.21+fabric
|
emi_version=1.1.10+1.21+fabric
|
||||||
libgui_version=6.0.0+1.19
|
libgui_version=6.0.0+1.19
|
||||||
|
|||||||
@@ -104,8 +104,7 @@ unifiedPublishing {
|
|||||||
curseforge {
|
curseforge {
|
||||||
token = CURSEFORGE_TOKEN
|
token = CURSEFORGE_TOKEN
|
||||||
id = rootProject.curseforge_id
|
id = rootProject.curseforge_id
|
||||||
gameVersions.addAll "Java 21", project.minecraft_version
|
gameVersions.addAll "Java 21", project.minecraft_version, project.supported_versions
|
||||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,8 +114,7 @@ unifiedPublishing {
|
|||||||
token = MODRINTH_TOKEN
|
token = MODRINTH_TOKEN
|
||||||
id = rootProject.modrinth_id
|
id = rootProject.modrinth_id
|
||||||
version = "$project.version-$project.name"
|
version = "$project.version-$project.name"
|
||||||
gameVersions.addAll project.minecraft_version
|
gameVersions.addAll project.minecraft_version, project.supported_versions
|
||||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package eu.midnightdust.midnightcontrols.client.util.platform.neoforge;
|
|||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.network.packet.CustomPayload;
|
import net.minecraft.network.packet.CustomPayload;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
||||||
|
|
||||||
@@ -19,12 +19,7 @@ public class NetworkUtilImpl {
|
|||||||
handler.send(packet);
|
handler.send(packet);
|
||||||
}
|
}
|
||||||
public static void sendPayloadC2S(CustomPayload payload) {
|
public static void sendPayloadC2S(CustomPayload payload) {
|
||||||
if (handler != null && client.world != null) {
|
if (handler != null && client.world != null && handler.hasChannel(payload.getId().id()))
|
||||||
try {
|
PacketDistributor.sendToServer(payload);
|
||||||
handler.send(new CustomPayloadC2SPacket(payload));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.fillInStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user