Skip to content

Commit

Permalink
Added Location detection and switched to mod api for inSB
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Dec 8, 2024
1 parent 1b0ed55 commit c8bfb91
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 179 deletions.
63 changes: 32 additions & 31 deletions src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
Expand All @@ -30,7 +29,6 @@
import net.minecraft.scoreboard.ScoreboardObjective;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import wtf.cheeze.sbt.command.SBTCommand;
import wtf.cheeze.sbt.config.SBTConfig;
import wtf.cheeze.sbt.config.migration.BarColorTransformation;
Expand All @@ -39,13 +37,14 @@
import wtf.cheeze.sbt.features.chat.ChatProtections;
import wtf.cheeze.sbt.features.chat.PartyFeatures;
import wtf.cheeze.sbt.features.huds.*;
import wtf.cheeze.sbt.utils.*;
import wtf.cheeze.sbt.utils.actionbar.ActionBarTransformer;
import wtf.cheeze.sbt.hud.HUD;
import wtf.cheeze.sbt.utils.NotificationHandler;
import wtf.cheeze.sbt.utils.UpdateChecker;
import wtf.cheeze.sbt.utils.Version;
import wtf.cheeze.sbt.utils.actionbar.ActionBarTransformer;
import wtf.cheeze.sbt.utils.skyblock.ModAPIUtils;
import wtf.cheeze.sbt.utils.skyblock.ProfileManager;
import wtf.cheeze.sbt.utils.skyblock.SkyblockData;

import java.util.ArrayList;

public class SkyblockTweaks implements ModInitializer {
Expand All @@ -64,6 +63,7 @@ public void onInitialize() {
//MigrationManager.handleMigrations();



SBTConfig.HANDLER.load();

MigrationManager.runTransformation(BarColorTransformation.INSTANCE);
Expand All @@ -72,6 +72,7 @@ public void onInitialize() {
HUDS.add(SkillHUDManager.INSTANCE.SKILL_HUD);
HUDS.add(SkillHUDManager.INSTANCE.SKILL_BAR);


HUDS.add(new SpeedHUD());
HUDS.add(new DefenseHUD());
HUDS.add(new EhpHUD());
Expand Down Expand Up @@ -107,32 +108,32 @@ public void onInitialize() {

UpdateChecker.checkForUpdates();

// TODO: Checking this every tick may be overkill, change this later
// TODO: Use the mod api for this
ClientTickEvents.END_CLIENT_TICK.register(client -> {

if (mc != null && mc.world != null) {
Scoreboard scoreboard = mc.world.getScoreboard();
if (scoreboard != null) {
ScoreboardObjective objective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.SIDEBAR);
if (objective != null) {
var name = objective.getDisplayName().getString();
if (name.contains("SKYBLOCK") || name.contains("SKIBLOCK")) {
DATA.inSB = true;
} else {
DATA.inSB = false;
}
} else {
DATA.inSB = false;
}
} else {
DATA.inSB = false;
}
} else {
DATA.inSB = false;
}

});
// // TODO: Checking this every tick may be overkill, change this later
// // TODO: Use the mod api for this
// ClientTickEvents.END_CLIENT_TICK.register(client -> {
//
// if (mc != null && mc.world != null) {
// Scoreboard scoreboard = mc.world.getScoreboard();
// if (scoreboard != null) {
// ScoreboardObjective objective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.SIDEBAR);
// if (objective != null) {
// var name = objective.getDisplayName().getString();
// if (name.contains("SKYBLOCK") || name.contains("SKIBLOCK")) {
// DATA.inSB = true;
// } else {
// DATA.inSB = false;
// }
// } else {
// DATA.inSB = false;
// }
// } else {
// DATA.inSB = false;
// }
// } else {
// DATA.inSB = false;
// }
//
// });



Expand Down
40 changes: 40 additions & 0 deletions src/main/java/wtf/cheeze/sbt/command/CommandUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import wtf.cheeze.sbt.utils.skyblock.SkyblockConstants;

import java.util.function.Supplier;

Expand All @@ -45,4 +47,42 @@ public static SuggestionProvider<FabricClientCommandSource> getArrayAsSuggestion
return builder.buildFuture();
};
}

static int[] getCalcPetTable(SkyblockConstants.Rarity rarity) {
return switch (rarity) {
case COMMON -> SkyblockConstants.PET_LEVELS_COMMON;
case UNCOMMON -> SkyblockConstants.PET_LEVELS_UNCOMMON;
case RARE -> SkyblockConstants.PET_LEVELS_RARE;
case EPIC -> SkyblockConstants.PET_LEVELS_EPIC;
case LEGENDARY, MYTHIC -> SkyblockConstants.PET_LEVELS_LEGENDARY;
default -> null;
};
}

static int[] getCalcSlayerTable(SkyblockConstants.Slayers slayer) {
return switch (slayer) {
case ZOMBIE -> SkyblockConstants.SLAYER_LEVELS_ZOMBIE;
case SPIDER -> SkyblockConstants.SLAYER_LEVELS_SPIDER;
case WOLF, ENDERMAN, BLAZE -> SkyblockConstants.SLAYER_LEVELS_WEB;
case VAMPIRE -> SkyblockConstants.SLAYER_LEVELS_VAMPIRE;
};
}

static int[] getCalcCropTable(SkyblockConstants.Crops crop) {
return switch (crop) {
case WHEAT, PUMPKIN, MUSHROOM -> SkyblockConstants.CROP_LEVELS_WPMS;
case CARROT, POTATO -> SkyblockConstants.CROP_LEVELS_CP;
case MELON -> SkyblockConstants.CROP_LEVELS_MELON;
case SUGAR_CANE, CACTUS -> SkyblockConstants.CROP_LEVELS_SCC;
case COCOA_BEANS, NETHER_WART -> SkyblockConstants.CROP_LEVELS_CBNW;
};
}

static Text getDebugText(String name, boolean value) {
return Text.of("§3" + name + ": §" + (value ? "a" : "c") + value);
}

static Text getDebugText(String name, String value) {
return Text.of("§3" + name + ": §e" + value);
}
}
74 changes: 19 additions & 55 deletions src/main/java/wtf/cheeze/sbt/command/SBTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class SBTCommand {
return 0;
}

