Skip to content

Commit

Permalink
Add Island Pickobulus Block
Browse files Browse the repository at this point in the history
Introduced an option to block the Pickobulus ability on private islands.
  • Loading branch information
Manchick0 committed Jan 17, 2025
1 parent 15bce9f commit 7de1f1e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.name(Text.translatable("skyblocker.config.mining"))

//Uncategorized Options
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.mining.islandPickobulusBlock"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.mining.islandPickobulusBlock.@Tooltip")))
.binding(defaults.mining.islandPickobulusBlock,
() -> config.mining.islandPickobulusBlock,
newValue -> config.mining.islandPickobulusBlock = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.mining.enableDrillFuel"))
.binding(defaults.mining.enableDrillFuel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import java.util.List;

public class MiningConfig {

@SerialEntry
public boolean islandPickobulusBlock = false;

@SerialEntry
public boolean enableDrillFuel = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.hysky.skyblocker.skyblock;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;

public final class IslandPickobulusBlock {

@Init
public static void init() {
UseItemCallback.EVENT.register((player, world, hand) ->
IslandPickobulusBlock.checkForPickobulus(player, hand));
UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) ->
IslandPickobulusBlock.checkForPickobulus(player, hand));
}

private static ActionResult checkForPickobulus(PlayerEntity player, Hand hand) {
var config = SkyblockerConfigManager.get();
if (config.mining.islandPickobulusBlock
&& Utils.getLocation() == Location.PRIVATE_ISLAND) {
var stack = player.getStackInHand(hand);
var ability = ItemUtils.getAbility(stack);
if (ability.isPresent()) {
var name = ability.get();
if (name.equalsIgnoreCase("pickobulus")) {
return ActionResult.FAIL; // Cancels and doesn't send a package
}
}
}
return ActionResult.PASS;
}
}
8 changes: 7 additions & 1 deletion src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class ItemUtils {
public static final String ID = "id";
public static final String UUID = "uuid";
public static final Pattern NOT_DURABILITY = Pattern.compile("[^0-9 /]");
public static final Pattern ABILITY = Pattern.compile("ability:\\s+(?<ability>[\\w\\s]+?)\\s+right\\s+click", Pattern.CASE_INSENSITIVE);
public static final Predicate<String> FUEL_PREDICATE = line -> line.contains("Fuel: ");
private static final Codec<RegistryEntry<Item>> EMPTY_ALLOWING_ITEM_CODEC = Registries.ITEM.getEntryCodec();
public static final Codec<ItemStack> EMPTY_ALLOWING_ITEMSTACK_CODEC = Codec.lazyInitialized(() -> RecordCodecBuilder.create(instance -> instance.group(
Expand Down Expand Up @@ -424,6 +425,11 @@ public static Matcher getLoreLineIfContainsMatch(ItemStack stack, Pattern patter
return stack.getOrDefault(DataComponentTypes.LORE, LoreComponent.DEFAULT).styledLines();
}

public static Optional<String> getAbility(ItemStack stack) {
var match = ItemUtils.getLoreLineIfMatch(stack, ABILITY);
return Optional.ofNullable(match).map(m -> m.group("ability"));
}

public static @NotNull PropertyMap propertyMapWithTexture(String textureValue) {
return Codecs.GAME_PROFILE_PROPERTY_MAP.parse(JsonOps.INSTANCE, JsonParser.parseString("[{\"name\":\"textures\",\"value\":\"" + textureValue + "\"}]")).getOrThrow();
}
Expand Down Expand Up @@ -475,4 +481,4 @@ public static Matcher getLoreLineIfContainsMatch(ItemStack stack, Pattern patter
}
return stringBuilder.toString();
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@

"skyblocker.config.mining": "Mining",

"skyblocker.config.mining.islandPickobulusBlock": "Island Pickobulus Block",
"skyblocker.config.mining.islandPickobulusBlock.@Tooltip": "Blocks the pickobulus ability when on your private island.",

"skyblocker.config.mining.commissionWaypoints": "Commission Waypoints",
"skyblocker.config.mining.commissionWaypoints.mode": "Enable Commission Waypoints",
"skyblocker.config.mining.commissionWaypoints.mode.@Tooltip[0]": "Off: Do not show Commission waypoint.",
Expand Down

0 comments on commit 7de1f1e

Please sign in to comment.