Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20 refactor #238

Merged
merged 51 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
df613de
Rename AbsolutePositions to NonCubeBlockAbsolutePositions
boholder Dec 23, 2023
d83ed7b
Change block type checking to same style in POIBlocks
boholder Dec 23, 2023
78c164f
Add logging for qualified position when checking for fall
boholder Dec 30, 2023
c61df7b
Remove commented out playSound variable in FallDetector
boholder Dec 30, 2023
5b98c73
Refactor POIBlocks to use arrays and stream for block predicates
boholder Dec 30, 2023
575802d
Replace all e.printStackTrace() with proper error log
boholder Dec 30, 2023
3f6a7f5
Add RAY_CAST_DISTANCE constant and extract common logic
boholder Dec 30, 2023
1836935
Rename predicate list in POIBlocks
boholder Dec 30, 2023
0ef16de
Move isLockingKeyPressed variable to where it is used first time
boholder Jan 6, 2024
96c1dec
Remove labeled break, directly return and wait for execution of next …
boholder Jan 6, 2024
aa0b966
Simplify the logic of continuous locking after eye of ender disappears
boholder Jan 6, 2024
0f690d2
Add description about special logic of POI Entity Locking in manual
boholder Jan 6, 2024
f78bca6
Extract player.lookAt as util method
boholder Jan 6, 2024
334b049
Remove isLockedOntoLadder variable, replace it with a simple way
boholder Jan 7, 2024
48e3942
Correct description about ladder automatically unlocking
boholder Jan 7, 2024
a083129
Extract player look at entity method
boholder Jan 7, 2024
6a614dc
Add BlockPos3d which extends BlockPos
boholder Jan 7, 2024
0815f0f
Add description about automatic lock release on block destruction or …
boholder Jan 7, 2024
2a4ee5b
Rename `ClientPlayerEntityProxy` to `PlayerUtils`, and move methods u…
boholder Jan 7, 2024
65ef4dd
Move playSoundAtPosition method to PositionUtils
boholder Jan 7, 2024
7daaff8
Remove MinecraftClient param on playUnlockingSound method
boholder Jan 7, 2024
b13a4a6
Extract two special case methods in LockingHandler
boholder Jan 7, 2024
d24e3f6
Remove client param from methods
boholder Jan 7, 2024
547c725
Rearrange locking key press checking logic
boholder Jan 7, 2024
0671daf
Rename two variables
boholder Jan 7, 2024
57547f4
Extract unlock method
boholder Jan 7, 2024
214839d
Rename isLockedOntoEyeOfEnderTarget variable
boholder Jan 7, 2024
164b2fb
public lockOnEntity method and replace logic in EyeOfEnderEntityMixin
boholder Jan 7, 2024
d1dd03b
Extract entity narration method as util method
boholder Jan 7, 2024
cb152ca
Move getNarratableNumber method from PositionUtils to NarrationUtils …
boholder Jan 7, 2024
a00891c
Remove unused imports
boholder Jan 7, 2024
a55ddf3
Move getPositionDifference method from PositionUtils to NarrationUtil…
boholder Jan 7, 2024
d37e0e6
Move getPosition method from PositionUtils to NarrationUtils and rena…
boholder Jan 7, 2024
c1cc1a4
Move two play sound methods from PositionUtils to WorldUtils and dele…
boholder Jan 7, 2024
82081af
Move methods from ClientPlayerEntityUtils to PlayerUtils
boholder Jan 7, 2024
ef2c6cc
Use NarrationUtils for entity narration in LockingHandler
boholder Jan 7, 2024
d3f34dc
Extract is player in fluid logic as util method
boholder Jan 7, 2024
f5afcf3
Make methods in PlayerUtils use WorldUtils getClientPlayer() method
boholder Jan 7, 2024
0213a3e
Replace player in fluid check in NarratorMenu with util method
boholder Jan 7, 2024
6337609
Add is alive checking in lockOnEntity method
boholder Jan 7, 2024
8c66fcd
Only check locked block entries change
boholder Jan 7, 2024
c09e6c4
Remove client param on get...AbsolutePosition methods
boholder Jan 7, 2024
83714cc
Remove client invoking in lockOnBlock method and rename it
boholder Jan 7, 2024
071ccb5
Simplify logic of finding nearest block in scanned blocks
boholder Jan 7, 2024
3182a3d
Extract block narration as util method
boholder Jan 7, 2024
868e6cd
Simplify locked block narration
boholder Jan 7, 2024
a3cff5f
Fix the bug that ignored non-cube blocks locking position
boholder Jan 7, 2024
e1ebce9
Rename block locking methods
boholder Jan 7, 2024
e83d8bc
Fix the bug that throws NPE
boholder Jan 8, 2024
c2ad423
Simplify unlock sound playing, make every non-inner-invoking unlock s…
boholder Jan 8, 2024
7a5107f
Replace config "Play Unlocking Sound" with "Play Sound Instead Of Spe…
boholder Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void loadConfig() {
ConfigMap.setInstance(configMap);

} catch (Exception e) {
MainClass.errorLog("An error occurred while reading config.json file, resetting to default");
e.printStackTrace();
MainClass.errorLog("An error occurred while reading config.json file, resetting to default", e);
resetConfigToDefault();
} finally {
MainClass.infoLog("Loaded configurations from config.json");
Expand All @@ -81,8 +80,7 @@ protected void resetConfigToDefault() {
this.configMap = ConfigMap.buildDefault();
writeJSON();
} catch (Exception e) {
MainClass.errorLog("An error occurred while resetting config.json file to default.");
e.printStackTrace();
MainClass.errorLog("An error occurred while resetting config.json file to default.", e);
}
}

