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

Add Island Pickobulus Block #1139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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,38 @@
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 != null) {
if (ability.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 String getAbility(ItemStack stack) {
var match = ItemUtils.getLoreLineIfMatch(stack, ABILITY);
return match == null ? null : match.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
Loading