Skip to content

Commit 5136d0c

Browse files
committed
Bugfix : Fix Silk Touch Behaviors
1 parent eefdab9 commit 5136d0c

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/main/java/com/ghostipedia/cosmiccore/common/glm/NoSilkTouchOreLootModifier.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.ghostipedia.cosmiccore.common.glm;
22

33
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
4-
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
54
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
6-
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
75

86
import net.minecraft.world.item.ItemStack;
97
import net.minecraft.world.item.enchantment.Enchantments;
8+
import net.minecraft.world.level.block.state.BlockState;
109
import net.minecraft.world.level.storage.loot.LootContext;
10+
import net.minecraft.world.level.storage.loot.LootParams;
1111
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
1212
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
13+
import net.minecraftforge.common.Tags;
1314
import net.minecraftforge.common.loot.IGlobalLootModifier;
1415
import net.minecraftforge.common.loot.LootModifier;
1516

@@ -35,38 +36,46 @@ protected NoSilkTouchOreLootModifier(LootItemCondition[] conditionsIn) {
3536
return generatedLoot;
3637
}
3738

38-
Material material = null;
39-
for (ItemStack stack : generatedLoot) {
40-
var materialStack = ChemicalHelper.getMaterialStack(stack);
41-
if (materialStack != null && materialStack.material() != null) {
42-
Material mat = materialStack.material();
43-
if (mat.hasProperty(PropertyKey.ORE)) {
44-
material = mat;
45-
break;
46-
}
47-
}
39+
BlockState state = context.getParamOrNull(LootContextParams.BLOCK_STATE);
40+
if (state == null || !state.is(Tags.Blocks.ORES)) {
41+
return generatedLoot;
4842
}
4943

50-
if (material == null) {
44+
ItemStack blockItem = new ItemStack(state.getBlock());
45+
var materialStack = ChemicalHelper.getMaterialStack(blockItem);
46+
if (materialStack == null || materialStack.material() == null) {
5147
return generatedLoot;
5248
}
5349

54-
ItemStack rawOre = ChemicalHelper.get(TagPrefix.rawOre, material);
55-
if (rawOre.isEmpty()) {
50+
if (!materialStack.material().hasProperty(PropertyKey.ORE)) {
5651
return generatedLoot;
5752
}
5853

59-
int dropCount = 1;
60-
var oreProperty = material.getProperty(PropertyKey.ORE);
61-
if (oreProperty != null) {
62-
dropCount = oreProperty.getOreMultiplier();
54+
ItemStack fakeTool = tool.copy();
55+
fakeTool.getEnchantmentTags().clear();
56+
for (var entry : tool.getAllEnchantments().entrySet()) {
57+
if (entry.getKey() != Enchantments.SILK_TOUCH) {
58+
fakeTool.enchant(entry.getKey(), entry.getValue());
59+
}
6360
}
6461

65-
generatedLoot.clear();
66-
ItemStack drop = rawOre.copy();
67-
drop.setCount(dropCount);
68-
generatedLoot.add(drop);
62+
LootParams.Builder builder = new LootParams.Builder(context.getLevel())
63+
.withParameter(LootContextParams.BLOCK_STATE, state)
64+
.withParameter(LootContextParams.ORIGIN, context.getParam(LootContextParams.ORIGIN))
65+
.withParameter(LootContextParams.TOOL, fakeTool);
6966

67+
var entity = context.getParamOrNull(LootContextParams.THIS_ENTITY);
68+
if (entity != null) {
69+
builder.withOptionalParameter(LootContextParams.THIS_ENTITY, entity);
70+
}
71+
72+
var explosionRadius = context.getParamOrNull(LootContextParams.EXPLOSION_RADIUS);
73+
if (explosionRadius != null) {
74+
builder.withOptionalParameter(LootContextParams.EXPLOSION_RADIUS, explosionRadius);
75+
}
76+
77+
generatedLoot.clear();
78+
generatedLoot.addAll(state.getDrops(builder));
7079
return generatedLoot;
7180
}
7281

0 commit comments

Comments
 (0)