Hello everyone,
I created an Entity for my Mod. It works fine, but when I create a new registry inside the NewRegistry-Event, summoning the Entity will result in an error. I have this code:
@GameRegistry.ObjectHolder(WizardItemsMod.MOD_ID)
public static class ENTITY_ENTRIES {
public static int ID = 0;
public static EntityEntry FLYING_BROOMSTICK = EntityEntryBuilder.create()
.entity(EntityFlyingBroomstick.class)
.tracker(64, 20, true)
.id("wizarditems:flying_broomstick", ID++)
.name("flying_broomstick").build();
}
// ...
@SubscribeEvent
public static void registerEntities(RegistryEvent.Register<EntityEntry> event) {
event.getRegistry().register(ENTITY_ENTRIES.FLYING_BROOMSTICK);
}
@SubscribeEvent
public static void newRegistry(RegistryEvent.NewRegistry event) {
// when I add the following code, using the Entity will fail
SPELL_REGISTRY = new RegistryBuilder<Spell>()
.setName(new ResourceLocation("wizarditems", "magic_spells"))
.setType(Spell.class)
.setIDRange(0, SPELLS4REGISTRY.length).create();
}
When I try to summon the Entity using /summon wizarditems:flying_broomstick, I get this error (although the chat displays "Object successfully summoned"):
When I load an existing world containing the entity, the game crashes:
As I said, this only happens when I add the code for creating the new registry. Does anyone know why this is happening, because creating a new registry shouldn't affect Entities??? Am I doing anything wrong?
I found out that this could have something to do with the ModContainer and calling Loader.instance().activeModContainer().
(Interestingly, I had to add my Mod-ID to every registry name (Blocks, Items, ...) once I added the code for the new registry, because suddenly the domain name wasn't automatically set to my Mod's ID.)
Thanks in advance!