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.

Announcements



×
×
  • Create New...

Important Information

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