Skip to content

Commit d928488

Browse files
feat: overhauled mining system
1 parent c128b13 commit d928488

33 files changed

Lines changed: 671 additions & 100 deletions

configuration/skyblock/items/vanilla/items/tools/axes.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ items:
55
damage: 10.0
66
components:
77
- id: AXE
8+
axe_strength: 2
89
- id: DEFAULT_CRAFTABLE
910
recipes:
1011
- type: SHAPED
@@ -50,6 +51,7 @@ items:
5051
damage: 15.0
5152
components:
5253
- id: AXE
54+
axe_strength: 4
5355
- id: DEFAULT_CRAFTABLE
5456
recipes:
5557
- type: SHAPED
@@ -95,6 +97,7 @@ items:
9597
damage: 25.0
9698
components:
9799
- id: AXE
100+
axe_strength: 6
98101
- id: DEFAULT_CRAFTABLE
99102
recipes:
100103
- type: SHAPED
@@ -140,6 +143,7 @@ items:
140143
damage: 20.0
141144
components:
142145
- id: AXE
146+
axe_strength: 12
143147
- id: DEFAULT_CRAFTABLE
144148
recipes:
145149
- type: SHAPED
@@ -185,6 +189,7 @@ items:
185189
damage: 30.0
186190
components:
187191
- id: AXE
192+
axe_strength: 8
188193
- id: DEFAULT_CRAFTABLE
189194
recipes:
190195
- type: SHAPED

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/SkyBlockGenericLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
import net.swofty.type.skyblockgeneric.noteblock.SkyBlockSongsHandler;
6666
import net.swofty.type.skyblockgeneric.redis.RedisAuthenticate;
6767
import net.swofty.type.generic.redis.RedisOriginServer;
68-
import net.swofty.type.skyblockgeneric.region.SkyBlockMiningConfiguration;
68+
import net.swofty.type.skyblockgeneric.region.SkyBlockRegenConfiguration;
6969
import net.swofty.type.skyblockgeneric.region.SkyBlockRegion;
7070
import net.swofty.type.skyblockgeneric.server.attribute.SkyBlockServerAttributes;
7171
import net.swofty.type.skyblockgeneric.server.eventcaller.CustomEventCaller;
@@ -270,7 +270,7 @@ public void initialize(MinecraftServer server) {
270270
* Load regions
271271
*/
272272
SkyBlockRegion.cacheRegions();
273-
SkyBlockMiningConfiguration.startRepeater(MinecraftServer.getSchedulerManager());
273+
SkyBlockRegenConfiguration.startRepeater(MinecraftServer.getSchedulerManager());
274274
MinecraftServer.getDimensionTypeRegistry().register(
275275
Key.key("skyblock:island"),
276276
DimensionType.builder()
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package net.swofty.type.skyblockgeneric.commands;
2+
3+
import net.swofty.type.generic.command.CommandParameters;
4+
import net.swofty.type.generic.command.HypixelCommand;
5+
import net.swofty.type.generic.user.categories.Rank;
6+
import net.swofty.type.skyblockgeneric.item.SkyBlockItemComponent;
7+
import net.swofty.type.skyblockgeneric.item.components.AxeComponent;
8+
import net.swofty.type.skyblockgeneric.item.components.DrillComponent;
9+
import net.swofty.type.skyblockgeneric.item.components.HoeComponent;
10+
import net.swofty.type.skyblockgeneric.item.components.PickaxeComponent;
11+
import net.swofty.type.skyblockgeneric.region.mining.MineableBlock;
12+
import net.swofty.type.skyblockgeneric.region.mining.handler.SkyBlockMiningHandler;
13+
14+
import java.util.ArrayList;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
@CommandParameters(aliases = "mininginfo",
20+
description = "Debug command to display mining handler relationships",
21+
usage = "/miningdebug",
22+
permission = Rank.ADMIN,
23+
allowsConsole = false)
24+
public class MiningDebugCommand extends HypixelCommand {
25+
26+
@Override
27+
public void registerUsage(MinestomCommand command) {
28+
command.addSyntax((sender, context) -> {
29+
if (!permissionCheck(sender)) return;
30+
31+
sender.sendMessage("§6§l=== Mining Handler Debug ===");
32+
sender.sendMessage("");
33+
34+
// Group blocks by handler type
35+
Map<String, List<MineableBlock>> blocksByHandler = new HashMap<>();
36+
37+
for (MineableBlock block : MineableBlock.values()) {
38+
SkyBlockMiningHandler handler = block.getMiningHandler();
39+
String handlerName = handler.getHandlerName();
40+
blocksByHandler.computeIfAbsent(handlerName, k -> new ArrayList<>()).add(block);
41+
}
42+
43+
// Print blocks grouped by handler
44+
sender.sendMessage("§e§lBlocks by Handler Type:");
45+
for (Map.Entry<String, List<MineableBlock>> entry : blocksByHandler.entrySet()) {
46+
sender.sendMessage("");
47+
sender.sendMessage("§b" + entry.getKey() + " Handler §7(" + entry.getValue().size() + " blocks):");
48+
for (MineableBlock block : entry.getValue()) {
49+
SkyBlockMiningHandler handler = block.getMiningHandler();
50+
String strengthInfo = handler.breaksInstantly() ? "§aInstant" : "§7Strength: " + handler.getStrength();
51+
String powerInfo = handler.getMiningPowerRequirement() > 0 ? " §7Power: " + handler.getMiningPowerRequirement() : "";
52+
sender.sendMessage(" §7- §f" + block.name() + " §7(" + strengthInfo + powerInfo + "§7)");
53+
}
54+
}
55+
56+
sender.sendMessage("");
57+
sender.sendMessage("§e§lTool Component Mappings:");
58+
59+
// Print tool -> blocks relationships
60+
printToolBlocks(sender, "Pickaxe/Drill", PickaxeComponent.class, DrillComponent.class);
61+
printToolBlocks(sender, "Axe", AxeComponent.class);
62+
printToolBlocks(sender, "Hoe", HoeComponent.class);
63+
64+
sender.sendMessage("");
65+
sender.sendMessage("§6§l=========================");
66+
});
67+
}
68+
69+
@SafeVarargs
70+
private void printToolBlocks(Object sender, String toolName, Class<? extends SkyBlockItemComponent>... componentClasses) {
71+
List<String> breakableBlocks = new ArrayList<>();
72+
73+
for (MineableBlock block : MineableBlock.values()) {
74+
SkyBlockMiningHandler handler = block.getMiningHandler();
75+
List<Class<? extends SkyBlockItemComponent>> validComponents = handler.getValidToolComponents();
76+
77+
for (Class<? extends SkyBlockItemComponent> componentClass : componentClasses) {
78+
if (validComponents.contains(componentClass)) {
79+
breakableBlocks.add(block.name());
80+
break;
81+
}
82+
}
83+
}
84+
85+
if (!breakableBlocks.isEmpty()) {
86+
((net.minestom.server.command.CommandSender) sender).sendMessage("§b" + toolName + " §7can break " + breakableBlocks.size() + " blocks:");
87+
((net.minestom.server.command.CommandSender) sender).sendMessage(" §7" + String.join(", ", breakableBlocks));
88+
} else {
89+
((net.minestom.server.command.CommandSender) sender).sendMessage("§b" + toolName + " §7has no breakable blocks configured");
90+
}
91+
}
92+
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/event/actions/custom/ActionPlayerDamageBlock.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import net.swofty.type.generic.event.HypixelEventClass;
1313
import net.swofty.type.skyblockgeneric.event.custom.PlayerDamageSkyBlockBlockEvent;
1414
import net.swofty.type.skyblockgeneric.item.SkyBlockItem;
15-
import net.swofty.type.skyblockgeneric.item.components.DrillComponent;
16-
import net.swofty.type.skyblockgeneric.item.components.PickaxeComponent;
1715
import net.swofty.type.skyblockgeneric.region.SkyBlockRegion;
1816
import net.swofty.type.skyblockgeneric.region.mining.BreakingTask;
17+
import net.swofty.type.skyblockgeneric.region.mining.MineableBlock;
18+
import net.swofty.type.skyblockgeneric.region.mining.handler.SkyBlockMiningHandler;
1919
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
2020

2121
import java.util.HashMap;
@@ -57,9 +57,16 @@ public void run(PlayerDamageSkyBlockBlockEvent event) {
5757
return;
5858
}
5959

60-
// Ensure that the player isn't just using their hand
60+
// Check if the player's tool can break this block using the handler system
6161
SkyBlockItem item = new SkyBlockItem(player.getItemInMainHand());
62-
if (!item.hasComponent(PickaxeComponent.class) && !item.hasComponent(DrillComponent.class)) return;
62+
MineableBlock mineableBlock = MineableBlock.get(player.getInstance().getBlock(event.getBlockPosition()));
63+
if (mineableBlock != null) {
64+
SkyBlockMiningHandler handler = mineableBlock.getMiningHandler();
65+
// If block doesn't break instantly and tool can't break it, return
66+
if (!handler.breaksInstantly() && !handler.canToolBreak(item)) {
67+
return;
68+
}
69+
}
6370

6471
BreakingTask task = new BreakingTask(
6572
player,

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/event/actions/custom/collection/ActionCollectionDisplay.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.swofty.type.skyblockgeneric.event.custom.CollectionUpdateEvent;
1313
import net.swofty.type.skyblockgeneric.item.updater.NonPlayerItemUpdater;
1414
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
15+
import org.tinylog.Logger;
1516

1617
import java.util.Arrays;
1718

@@ -71,6 +72,11 @@ public void run(CollectionUpdateEvent event) {
7172
Arrays.stream(oldReward.unlocks()).forEach(unlock -> {
7273
switch (unlock.type()) {
7374
case RECIPE -> {
75+
CollectionCategory.UnlockRecipe recipeUnlock = (CollectionCategory.UnlockRecipe) unlock;
76+
if (recipeUnlock.getRecipe() != null) {
77+
Logger.error("We have a null recipe in collection unlocks for " + event.getItemType().name() + " in " + event.getPlayer().getCollection().get(event.getItemType()));
78+
return;
79+
}
7480
ItemStack.Builder item = ((CollectionCategory.UnlockRecipe) unlock).getRecipe().getResult().getItemStackBuilder();
7581
item = new NonPlayerItemUpdater(item).getUpdatedItem();
7682

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/event/actions/player/region/ActionRegionBlockBreak.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
import net.swofty.type.skyblockgeneric.item.SkyBlockItem;
1818
import net.swofty.type.skyblockgeneric.item.components.CustomDropComponent;
1919
import net.swofty.type.skyblockgeneric.region.RegionType;
20-
import net.swofty.type.skyblockgeneric.region.SkyBlockMiningConfiguration;
20+
import net.swofty.type.skyblockgeneric.region.SkyBlockRegenConfiguration;
2121
import net.swofty.type.skyblockgeneric.region.SkyBlockRegion;
2222
import net.swofty.type.skyblockgeneric.region.mining.MineableBlock;
23+
import net.swofty.type.skyblockgeneric.region.mining.handler.SkyBlockMiningHandler;
2324
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
2425

2526
import java.util.List;
@@ -49,20 +50,29 @@ public void run(PlayerBlockBreakEvent event) {
4950
// Handle region-specific block breaks
5051
else if (region != null) {
5152
RegionType type = region.getType();
52-
SkyBlockMiningConfiguration mining = type.getMiningHandler();
53+
SkyBlockRegenConfiguration mining = type.getMiningHandler();
5354

5455
// Validate if block can be mined in this region
5556
if (material != null && mining != null && !mining.getMineableBlocks(player.getInstance(), event.getBlockPosition()).contains(material)) {
5657
event.setCancelled(true);
5758
return;
5859
}
5960

60-
// Check if player has sufficient breaking power
61+
// Check if player's tool can break this block using the handler system
6162
MineableBlock mineableBlock = MineableBlock.get(block);
6263
if (mineableBlock != null) {
6364
SkyBlockItem heldItem = new SkyBlockItem(player.getItemInMainHand());
65+
SkyBlockMiningHandler handler = mineableBlock.getMiningHandler();
66+
67+
// Check if tool can break this block (unless it breaks instantly)
68+
if (!handler.breaksInstantly() && !handler.canToolBreak(heldItem)) {
69+
event.setCancelled(true);
70+
return;
71+
}
72+
73+
// Check breaking power requirement
6474
int playerBreakingPower = heldItem.getAttributeHandler().getBreakingPower();
65-
if (playerBreakingPower < mineableBlock.getMiningPowerRequirement()) {
75+
if (playerBreakingPower < handler.getMiningPowerRequirement()) {
6676
event.setCancelled(true);
6777
return;
6878
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/item/ItemConfigParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public static ConfigurableSkyBlockItem parseItem(Map<String, Object> config) {
8080
String category = (String) config.get("category");
8181
yield new AuctionCategoryComponent(category);
8282
}
83-
case "AXE" -> new AxeComponent();
83+
case "AXE" -> {
84+
int axeStrength = config.containsKey("axe_strength") ? (int) config.get("axe_strength") : 1;
85+
yield new AxeComponent(axeStrength);
86+
}
8487
case "BACKPACK" -> {
8588
int rows = (int) config.get("rows");
8689
String skullTexture = (String) config.get("skull-texture");
@@ -167,6 +170,7 @@ yield new EnchantableComponent(
167170
String texture = (String) config.get("skull_texture");
168171
yield new GemstoneImplComponent(rarity, gemstone, texture);
169172
}
173+
case "HOE" -> new HoeComponent();
170174
case "HOT_POTATO" -> {
171175
String type = (String) config.get("potato_type");
172176

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package net.swofty.type.skyblockgeneric.item.components;
22

3+
import lombok.Getter;
34
import net.swofty.commons.item.reforge.ReforgeType;
45
import net.swofty.type.skyblockgeneric.item.SkyBlockItemComponent;
56
import net.swofty.type.skyblockgeneric.utility.groups.EnchantItemGroups;
67

78
import java.util.List;
89

10+
@Getter
911
public class AxeComponent extends SkyBlockItemComponent {
10-
public AxeComponent() {
12+
private final int axeStrength;
13+
14+
/**
15+
* Create an axe component with specified strength.
16+
* @param axeStrength The axe's breaking speed (higher = faster). Used to calculate break time.
17+
*/
18+
public AxeComponent(int axeStrength) {
19+
this.axeStrength = axeStrength;
1120
addInheritedComponent(new ExtraRarityComponent("AXE"));
1221
addInheritedComponent(new ReforgableComponent(ReforgeType.AXES));
1322
addInheritedComponent(new EnchantableComponent(List.of(EnchantItemGroups.TOOLS), true));
1423
addInheritedComponent(new TrackedUniqueComponent());
1524
}
16-
}
25+
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.swofty.type.skyblockgeneric.item.components;
2+
3+
import net.swofty.commons.item.reforge.ReforgeType;
4+
import net.swofty.type.skyblockgeneric.item.SkyBlockItemComponent;
5+
import net.swofty.type.skyblockgeneric.utility.groups.EnchantItemGroups;
6+
7+
import java.util.List;
8+
9+
/**
10+
* Component for hoe tools.
11+
* Placeholder for future farming speed bonuses.
12+
*/
13+
public class HoeComponent extends SkyBlockItemComponent {
14+
public HoeComponent() {
15+
addInheritedComponent(new ExtraRarityComponent("HOE"));
16+
addInheritedComponent(new ReforgableComponent(ReforgeType.HOES));
17+
addInheritedComponent(new EnchantableComponent(List.of(EnchantItemGroups.TOOLS), true));
18+
addInheritedComponent(new TrackedUniqueComponent());
19+
}
20+
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/packets/client/PacketListenerPlayerDig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public void run(PlayerPacketEvent event, ClientPacket packet, HypixelPlayer play
2828

2929
@Override
3030
public boolean overrideMinestomProcessing() {
31-
return true;
31+
return false;
3232
}
3333
}

0 commit comments

Comments
 (0)