Jump to content

Registering Object Classes


Vintagebob

Recommended Posts

Hello there,

I recently decidet to update my mod to the newest version, and i noticed, that my custom classes are not registering. Every object, that had a custom class and thus a custom functionality, stopped working. In addition, when i try to spawn an entity with such a class, my game crashes with the crash log in the VS crash reporter:

System.Exception: Don't know how to instantiate entity of type CustomEntity did you forget to register a mapping?
   at Vintagestory.Common.ClassRegistry.CreateEntity(String className) in VintagestoryLib\Common\ClassRegistry.cs:line 333
   at Vintagestory.Common.ClassRegistryAPI.CreateEntity(EntityProperties entityType) in VintagestoryLib\Common\API\ClassRegistryAPI.cs:line 85
   at Vintagestory.GameContent.ItemCreature.OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, Boolean firstEvent,  ...

 

Im currently registering classes by this mehtod:

namespace custommod
{
    public class CustomMod : ModSystem
    {
        public override void Start(ICoreAPI api)
        {
            base.Start(api);
            //---------Entities
            api.RegisterEntityClass("CustomEntity", typeof(CustomEntity));
            //------------Blocks
            api.RegisterBlockClass("CustomBlock", typeof(CustomBlock));
            //------------BlockEntities
            api.RegisterBlockEntityClass("CustomBlockEntity", typeof(CustomBlockEntity));
            //------------Items
            api.RegisterItemClass("CustomItem", typeof(CustomItem));
        }
    }
}

This is also the method shown in the wiki, and it worked bevore.

So what do i need to change, or what is the new method of registering custom Classes in VS version 1.18.1?

 

Thank You

Link to comment
Share on other sites

I don't think anything has changed with respect to class registrations.  For entities I AM using this though:
api.RegisterEntity()

The rest looks good. i.e.
https://github.com/SpearAndFang/primitive-survival/blob/main/PrimitiveSurvival/ModSystem/PrimitiveSurvivalSystem.cs#L109
called from
https://github.com/SpearAndFang/primitive-survival/blob/main/PrimitiveSurvival/ModSystem/PrimitiveSurvivalSystem.cs#L287

Edited by Spear and Fang
  • Like 1
Link to comment
Share on other sites

Yes, the error was, that i tried to get the rotated block code with an outdated method. I used a dictionary, but this is the right way:

BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel);
if (blockSel.Face.IsVertical){ horVer[1] = blockSel.Face; }
AssetLocation code = this.CodeWithVariants(new string[] { "verticalorientation", "horizontalorientation" }, new string[] { horVer[1].Code, horVer[0].Code });
Block block = blockAccessor.GetBlock(code);
Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.