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 register a simple minecart entity but it does not seem to appear in-game. No errors are thrown either.

 

Here is my Minecart entity class:

public class MinerCartEntity extends AbstractMinecartEntity {

    public MinerCartEntity(EntityType<?> type, World worldIn) {
        super(type, worldIn);
    }

    @Override
    public Type getMinecartType() {
        return Type.CHEST;
    }
}

 

Here is how I register it,

public class AllEntities {

    public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MODID);

    private static <T extends EntityType<?>> RegistryObject<EntityType<?>> register(String name, Supplier<T> entity) {
        System.out.println("REGISTERING MOD ENTITY: " + name);
        return ENTITIES.register(name, entity);
    }

    public static final RegistryObject<EntityType<?>> MINER_MINECART = register("miner_minecart",
            () -> EntityType.Builder.<AbstractMinecartEntity>create(MinerCartEntity::new, EntityClassification.MISC)
            .size(0.98F, 0.7F).trackingRange(8)
            .build(new ResourceLocation(MODID, "miner_minecart").toString()));
}

and in the main file simply:

        IEventBus fmlContext = FMLJavaModLoadingContext.get().getModEventBus();
        AllBlocks.BLOCKS.register(fmlContext);
        AllTileEntities.TILE_ENTITIES.register(fmlContext);
        AllItems.ITEMS.register(fmlContext);
        AllEntities.ENTITIES.register(fmlContext);	// <------ over here

 

My first guess was to follow the same way to register entities as blocks or items while using the entity builder shown in Minecraft's source code.

Any guess as to why it does not load in-game or not throwing errors? Is this even the right way?

9 hours ago, than00ber1 said:

I am trying to register a simple minecart entity but it does not seem to appear in-game. No errors are thrown either.

You need to override createSpawnPacket() (called getAddEntityPacket() in the official mappings) and return this:

NetworkHooks.getEntitySpawningPacket(this)

 

  • Author

Where would I call this? 

NetworkHooks.getEntitySpawningPacket(this)

In the constructor of the minecart class?

29 minutes ago, than00ber1 said:

here would I call this? 

In the constructor of the minecart class?

@vemerion has already told you what you have to do

3 hours ago, vemerion said:

You need to override createSpawnPacket() (called getAddEntityPacket() in the official mappings) and return this:

 

 

Edited by Luis_ST

  • Author

Ah I managed to do this. The problem was really dumb, I didn't register the actual item itself.

 

For any in the future that want to know how to it, this how I did it:

Create the item:

public class MinerCartItem extends MinecartItem {

    public MinerCartItem() {
        super(AbstractMinecartEntity.Type.RIDEABLE, (new Item.Properties()).maxStackSize(1).group(ItemGroup.FOOD));
    }
}

and then register it the same way you would do for other registries:

    public static final RegistryObject<Item> MINER_ITEM = ITEMS.register("miner_item", MinerCartItem::new);

 

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.