Jump to content

Recommended Posts

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?

Posted
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)

 

Posted (edited)
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
  • Like 1
Posted

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

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