Jump to content

[SOLVED] [1.16.5] Custom minecarts are not rendered


Sabotember

Recommended Posts

I am trying to make a custom minecart whose model is just the same as vanilla minecart.

Here is MyMinecartEntity class:

public class MyMinecartEntity extends AbstractMinecartEntity {
    public MyMinecartEntity(EntityType<?> entityType, World world) {
        super(entityType, world);
    }

    public MyMinecartEntity(World world, double xin, double yin, double zin) {
        super(RegisterEntities.Entities.MY_MINECART.get(), world, xin, yin, zin);
    }

    @Override
    @Nonnull
    public IPacket<?> getAddEntityPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    @Nonnull
    public AbstractMinecartEntity.Type getMinecartType() {
        return Type.RIDEABLE;
    }
}

and the renderer is:

@OnlyIn(Dist.CLIENT)
public class MyMinecartRenderer<T extends MyMinecartEntity> extends MinecartRenderer<T> {
    private static final ResourceLocation MY_MINECART_LOCATION
            = new ResourceLocation(MYMOD.MOD_ID,"textures/entity/my_minecart.png");

    public MyMinecartRenderer(EntityRendererManager manager) {
        super(manager);
    }

    @Override
    @Nonnull
    public ResourceLocation getTextureLocation(@Nonnull T entity) {
        return MY_MINECART_LOCATION;
    }
}

I intend to use vanilla MinecartModel class, so I did not create new model class.
To register the entity and the renderer, I made a class like:
 

public class RegisterEntities {
    public static class Entities {
        public static final RegistryObject<EntityType<?>> MY_MINECART;
        private static final DeferredRegister<EntityType<?>> ENTITIES;

        static {
            ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MYMOD.MOD_ID);
            MY_MINECART = ENTITIES.register("my_minecart",
                    () -> EntityType.Builder.of(MyMinecartEntity::new, EntityClassification.MISC)
                            .sized(0.98F, 0.7F)
                            .setTrackingRange(8)
                            .build("my_minecart"));
        }

        public static void register(IEventBus eventBus) {
            ENTITIES.register(eventBus);
        }

        public static void registerRenderer() {
            RenderingRegistry.registerEntityRenderingHandler((EntityType<MyMinecartEntity>)MY_MINECART.get(), MyMinecartRenderer::new);
        }
    }
}

and called the registering procedures from my main mod as:

public MYMOD() {
    IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
    RegisterItems.Items.register(modEventBus);
    RegisterBlocks.Blocks.register(modEventBus);
    RegisterEntities.Entities.register(modEventBus);

    MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, GenerateOres::generateOres);
    FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
    MinecraftForge.EVENT_BUS.register(this);
}

private void clientSetup(final FMLClientSetupEvent event) {
    RegisterEntities.Entities.registerRenderer();
}

I tried to summon a MyMinecart entity by world.getChunk(i, j).addEntity(entity), and it seems that Minecraft tried to summon the cart (because something transparent prevented me from interacting with the rail below), but the cart was never rendered.
How can I get the carts rendered?

 

Thank you.

Edited by Sabotember
The problem has been solved
Link to comment
Share on other sites

3 hours ago, diesieben07 said:

That is not how you spawn entities. You have to use World#addFreshEntity on the server.

Also, do not use @OnlyIn.

Now the problem has been solved. Thank you.
I mistook (!world.isClientSide) in the vanilla MinecartItem class for (world.isClientSide).

Link to comment
Share on other sites

  • Sabotember changed the title to [SOLVED] [1.16.5] Custom minecarts are not rendered

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.