Intellij Idea Loot modifiers not being applied Minecraft Forge 1.20.1

zf2sa74q  于 2023-08-03  发布在  其他
关注(0)|答案(1)|浏览(102)

怪物不会掉落我通过战利品修改器添加到他们战利品表中的物品。我有大约60个战利品修改器文件,但为了简单起见,让我们假设我唯一的战利品修改器是spider_charm_from_spiders.json。该文件看起来像:

{
  "type": "reinvigoration:add_item",
  "conditions": [
    {
      "condition": "minecraft:entity_properties",
      "predicate": {
        "type": "minecraft:spider"
      },
      "entity": "this"
    },
    {
      "condition": "minecraft:killed_by_player"
    }
  ],
  "item": "reinvigoration:spider_charm"
}

字符串
位于src/main/resources/data/reinvigoration/loot_modifiers/spider_charm_from_spiders.json
我的global_loot_modifiers. json类位于src/main/resources/data/forge/loot_modifiers/global_loot_modifiers. json,看起来像这样:

{
  "replace": false,
  "entries": [
    "reinvigoration:spider_charm_from_spiders"
  ]
}


我有两个类,AddItemModifier.java和ModLootModifiers.java,在src/main/java/com/soliid/reinvigoraion/loot中。
AddItemModifier:

package com.soliid.reinvigoration.loot;

import com.google.common.base.Suppliers;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.LootModifier;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

public class AddItemModifier extends LootModifier {
    public static final Supplier<Codec<AddItemModifier>> CODEC = Suppliers.memoize(()
            -> RecordCodecBuilder.create(inst -> codecStart(inst).and(ForgeRegistries.ITEMS.getCodec()
            .fieldOf("item").forGetter(m -> m.item)).apply(inst, AddItemModifier::new)));
    private final Item item;

    protected AddItemModifier(LootItemCondition[] conditionsIn, Item item) {
        super(conditionsIn);
        this.item = item;
    }

    @Override
    @NotNull
    protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
        generatedLoot.add(new ItemStack(item));
        return generatedLoot;
    }

    @Override
    public Codec<? extends IGlobalLootModifier> codec() {
        return CODEC.get();
    }
}


ModLootModifiers:

package com.soliid.reinvigoration.loot;

import com.mojang.serialization.Codec;
import com.soliid.reinvigoration.Reinvigoration;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModLootModifiers  {
public static final DeferredRegister<Codec<? extends IGlobalLootModifier>> LOOT_MODIFIER_SERIALIZERS =
            DeferredRegister.create(ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, Reinvigoration.MODID);

    public static final RegistryObject<Codec<? extends IGlobalLootModifier>> ADD_ITEM =
            LOOT_MODIFIER_SERIALIZERS.register("add_item", AddItemModifier.CODEC);

    public static void register(IEventBus bus) {
        LOOT_MODIFIER_SERIALIZERS.register(bus);
    }
}


我在我的主类中注册了LOOT_MODIFIER_SERIALIZERS:

ModLootModifiers.register(modEventBus);


当我建造和玩游戏时,蜘蛛不会掉蜘蛛符咒。我正在修改IntelliJ IDEA社区版2023.1.2

1qczuiv0

1qczuiv01#

我也有同样的问题。这显然是在最新的锻造版本中被打破的。有一个PR等待合并,以解决问题:https://github.com/MinecraftForge/MinecraftForge/pull/9554

相关问题