From 0c1eea905ed1ba24b89ffaea36d654fb5c2738ea Mon Sep 17 00:00:00 2001 From: stellanera Date: Tue, 16 Dec 2025 11:24:59 +0100 Subject: [PATCH] try again --- .../bloodmagic/loot/GlobalLootModifier.java | 53 +++++++------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/main/java/wayoftime/bloodmagic/loot/GlobalLootModifier.java b/src/main/java/wayoftime/bloodmagic/loot/GlobalLootModifier.java index 57057dad3..589259040 100644 --- a/src/main/java/wayoftime/bloodmagic/loot/GlobalLootModifier.java +++ b/src/main/java/wayoftime/bloodmagic/loot/GlobalLootModifier.java @@ -12,6 +12,7 @@ import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; @@ -50,19 +51,6 @@ public class GlobalLootModifier public static final RegistryObject> SMELT = GLM.register("smelt", SmeltingModifier.CODEC); public static final RegistryObject> VOID = GLM.register("voiding", VoidingModifier.CODEC); - private static LootParams.Builder copyBlockNoTool(LootContext context) { - LootParams.Builder builder = new LootParams.Builder(context.getLevel()); - builder.withLuck(context.getLuck()); - builder.withParameter(LootContextParams.BLOCK_STATE, context.getParam(LootContextParams.BLOCK_STATE)); - builder.withParameter(LootContextParams.ORIGIN, context.getParam(LootContextParams.ORIGIN)); - - builder.withOptionalParameter(LootContextParams.THIS_ENTITY, context.getParamOrNull(LootContextParams.THIS_ENTITY)); - builder.withOptionalParameter(LootContextParams.BLOCK_ENTITY, context.getParamOrNull(LootContextParams.BLOCK_ENTITY)); - builder.withOptionalParameter(LootContextParams.EXPLOSION_RADIUS, context.getParamOrNull(LootContextParams.EXPLOSION_RADIUS)); - - return builder; - } - private static class SilkTouchTestModifier extends LootModifier { public static final Supplier> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, SilkTouchTestModifier::new))); @@ -75,7 +63,6 @@ public SilkTouchTestModifier(LootItemCondition[] conditionsIn) @Nonnull @Override protected @NotNull ObjectArrayList doApply(ObjectArrayList generatedLoot, LootContext context) { - BMLog.DEFAULT.info("doApply!"); ItemStack ctxTool = context.getParamOrNull(LootContextParams.TOOL); if (ctxTool.is(BloodMagicTags.CHARGES)) { return generatedLoot; @@ -83,7 +70,6 @@ public SilkTouchTestModifier(LootItemCondition[] conditionsIn) // return early if silk-touch is already applied (otherwise we'll get stuck in // an infinite loop). if (EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH)) { - BMLog.DEFAULT.info("silk touch present, returning data '{}'", generatedLoot.get(0).getOrCreateTag()); return generatedLoot; } AnointmentHolder holder = AnointmentHolder.fromItemStack(ctxTool); @@ -92,13 +78,18 @@ public SilkTouchTestModifier(LootItemCondition[] conditionsIn) return generatedLoot; } + BlockPos pos = BlockPos.containing(context.getParam(LootContextParams.ORIGIN)); + BlockState state = context.getParam(LootContextParams.BLOCK_STATE); + BlockEntity tile = context.getParamOrNull(LootContextParams.BLOCK_ENTITY); + ItemStack fakeTool = ctxTool.copy(); fakeTool.enchant(Enchantments.SILK_TOUCH, 1); - LootParams.Builder builder = copyBlockNoTool(context); - builder.withParameter(LootContextParams.TOOL, fakeTool); - LootTable lootTable = context.getLevel().getServer().getLootData().getLootTable(context.getParam(LootContextParams.BLOCK_STATE).getBlock().getLootTable()); - BMLog.DEFAULT.info("loot table I guess '{}'", lootTable.getLootTableId()); - return lootTable.getRandomItems(builder.create(LootContextParamSets.EMPTY)); + + List drops = Block.getDrops(state, context.getLevel(), pos, tile, null, fakeTool); + ObjectArrayList returnList = new ObjectArrayList<>(); + returnList.addAll(drops); + + return returnList; } @Override @@ -154,23 +145,15 @@ public FortuneModifier(LootItemCondition[] conditionsIn) enchants.put(Enchantments.BLOCK_FORTUNE, baseFortuneLevel + additionalFortune); EnchantmentHelper.setEnchantments(enchants, fakeTool); -// EnchantmentHelper.setEnchantmentLevel(p_182441_, p_182442_); + BlockPos pos = BlockPos.containing(context.getParam(LootContextParams.ORIGIN)); + BlockState state = context.getParam(LootContextParams.BLOCK_STATE); + BlockEntity tile = context.getParamOrNull(LootContextParams.BLOCK_ENTITY); - LootParams.Builder builder = new LootParams.Builder(context.getLevel()); - builder.withParameter(LootContextParams.TOOL, fakeTool); - - Vec3 vec = context.getParam(LootContextParams.ORIGIN); - if (vec != null) { - BlockPos pos = BlockPos.containing(vec); - BlockEntity be = context.getLevel().getBlockEntity(pos); - if (be != null) { - builder.withParameter(LootContextParams.BLOCK_ENTITY, be); - } - } + List drops = Block.getDrops(state, context.getLevel(), pos, tile, null, fakeTool); + ObjectArrayList returnList = new ObjectArrayList<>(); + returnList.addAll(drops); - LootParams ctx = builder.create(LootContextParamSets.EMPTY); - LootTable loottable = context.getLevel().getServer().getLootData().getLootTable(context.getParamOrNull(LootContextParams.BLOCK_STATE).getBlock().getLootTable()); - return loottable.getRandomItems(ctx); + return returnList; } @Override