Jump to content

[ 1.15.2 ] Unable to register entity [ SOLVED ]


saoj12

Recommended Posts

I'm trying to create a custom entity that extends the VillagerEntity class and uses a player model. Here is my code:

public class RegistryHandler {

    public static void init(){
        RenderingRegistry.registerEntityRenderingHandler(MyEntity.class, MyRenderFactory.INSTANCE);
    }

}

 

The problem I have is that the registerEntityRenderingHandler method won't accept MyEntity.class as a parameter as it says it is of type Class<MyEntity> when it should be EntityType<T>

Here is the MyEntity class:

public class MyEntity extends VillagerEntity {

    public MyEntity(EntityType<? extends VillagerEntity> entityTypeIn, World worldIn) {
        super(entityTypeIn, worldIn);
    }

    @Override
    protected void registerData() {

    }

    @Override
    public void readAdditional(CompoundNBT compound) {

    }

    @Override
    public void writeAdditional(CompoundNBT compound) {

    }

    @Override
    public IPacket<?> createSpawnPacket() {
        return null;
    }
}

 

Any help would be appreciated

Edited by saoj12
Link to comment
Share on other sites

57 minutes ago, saoj12 said:

The problem I have is that the registerEntityRenderingHandler method won't accept MyEntity.class as a parameter as it says it is of type Class<MyEntity> when it should be EntityType<T>

You need to create and register an EntityType<T extends Entity> now in order to make an Entity.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

2 hours ago, Animefan8888 said:

You need to create and register an EntityType<T extends Entity> now in order to make an Entity.

Okay thank you. Then do i pass this into the registerEntityRenderingHandler method instead of  MyEntity.class?

Link to comment
Share on other sites

2 hours ago, Animefan8888 said:

You need to create and register an EntityType<T extends Entity> now in order to make an Entity.

It seems like in other people's code they are able to put MyEntity.class as a parameter and it works fine? i can put the EntityType as a parameter and this works fine but then when i try and spawn the mob in-game I get an error message in the chat log

 

here is my new code:

public class RegistryHandler {

    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Obamium.MOD_ID);

    public static void init(){
        ENTITY_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

    //Entities
    public static final RegistryObject<EntityType<MyEntity>> MYENTITY = ENTITY_TYPES.register("my_entity", () -> EntityType.Builder.create(ObamaEntity::new, EntityClassification.AMBIENT).size(1F, 2F).build("my_entity"));

}

 

I am now calling registerEntityRenderingHandler in the doClientStuff method of my main class because someone said that's where I should put it since the rendering is done clientside. I have tried calling it elsewhere but the result is the same

 

here's what the console outputs:

java.lang.NullPointerException: null
	at net.minecraft.network.datasync.EntityDataManager.set(EntityDataManager.java:123) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.setHealth(LivingEntity.java:877) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:200) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.MobEntity.<init>(MobEntity.java:99) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.CreatureEntity.<init>(CreatureEntity.java:13) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.AgeableEntity.<init>(AgeableEntity.java:25) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.merchant.villager.AbstractVillagerEntity.<init>(AbstractVillagerEntity.java:47) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.merchant.villager.VillagerEntity.<init>(VillagerEntity.java:116) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.merchant.villager.VillagerEntity.<init>(VillagerEntity.java:112) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at com.saoj.obamiummod.core.entities.ObamaEntity.<init>(ObamaEntity.java:12) ~[main/:?] {re:classloading}
	at net.minecraft.entity.EntityType.create(EntityType.java:421) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.EntityType.lambda$loadEntityUnchecked$0(EntityType.java:432) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_241] {}
	at net.minecraft.entity.EntityType.loadEntityUnchecked(EntityType.java:431) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.EntityType.loadEntity(EntityType.java:479) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.EntityType.func_220335_a(EntityType.java:461) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.command.impl.SummonCommand.summonEntity(SummonCommand.java:50) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.command.impl.SummonCommand.lambda$register$1(SummonCommand.java:32) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:262) ~[brigadier-1.0.17.jar:?] {}
	at net.minecraft.command.Commands.handleCommand(Commands.java:210) ~[?:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.handleSlashCommand(ServerPlayNetHandler.java:1028) ~[?:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.processChatMessage(ServerPlayNetHandler.java:1008) ~[?:?] {re:classloading}
	at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:37) ~[?:?] {re:classloading}
	at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:8) ~[?:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[?:?] {re:classloading}
	at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) [?:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) [?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:756) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:141) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.func_213205_aW(MinecraftServer.java:739) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:733) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:718) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:663) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241] {}
