Skip to content

Commit

Permalink
Merge pull request #238 from boholder/1.20-refactor
Browse files Browse the repository at this point in the history
1.20 refactor
  • Loading branch information
khanshoaib3 authored Jan 14, 2024
2 parents d7ad64c + 7a5107f commit afc66b9
Show file tree
Hide file tree
Showing 35 changed files with 994 additions and 1,009 deletions.
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

0 comments on commit afc66b9

Please sign in to comment.