@@ -3,12 +3,15 @@ package dev.sterner.registry
3
3
import com.google.common.collect.Multimap
4
4
import com.sammy.malum.common.events.MalumCodexEvents
5
5
import dev.sterner.api.ClientTickHandler
6
+ import dev.sterner.api.VoidBoundApi
7
+ import dev.sterner.api.item.ItemAbility
6
8
import dev.sterner.client.event.*
7
9
import dev.sterner.common.components.VoidBoundPlayerComponent
8
10
import dev.sterner.common.components.VoidBoundWorldComponent
9
11
import dev.sterner.common.item.tool.TidecutterItem
10
12
import dev.sterner.common.item.tool.UpgradableTool
11
13
import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents
14
+ import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents.BlockBreak
12
15
import net.fabricmc.api.EnvType
13
16
import net.fabricmc.api.Environment
14
17
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
@@ -17,12 +20,19 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents
17
20
import net.fabricmc.fabric.api.event.player.UseBlockCallback
18
21
import net.fabricmc.fabric.api.event.player.UseEntityCallback
19
22
import net.fabricmc.fabric.api.item.v1.ModifyItemAttributeModifiersCallback
23
+ import net.fabricmc.fabric.api.loot.v2.LootTableEvents
24
+ import net.minecraft.server.level.ServerLevel
20
25
import net.minecraft.world.entity.EquipmentSlot
21
26
import net.minecraft.world.entity.ai.attributes.Attribute
22
27
import net.minecraft.world.entity.ai.attributes.AttributeModifier
23
28
import net.minecraft.world.entity.ai.attributes.Attributes
24
29
import net.minecraft.world.item.ItemStack
30
+ import net.minecraft.world.item.crafting.RecipeType
31
+ import net.minecraft.world.item.crafting.SmeltingRecipe
32
+ import net.minecraft.world.level.block.Block
33
+ import net.minecraft.world.level.block.entity.FurnaceBlockEntity
25
34
import java.util.*
35
+ import io.github.fabricators_of_create.porting_lib.loot.LootModifier;
26
36
27
37
28
38
object VoidBoundEvents {
@@ -33,6 +43,55 @@ object VoidBoundEvents {
33
43
BlockEvents .BLOCK_BREAK .register(VoidBoundWorldComponent .Companion ::removeWard)
34
44
BlockEvents .BLOCK_BREAK .register(TidecutterItem .Companion ::breakBlock)
35
45
46
+ BlockEvents .BLOCK_BREAK .register { event ->
47
+ val player = event?.player
48
+
49
+ if (player?.level() is ServerLevel ) {
50
+ val level = player.level() as ? ServerLevel
51
+ val pos = event.pos
52
+ if (VoidBoundApi .hasItemAbility(player.mainHandItem, ItemAbility .AUTOSMELT ) && false ) {
53
+ val blockState = level!! .getBlockState(pos)
54
+ val blockEntity = level.getBlockEntity(pos)
55
+
56
+ // Get the list of dropped items from the block
57
+ val drops: MutableList <ItemStack > = Block .getDrops(blockState, level, pos, blockEntity)
58
+
59
+ // Retrieve all smelting recipes
60
+ val allSmeltingRecipes = level.recipeManager.getAllRecipesFor(RecipeType .SMELTING )
61
+
62
+ // Create a map of ItemStack to its smelted result
63
+ val smeltedResults = mutableMapOf<ItemStack , ItemStack >()
64
+
65
+ // Populate the smeltedResults map
66
+ for (recipe in allSmeltingRecipes) {
67
+ if (recipe is SmeltingRecipe ) {
68
+ for (ingredient in recipe.ingredients) {
69
+ val smeltedResult = recipe.getResultItem(level.registryAccess())
70
+ for (item in drops) {
71
+ if (ingredient.test(item)) {
72
+ smeltedResults[item] = smeltedResult
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ // Drop smelted items instead of original items
80
+ for ((item, smeltedResult) in smeltedResults) {
81
+ // Remove the original item from the list
82
+ drops.remove(item)
83
+ // Drop the smelted result
84
+ Block .popResource(level, pos, smeltedResult)
85
+ }
86
+
87
+ // Drop the original items that didn't have a smelting recipe
88
+ for (item in drops) {
89
+ Block .popResource(level, pos, item)
90
+ }
91
+ }
92
+ }
93
+ }
94
+
36
95
/* *
37
96
* Add extra damage to UpgradableTools when it has extra damage
38
97
*/
0 commit comments