Expand All @@ -102,7 +100,7 @@ public void writeJSON() {
try (Writer writer = new FileWriter(CONFIG_FILE_PATH)) {
writer.write(gson.toJson(configMap));
} catch (Exception e) {
e.printStackTrace();
MainClass.errorLog("An error occurred while saving config.json file.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class POILockingConfigMap {
private boolean lockOnBlocks;
@SerializedName("Speak Relative Distance to Entity/Block")
private boolean speakDistance;
@SerializedName("Play Unlocking Sound")
private boolean unlockingSound;
@SerializedName("Play Sound Instead Of Speak")
private boolean unlockingSound = false;
@SerializedName("Auto Lock on to Eye of Ender when Used")
private boolean autoLockEyeOfEnderEntity;
@SerializedName("Delay (in milliseconds)")
Expand All @@ -37,7 +37,7 @@ public static POILockingConfigMap buildDefault() {
m.setEnabled(true);
m.setLockOnBlocks(true);
m.setSpeakDistance(false);
m.setUnlockingSound(true);
m.setUnlockingSound(false);
m.setAutoLockEyeOfEnderEntity(true);
m.setDelay(100);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void update() {
}

} catch (Exception e) {
MainClass.errorLog("An error occurred while narrating biome.");
e.printStackTrace();
MainClass.errorLog("An error occurred while narrating biome.", e);
}
}

/**
* Gets the biome name from registry entry
*
* @param biome the biome's registry entry
* @return the biome's name
*/
Expand All @@ -58,13 +58,14 @@ public static String getBiomeName(RegistryEntry<Biome> biome) {

/**
* Gets the biome translation key from registry entry
*
* @param biome the biome's registry entry
* @return the biome's translation key
*/
private static String getBiomeTranslationKey(RegistryEntry<Biome> biome) {
return biome.getKeyOrValue().map(
(biomeKey) -> "biome." + biomeKey.getValue().getNamespace() + "." + biomeKey.getValue().getPath(),
(biomeValue) -> "[unregistered " + biomeValue + "]" // For unregistered biome
(biomeKey) -> "biome." + biomeKey.getValue().getNamespace() + "." + biomeKey.getValue().getPath(),
(biomeValue) -> "[unregistered " + biomeValue + "]" // For unregistered biome
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void update() {
boolean wasAnyKeyPressed = keyListener();
if (wasAnyKeyPressed) interval.start();
} catch (Exception e) {
MainClass.errorLog("\nError encountered in Camera Controls feature.");
e.printStackTrace();
MainClass.errorLog("Error encountered in Camera Controls feature.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.utils.KeyBindingsHandler;
import com.github.khanshoaib3.minecraft_access.utils.NarrationUtils;
import com.github.khanshoaib3.minecraft_access.utils.position.PlayerPositionUtils;
import com.github.khanshoaib3.minecraft_access.utils.position.PositionUtils;
import com.github.khanshoaib3.minecraft_access.utils.system.KeyUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
Expand All @@ -28,7 +28,7 @@ public void update() {
String toSpeak;
if (isLeftAltPressed) {
int angle = new PlayerPositionUtils(minecraftClient).getVerticalFacingDirection();
toSpeak = PositionUtils.getNarratableNumber(angle);
toSpeak = NarrationUtils.narrateNumber(angle);
} else {

/* TODO add to config and add left alt combination to readme
Expand All @@ -44,8 +44,7 @@ public void update() {

MainClass.speakWithNarrator(toSpeak, true);
} catch (Exception e) {
MainClass.errorLog("An error occurred in DirectionNarrator.");
e.printStackTrace();
MainClass.errorLog("An error occurred in DirectionNarrator.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class FallDetector {
private boolean enabled;
private int range;
private int depth;
// private boolean playSound;
private float volume;
private int delayInMilliseconds;

Expand Down Expand Up @@ -70,8 +69,7 @@ public void update() {
SearchNearbyPositions();
MainClass.infoLog("Searching ended.");
} catch (Exception e) {
MainClass.errorLog("An error occurred in fall detector.");
e.printStackTrace();
MainClass.errorLog("An error occurred in fall detector.", e);
}
}

Expand Down Expand Up @@ -118,13 +116,13 @@ private boolean isValid(BlockPos dir, BlockPos center, HashSet<BlockPos> searche
}

private void checkForFall(BlockPos toCheck) {
MainClass.infoLog("%d) Checking fall for x:%d y:%d z:%d".formatted(++count, toCheck.getX(), toCheck.getY(), toCheck.getZ()));

if (minecraftClient.world == null) return;
if (!(minecraftClient.world.getBlockState(toCheck).isAir())) return;

if (getDepth(toCheck, depth) < depth) return;

MainClass.infoLog("%d) Found qualified fall position: x:%d y:%d z:%d".formatted(++count, toCheck.getX(), toCheck.getY(), toCheck.getZ()));
minecraftClient.world.playSoundAtBlockCenter(toCheck, SoundEvents.BLOCK_ANVIL_HIT, SoundCategory.BLOCKS, volume, 1f, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.khanshoaib3.minecraft_access.MainClass;
import com.github.khanshoaib3.minecraft_access.config.config_maps.FluidDetectorConfigMap;
import com.github.khanshoaib3.minecraft_access.utils.position.PositionUtils;
import com.github.khanshoaib3.minecraft_access.utils.NarrationUtils;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -75,7 +75,7 @@ private void findClosestFluidSource(boolean water) {
minecraftClient.world.playSound(minecraftClient.player, closestFluidPos, SoundEvents.ENTITY_ITEM_PICKUP,
SoundCategory.BLOCKS, this.volume, 1f);

String posDifference = PositionUtils.getPositionDifference(closestFluidPos);
String posDifference = NarrationUtils.narrateRelativePositionOfPlayerAnd(closestFluidPos);
String name = minecraftClient.world.getBlockState(closestFluidPos).getBlock().getName().getString();

MainClass.speakWithNarrator(name + ", " + posDifference, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* - Speak Player Health and Hunger Key (default: R) = Speaks the health and hunger.<br>
*/
public class HealthNHunger {
public void update(){
public void update() {
try {
MinecraftClient minecraftClient = MinecraftClient.getInstance();
if (minecraftClient == null) return;
Expand All @@ -29,9 +29,8 @@ public void update(){

String toSpeak = I18n.translate("minecraft_access.healthHunger.format", health, hunger);
MainClass.speakWithNarrator(toSpeak, true);
} catch (Exception e){
MainClass.errorLog("An error occurred in HealthNHunger.");
e.printStackTrace();
} catch (Exception e) {
MainClass.errorLog("An error occurred in HealthNHunger.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public static void update(MinecraftClient minecraftClient) {
moveMouseCursor(minecraftClient);
}
} catch (Exception e) {
MainClass.errorLog("\nError encountered while running the menu fix feature");
e.printStackTrace();
MainClass.errorLog("Error encountered while running the menu fix feature", e);
}
}

Expand All @@ -98,8 +97,7 @@ private static void moveMouseCursor(MinecraftClient minecraftClient) {

MouseUtils.moveAndLeftClick(movePosX, movePosY);
} catch (Exception e) {
MainClass.errorLog("\nError encountered while moving the mouse for the menu fix feature");
e.printStackTrace();
MainClass.errorLog("Error encountered while moving the mouse for the menu fix feature", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void update() {

airWarning(air);
} catch (Exception e) {
MainClass.errorLog("An error occurred in PlayerWarnings.");
e.printStackTrace();
MainClass.errorLog("An error occurred in PlayerWarnings.", e);
}
}

Expand All @@ -76,13 +75,13 @@ private void healthWarning(double health) {
if (health < firstHealthThreshold && health > secondHealthThreshold && !isHealthBelowFirstThreshold && !isHealthBelowSecondThreshold) {
isHealthBelowFirstThreshold = true;
MainClass.speakWithNarrator(I18n.translate("minecraft_access.player_warnings.health_low", health), true);
if(playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
if (playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
}

if (health < secondHealthThreshold && health > 0 && isHealthBelowFirstThreshold && !isHealthBelowSecondThreshold) {
isHealthBelowSecondThreshold = true;
MainClass.speakWithNarrator(I18n.translate("minecraft_access.player_warnings.health_low", health), true);
if(playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
if (playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
}

if (isHealthBelowFirstThreshold && health >= firstHealthThreshold) isHealthBelowFirstThreshold = false;
Expand All @@ -95,7 +94,7 @@ private void hungerWarning(double hunger) {
if (hunger < hungerThreshold && hunger > 0 && !isFoodBelowThreshold) {
isFoodBelowThreshold = true;
MainClass.speakWithNarrator(I18n.translate("minecraft_access.player_warnings.hunger_low", hunger), true);
if(playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
if (playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
}

if (isFoodBelowThreshold && hunger >= hungerThreshold) isFoodBelowThreshold = false;
Expand All @@ -107,7 +106,7 @@ private void airWarning(double air) {
if (air < airThreshold && air > 0 && !isAirBelowThreshold) {
isAirBelowThreshold = true;
MainClass.speakWithNarrator(I18n.translate("minecraft_access.player_warnings.air_low", air), true);
if(playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
if (playSound) minecraftClient.player.playSound(SoundEvents.BLOCK_ANVIL_LAND, SoundCategory.PLAYERS, (float) 1, (float) 1);
}

if (isAirBelowThreshold && air >= airThreshold) isAirBelowThreshold = false;
Expand Down
Loading