port: Mounts of Mayham (1.21.11)

This commit is contained in:
Martin Prokoph
2025-12-11 16:27:12 +01:00
parent d668707300
commit 381d715fa8
13 changed files with 54 additions and 54 deletions

View File

@@ -12,7 +12,7 @@ package eu.midnightdust.midnightcontrols;
import net.minecraft.text.Text;
import net.minecraft.text.object.AtlasTextObjectContents;
import net.minecraft.util.Atlases;
import net.minecraft.util.TranslatableOption;
import net.minecraft.util.StringIdentifiable;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@@ -27,7 +27,7 @@ import static eu.midnightdust.midnightcontrols.MidnightControls.id;
* @version 1.7.0
* @since 1.0.0
*/
public enum ControlsMode implements TranslatableOption {
public enum ControlsMode implements StringIdentifiable {
DEFAULT("icon/keyboard_mouse"),
CONTROLLER("icon/controller"),
TOUCHSCREEN("icon/touchscreen");
@@ -49,15 +49,10 @@ public enum ControlsMode implements TranslatableOption {
return v[this.ordinal() + 1];
}
@Override
public int getId() {
return this.ordinal();
}
@Override
public Text getText() {
return Text.object(new AtlasTextObjectContents(Atlases.GUI, id(emoji))).append(" ").append(Text.translatable(getTranslationKey()));
}
// @Override
// public Text getText() {
// return Text.object(new AtlasTextObjectContents(Atlases.GUI, id(emoji))).append(" ").append(Text.translatable(getTranslationKey()));
// }
/**
* Gets the translation key of this controls mode.
@@ -83,4 +78,9 @@ public enum ControlsMode implements TranslatableOption {
public static Optional<ControlsMode> byId(@NotNull String id) {
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst();
}
@Override
public String asString() {
return getTranslationKey();
}
}

View File

@@ -204,7 +204,7 @@ public class MidnightControlsClient extends MidnightControls {
client = MinecraftClient.getInstance();
if (screen == null && MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN) {
screen = new TouchscreenOverlay();
screen.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
screen.init(client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
client.skipGameRender = false;
client.currentScreen = screen;
} else if (screen != null) {

View File

@@ -94,9 +94,9 @@ public class InputHandlers {
nextTab = tabs.size() - 1;
else if (nextTab >= tabs.size())
nextTab = 0;
currentTab.setToggled(false);
currentTab.active = false;
recipeBookAccessor.setCurrentTab(currentTab = tabs.get(nextTab));
currentTab.setToggled(true);
currentTab.active = true;
recipeBookScreen.refreshRecipeBook();
return true;
} else if (client.currentScreen instanceof AdvancementsScreenAccessor screen) {

View File

@@ -221,7 +221,7 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
this.resetOption = SpruceSimpleActionOption.reset(btn -> {
MidnightControlsConfig.reset();
var client = MinecraftClient.getInstance();
this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
this.init(client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
});
// Gameplay options
this.analogMovementOption = new SpruceToggleBooleanOption("midnightcontrols.menu.analog_movement",

View File

@@ -33,7 +33,7 @@ public class ReloadControllerMappingsOption {
before.accept(btn);
Controller.updateMappings();
if (client.currentScreen instanceof MidnightControlsSettingsScreen)
client.currentScreen.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
client.currentScreen.init(client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
client.getToastManager().add(SystemToast.create(client, SystemToast.Type.PERIODIC_NOTIFICATION,
Text.translatable("midnightcontrols.controller.mappings.updated"), Text.empty()));
}, TooltipData.builder().text(Text.translatable("midnightcontrols.tooltip.reload_controller_mappings")).build());

View File

@@ -11,7 +11,7 @@ import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
import eu.midnightdust.midnightcontrols.client.gui.MidnightControlsRenderer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.font.DrawnTextConsumer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
@@ -36,7 +36,7 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
public static void add(ButtonBinding binding, MidnightConfigListWidget list, MidnightConfigScreen screen) {
ControllerBindingButton editButton = new ControllerBindingButton(screen.width - 185 + 22, 0, 128, 20, binding);
TextIconButtonWidget resetButton = TextIconButtonWidget.builder(Text.translatable("controls.reset"), (button -> {
TextIconButtonWidget resetButton = TextIconButtonWidget.builder(net.minecraft.text.Text.translatable("controls.reset"), (button -> {
MidnightControlsConfig.setButtonBinding(binding, binding.getDefaultButton());
MidnightControlsClient.input.beginControlsInput(null);
editButton.updateMessage(false);
@@ -46,7 +46,7 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
editButton.updateMessage(false);
EntryInfo info = new EntryInfo(null, screen.modid);
TextIconButtonWidget unbindButton = TextIconButtonWidget.builder(Text.translatable("midnightcontrols.narrator.unbound", binding.getText()), (button -> {
TextIconButtonWidget unbindButton = TextIconButtonWidget.builder(net.minecraft.text.Text.translatable("midnightcontrols.narrator.unbound", binding.getText()), (button -> {
MidnightControlsConfig.setButtonBinding(binding, UNBOUND);
MidnightControlsClient.input.beginControlsInput(null);
editButton.updateMessage(false);
@@ -56,7 +56,7 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
unbindButton.active = !binding.isNotBound();
editButton.unbindButton = unbindButton;
list.addButton(Lists.newArrayList(editButton, resetButton, unbindButton), Text.translatable(binding.getTranslationKey()), info);
list.addButton(Lists.newArrayList(editButton, resetButton, unbindButton), net.minecraft.text.Text.translatable(binding.getTranslationKey()), info);
}
private final ButtonBinding binding;
@@ -64,7 +64,7 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
private @Nullable ClickableWidget unbindButton;
public ControllerBindingButton(int x, int y, int width, int height, ButtonBinding binding) {
super(x, y, width, height, binding.getText(), (button) -> {},
(textSupplier) -> binding.isNotBound() ? Text.translatable("narrator.controls.unbound", binding.getTranslationKey()) : Text.translatable("narrator.controls.bound", binding.getTranslationKey(), textSupplier.get()));
(textSupplier) -> binding.isNotBound() ? net.minecraft.text.Text.translatable("narrator.controls.unbound", binding.getTranslationKey()) : net.minecraft.text.Text.translatable("narrator.controls.bound", binding.getTranslationKey(), textSupplier.get()));
this.binding = binding;
updateMessage(false);
}
@@ -78,8 +78,8 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
public void updateMessage(boolean focused) {
AtomicBoolean hasConflicts = new AtomicBoolean(false);
MutableText conflictingBindings = Text.empty();
if (focused) this.setMessage(Text.literal("> ").append(getTranslatedButtons().copy().formatted(Formatting.WHITE, Formatting.UNDERLINE)).append(" <").formatted(Formatting.YELLOW));
MutableText conflictingBindings = net.minecraft.text.Text.empty();
if (focused) this.setMessage(net.minecraft.text.Text.literal("> ").append(getTranslatedButtons().copy().formatted(Formatting.WHITE, Formatting.UNDERLINE)).append(" <").formatted(Formatting.YELLOW));
else {
this.setMessage(getTranslatedButtons());
@@ -89,7 +89,7 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
if (hasConflicts.get()) conflictingBindings.append(", ");
hasConflicts.set(true);
conflictingBindings.append(Text.translatable(keyBinding.getTranslationKey()));
conflictingBindings.append(net.minecraft.text.Text.translatable(keyBinding.getTranslationKey()));
}
});
}
@@ -99,26 +99,25 @@ public class ControllerBindingButton extends ButtonWidget implements ControlsInp
if (this.unbindButton != null) this.unbindButton.active = !binding.isNotBound();
if (hasConflicts.get()) {
this.setMessage(Text.literal("[ ").append(this.getMessage().copy().formatted(Formatting.WHITE)).append(" ]").formatted(Formatting.RED));
this.setTooltip(Tooltip.of(Text.translatable("controls.keybinds.duplicateKeybinds", conflictingBindings)));
this.setMessage(net.minecraft.text.Text.literal("[ ").append(this.getMessage().copy().formatted(Formatting.WHITE)).append(" ]").formatted(Formatting.RED));
this.setTooltip(Tooltip.of(net.minecraft.text.Text.translatable("controls.keybinds.duplicateKeybinds", conflictingBindings)));
} else {
this.setTooltip(null);
}
}
private Text getTranslatedButtons() {
private net.minecraft.text.Text getTranslatedButtons() {
return this.binding.isNotBound() ? SpruceTexts.NOT_BOUND.copy() :
(binding.getButton().length > 0 ? ButtonBinding.getLocalizedButtonName(binding.getButton()[0]) : Text.literal("..."));
(binding.getButton().length > 0 ? ButtonBinding.getLocalizedButtonName(binding.getButton()[0]) : net.minecraft.text.Text.literal("..."));
}
@Override
public void drawMessage(DrawContext context, TextRenderer textRenderer, int color) {
if (this.binding.getButton().length < 2) super.drawMessage(context, textRenderer, color);
public void drawLabel(DrawnTextConsumer consumer) {
if (this.binding.getButton().length < 2) super.drawLabel(consumer);
}
@Override
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
super.renderWidget(context, mouseX, mouseY, deltaTicks);
protected void drawIcon(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
int x = this.getX();
if (this.binding.getButton().length > 1) {
x += (this.width / 2 - iconWidth / 2) - 4;

View File

@@ -19,6 +19,7 @@ public abstract class CursorRenderer {
public static void drawUnalignedTexturedQuad(RenderPipeline pipeline, Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float u1, float u2, float v1, float v2) {
DrawContextAccessor accessor = (DrawContextAccessor) context;
accessor.getState().addSimpleElement(new UnalignedTexturedQuadGuiElementRenderState(pipeline, TextureSetup.withoutGlTexture(client.getTextureManager().getTexture(texture).getGlTextureView()), new Matrix3x2f(context.getMatrices()), x1, y1, x2, y2, u1, u2, v1, v2, 0xffffffff, accessor.getScissorStack().peekLast()));
var tex = client.getTextureManager().getTexture(texture);
accessor.getState().addSimpleElement(new UnalignedTexturedQuadGuiElementRenderState(pipeline, TextureSetup.of(tex.getGlTextureView(), tex.getSampler()), new Matrix3x2f(context.getMatrices()), x1, y1, x2, y2, u1, u2, v1, v2, 0xffffffff, accessor.getScissorStack().peekLast()));
}
}

View File

@@ -28,11 +28,11 @@ public abstract class ScreenMixin {
@Shadow public int width;
@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At("TAIL"))
public void midnightcontrols$addCloseButton(MinecraftClient client, int width, int height, CallbackInfo ci) {
@Inject(method = "init(II)V", at = @At("TAIL"))
public void midnightcontrols$addCloseButton(int width, int height, CallbackInfo ci) {
if (MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN && (MidnightControlsConfig.closeButtonScreens.stream().anyMatch(s -> this.getClass().getName().startsWith(s) || ((Object)this) instanceof HandledScreen<?>))) {
this.addDrawableChild(new SilentTexturedButtonWidget(Position.of(this.width - 30, 10), 20, 20, Text.empty(), btn ->
InputHandlers.handleExit().press(client, ButtonBinding.BACK, 0f, ButtonState.PRESS), 20, 160, 20, WIDGETS_LOCATION));
InputHandlers.handleExit().press(MinecraftClient.getInstance(), ButtonBinding.BACK, 0f, ButtonState.PRESS), 20, 160, 20, WIDGETS_LOCATION));
}
}
}

View File

@@ -77,11 +77,11 @@ public abstract class WorldRendererMixin {
var outlineShape = this.world.getBlockState(blockPos).getOutlineShape(this.client.world, blockPos, ShapeContext.of(camera.getFocusedEntity()));
Color rgb = MidnightColorUtil.hex2Rgb(MidnightControlsConfig.touchOutlineColorHex);
if (MidnightControlsConfig.touchOutlineColorHex.isEmpty()) rgb = RainbowColor.radialRainbow(1,1);
var pos = camera.getPos();
var pos = camera.getCameraPos();
matrices.push();
var vertexConsumer = immediate.getBuffer(RenderLayer.getLines());
var vertexConsumer = immediate.getBuffer(RenderLayers.lines());
VertexRendering.drawOutline(matrices, vertexConsumer, outlineShape, blockPos.getX() - pos.getX(), blockPos.getY() - pos.getY(), blockPos.getZ() - pos.getZ(),
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()));
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()), 4);
matrices.pop();
}
}
@@ -105,15 +105,15 @@ public abstract class WorldRendererMixin {
var placementState = block.getPlacementState(context);
if (placementState == null)
return;
var pos = camera.getPos();
var pos = camera.getCameraPos();
var outlineShape = placementState.getOutlineShape(this.client.world, blockPos, ShapeContext.of(camera.getFocusedEntity()));
Color rgb = MidnightColorUtil.hex2Rgb(MidnightControlsConfig.reacharoundOutlineColorHex);
if (MidnightControlsConfig.reacharoundOutlineColorHex.isEmpty()) rgb = RainbowColor.radialRainbow(1,1);
matrices.push();
var vertexConsumer = immediate.getBuffer(RenderLayer.getLines());
var vertexConsumer = immediate.getBuffer(RenderLayers.lines());
VertexRendering.drawOutline(matrices, vertexConsumer, outlineShape, blockPos.getX() - pos.getX(), blockPos.getY() - pos.getY(), blockPos.getZ() - pos.getZ(),
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()));
ColorHelper.withAlpha(MidnightControlsConfig.touchOutlineColorAlpha, rgb.getRGB()), 4);
matrices.pop();
}
}

View File

@@ -62,7 +62,7 @@ public class TouchUtils {
.unproject((float) x / displayWidth * viewport[2],
(float) (displayHeight - y) / displayHeight * viewport[3], (float) d, viewport, target);
return new Vec3d(target.x, target.y, target.z).add(camera.getPos());
return new Vec3d(target.x, target.y, target.z).add(camera.getCameraPos());
}
public static boolean hasInWorldUseAction(ItemStack stack) {