首页 > 解决方案 > 无法在多人游戏中注册自定义剑

问题描述

在客户端和服务器端出现一些大的“nooby”错误之后(我编辑了我以前的线程),我认为我让它正常工作。现在的问题是我的自定义项目注册似乎不起作用(它没有失败,只是似乎没有效果)。我找不到如何在 Forge 1.14.4 版本上正确执行此操作的示例,因此非常感谢任何帮助或想法。

如果我在单人模式下(从 Eclipse 环境)测试它,它可以完美运行,但在我运行 Forge 服务器时却不行(同样,在任何地方都没有错误或调试输出)。

编辑:我更改为其他注册方法(使用 DeferredRegister 和 RegistryObject)......结果相同:(它在单人游戏中完美运行,但对服务器端没有影响。

这是我的主类中的新注册方法:

@Mod("simpleclock")
public class SimpleClock {
    
    public static final String MODID = "simpleclock";
    public static final String NAME = "alef's Simple Clock";
    public static final String VERSION = "1.5.5";
    
    private static final Logger LOGGER = LogManager.getLogger();
    
    public static World WORLD;
    public static PlayerEntity PLAYER;
    public static final Item TIMESWORD = new SwordItem(TimeSwordTier.time_sword, 0, -2, new Item.Properties().group(ItemGroup.COMBAT));
    
    public static final DeferredRegister<Item> CONTAINER = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);
    public static final RegistryObject<Item> ITEM = CONTAINER.register("time_sword", () -> TIMESWORD);
    
    public SimpleClock() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
        
        // Register items and other stuff
        CONTAINER.register(FMLJavaModLoadingContext.get().getModEventBus());
        
        // Load config file
        ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, ConfigFile.spec);
    }

这是我的 TimeSwordTier 课程:

public enum TimeSwordTier implements IItemTier {

    time_sword(5.0f, 9.0f, 5000, 3, 25, null);

    private float attackDamage, efficiency;
    private int durability, harvestLevel, enchantability;
    private Item repairMaterial;
    private static double knockback = 1.5;

    private TimeSwordTier(float attackDamage, float efficiency, int durability, int harvestLevel, int enchantability, Item repairMaterial) {
        this.attackDamage = attackDamage;
        this.efficiency = efficiency;
        this.durability = durability;
        this.harvestLevel = harvestLevel;
        this.enchantability = enchantability;
        this.repairMaterial = repairMaterial;
    }

    @Override
    public float getAttackDamage()
    {
        return this.attackDamage;
    }

    @Override
    public float getEfficiency()
    {
        return this.efficiency;
    }

    @Override
    public int getEnchantability()
    {
        return this.enchantability;
    }

    @Override
    public int getHarvestLevel()
    {
        return this.harvestLevel;
    }

    @Override
    public int getMaxUses()
    {
        return this.durability;
    }

    @Override
    public Ingredient getRepairMaterial()
    {
        return Ingredient.fromItems(this.repairMaterial);
    }
    
    public static double getKnockback()
    {
        return TimeSwordTier.knockback;
    }
}

标签: javaminecraftminecraft-forge

解决方案


(来自评论)

从各处去除“静态”


推荐阅读