var table = getCalcSlayerTable(slayer);
var table = CommandUtils.getCalcSlayerTable(slayer);
var needed = table[levelEnd] - table[levelStart];
context.getSource().sendFeedback(Text.of(PREFIX + " §3Total Slayer XP Required: §e" + NumberUtils.formatNumber(needed, ",")));
return 1;
Expand Down Expand Up @@ -148,7 +148,7 @@ public class SBTCommand {
return 0;
}

var newArr = Arrays.stream(getCalcPetTable(rarity)).skip(levelStart).limit(levelEnd - levelStart).toArray();
var newArr = Arrays.stream(CommandUtils.getCalcPetTable(rarity)).skip(levelStart).limit(levelEnd - levelStart).toArray();
var total = Arrays.stream(newArr).sum();
context.getSource().sendFeedback(Text.of(PREFIX + " §3Total Pet XP Required: §e" + NumberUtils.formatNumber(total, ",")));
return 1;
Expand Down Expand Up @@ -229,7 +229,7 @@ public class SBTCommand {
return 0;
}

var newArr = Arrays.stream(getCalcCropTable(crop)).skip(levelStart).limit(levelEnd - levelStart).toArray();
var newArr = Arrays.stream(CommandUtils.getCalcCropTable(crop)).skip(levelStart).limit(levelEnd - levelStart).toArray();
var total = Arrays.stream(newArr).sum();
context.getSource().sendFeedback(Text.of(PREFIX + " §3Total Crop XP Required: §e" + NumberUtils.formatNumber(total, ",")));
return 1;
Expand Down Expand Up @@ -337,12 +337,12 @@ public static void registerEvents() {
.then(literal("sysInfo").executes(context -> {
var source = context.getSource();
source.sendFeedback(Text.literal(PREFIX + " §3System Information"));
source.sendFeedback(getDebugText("Minecraft Version", MinecraftVersion.CURRENT.getName()));
source.sendFeedback(getDebugText("Operating System", System.getProperty("os.name")));
source.sendFeedback(getDebugText("OS Version", System.getProperty("os.version")));
source.sendFeedback(getDebugText("Architecture", System.getProperty("os.arch")));
source.sendFeedback(getDebugText("Java Version", System.getProperty("java.version")));
source.sendFeedback(getDebugText("Java Vendor", System.getProperty("java.vendor")));
source.sendFeedback(CommandUtils.getDebugText("Minecraft Version", MinecraftVersion.CURRENT.getName()));
source.sendFeedback(CommandUtils.getDebugText("Operating System", System.getProperty("os.name")));
source.sendFeedback(CommandUtils.getDebugText("OS Version", System.getProperty("os.version")));
source.sendFeedback(CommandUtils.getDebugText("Architecture", System.getProperty("os.arch")));
source.sendFeedback(CommandUtils.getDebugText("Java Version", System.getProperty("java.version")));
source.sendFeedback(CommandUtils.getDebugText("Java Vendor", System.getProperty("java.vendor")));
return 1;

}))
Expand Down Expand Up @@ -391,14 +391,15 @@ public static void registerEvents() {
).executes(context -> {
var source = context.getSource();
source.sendFeedback(Text.literal(PREFIX + " §3Debug Information"));
source.sendFeedback(getDebugText("Version", SkyblockTweaks.VERSION.getVersionString()));
source.sendFeedback(getDebugText("In Skyblock", SkyblockTweaks.DATA.inSB));
source.sendFeedback(getDebugText("Mode", SkyblockTweaks.DATA.mode));
source.sendFeedback(getDebugText("On Alpha Network", SkyblockTweaks.DATA.alphaNetwork));
source.sendFeedback(getDebugText("In Party", SkyblockTweaks.DATA.inParty));
source.sendFeedback(getDebugText("Am I The Leader", SkyblockTweaks.DATA.amITheLeader));
source.sendFeedback(getDebugText("Current Profile", SkyblockTweaks.DATA.currentProfile));
source.sendFeedback(getDebugText("Unique Profile ID", SkyblockTweaks.DATA.getCurrentProfileUnique()));
source.sendFeedback(CommandUtils.getDebugText("Version", SkyblockTweaks.VERSION.getVersionString()));
source.sendFeedback(CommandUtils.getDebugText("In Skyblock", SkyblockTweaks.DATA.inSB));
//source.sendFeedback(CommandUtils.getDebugText("Mode", SkyblockTweaks.DATA.mode));
source.sendFeedback(CommandUtils.getDebugText("Location", SkyblockTweaks.DATA.location.getName()));
source.sendFeedback(CommandUtils.getDebugText("On Alpha Network", SkyblockTweaks.DATA.alphaNetwork));
source.sendFeedback(CommandUtils.getDebugText("In Party", SkyblockTweaks.DATA.inParty));
source.sendFeedback(CommandUtils.getDebugText("Am I The Leader", SkyblockTweaks.DATA.amITheLeader));
source.sendFeedback(CommandUtils.getDebugText("Current Profile", SkyblockTweaks.DATA.currentProfile));
source.sendFeedback(CommandUtils.getDebugText("Unique Profile ID", SkyblockTweaks.DATA.getCurrentProfileUnique()));

return 1;
})
Expand All @@ -418,42 +419,5 @@ public static void registerEvents() {
)
));
}
}

