Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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).

  • 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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.