MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a sample global loot modifier"
/* To create a sample global loot modifier in Minecraft Forge, you need to extend the GlobalLootModifierSerializer class and override the read and write methods. Here's an example of a simple global loot modifier that doubles the amount of dropped items. */ // CustomLootModifier.java public class CustomLootModifier extends GlobalLootModifier { public CustomLootModifier(LootItemCondition[] conditionsIn) { super(conditionsIn); } @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { List<ItemStack> newLoot = new ArrayList<>(); for (ItemStack stack : generatedLoot) { ItemStack doubledStack = stack.copy(); doubledStack.setCount(stack.getCount() * 2); newLoot.add(doubledStack); } return newLoot; } public static class Serializer extends GlobalLootModifierSerializer<CustomLootModifier> { @Override public CustomLootModifier read(ResourceLocation name, JsonObject object, LootItemCondition[] conditionsIn) { return new CustomLootModifier(conditionsIn); } @Override public JsonObject write(CustomLootModifier instance) { return makeConditions(instance.conditions); } } } /* Don't forget to register the serializer in your mod event bus. */ // In your main mod class or a dedicated registry class public static final DeferredRegister<GlobalLootModifierSerializer<?>> GLM_SERIALIZERS = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS, MOD_ID); public static final RegistryObject<GlobalLootModifierSerializer<?>> CUSTOM_LOOT_MODIFIER = GLM_SERIALIZERS.register("custom_loot_modifier", CustomLootModifier.Serializer::new); // In your main mod class or a dedicated setup method GLM_SERIALIZERS.register(modEventBus);