MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"what are global loot modifiers. give one example"
/* Global Loot Modifiers are a way to modify the loot tables of various blocks, entities, and chests in Minecraft Forge without directly editing the loot tables themselves. They allow you to add, remove, or change the items that are dropped when a certain event occurs, such as breaking a block or killing a mob. Here's an example of a simple global loot modifier that adds a diamond to the drops of any mob killed by a player: */ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.loot.GlobalLootModifierSerializer; import net.minecraftforge.common.loot.LootModifier; import java.util.List; public class DiamondMobKillLootModifier extends LootModifier { public DiamondMobKillLootModifier(ResourceLocation name) { super(name); } @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { generatedLoot.add(new ItemStack(Items.DIAMOND)); return generatedLoot; } public static class Serializer extends GlobalLootModifierSerializer<DiamondMobKillLootModifier> { @Override public DiamondMobKillLootModifier read(ResourceLocation name, JsonObject json, ILootCondition[] conditions) { return new DiamondMobKillLootModifier(name); } @Override public JsonObject write(DiamondMobKillLootModifier instance) { return makeConditions(instance.conditions); } } } /* This modifier would be registered in your mod's main class or a dedicated registry class, and then added to a global_loot_modifiers.json file in your mod's resources folder. */