mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 07:15:10 +01:00
✨ Add front block placing and clean up the code.
This commit is contained in:
@@ -54,7 +54,7 @@ dependencies {
|
||||
//modCompile "io.github.cottonmc:cotton-client-commands:0.4.2+1.14.3-SNAPSHOT"
|
||||
|
||||
// Compatibility mods
|
||||
modCompile "io.github.joaoh1:okzoomer:1.0.3"
|
||||
modCompile "io.github.joaoh1:okzoomer:2.0.1"
|
||||
|
||||
api project(":common")
|
||||
include project(":common")
|
||||
|
||||
@@ -30,6 +30,8 @@ import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.aperlambda.lambdacommon.utils.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@@ -32,14 +32,19 @@ import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y;
|
||||
*/
|
||||
public class LambdaControlsConfig
|
||||
{
|
||||
private static final ControlsMode DEFAULT_CONTROLS_MODE = ControlsMode.DEFAULT;
|
||||
private static final boolean DEFAULT_AUTO_SWITCH_MODE = false;
|
||||
private static final boolean DEFAULT_HUD_ENABLE = true;
|
||||
private static final HudSide DEFAULT_HUD_SIDE = HudSide.LEFT;
|
||||
private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT;
|
||||
private static final double DEFAULT_DEAD_ZONE = 0.25;
|
||||
private static final double DEFAULT_ROTATION_SPEED = 40.0;
|
||||
private static final double DEFAULT_MOUSE_SPEED = 25.0;
|
||||
// General
|
||||
private static final ControlsMode DEFAULT_CONTROLS_MODE = ControlsMode.DEFAULT;
|
||||
private static final boolean DEFAULT_AUTO_SWITCH_MODE = false;
|
||||
// HUD
|
||||
private static final boolean DEFAULT_HUD_ENABLE = true;
|
||||
private static final HudSide DEFAULT_HUD_SIDE = HudSide.LEFT;
|
||||
// Gameplay
|
||||
private static final boolean DEFAULT_FRONT_BLOCK_PLACING = false;
|
||||
// Controller
|
||||
private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT;
|
||||
private static final double DEFAULT_DEAD_ZONE = 0.25;
|
||||
private static final double DEFAULT_ROTATION_SPEED = 40.0;
|
||||
private static final double DEFAULT_MOUSE_SPEED = 25.0;
|
||||
|
||||
private static final Pattern BUTTON_BINDING_PATTERN = Pattern.compile("(-?\\d+)\\+?");
|
||||
|
||||
@@ -110,10 +115,15 @@ public class LambdaControlsConfig
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
// General
|
||||
this.set_controls_mode(DEFAULT_CONTROLS_MODE);
|
||||
this.set_auto_switch_mode(DEFAULT_AUTO_SWITCH_MODE);
|
||||
// HUD
|
||||
this.set_hud_enabled(DEFAULT_HUD_ENABLE);
|
||||
this.set_hud_side(DEFAULT_HUD_SIDE);
|
||||
// Gameplay
|
||||
this.set_front_block_placing(DEFAULT_FRONT_BLOCK_PLACING);
|
||||
// Controller
|
||||
this.set_controller_type(DEFAULT_CONTROLLER_TYPE);
|
||||
this.set_dead_zone(DEFAULT_DEAD_ZONE);
|
||||
this.set_rotation_speed(DEFAULT_ROTATION_SPEED);
|
||||
@@ -164,6 +174,10 @@ public class LambdaControlsConfig
|
||||
this.config.set("auto_switch_mode", auto_switch_mode);
|
||||
}
|
||||
|
||||
/*
|
||||
HUD settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns whether the HUD is enabled.
|
||||
*
|
||||
@@ -206,6 +220,34 @@ public class LambdaControlsConfig
|
||||
this.config.set("hud.side", hud_side.get_name());
|
||||
}
|
||||
|
||||
/*
|
||||
Gameplay settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns whether front block placing is enabled or not.
|
||||
*
|
||||
* @return True if front block placing is enabled, else false.
|
||||
*/
|
||||
public boolean has_front_block_placing()
|
||||
{
|
||||
return this.config.getOrElse("gameplay.front_block_placing", DEFAULT_FRONT_BLOCK_PLACING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether front block placing is enabled or not.
|
||||
*
|
||||
* @param enable True if front block placing is enabled, else false.
|
||||
*/
|
||||
public void set_front_block_placing(boolean enable)
|
||||
{
|
||||
this.config.set("gameplay.front_block_placing", enable);
|
||||
}
|
||||
|
||||
/*
|
||||
Controller settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the used controller.
|
||||
*
|
||||
|
||||
@@ -170,7 +170,7 @@ public class LambdaInput
|
||||
double mouse_x = this.prev_target_mouse_x + (this.target_mouse_x - this.prev_target_mouse_x) * client.getTickDelta() + 0.5;
|
||||
double mouse_y = this.prev_target_mouse_y + (this.target_mouse_y - this.prev_target_mouse_y) * client.getTickDelta() + 0.5;
|
||||
GLFW.glfwSetCursorPos(client.getWindow().getHandle(), mouse_x, mouse_y);
|
||||
((MouseAccessor) client.mouse).on_cursor_pos(client.getWindow().getHandle(), mouse_x, mouse_y);
|
||||
((MouseAccessor) client.mouse).lambdacontrols_on_cursor_pos(client.getWindow().getHandle(), mouse_x, mouse_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ public class LambdaInput
|
||||
if (client.currentScreen instanceof AbstractContainerScreen && client.interactionManager != null && client.player != null) {
|
||||
double pos_x = client.mouse.getX() * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth();
|
||||
double pos_y = client.mouse.getY() * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight();
|
||||
Slot slot = ((AbstractContainerScreenAccessor) client.currentScreen).get_slot_at(pos_x, pos_y);
|
||||
Slot slot = ((AbstractContainerScreenAccessor) client.currentScreen).lambdacontrols_get_slot_at(pos_x, pos_y);
|
||||
if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && slot != null) {
|
||||
client.interactionManager.clickSlot(((AbstractContainerScreen) client.currentScreen).getContainer().syncId, slot.id, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player);
|
||||
this.action_gui_cooldown = 5;
|
||||
@@ -527,7 +527,7 @@ public class LambdaInput
|
||||
this.action_gui_cooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks.
|
||||
return false;
|
||||
} else if (element instanceof AlwaysSelectedEntryListWidget) {
|
||||
((EntryListWidgetAccessor) element).move_selection(right ? 1 : -1);
|
||||
((EntryListWidgetAccessor) element).lambdacontrols_move_selection(right ? 1 : -1);
|
||||
return false;
|
||||
} else if (element instanceof ParentElement) {
|
||||
ParentElement entry_list = (ParentElement) element;
|
||||
@@ -597,8 +597,8 @@ public class LambdaInput
|
||||
if (screen instanceof AbstractContainerScreen) {
|
||||
AbstractContainerScreen inventory_screen = (AbstractContainerScreen) screen;
|
||||
AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) inventory_screen;
|
||||
int gui_left = accessor.get_x();
|
||||
int gui_top = accessor.get_y();
|
||||
int gui_left = accessor.lambdacontrols_get_x();
|
||||
int gui_top = accessor.lambdacontrols_get_y();
|
||||
int mouse_x = (int) (target_mouse_x * (double) client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth());
|
||||
int mouse_y = (int) (target_mouse_y * (double) client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight());
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
package me.lambdaurora.lambdacontrols.client.compat;
|
||||
|
||||
import io.github.joaoh1.okzoomer.OkZoomer;
|
||||
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
||||
import me.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
|
||||
import me.lambdaurora.lambdacontrols.client.controller.InputManager;
|
||||
@@ -31,12 +32,8 @@ public class OkZoomerCompat implements CompatHandler
|
||||
@Override
|
||||
public void handle(@NotNull LambdaControlsClient mod)
|
||||
{
|
||||
LambdaReflection.get_first_field_of_type(io.github.joaoh1.okzoomer.OkZoomer.class, FabricKeyBinding.class)
|
||||
.map(field -> (FabricKeyBinding) LambdaReflection.get_field_value(null, field))
|
||||
.ifPresent(zoom_key_binding -> {
|
||||
ButtonBinding binding = InputManager.register_binding(new ButtonBinding("zoom", new int[]{GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X}, true));
|
||||
binding.set_key_binding(zoom_key_binding);
|
||||
ButtonBinding.MISC_CATEGORY.register_binding(binding);
|
||||
});
|
||||
ButtonBinding binding = InputManager.register_binding(new ButtonBinding("zoom", new int[]{GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X}, true));
|
||||
binding.set_key_binding(OkZoomer.zoomKeyBinding);
|
||||
ButtonBinding.MISC_CATEGORY.register_binding(binding);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
package me.lambdaurora.lambdacontrols.client.controller;
|
||||
|
||||
import me.lambdaurora.lambdacontrols.client.ButtonState;
|
||||
import me.lambdaurora.lambdacontrols.client.util.CreativeInventoryScreenAccessor;
|
||||
import me.lambdaurora.lambdacontrols.client.mixin.CreativeInventoryScreenAccessor;
|
||||
import me.lambdaurora.lambdacontrols.client.util.KeyBindingAccessor;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
|
||||
@@ -49,13 +49,13 @@ public class InputHandlers
|
||||
return true;
|
||||
} else if (client.currentScreen instanceof CreativeInventoryScreen) {
|
||||
CreativeInventoryScreenAccessor creative_inventory = (CreativeInventoryScreenAccessor) client.currentScreen;
|
||||
int current_selected_tab = creative_inventory.get_selected_tab();
|
||||
int current_selected_tab = creative_inventory.lambdacontrols_get_selected_tab();
|
||||
int next_tab = current_selected_tab + (right ? 1 : -1);
|
||||
if (next_tab < 0)
|
||||
next_tab = ItemGroup.GROUPS.length - 1;
|
||||
else if (next_tab >= ItemGroup.GROUPS.length)
|
||||
next_tab = 0;
|
||||
creative_inventory.set_selected_tab(ItemGroup.GROUPS[next_tab]);
|
||||
creative_inventory.lambdacontrols_set_selected_tab(ItemGroup.GROUPS[next_tab]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -39,25 +39,27 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
public static final String GAMEPAD_TOOL_URL = "http://generalarcade.com/gamepadtool/";
|
||||
final LambdaControlsClient mod;
|
||||
private final Screen parent;
|
||||
private final boolean hide_controls;
|
||||
private final boolean hide_controls;
|
||||
// General options
|
||||
private final Option auto_switch_mode_option;
|
||||
private final Option rotation_speed_option;
|
||||
private final Option mouse_speed_option;
|
||||
private final Option reset_option;
|
||||
private final Option auto_switch_mode_option;
|
||||
private final Option rotation_speed_option;
|
||||
private final Option mouse_speed_option;
|
||||
private final Option reset_option;
|
||||
// Gameplay options
|
||||
private final Option front_block_placing_option;
|
||||
// Controller options
|
||||
private final Option controller_option;
|
||||
private final Option second_controller_option;
|
||||
private final Option controller_type_option;
|
||||
private final Option dead_zone_option;
|
||||
private final Option inverts_right_x_axis;
|
||||
private final Option inverts_right_y_axis;
|
||||
private final Option controller_option;
|
||||
private final Option second_controller_option;
|
||||
private final Option controller_type_option;
|
||||
private final Option dead_zone_option;
|
||||
private final Option inverts_right_x_axis;
|
||||
private final Option inverts_right_y_axis;
|
||||
// Hud options
|
||||
private final Option hud_enable_option;
|
||||
private final Option hud_side_option;
|
||||
private final String controller_mappings_url_text = I18n.translate("lambdacontrols.controller.mappings.2", Formatting.GOLD.toString(), GAMEPAD_TOOL_URL, Formatting.RESET.toString());
|
||||
private ButtonListWidget list;
|
||||
private SpruceLabelWidget gamepad_tool_url_label;
|
||||
private final Option hud_enable_option;
|
||||
private final Option hud_side_option;
|
||||
private final String controller_mappings_url_text = I18n.translate("lambdacontrols.controller.mappings.2", Formatting.GOLD.toString(), GAMEPAD_TOOL_URL, Formatting.RESET.toString());
|
||||
private ButtonListWidget list;
|
||||
private SpruceLabelWidget gamepad_tool_url_label;
|
||||
|
||||
public LambdaControlsSettingsScreen(Screen parent, @NotNull GameOptions options, boolean hide_controls)
|
||||
{
|
||||
@@ -87,6 +89,9 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
|
||||
});
|
||||
// Gameplay options
|
||||
this.front_block_placing_option = new SpruceBooleanOption("lambdacontrols.menu.front_block_placing", game_options -> this.mod.config.has_front_block_placing(),
|
||||
(game_options, new_value) -> this.mod.config.set_front_block_placing(new_value), new TranslatableText("lambdacontrols.tooltip.front_block_placing"));
|
||||
// Controller options
|
||||
this.controller_option = new CyclingOption("lambdacontrols.menu.controller", (game_options, amount) -> {
|
||||
int current_id = this.mod.config.get_controller().get_id();
|
||||
@@ -202,6 +207,9 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.general", true, null));
|
||||
this.list.addOptionEntry(this.rotation_speed_option, this.mouse_speed_option);
|
||||
this.list.addSingleOptionEntry(this.auto_switch_mode_option);
|
||||
// Gameplay options
|
||||
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.gameplay", true, null));
|
||||
this.list.addSingleOptionEntry(this.front_block_placing_option);
|
||||
// Controller options
|
||||
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.controller", true, null));
|
||||
this.list.addSingleOptionEntry(this.controller_option);
|
||||
|
||||
@@ -17,5 +17,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface AbstractButtonWidgetAccessor
|
||||
{
|
||||
@Accessor("height")
|
||||
int get_height();
|
||||
int lambdacontrols_get_height();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.container.Slot;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -29,29 +30,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class AbstractContainerScreenMixin implements AbstractContainerScreenAccessor
|
||||
{
|
||||
protected int x;
|
||||
|
||||
protected int y;
|
||||
|
||||
@Shadow
|
||||
protected abstract Slot getSlotAt(double xPosition, double yPosition);
|
||||
|
||||
@Override
|
||||
public int get_x()
|
||||
public int lambdacontrols_get_x()
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get_y()
|
||||
public int lambdacontrols_get_y()
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot get_slot_at(double pos_x, double pos_y)
|
||||
{
|
||||
return this.getSlotAt(pos_x, pos_y);
|
||||
}
|
||||
@Invoker("getSlotAt")
|
||||
public abstract Slot lambdacontrols_get_slot_at(double pos_x, double pos_y);
|
||||
|
||||
@Inject(method = "render", at = @At("RETURN"))
|
||||
public void render(int mouseX, int mouseY, float delta, CallbackInfo ci)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ControlsOptionsScreenMixin extends GameOptionsScreen
|
||||
if (this.parent instanceof LambdaControlsControlsScreen)
|
||||
return this.addButton(btn);
|
||||
else
|
||||
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).get_height(), I18n.translate("menu.options"),
|
||||
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).lambdacontrols_get_height(), I18n.translate("menu.options"),
|
||||
b -> this.minecraft.openScreen(new LambdaControlsSettingsScreen(this, this.gameOptions, true))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,19 @@
|
||||
* see the LICENSE file.
|
||||
*/
|
||||
|
||||
package me.lambdaurora.lambdacontrols.client.util;
|
||||
package me.lambdaurora.lambdacontrols.client.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
/**
|
||||
* Represents an accessor to CreativeInventoryScreen.
|
||||
*/
|
||||
@Mixin(CreativeInventoryScreen.class)
|
||||
public interface CreativeInventoryScreenAccessor
|
||||
{
|
||||
/**
|
||||
@@ -22,12 +27,14 @@ public interface CreativeInventoryScreenAccessor
|
||||
*
|
||||
* @return The selected tab index.
|
||||
*/
|
||||
int get_selected_tab();
|
||||
@Accessor("selectedTab")
|
||||
int lambdacontrols_get_selected_tab();
|
||||
|
||||
/**
|
||||
* Sets the selected tab.
|
||||
*
|
||||
* @param group The tab's item group.
|
||||
*/
|
||||
void set_selected_tab(@NotNull ItemGroup group);
|
||||
@Invoker("setSelectedTab")
|
||||
void lambdacontrols_set_selected_tab(@NotNull ItemGroup group);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2020 LambdAurora <aurora42lambda@gmail.com>
|
||||
*
|
||||
* This file is part of LambdaControls.
|
||||
*
|
||||
* Licensed under the MIT license. For more information,
|
||||
* see the LICENSE file.
|
||||
*/
|
||||
|
||||
package me.lambdaurora.lambdacontrols.client.mixin;
|
||||
|
||||
import me.lambdaurora.lambdacontrols.client.util.CreativeInventoryScreenAccessor;
|
||||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(CreativeInventoryScreen.class)
|
||||
public abstract class CreativeInventoryScreenMixin implements CreativeInventoryScreenAccessor
|
||||
{
|
||||
@Shadow
|
||||
protected abstract void setSelectedTab(ItemGroup itemGroup);
|
||||
|
||||
@Accessor("selectedTab")
|
||||
public abstract int get_selected_tab();
|
||||
|
||||
@Override
|
||||
public void set_selected_tab(@NotNull ItemGroup group)
|
||||
{
|
||||
this.setSelectedTab(group);
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,5 @@ import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
public interface EntryListWidgetAccessor
|
||||
{
|
||||
@Invoker("moveSelection")
|
||||
void move_selection(int amount);
|
||||
void lambdacontrols_move_selection(int amount);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,27 @@ package me.lambdaurora.lambdacontrols.client.mixin;
|
||||
import me.lambdaurora.lambdacontrols.ControlsMode;
|
||||
import me.lambdaurora.lambdacontrols.client.LambdaControlsClient;
|
||||
import me.lambdaurora.lambdacontrols.client.gui.TouchscreenOverlay;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -22,6 +40,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public abstract class MinecraftClientMixin
|
||||
@@ -36,26 +55,46 @@ public abstract class MinecraftClientMixin
|
||||
@Shadow
|
||||
public Screen currentScreen;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public HitResult crosshairTarget;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public ClientPlayerEntity player;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public ClientPlayerInteractionManager interactionManager;
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public ClientWorld world;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public GameRenderer gameRenderer;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void on_init(CallbackInfo ci)
|
||||
private void lambdacontrols_on_init(CallbackInfo ci)
|
||||
{
|
||||
LambdaControlsClient.get().on_mc_init((MinecraftClient) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"))
|
||||
private void on_render(boolean full_render, CallbackInfo ci)
|
||||
private void lambdacontrols_on_render(boolean full_render, CallbackInfo ci)
|
||||
{
|
||||
LambdaControlsClient.get().on_render((MinecraftClient) (Object) (this));
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void on_handle_input_events(CallbackInfo ci)
|
||||
private void lambdacontrols_on_handle_input_events(CallbackInfo ci)
|
||||
{
|
||||
LambdaControlsClient.get().on_tick((MinecraftClient) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "openScreen", at = @At("RETURN"))
|
||||
private void on_open_screen(@Nullable Screen screen, CallbackInfo ci)
|
||||
private void lambdacontrols_on_open_screen(@Nullable Screen screen, CallbackInfo ci)
|
||||
{
|
||||
LambdaControlsClient mod = LambdaControlsClient.get();
|
||||
if (screen == null && mod.config.get_controls_mode() == ControlsMode.TOUCHSCREEN) {
|
||||
@@ -67,4 +106,50 @@ public abstract class MinecraftClientMixin
|
||||
mod.input.on_screen_open(((MinecraftClient) (Object) this), this.window.getWidth(), this.window.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "doItemUse()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/HitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
|
||||
private void lambdacontrols_on_item_use(CallbackInfo ci, Hand[] hands, int hand_count, int hand_index, Hand hand, ItemStack stack_in_hand)
|
||||
{
|
||||
LambdaControlsClient mod = LambdaControlsClient.get();
|
||||
if (!stack_in_hand.isEmpty() && this.player.pitch > 0.0F && mod.config.has_front_block_placing()) {
|
||||
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.onGround) {
|
||||
if (!stack_in_hand.isEmpty() && stack_in_hand.getItem() instanceof BlockItem) {
|
||||
BlockPos player_pos = this.player.getBlockPos().down();
|
||||
BlockPos target_pos = new BlockPos(this.crosshairTarget.getPos()).subtract(player_pos);
|
||||
BlockPos vector = new BlockPos(MathHelper.clamp(target_pos.getX(), -1, 1), 0, MathHelper.clamp(target_pos.getZ(), -1, 1));
|
||||
BlockPos block_pos = player_pos.add(vector);
|
||||
|
||||
Direction direction = player.getHorizontalFacing();
|
||||
|
||||
BlockState adjacent_block_state = this.world.getBlockState(block_pos.offset(direction.getOpposite()));
|
||||
if (adjacent_block_state.isAir() || adjacent_block_state.getBlock() instanceof FluidBlock) {
|
||||
adjacent_block_state = this.world.getBlockState(player_pos.offset(direction.getOpposite()));
|
||||
if (adjacent_block_state.isAir() || adjacent_block_state.getBlock() instanceof FluidBlock)
|
||||
return;
|
||||
else
|
||||
block_pos = player_pos;
|
||||
}
|
||||
|
||||
BlockHitResult hit_result = new BlockHitResult(this.crosshairTarget.getPos(), direction.getOpposite(), block_pos, false);
|
||||
|
||||
int previous_stack_count = stack_in_hand.getCount();
|
||||
ActionResult result = this.interactionManager.interactBlock(this.player, this.world, hand, hit_result);
|
||||
if (result.isAccepted()) {
|
||||
if (result.shouldSwingHand()) {
|
||||
this.player.swingHand(hand);
|
||||
if (!stack_in_hand.isEmpty() && (stack_in_hand.getCount() != previous_stack_count || this.interactionManager.hasCreativeInventory())) {
|
||||
this.gameRenderer.firstPersonRenderer.resetEquipProgress(hand);
|
||||
}
|
||||
}
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
if (result == ActionResult.FAIL) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,7 @@ public abstract class MouseMixin implements MouseAccessor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void on_mouse_button(long window, int button, int action, int mods)
|
||||
{
|
||||
this.onMouseButton(window, button, action, mods);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void on_cursor_pos(long window, double x, double y)
|
||||
public void lambdacontrols_on_cursor_pos(long window, double x, double y)
|
||||
{
|
||||
this.onCursorPos(window, x, y);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SettingsScreenMixin extends Screen
|
||||
private AbstractButtonWidget on_init(SettingsScreen screen, AbstractButtonWidget btn)
|
||||
{
|
||||
if (LambdaControlsClient.get().config.get_controls_mode() == ControlsMode.CONTROLLER) {
|
||||
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).get_height(), btn.getMessage(),
|
||||
return this.addButton(new ButtonWidget(btn.x, btn.y, btn.getWidth(), ((AbstractButtonWidgetAccessor) btn).lambdacontrols_get_height(), btn.getMessage(),
|
||||
b -> this.minecraft.openScreen(new LambdaControlsControlsScreen(this, false))));
|
||||
} else {
|
||||
return this.addButton(btn);
|
||||
|
||||
@@ -21,14 +21,14 @@ public interface AbstractContainerScreenAccessor
|
||||
*
|
||||
* @return The left coordinate of the GUI.
|
||||
*/
|
||||
int get_x();
|
||||
int lambdacontrols_get_x();
|
||||
|
||||
/**
|
||||
* Gets the top coordinate of the GUI.
|
||||
*
|
||||
* @return The top coordinate of the GUI.
|
||||
*/
|
||||
int get_y();
|
||||
int lambdacontrols_get_y();
|
||||
|
||||
/**
|
||||
* Gets the slot at position.
|
||||
@@ -37,5 +37,5 @@ public interface AbstractContainerScreenAccessor
|
||||
* @param pos_y The Y position to check.
|
||||
* @return The slot at the specified position.
|
||||
*/
|
||||
Slot get_slot_at(double pos_x, double pos_y);
|
||||
Slot lambdacontrols_get_slot_at(double pos_x, double pos_y);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,5 @@ package me.lambdaurora.lambdacontrols.client.util;
|
||||
*/
|
||||
public interface MouseAccessor
|
||||
{
|
||||
void on_mouse_button(long window, int button, int action, int mods);
|
||||
|
||||
void on_cursor_pos(long window, double x, double y);
|
||||
void lambdacontrols_on_cursor_pos(long window, double x, double y);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
},
|
||||
"recommends": {
|
||||
"modmenu": ">=1.8.0+build.16",
|
||||
"okzoomer": ">=1.0.3"
|
||||
"okzoomer": ">=1.0.4"
|
||||
},
|
||||
"suggests": {
|
||||
"flamingo": "*"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"AbstractButtonWidgetAccessor",
|
||||
"AbstractContainerScreenMixin",
|
||||
"ControlsOptionsScreenMixin",
|
||||
"CreativeInventoryScreenMixin",
|
||||
"CreativeInventoryScreenAccessor",
|
||||
"EntryListWidgetAccessor",
|
||||
"GameRendererMixin",
|
||||
"KeyBindingMixin",
|
||||
|
||||
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.7.2+build.174
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.1.0-test4
|
||||
mod_version = 1.1.0-test5
|
||||
maven_group = me.lambdaurora
|
||||
archives_base_name = lambdacontrols
|
||||
|
||||
|
||||
Reference in New Issue
Block a user