[20:55:01] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] Unable to summon entity
[20:55:07] [Server thread/INFO] [minecraft/IntegratedServer]: Saving and pausing game...
[20:55:07] [Server thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'Test'/minecraft:overworld
[20:55:07] [Server thread/DEBUG] [ne.mi.fm.FMLWorldPersistenceHook/WP]: Gathering id map for writing to world save Test

 

Edited by saoj12
Link to comment
Share on other sites

4 minutes ago, saoj12 said:

I am now calling registerEntityRenderingHandler in the doClientStuff method of my main class because someone said that's where I should put it since the rendering is done clientside.

This is correct.

4 minutes ago, saoj12 said:

but then when i try and spawn the mob in-game I get an error message in the chat log

Post the error.

Edited by Animefan8888
  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

4 minutes ago, saoj12 said:

i edited my last message with some extra details too

I need to see more of your code. Preferably as a github repo.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

I need to see more of your code. Preferably as a github repo.

unfortunately I didn't make a github repo for this project as I only intended for it to be a little test but I can send you all the code that I think would be relevant on here. Sorry if it's messy and thanks again for your help so far. You've already got the registry handler and my entity class so I'll just send the rest:

@Mod("my_mod")
public class MyMod
{
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "my_mod";

    public Obamium() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        RegistryHandler.init();

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event){
        OreGenerator.setupOreGen();
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.OBAMA.get(), ObamaRenderFactory.INSTANCE);
    }

}

 

public class MyRenderFactory implements IRenderFactory<MyEntity> {
    public static final MyRenderFactory INSTANCE = new MyRenderFactory();

    @Override
    public EntityRenderer<? super MyEntity> createRenderFor(EntityRendererManager manager) {
        if (FMLEnvironment.dist.isDedicatedServer())
            throw new IllegalStateException("Only run this on client!");

        return new MyRenderer(manager);
    }
}

 

@OnlyIn(Dist.CLIENT)
public class MyRenderer extends MobRenderer<MyEntity, PlayerModel<MyEntity>> {

    private static final ResourceLocation SKIN = new ResourceLocation(MyMod.MOD_ID,"textures/entity/mytexture.png");

    @Nullable
    public MyRenderer(EntityRendererManager rendererManager) {
        //   (renderManager,               model,     shadowSize);
        super(rendererManager, new PlayerModel<>(1, false),0.6f);
    }

    @Override
    public ResourceLocation getEntityTexture(MyEntity entity) {
        return SKIN;
    }

}

 

And I'm pretty sure that's everything that relates in any way to the entity.

Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

You have overridden registerData to do nothing, hence the parent classes of your entity do not get to register their data parameters, such as health.

Thus, setting the health fails.

What prompted you to do this?

Ohhh you're right! I fixed this and now it works, thanks so much! I'm not sure why that was done. I definitely didn't do it by hand so it was probably auto-generated when I accidentally extended the wrong super class or something. Good spot! My entity is now working but the skin is a bit messed up. Any idea how to implement a skin for a PlayerModel model? a regular player skin off planet minecraft doesn't seem to map properly

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3fe22b60, pid=15228, tid=5140 # # JRE version: OpenJDK Runtime Environment Microsoft-8035246 (17.0.8+7) (build 17.0.8+7-LTS) # Java VM: OpenJDK 64-Bit Server VM Microsoft-8035246 (17.0.8+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # C [atio6axx.dll+0x192b60] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # If you would like to submit a bug report, please visit: # https://aka.ms/minecraftjavacrashes # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug i have no idea why please help
    • Considering the financial revolution sparked by cryptocurrencies like Bitcoin, the digital era has opened up a plethora of opportunities. But this exciting new world also comes with a terrible reality: in the harsh, brutal blockchain environment, there's always a danger you could lose your precious digital assets. Services like ADWARE RECOVERY SPECIALIST are not merely recovery agents in this case; they are crypto lifelines, and my own experience attests to their vital importance. I had an amazing time exploring the world of Bitcoin on my own; it was exciting to be in a completely new place and to see the possibility of independent money. However, a careless mistake of choosing the incorrect platform for my investment sent me into total despair. It seemed as though my digital lifeblood, Bitcoin, had been devoured by the blockchain's vicious maw. Overwhelmed with hope, I began a frantic quest for solutions, looking up any clue of assistance on the internet. I discovered  ADWARE RECOVERY SPECIALIST at that point.  Initially, I was filled with misgivings, but their unwavering professionalism and clear communication offered me a glimpse of hope. I set them the very impossible task of locating my missing fortune. The ADWARE RECOVERY SPECIALIST team of professionals meticulously penetrated the labyrinthine depths of the blockchain with the aid of cutting-edge technology and years of honed experience, treating my case with the utmost care and respect and keeping me informed at every turn. I had never encountered anything like the recuperation process. The days of confusing technical jargon and excruciatingly long wait times were over. And then the miraculous happened. My Bitcoin miraculously reappeared in my wallet, coming safe and sound from the digital void in an almost amazing length of time. Integrating  ADWARE RECOVERY SPECIALIST into your Bitcoin recovery process is not as magical as waving a wand, but it sure feels like it with the seamless and effective tools it offers. By following best practices, training your staff, and learning from successful case studies, you can optimize your Bitcoin recovery efforts and stay ahead of potential risks. The future outlook for Bitcoin recovery with ADWARE RECOVERY SPECIALIST looks promising, providing users with the confidence and tools they need to navigate the ever-evolving landscape of digital assets. It was a very happy moment that showcased the ADWARE RECOVERY SPECIALIST team's remarkable talent and dedication. However, my experience serves more purposes than just self-interest; it serves as a sobering reminder of the expanding demand for dependable and trustworthy bitcoin recovery services, such as ADWARE online recovery.
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.