|
11 | 11 | import net.swofty.types.generic.event.EventNodes; |
12 | 12 | import net.swofty.types.generic.event.SkyBlockEventClass; |
13 | 13 | import net.swofty.types.generic.event.SkyBlockEventHandler; |
14 | | -import net.swofty.types.generic.item.ItemDropChanger; |
15 | 14 | import net.swofty.types.generic.item.SkyBlockItem; |
| 15 | +import net.swofty.types.generic.item.components.CustomDropComponent; |
16 | 16 | import net.swofty.types.generic.region.RegionType; |
17 | 17 | import net.swofty.types.generic.region.SkyBlockMiningConfiguration; |
18 | 18 | import net.swofty.types.generic.region.SkyBlockRegion; |
|
21 | 21 | import net.swofty.types.generic.event.SkyBlockEvent; |
22 | 22 | import net.swofty.types.generic.event.custom.CustomBlockBreakEvent; |
23 | 23 |
|
| 24 | +import java.util.List; |
| 25 | + |
24 | 26 | public class ActionRegionBlockBreak implements SkyBlockEventClass { |
25 | 27 |
|
26 | 28 | @SkyBlockEvent(node = EventNodes.PLAYER, requireDataLoaded = false) |
@@ -68,74 +70,85 @@ else if (region != null) { |
68 | 70 |
|
69 | 71 | // Handle item drops for valid breaks |
70 | 72 | if (material != null && shouldItemDrop) { |
71 | | - // Determine which item should be dropped |
72 | | - SkyBlockItem item = ItemDropChanger.get(material) != null ? |
73 | | - ItemDropChanger.get(material).getItemSupplier().get() : |
74 | | - new SkyBlockItem(material); |
| 73 | + SkyBlockItem brokenBlockItem = new SkyBlockItem(material); |
| 74 | + |
| 75 | + // Determine which item(s) should be dropped using CustomDropComponent |
| 76 | + List<SkyBlockItem> customDrops = CustomDropComponent.simulateDrop( |
| 77 | + brokenBlockItem, |
| 78 | + player, |
| 79 | + new SkyBlockItem(player.getItemInMainHand()), |
| 80 | + region, |
| 81 | + SkyBlockConst.isIslandServer() |
| 82 | + ); |
75 | 83 |
|
76 | 84 | // Call custom break event |
77 | 85 | SkyBlockEventHandler.callSkyBlockEvent(new CustomBlockBreakEvent( |
78 | | - player, item.getMaterial(), event.getBlockPosition() |
| 86 | + player, material, event.getBlockPosition(), customDrops |
79 | 87 | )); |
80 | 88 |
|
81 | | - // Calculate drop amount with fortune multiplier |
82 | | - int dropAmount; |
83 | | - try { |
84 | | - MineableBlock mineableBlock = MineableBlock.get(block); |
85 | | - double baseFortune = player.getStatistics().allStatistics().getOverall(mineableBlock.getBlockType().baseSkillFortune()); //might need to return 100 if null |
86 | | - double specificFortune = player.getStatistics().allStatistics().getOverall(mineableBlock.getBlockType().specificBlockFortune()); |
87 | | - double fortune = baseFortune + specificFortune; |
88 | | - double dropMultiplicator = (1 + (fortune * 0.01)); |
89 | | - dropAmount = mineableBlock.getDrops().getAmount(dropMultiplicator); |
90 | | - } catch (NullPointerException e) { |
91 | | - dropAmount = 1; |
92 | | - } |
| 89 | + // Process each drop with fortune multiplier |
| 90 | + for (SkyBlockItem dropItem : customDrops) { |
| 91 | + // Calculate drop amount with fortune multiplier |
| 92 | + int dropAmount = dropItem.getAmount(); // Base amount from CustomDropComponent |
| 93 | + |
| 94 | + try { |
| 95 | + MineableBlock mineableBlock = MineableBlock.get(block); |
| 96 | + if (mineableBlock != null) { |
| 97 | + double baseFortune = player.getStatistics().allStatistics().getOverall(mineableBlock.getBlockType().baseSkillFortune()); |
| 98 | + double specificFortune = player.getStatistics().allStatistics().getOverall(mineableBlock.getBlockType().specificBlockFortune()); |
| 99 | + double fortune = baseFortune + specificFortune; |
| 100 | + double dropMultiplier = (1 + (fortune * 0.01)); |
| 101 | + dropAmount = (int) Math.ceil(dropAmount * dropMultiplier); |
| 102 | + } |
| 103 | + } catch (NullPointerException e) { |
| 104 | + // Keep base amount if fortune calculation fails |
| 105 | + } |
93 | 106 |
|
94 | | - // Create the item to be given to the player |
95 | | - SkyBlockItem skyBlockItem = new SkyBlockItem(item.getItemStackBuilder().amount(dropAmount).build()); |
96 | | - ItemType droppedItemType = skyBlockItem.getAttributeHandler().getPotentialType(); |
97 | | - |
98 | | -// Handle item distribution based on player conditions |
99 | | - if (player.canInsertItemIntoSacks(droppedItemType, dropAmount)) { |
100 | | - player.getSackItems().increase(droppedItemType, dropAmount); |
101 | | - } else if (player.getSkyBlockExperience().getLevel().asInt() >= 6) { |
102 | | - player.addAndUpdateItem(skyBlockItem); |
103 | | - } else { |
104 | | - // Determine nearest air block between ore and player |
105 | | - Pos orePos = Pos.fromPoint(event.getBlockPosition()); |
106 | | - Pos playerPos = player.getPosition(); |
107 | | - |
108 | | - Pos[] offsets = { |
109 | | - new Pos(1, 0, 0), new Pos(-1, 0, 0), |
110 | | - new Pos(0, 1, 0), new Pos(0, -1, 0), |
111 | | - new Pos(0, 0, 1), new Pos(0, 0, -1) |
112 | | - }; |
113 | | - |
114 | | - Pos nearestAirBlock = null; |
115 | | - double closestDistanceSquared = Double.MAX_VALUE; |
116 | | - |
117 | | - for (Pos offset : offsets) { |
118 | | - Pos adjacentPos = orePos.add(offset); |
119 | | - Block block2 = player.getInstance().getBlock(adjacentPos); |
120 | | - |
121 | | - if (block2.isAir()) { |
122 | | - double distanceSquared = adjacentPos.distanceSquared(playerPos); |
123 | | - if (distanceSquared < closestDistanceSquared) { |
124 | | - closestDistanceSquared = distanceSquared; |
125 | | - nearestAirBlock = adjacentPos; |
| 107 | + // Update the drop item amount |
| 108 | + dropItem.setAmount(dropAmount); |
| 109 | + ItemType droppedItemType = dropItem.getAttributeHandler().getPotentialType(); |
| 110 | + |
| 111 | + // Handle item distribution based on player conditions |
| 112 | + if (player.canInsertItemIntoSacks(droppedItemType, dropAmount)) { |
| 113 | + player.getSackItems().increase(droppedItemType, dropAmount); |
| 114 | + } else if (player.getSkyBlockExperience().getLevel().asInt() >= 6) { |
| 115 | + player.addAndUpdateItem(dropItem); |
| 116 | + } else { |
| 117 | + // Determine nearest air block between ore and player |
| 118 | + Pos orePos = Pos.fromPoint(event.getBlockPosition()); |
| 119 | + Pos playerPos = player.getPosition(); |
| 120 | + |
| 121 | + Pos[] offsets = { |
| 122 | + new Pos(1, 0, 0), new Pos(-1, 0, 0), |
| 123 | + new Pos(0, 1, 0), new Pos(0, -1, 0), |
| 124 | + new Pos(0, 0, 1), new Pos(0, 0, -1) |
| 125 | + }; |
| 126 | + |
| 127 | + Pos nearestAirBlock = null; |
| 128 | + double closestDistanceSquared = Double.MAX_VALUE; |
| 129 | + |
| 130 | + for (Pos offset : offsets) { |
| 131 | + Pos adjacentPos = orePos.add(offset); |
| 132 | + Block block2 = player.getInstance().getBlock(adjacentPos); |
| 133 | + |
| 134 | + if (block2.isAir()) { |
| 135 | + double distanceSquared = adjacentPos.distanceSquared(playerPos); |
| 136 | + if (distanceSquared < closestDistanceSquared) { |
| 137 | + closestDistanceSquared = distanceSquared; |
| 138 | + nearestAirBlock = adjacentPos; |
| 139 | + } |
126 | 140 | } |
127 | 141 | } |
128 | | - } |
129 | 142 |
|
130 | | - // Use the nearest air block or fallback to default position |
131 | | - Pos dropPos = (nearestAirBlock != null) ? nearestAirBlock.add(0.5, 0.5, 0.5) : orePos.add(0.5, 1.5, 0.5); |
| 143 | + // Use the nearest air block or fallback to default position |
| 144 | + Pos dropPos = (nearestAirBlock != null) ? nearestAirBlock.add(0.5, 0.5, 0.5) : orePos.add(0.5, 1.5, 0.5); |
132 | 145 |
|
133 | | - // Spawn the item |
134 | | - DroppedItemEntityImpl droppedItem = new DroppedItemEntityImpl(skyBlockItem, player); |
135 | | - droppedItem.setInstance(player.getInstance(), dropPos); |
136 | | - droppedItem.addViewer(player); |
| 146 | + // Spawn the item |
| 147 | + DroppedItemEntityImpl droppedItem = new DroppedItemEntityImpl(dropItem, player); |
| 148 | + droppedItem.setInstance(player.getInstance(), dropPos); |
| 149 | + droppedItem.addViewer(player); |
| 150 | + } |
137 | 151 | } |
138 | | - |
139 | 152 | } |
140 | 153 | } |
141 | 154 | } |
|
0 commit comments