Skip to content

Commit

Permalink
- Fixed Auto Reply sending messages in public chat on the 1.19.2 version
Browse files Browse the repository at this point in the history
- Anti Place will no longer prevent opening chests/other guis when holding grass/heads
- Anti Place now works with items in your offhand
- Anti Place now notifies you when it prevents placement of heads/grass
- Tool Saver no longer prevents you from interacting with blocks/entities if it won't reduce your tools durability
- Auto Silk can now be configured to target any tool that supports Silk Touch (Target Tool setting)
- Auto Raffle will now notify you if you don't have enough grass
- Auto Raffle will now buy the maximum amount of tickets you can afford, if you cannot afford the configured amount
- Fixed Auto Advert not detecting the current server properly after the update
- Fixed Auto Raffle not detecting the end of the raffle after the update
- Added new Double Spin option to Auto Crate (opens two keys at once)
- Enchant All no longer excludes Soul Speed and Swift Sneak
- Updated Auto Fix cooldown detection
- Removed shop logging (until transaction messages come back)
  • Loading branch information
hashalite committed Apr 29, 2023
1 parent 4e75902 commit 07b5e98
Show file tree
Hide file tree
Showing 21 changed files with 352 additions and 190 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mc_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.19
# Mod Properties
mod_version=1.0.7
mod_version=1.1.0
maven_group=net.xolt
archives_base_name=sbutils
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.78.0+1.19.4
fabric_version=0.79.0+1.19.4
modmenu_version=6.2.0
yacl_version=2.4.1
exp4j_version = 0.4.8
60 changes: 40 additions & 20 deletions src/main/java/net/xolt/sbutils/config/ConfigGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,26 +559,26 @@ private static ConfigCategory buildChatLoggerCategory(ModConfig defaults, ModCon
.name(Text.translatable("text.sbutils.config.category.chatlogger"))
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.sbutils.config.group.chatLogger"))
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("text.sbutils.config.option.shopLoggerIncoming"))
.tooltip(Text.translatable("text.sbutils.config.option.shopLoggerIncoming.tooltip"))
.binding(
defaults.shopLoggerIncoming,
() -> config.shopLoggerIncoming,
(value) -> config.shopLoggerIncoming = value
)
.controller(TickBoxController::new)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("text.sbutils.config.option.shopLoggerOutgoing"))
.tooltip(Text.translatable("text.sbutils.config.option.shopLoggerOutgoing.tooltip"))
.binding(
defaults.shopLoggerOutgoing,
() -> config.shopLoggerOutgoing,
(value) -> config.shopLoggerOutgoing = value
)
.controller(TickBoxController::new)
.build())
// .option(Option.createBuilder(boolean.class)
// .name(Text.translatable("text.sbutils.config.option.shopLoggerIncoming"))
// .tooltip(Text.translatable("text.sbutils.config.option.shopLoggerIncoming.tooltip"))
// .binding(
// defaults.shopLoggerIncoming,
// () -> config.shopLoggerIncoming,
// (value) -> config.shopLoggerIncoming = value
// )
// .controller(TickBoxController::new)
// .build())
// .option(Option.createBuilder(boolean.class)
// .name(Text.translatable("text.sbutils.config.option.shopLoggerOutgoing"))
// .tooltip(Text.translatable("text.sbutils.config.option.shopLoggerOutgoing.tooltip"))
// .binding(
// defaults.shopLoggerOutgoing,
// () -> config.shopLoggerOutgoing,
// (value) -> config.shopLoggerOutgoing = value
// )
// .controller(TickBoxController::new)
// .build())
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("text.sbutils.config.option.msgLoggerIncoming"))
.tooltip(Text.translatable("text.sbutils.config.option.msgLoggerIncoming.tooltip"))
Expand Down Expand Up @@ -951,6 +951,16 @@ private static ConfigCategory buildAutoSilkCategory(ModConfig defaults, ModConfi
)
.controller(TickBoxController::new)
.build())
.option(Option.createBuilder(ModConfig.SilkTarget.class)
.name(Text.translatable("text.sbutils.config.option.targetTool"))
.tooltip(Text.translatable("text.sbutils.config.option.targetTool.tooltip"))
.binding(
defaults.targetTool,
() -> config.targetTool,
(value) -> config.targetTool = value
)
.controller(EnumController::new)
.build())
.option(Option.createBuilder(double.class)
.name(Text.translatable("text.sbutils.config.option.autoSilkDelay"))
.tooltip(Text.translatable("text.sbutils.config.option.autoSilkDelay.tooltip"))
Expand Down Expand Up @@ -990,6 +1000,16 @@ private static ConfigCategory buildAutoCrateCategory(ModConfig defaults, ModConf
)
.controller(EnumController::new)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("text.sbutils.config.option.doubleSpin"))
.tooltip(Text.translatable("text.sbutils.config.option.doubleSpin.tooltip"))
.binding(
defaults.doubleSpin,
() -> config.doubleSpin,
(value) -> config.doubleSpin = value
)
.controller(TickBoxController::new)
.build())
.option(Option.createBuilder(double.class)
.name(Text.translatable("text.sbutils.config.option.crateDelay"))
.tooltip(Text.translatable("text.sbutils.config.option.crateDelay.tooltip"))
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/net/xolt/sbutils/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import dev.isxander.yacl.api.NameableEnum;
import dev.isxander.yacl.config.ConfigEntry;
import dev.isxander.yacl.config.ConfigInstance;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -92,8 +94,8 @@ public class ModConfig {

// Chat Logger Settings

@ConfigEntry public boolean shopLoggerIncoming = false;
@ConfigEntry public boolean shopLoggerOutgoing = false;
//@ConfigEntry public boolean shopLoggerIncoming = false;
//@ConfigEntry public boolean shopLoggerOutgoing = false;
@ConfigEntry public boolean msgLoggerIncoming = false;
@ConfigEntry public boolean msgLoggerOutgoing = false;
@ConfigEntry public boolean visitLogger = false;
Expand Down Expand Up @@ -159,13 +161,15 @@ public class ModConfig {
// Auto Silk Settings

@ConfigEntry public boolean autoSilk = false;
@ConfigEntry public SilkTarget targetTool = SilkTarget.DIAMOND_PICKAXE;
@ConfigEntry public double autoSilkDelay = 0.25;


// Auto Crate Settings

@ConfigEntry public boolean autoCrate = false;
@ConfigEntry public CrateMode crateMode = CrateMode.VOTER;
@ConfigEntry public boolean doubleSpin = true;
@ConfigEntry public double crateDelay = 0.25;
@ConfigEntry public double crateDistance = 4.0;

Expand Down Expand Up @@ -247,6 +251,28 @@ public Text getDisplayName() {
}
}

public enum SilkTarget implements NameableEnum {
DIAMOND_PICKAXE(Items.DIAMOND_PICKAXE),
DIAMOND_AXE(Items.DIAMOND_AXE),
DIAMOND_SHOVEL(Items.DIAMOND_SHOVEL),
DIAMOND_HOE(Items.DIAMOND_HOE),
SHEARS(Items.SHEARS);

private final Item tool;

SilkTarget(Item tool) {
this.tool = tool;
}

public Item getTool() {
return tool;
}

public Text getDisplayName() {
return Text.translatable(tool.getTranslationKey());
}
}

public enum NotifSound implements NameableEnum, StringIdentifiable {
EXPERIENCE(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP.getId().toShortTranslationKey(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP),
LAY_EGG(SoundEvents.ENTITY_CHICKEN_EGG.getId().toShortTranslationKey(), SoundEvents.ENTITY_CHICKEN_EGG),
Expand Down
49 changes: 34 additions & 15 deletions src/main/java/net/xolt/sbutils/features/AntiPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.xolt.sbutils.config.ModConfig;
import net.xolt.sbutils.util.Messenger;

import static net.xolt.sbutils.SbUtils.MC;

public class AntiPlace {

private static long lastMessageSentAt;

public static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher) {
LiteralCommandNode<FabricClientCommandSource> antiPlaceNode = dispatcher.register(ClientCommandManager.literal("antiplace")
.then(ClientCommandManager.literal("heads")
Expand Down Expand Up @@ -61,31 +69,42 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
.redirect(antiPlaceNode));
}

public static boolean onHandleBlockPlace() {
if (ModConfig.INSTANCE.getConfig().antiPlaceHeads && isHoldingNamedHead()) {
public static boolean shouldCancelBlockInteract(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult) {
if (MC.world == null) {
return false;
}

ActionResult actionResult = MC.world.getBlockState(hitResult.getBlockPos()).onUse(MC.world, player, hand, hitResult);
if ((actionResult == ActionResult.CONSUME || actionResult == ActionResult.SUCCESS) && !player.isSneaking()) {
return false;
}

ItemStack held = player.getStackInHand(hand);
if (ModConfig.INSTANCE.getConfig().antiPlaceHeads && isNamedHead(held)) {
notifyBlocked("message.sbutils.antiPlace.headBlocked");
return true;
}
if (ModConfig.INSTANCE.getConfig().antiPlaceGrass && isHoldingGrass()) {

if (ModConfig.INSTANCE.getConfig().antiPlaceGrass && isGrass(held)) {
notifyBlocked("message.sbutils.antiPlace.grassBlocked");
return true;
}

return false;
}

private static boolean isHoldingNamedHead() {
if (MC.player == null) {
return false;
}
private static boolean isNamedHead(ItemStack item) {
return item.getItem().equals(Items.PLAYER_HEAD) && item.hasCustomName();
}

ItemStack held = MC.player.getMainHandStack();
return held.getItem().equals(Items.PLAYER_HEAD) && held.hasCustomName();
private static boolean isGrass(ItemStack item) {
return item.getItem().equals(Items.GRASS_BLOCK);
}

private static boolean isHoldingGrass() {
if (MC.player == null) {
return false;
private static void notifyBlocked(String message) {
if (System.currentTimeMillis() - lastMessageSentAt >= 5000) {
Messenger.printMessage(message, Formatting.RED);
lastMessageSentAt = System.currentTimeMillis();
}

ItemStack held = MC.player.getMainHandStack();
return held.getItem().equals(Items.GRASS_BLOCK);
}
}
29 changes: 19 additions & 10 deletions src/main/java/net/xolt/sbutils/features/AutoAdvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.gui.screen.ProgressScreen;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import net.xolt.sbutils.config.ModConfig;
import net.xolt.sbutils.util.IOHandler;
Expand Down Expand Up @@ -291,16 +292,24 @@ public static void tick() {
adIndex = (adIndex + 1) % prevAdList.size();
}

public static void processTitle(Text title) {
if (RegexFilters.skyblockTitleFilter.matcher(title.getString()).matches()) {
currentServer = SbServer.SKYBLOCK;
prevAdList = getAdList();
} else if (RegexFilters.economyTitleFilter.matcher(title.getString()).matches()) {
currentServer = SbServer.ECONOMY;
prevAdList = getAdList();
} else if (RegexFilters.classicTitleFilter.matcher(title.getString()).matches()) {
currentServer = SbServer.CLASSIC;
prevAdList = getAdList();
public static void processMessage(Text message) {
if (RegexFilters.skyblockJoinFilter.matcher(message.getString()).matches()) {
List<Text> siblings = message.getSiblings();
if (siblings.size() < 1) {
return;
}

TextColor serverColor = siblings.get(siblings.size() - 1).getStyle().getColor();
if (serverColor.equals(TextColor.fromFormatting(Formatting.GREEN))) {
currentServer = SbServer.SKYBLOCK;
prevAdList = getAdList();
} else if (serverColor.equals(TextColor.fromFormatting(Formatting.LIGHT_PURPLE))) {
currentServer = SbServer.ECONOMY;
prevAdList = getAdList();
} else if (serverColor.equals(TextColor.fromFormatting(Formatting.YELLOW))) {
currentServer = SbServer.CLASSIC;
prevAdList = getAdList();
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/xolt/sbutils/features/AutoCrate.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -230,10 +231,19 @@ private static boolean isItemKey(ItemStack itemStack) {
}

private static boolean useKey(BlockPos cratePos) {
if (cratePos == null || MC.interactionManager == null) {
if (cratePos == null || MC.interactionManager == null || MC.getNetworkHandler() == null) {
return false;
}

if (ModConfig.INSTANCE.getConfig().doubleSpin) {
MC.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(MC.player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
}

MC.interactionManager.interactBlock(MC.player, Hand.MAIN_HAND, new BlockHitResult(cratePos.toCenterPos(), Direction.UP, cratePos, false));

if (ModConfig.INSTANCE.getConfig().doubleSpin) {
MC.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(MC.player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/xolt/sbutils/features/AutoFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static void processMessage(Text message) {
Matcher fixFailMatcher = RegexFilters.fixFailFilter.matcher(message.getString());
if (fixFailMatcher.matches()) {
String minutesText = fixFailMatcher.group(3);
String secondsText = fixFailMatcher.group(5);
String secondsText = fixFailMatcher.group(6);
int minutes = minutesText.length() > 0 ? Integer.parseInt(minutesText) : 0;
int seconds = secondsText.length() > 0 ? Integer.parseInt(secondsText) : 0;
lastActionPerformedAt = calculateLastCommandSentAt((((long)minutes * 60000) + ((long)seconds * 1000) + 2000));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/xolt/sbutils/features/AutoMine.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ private static int getMinDurability() {
}

public static boolean shouldMine() {
return MC.player != null && !MC.isPaused() && !AutoFix.fixing() && !ToolSaver.shouldCancelAction();
return MC.player != null && !MC.isPaused() && !AutoFix.fixing() && !ToolSaver.shouldCancelAttack();
}
}
26 changes: 19 additions & 7 deletions src/main/java/net/xolt/sbutils/features/AutoRaffle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AutoRaffle {

private static boolean enabled;
private static boolean waitingToBuy;
private static boolean shouldSendErrorMessage;
private static long checkedForGrassAt;

public static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher) {
Expand Down Expand Up @@ -66,7 +67,7 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
public static void tick() {
if (enabled != ModConfig.INSTANCE.getConfig().autoRaffle) {
enabled = ModConfig.INSTANCE.getConfig().autoRaffle;
waitingToBuy = enabled;
reset();
}

if (!ModConfig.INSTANCE.getConfig().autoRaffle || MC.getNetworkHandler() == null || MC.currentScreen instanceof ProgressScreen) {
Expand All @@ -80,13 +81,13 @@ public static void tick() {

public static void processMessage(Text message) {
if (ModConfig.INSTANCE.getConfig().autoRaffle && RegexFilters.raffleEndFilter.matcher(message.getString()).matches()) {
waitingToBuy = true;
reset();
}
}

public static void onGameJoin() {
public static void onJoinGame() {
if (ModConfig.INSTANCE.getConfig().autoRaffle) {
waitingToBuy = true;
reset();
}
}

Expand All @@ -96,15 +97,21 @@ private static void buyTickets() {
}

int numTickets = Math.min(Math.max(ModConfig.INSTANCE.getConfig().raffleTickets, 1), 2);
if (getGrassCount() < numTickets) {
int grassCount = getGrassCount();
if (grassCount < 1) {
waitingToBuy = true;
checkedForGrassAt = System.currentTimeMillis();
if (shouldSendErrorMessage) {
Messenger.printMessage("message.sbutils.autoRaffle.notEnoughGrass");
shouldSendErrorMessage = false;
}
return;
}

MC.getNetworkHandler().sendChatCommand("raffle buy " + numTickets);
int buyAmount = Math.min(numTickets, grassCount);
MC.getNetworkHandler().sendChatCommand("raffle buy " + buyAmount);
waitingToBuy = false;
Messenger.printMessage("message.sbutils.autoRaffle.buying");
Messenger.printWithPlaceholders("message.sbutils.autoRaffle.buying", buyAmount);
}

private static int getGrassCount() {
Expand All @@ -123,4 +130,9 @@ private static int getGrassCount() {
}
return counter;
}

private static void reset() {
waitingToBuy = true;
shouldSendErrorMessage = true;
}
}
Loading

0 comments on commit 07b5e98

Please sign in to comment.