Vintagebob Posted November 17, 2023 Report Posted November 17, 2023 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
Spear and Fang Posted November 17, 2023 Report Posted November 17, 2023 (edited) 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 November 17, 2023 by Spear and Fang 1
Vintagebob Posted November 18, 2023 Author Report Posted November 18, 2023 Thank You! Unfortunately it still does not work, but i think this is some other error in the code then...
Vintagebob Posted November 18, 2023 Author Report Posted November 18, 2023 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);
Recommended Posts