DragonITA Posted January 28, 2020 Posted January 28, 2020 Hello, I would like to register my EntityType thanks to the DeferredRegister, but I have no idea how. Any help is needed. Thanks for reading it. Quote New in Modding? == Still learning!
Cadiboo Posted January 28, 2020 Posted January 28, 2020 Show what you’ve tried. EntityType registration should work perfectly with DeferredRegister (aside from spawn eggs as I’ve said) 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 This means that I should rather not register with the DeferredRegister? (I asked so that I could know if it would be possible to register my Spawnegg with it. So now, if I want to use it for a Spawnegg, should I register it with my EntityType using the DeferredRegister or the other method?) Quote New in Modding? == Still learning!
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 55 minutes ago, Cadiboo said: Show what you’ve tried. https://github.com/DragonGamerDevelopers/NewFantasyMod-1.15.1/blob/master/src/main/java/mod/dragonita/fantasymod/init/ModItems.java Quote New in Modding? == Still learning!
Cadiboo Posted January 28, 2020 Posted January 28, 2020 That’s not right. If you look at the DeferredRegister documentation you’ll see why it isn’t right. I would just not use vanilla’s spawn egg code - it wasn’t made to be used by mods Or at least I would extend it and make it use a supplier for your entity type. Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 You have me completely confused. I don't understand anything anymore. Quote New in Modding? == Still learning!
Cadiboo Posted January 28, 2020 Posted January 28, 2020 public final class ModItems { // 1: This shouldn't be in a class called ModItems // 2: You shouldn't be using this method, thats why its depreciated, you should be using the registry events @SuppressWarnings("deprecation") private static <T extends Entity> EntityType<T> register(String key, EntityType.Builder<T> builder) { return Registry.register(Registry.ENTITY_TYPE, key, builder.build(key)); } public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, Main.MODID); // This shouldn't be in a class called ModItems //public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID); // 1: This shouldn't be in a class called ModItems // 2: You shouldn't use static initialisers // 3: You shouldn't register stuff statically // You should create and register your objects inside the registry events public static final EntityType<UnicornEntity> UNICORN = register("unicorn_entity", EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F)); // This is correct - it's how you should be doing your registration, but it shouldn't be in a class called ModItems //public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn_entity", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).build(null)); public static final RegistryObject<Item> RAINBOW_INGOT = ITEMS.register("rainbow_ingot",() -> new Item(new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP))); public static final RegistryObject<Item> UNICORN_ENTITY_EGG = ITEMS.register("unicorn_entity_egg", () -> new SpawnEggItem(UNICORN, 0xf0f0f0, 0xdf51f5, new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP))); } You should remove entity related stuff from your ModItems class and make a new class like so: public final class ModEntityTypes { public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Main.MODID); public static final RegistryObject<EntityType<UnicornEntity>> UNICORN = ENTITY_TYPES.register("unicorn", () -> EntityType.Builder.create(UnicornEntity::new, EntityClassification.AMBIENT).size(0.5F, 0.9F).build(null)); } and register your DeferredRegister in your mods constructor like this. 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 (edited) 4 hours ago, Cadiboo said: and register your DeferredRegister in your mods constructor like this. Okay, thanks a lot. This should be the last question, do I have to register it before the items or after? To understand what I mean please look at Github. I mean into the Main class Edited January 28, 2020 by DragonITA Quote New in Modding? == Still learning!
desht Posted January 28, 2020 Posted January 28, 2020 (edited) 9 minutes ago, DragonITA said: Okay, thanks a lot. This should be the last question, do I have to register it before the items or after? To understand what I mean please look at Github. If you're using DeferredRegister, it really doesn't matter; just make sure you register in your constructor, i.e. before any registry events are fired. Forge will make sure everything's done in the right order. If you've been paying attention, you'll have noticed that DeferredRegister does everything via Suppliers, so it's all lazy - nothing's actually initialized until the events are fired. Edited January 28, 2020 by desht 1 Quote
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 Nope, still getting errors logs, the lastest log: https://github.com/DragonGamerDevelopers/Minecraft-Modding-Logs/blob/master/EntityType-Error-2.log Quote New in Modding? == Still learning!
desht Posted January 28, 2020 Posted January 28, 2020 Assuming https://github.com/DragonGamerDevelopers/NewFantasyMod-1.15.1/blob/master/src/main/java/mod/dragonita/fantasymod/init/ModItems.java is your up to date code producing that error, then it's wrong. You're registering your entity type directly in the (vanilla) minecraft Registry in a class constructor which is called before any registration is happening. That's always going to fail, and you should never be touching the vanilla registry directly. Entity types work with DeferredRegister just like any other Forge registry entry. As an example, see PneumaticCraft entity registration here, which works fine: https://github.com/TeamPneumatic/pnc-repressurized/blob/1.14/src/main/java/me/desht/pneumaticcraft/common/core/ModEntities.java 1 Quote
DragonITA Posted January 28, 2020 Author Posted January 28, 2020 @desht I noticed a few minutes ago that I incorrectly updated my code on Github, check out the new code. Quote New in Modding? == Still learning!
Cadiboo Posted January 29, 2020 Posted January 29, 2020 EntityTypes get created after Items. You’re trying to use an EntityEntry from your item when you make a spawn egg. This can’t work. As I said, the situation is problematic. That’s why I said you should make your own spawn egg that accepts a Supplier<EntityType> instead of an actual EntityType. 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 29, 2020 Author Posted January 29, 2020 @Cadiboo But what if I need my EntityType somewhere else? Quote New in Modding? == Still learning!
DragonITA Posted January 29, 2020 Author Posted January 29, 2020 So in other words I have to copy the whole Spawnegg code and change it so that it works with Suppliers? Quote New in Modding? == Still learning!
DragonITA Posted January 29, 2020 Author Posted January 29, 2020 I hope I got it right. Quote New in Modding? == Still learning!
Cadiboo Posted January 29, 2020 Posted January 29, 2020 13 hours ago, DragonITA said: @Cadiboo But what if I need my EntityType somewhere else? If you need it before it exists, you’re out of luck. 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Cadiboo Posted January 29, 2020 Posted January 29, 2020 7 hours ago, DragonITA said: So in other words I have to copy the whole Spawnegg code and change it so that it works with Suppliers? Pretty much. You might be able to just extend it and use suppliers and you can probably clean up a bit of it’s code in your class. Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 30, 2020 Author Posted January 30, 2020 @CadibooBut then it's impossible to close an entity, because the renderer needs the EntityType and I don't think I really have to rewrite the whole renderer register now. If so then it's much harder than what I think. Quote New in Modding? == Still learning!
DragonITA Posted January 30, 2020 Author Posted January 30, 2020 But thanks a lot for your tips Quote New in Modding? == Still learning!
Cadiboo Posted January 30, 2020 Posted January 30, 2020 5 hours ago, DragonITA said: @CadibooBut then it's impossible to close an entity, because the renderer needs the EntityType and I don't think I really have to rewrite the whole renderer register now. If so then it's much harder than what I think. Renderers get registered after all registry events have finished. So after EntityTypes. I’ll put an example in my example mod Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 30, 2020 Author Posted January 30, 2020 Can I register my blocks with the DeferredRegister and register my items with the normal register method? I find the whole thing with the Deferred Registers too difficult. Quote New in Modding? == Still learning!
Cadiboo Posted January 31, 2020 Posted January 31, 2020 (edited) 16 hours ago, DragonITA said: I find the whole thing with the Deferred Registers too difficult. The whole point of them is that they are dead simple. The only issue with them is the spawn egg thing which is easily fixed right now (pass null into the constructor + anonymous subclass that overrides getType) and is likely to be made even easier in the future. Edited January 31, 2020 by Cadiboo Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DragonITA Posted January 31, 2020 Author Posted January 31, 2020 3 hours ago, Cadiboo said: pass null into the constructor Does the first parameter, the entity parameter, have to be or all three parameters? 3 hours ago, Cadiboo said: anonymous subclass that overrides getType I still have not understood how to override the function. Quote New in Modding? == Still learning!
DragonITA Posted January 31, 2020 Author Posted January 31, 2020 @diesieben07I know how to override it, but what I was trying to say was that I don't know what to change. Quote New in Modding? == Still learning!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.