I'm trying out using global loot modifiers to modify the loot tables of some vanilla entities for my mod. At first I thought I had it working fine: my custom item dropped for entities in the specified tag and didn't drop for entities outside of it. Great. The next day, though, while doing some testing in survival mode, I broke an oak log... and my custom item dropped for that too. And then again for stone, granite, and coal ore. Not great.
Can anyone tell me what I'm doing wrong? Why my loot modifier, with conditions that seem to imply that it should only drop for certain entity types, is also triggering for every block under the sun? I haven't found anything that derives from ILootCondition with a name that suggests it differentiates between blocks and entities, so I'm feeling stuck.
Here's the code for the loot modifier object:
package com.verdantartifice.primalmagic.common.loot.modifiers;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonObject;
import com.verdantartifice.primalmagic.common.items.ItemsPM;
import com.verdantartifice.primalmagic.common.util.ItemUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.ConstantRange;
import net.minecraft.loot.ItemLootEntry;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.RandomValueRange;
import net.minecraft.loot.conditions.ILootCondition;
import net.minecraft.loot.functions.LootingEnchantBonus;
import net.minecraft.loot.functions.SetCount;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;
/**
* Global loot modifier that allows mobs in the conditioned tag to drop Bloody Flesh when killed.
*
* @author Daedalus4096
*/
public class BloodyFleshModifier extends LootModifier {
public BloodyFleshModifier(ILootCondition[] conditionsIn) {
super(conditionsIn);
}
@SuppressWarnings("deprecation")
@Override
protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
LootTable table = LootTable.builder().addLootPool(LootPool.builder().rolls(ConstantRange.of(1)).addEntry(ItemLootEntry.builder(ItemsPM.BLOODY_FLESH.get()).acceptFunction(SetCount.builder(RandomValueRange.of(0.0F, 1.0F))).acceptFunction(LootingEnchantBonus.builder(RandomValueRange.of(0.0F, 1.0F))))).build();
List<ItemStack> lootList = new ArrayList<>();
table.generate(context, lootList::add); // Use deprecated version to avoid calling modifyLoot and prevent infinite recursion
return ItemUtils.mergeItemStackLists(generatedLoot, lootList);
}
public static class Serializer extends GlobalLootModifierSerializer<BloodyFleshModifier> {
@Override
public BloodyFleshModifier read(ResourceLocation location, JsonObject object, ILootCondition[] ailootcondition) {
return new BloodyFleshModifier(ailootcondition);
}
@Override
public JsonObject write(BloodyFleshModifier instance) {
return this.makeConditions(instance.conditions);
}
}
}
And here's the JSON file for the modifier:
{
"conditions": [
{
"condition": "minecraft:entity_properties",
"predicate": {
"type": "#primalmagic:drops_bloody_flesh"
},
"entity": "this"
}
],
"type": "primalmagic:bloody_flesh"
}
The GitHub repository can be found here if you need to look at anything else. Thank you for your time.