Skip to content

Commit

Permalink
Merge pull request #132 from boholder/1.20.x-camera-look-straight-up-…
Browse files Browse the repository at this point in the history
…down-wip-2

[1.20] Camera look straight up down WIP 2
  • Loading branch information
khanshoaib3 committed Aug 20, 2023
2 parents b5aa5c0 + c5ff569 commit 4120841
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.config.config_maps.CameraControlsConfigMap;
import com.github.khanshoaib3.minecraft_access.utils.KeyBindingsHandler;
import com.github.khanshoaib3.minecraft_access.utils.KeyUtils;
import com.github.khanshoaib3.minecraft_access.utils.PlayerPositionUtils;
import com.github.khanshoaib3.minecraft_access.utils.TimeUtils;
import com.github.khanshoaib3.minecraft_access.utils.*;
import com.github.khanshoaib3.minecraft_access.utils.condition.Interval;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -36,7 +34,7 @@ public class CameraControls {

private float normalRotatingDeltaAngle;
private float modifiedRotatingDeltaAngle;
private TimeUtils.Interval interval;
private Interval interval;

public CameraControls() {
loadConfigurations();
Expand Down Expand Up @@ -66,7 +64,7 @@ private void loadConfigurations() {
float delta90Degrees = 600f; // 90 / 0.15

CameraControlsConfigMap map = MainClass.config.getConfigMap().getCameraControlsConfigMap();
interval = TimeUtils.Interval.inMilliseconds(map.getDelayInMilliseconds(), interval);
interval = Interval.inMilliseconds(map.getDelayInMilliseconds(), interval);
float normalRotatingAngle = map.getNormalRotatingAngle();
float modifiedRotatingAngle = map.getModifiedRotatingAngle();
normalRotatingDeltaAngle = delta90Degrees / (90 / normalRotatingAngle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.config.config_maps.MouseSimulationConfigMap;
import com.github.khanshoaib3.minecraft_access.utils.KeyBindingsHandler;
import com.github.khanshoaib3.minecraft_access.utils.KeyUtils;
import com.github.khanshoaib3.minecraft_access.utils.MouseUtils;
import com.github.khanshoaib3.minecraft_access.utils.TimeUtils;
import com.github.khanshoaib3.minecraft_access.utils.*;
import com.github.khanshoaib3.minecraft_access.utils.condition.Interval;
import com.github.khanshoaib3.minecraft_access.utils.condition.Keystroke;
import net.minecraft.client.MinecraftClient;
import org.apache.commons.lang3.tuple.Triple;

import java.util.Arrays;
import java.util.Set;

/**
Expand All @@ -23,19 +23,24 @@ public class MouseKeySimulation {
private static final MouseKeySimulation instance;

private boolean enabled;
/**
* index 0,1,2 for left, middle, right mouse key
*/
private final boolean[] isMouseKeyPressedPreviousTick = new boolean[]{false, false, false};
private TimeUtils.Interval scrollUpDelay;
private TimeUtils.Interval scrollDownDelay;
private static final Keystroke[] mouseKeystrokes = new Keystroke[5];
private Interval scrollUpDelay;
private Interval scrollDownDelay;

static {
try {
instance = new MouseKeySimulation();
} catch (Exception e) {
throw new RuntimeException("Exception occurred in creating AttackAndUseSimulation instance");
}

// config keystroke conditions
KeyBindingsHandler kbh = KeyBindingsHandler.getInstance();
mouseKeystrokes[0] = new Keystroke(() -> KeyUtils.isAnyPressed(kbh.mouseSimulationLeftMouseKey));
mouseKeystrokes[1] = new Keystroke(() -> KeyUtils.isAnyPressed(kbh.mouseSimulationMiddleMouseKey));
mouseKeystrokes[2] = new Keystroke(() -> KeyUtils.isAnyPressed(kbh.mouseSimulationRightMouseKey));
mouseKeystrokes[3] = new Keystroke(() -> KeyUtils.isAnyPressed(kbh.mouseSimulationScrollUpKey));
mouseKeystrokes[4] = new Keystroke(() -> KeyUtils.isAnyPressed(kbh.mouseSimulationScrollDownKey));
}

public static synchronized MouseKeySimulation getInstance() {
Expand Down Expand Up @@ -63,40 +68,36 @@ public void update() {
private void loadConfigurations() {
MouseSimulationConfigMap map = MainClass.config.getConfigMap().getMouseSimulationConfigMap();
this.enabled = map.isEnabled();
this.scrollUpDelay = TimeUtils.Interval.inMilliseconds(map.getScrollDelayInMilliseconds(), this.scrollUpDelay);
this.scrollDownDelay = TimeUtils.Interval.inMilliseconds(map.getScrollDelayInMilliseconds(), this.scrollDownDelay);
this.scrollUpDelay = Interval.inMilliseconds(map.getScrollDelayInMilliseconds(), this.scrollUpDelay);
this.scrollDownDelay = Interval.inMilliseconds(map.getScrollDelayInMilliseconds(), this.scrollDownDelay);
}

private void execute() {
KeyBindingsHandler kbh = KeyBindingsHandler.getInstance();

Set.of(
Triple.<Boolean, TimeUtils.Interval, Runnable>of(KeyUtils.isAnyPressed(kbh.mouseSimulationScrollUpKey), scrollUpDelay, MouseUtils::scrollUp),
Triple.<Boolean, TimeUtils.Interval, Runnable>of(KeyUtils.isAnyPressed(kbh.mouseSimulationScrollDownKey), scrollDownDelay, MouseUtils::scrollDown)
Triple.<Keystroke, Interval, Runnable>of(mouseKeystrokes[3], scrollUpDelay, MouseUtils::scrollUp),
Triple.<Keystroke, Interval, Runnable>of(mouseKeystrokes[4], scrollDownDelay, MouseUtils::scrollDown)
).forEach(t -> {
if (t.getLeft() && t.getMiddle().isReady()) {
if (t.getLeft().isPressing() && t.getMiddle().isReady()) {
t.getRight().run();
}
});

Set.of(
new MouseKeyDTO(KeyUtils.isAnyPressed(kbh.mouseSimulationLeftMouseKey), 0, MouseUtils::leftDown, MouseUtils::leftUp),
new MouseKeyDTO(KeyUtils.isAnyPressed(kbh.mouseSimulationMiddleMouseKey), 1, MouseUtils::middleDown, MouseUtils::middleUp),
new MouseKeyDTO(KeyUtils.isAnyPressed(kbh.mouseSimulationRightMouseKey), 2, MouseUtils::rightDown, MouseUtils::rightUp)
new MouseKeyDTO(mouseKeystrokes[0], MouseUtils::leftDown, MouseUtils::leftUp),
new MouseKeyDTO(mouseKeystrokes[1], MouseUtils::middleDown, MouseUtils::middleUp),
new MouseKeyDTO(mouseKeystrokes[2], MouseUtils::rightDown, MouseUtils::rightUp)
).forEach(dto -> {
if (dto.keyPressed && !isMouseKeyPressedPreviousTick[dto.keyPressedPreviouslyIndex]) {
// key pressed
if (dto.keystroke.isPressed()) {
dto.keyDown.run();
} else if (!dto.keyPressed && isMouseKeyPressedPreviousTick[dto.keyPressedPreviouslyIndex]) {
// key released
} else if (dto.keystroke.isReleased()) {
dto.keyUp.run();
}

// update state
isMouseKeyPressedPreviousTick[dto.keyPressedPreviouslyIndex] = dto.keyPressed;
});

Arrays.stream(mouseKeystrokes).forEach(Keystroke::updateStateForNextTick);
}

private record MouseKeyDTO(Boolean keyPressed, int keyPressedPreviouslyIndex, Runnable keyDown, Runnable keyUp) {
private record MouseKeyDTO(Keystroke keystroke, Runnable keyDown, Runnable keyUp) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.github.khanshoaib3.minecraft_access.config.config_maps.RCPartialSpeakingConfigMap;
import com.github.khanshoaib3.minecraft_access.config.config_maps.ReadCrosshairConfigMap;
import com.github.khanshoaib3.minecraft_access.mixin.MobSpawnerLogicAccessor;
import com.github.khanshoaib3.minecraft_access.utils.condition.Interval;
import com.github.khanshoaib3.minecraft_access.utils.PlayerPositionUtils;
import com.github.khanshoaib3.minecraft_access.utils.TimeUtils;
import net.minecraft.block.*;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class ReadCrosshair {
private String previousQuery;
private boolean speakSide;
private boolean speakingConsecutiveBlocks;
private TimeUtils.Interval repeatSpeakingInterval;
private Interval repeatSpeakingInterval;
private boolean enablePartialSpeaking;
private boolean partialSpeakingWhitelistMode;
private boolean partialSpeakingFuzzyMode;
Expand Down Expand Up @@ -105,7 +105,7 @@ private void loadConfigurations() {
// affirmation for easier use
this.speakingConsecutiveBlocks = !rcMap.isDisableSpeakingConsecutiveBlocks();
long interval = rcMap.getRepeatSpeakingInterval();
this.repeatSpeakingInterval = TimeUtils.Interval.inMilliseconds(interval, this.repeatSpeakingInterval);
this.repeatSpeakingInterval = Interval.inMilliseconds(interval, this.repeatSpeakingInterval);

this.enablePartialSpeaking = rcpMap.isEnabled();
this.partialSpeakingFuzzyMode = rcpMap.isPartialSpeakingFuzzyMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.config.config_maps.InventoryControlsConfigMap;
import com.github.khanshoaib3.minecraft_access.mixin.*;
import com.github.khanshoaib3.minecraft_access.utils.KeyBindingsHandler;
import com.github.khanshoaib3.minecraft_access.utils.KeyUtils;
import com.github.khanshoaib3.minecraft_access.utils.MouseUtils;
import com.github.khanshoaib3.minecraft_access.utils.TimeUtils;
import com.github.khanshoaib3.minecraft_access.utils.*;
import com.github.khanshoaib3.minecraft_access.utils.condition.Interval;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.*;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
Expand Down Expand Up @@ -49,7 +47,7 @@
public class InventoryControls {
private boolean autoOpenRecipeBook;
private String rowAndColumnFormat;
private TimeUtils.Interval interval;
private Interval interval;
private MinecraftClient minecraftClient;

private HandledScreenAccessor previousScreen = null;
Expand Down Expand Up @@ -165,7 +163,7 @@ private void loadConfigurations() {
InventoryControlsConfigMap map = MainClass.config.getConfigMap().getInventoryControlsConfigMap();
autoOpenRecipeBook = map.isAutoOpenRecipeBook();
rowAndColumnFormat = map.getRowAndColumnFormat();
interval = TimeUtils.Interval.inMilliseconds(map.getDelayInMilliseconds(), interval);
interval = Interval.inMilliseconds(map.getDelayInMilliseconds(), interval);
}

/**
Expand Down
Loading

0 comments on commit 4120841

Please sign in to comment.