private static int[] getCalcPetTable(SkyblockConstants.Rarity rarity) {
return switch (rarity) {
case COMMON -> SkyblockConstants.PET_LEVELS_COMMON;
case UNCOMMON -> SkyblockConstants.PET_LEVELS_UNCOMMON;
case RARE -> SkyblockConstants.PET_LEVELS_RARE;
case EPIC -> SkyblockConstants.PET_LEVELS_EPIC;
case LEGENDARY, MYTHIC -> SkyblockConstants.PET_LEVELS_LEGENDARY;
default -> null;
};
}

private static int[] getCalcSlayerTable(SkyblockConstants.Slayers slayer) {
return switch (slayer) {
case ZOMBIE -> SkyblockConstants.SLAYER_LEVELS_ZOMBIE;
case SPIDER -> SkyblockConstants.SLAYER_LEVELS_SPIDER;
case WOLF, ENDERMAN, BLAZE -> SkyblockConstants.SLAYER_LEVELS_WEB;
case VAMPIRE -> SkyblockConstants.SLAYER_LEVELS_VAMPIRE;
};
}

private static int[] getCalcCropTable(SkyblockConstants.Crops crop) {
return switch (crop) {
case WHEAT, PUMPKIN, MUSHROOM -> SkyblockConstants.CROP_LEVELS_WPMS;
case CARROT, POTATO -> SkyblockConstants.CROP_LEVELS_CP;
case MELON -> SkyblockConstants.CROP_LEVELS_MELON;
case SUGAR_CANE, CACTUS -> SkyblockConstants.CROP_LEVELS_SCC;
case COCOA_BEANS, NETHER_WART -> SkyblockConstants.CROP_LEVELS_CBNW;
};
}

private static Text getDebugText(String name, boolean value) {
return Text.of("§3" + name + ": §" + (value ? "a" : "c") + value);
}
private static Text getDebugText(String name, String value) {
return Text.of("§3" + name + ": §e" + value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* A ConfigMigration will always be accompanied by an increase in the config version
*/
public interface ConfigMigration<Source, Target> {


Source migrate(Target config);

boolean isApplicable(int aVersion);
Expand All @@ -19,5 +17,4 @@ public interface ConfigMigration<Source, Target> {

Class<Source> getSourceClass();
Class<Target> getTargetClass();

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void save() {
writer.write(toWrite);
writer.close();
} catch (Exception e) {
e.printStackTrace();
SkyblockTweaks.LOGGER.error("Failed to save persistent data", e);
}
}

Expand All @@ -62,7 +62,7 @@ public static PersistentData load() {
return SkyblockTweaks.GSON.fromJson(content, PersistentData.class);

} catch (Exception e) {
e.printStackTrace();
SkyblockTweaks.LOGGER.error("Failed to load persistent data", e);
return new PersistentData();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/wtf/cheeze/sbt/features/CalcPowder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static interface CostFunction {

public static class Perk {
public int max;
public CalcPowder.CostFunction cost;
public CostFunction cost;
public Powder powder;

public Perk(int max, CalcPowder.CostFunction cost, Powder powder) {
public Perk(int max, CostFunction cost, Powder powder) {
this.max = max;
this.cost = cost;
this.powder = powder;
Expand Down
Loading

0 comments on commit c8bfb91

Please sign in to comment.