#How to register a mob entity in Fabric 0.136.0+1.21.10

1 messages · Page 1 of 1 (latest)

long needle
#

I'm just learning Fabric & Java so apologies if this is obvious. I'm following this tutorial (https://wiki.fabricmc.net/tutorial:entity) on creating a new mob similar to a Zombie (it extends the Zombie class). The part I'm stuck on is registering the entity.

public static final EntityType<StickZombieEntity> STICKZOMBIE = Registry.register(
   Registries.ENTITY_TYPE,
   Identifier.of("stick-mod", "stickzombie"),
   EntityType.Builder.create(StickZombieEntity::new, SpawnGroup.MONSTER)
         .dimensions(0.6f, 1.95f)
         .build("stickzombie")
);```
The above code is pasted directly from the tutorial with minimal changes.

Unfortunately VScode flags this and says
`The method build(RegistryKey<EntityType<?>>) in the type EntityType.Builder<StickZombieEntity> is not applicable for the arguments (String)`

I don't understand what the issue is. 

I've also tried using FabricEntityType.Builder instead, loosely following this outdated tutorial (https://wiki.fabricmc.net/tutorial:entity-old) since I could find nothing else to go off of:
```java
public static final EntityType<StickZombieEntity> STICKZOMBIE = Registry.register(
   Registries.ENTITY_TYPE,
   Identifier.of("stick-mod", "stickzombie"), 
   FabricEntityType.Builder.createMob(
       (EntityType.EntityFactory<StickZombieEntity>) StickZombieEntity::new,
       SpawnGroup.MONSTER,
       builder -> builder.dimensions(EntityDimensions.fixed(0.6F, 1.95F))
   )
);```

The flag this time is
`Type mismatch: cannot convert from EntityType.Builder<StickZombieEntity> to T`

Would appreciate some help. Thanks in advance.
tawny tusk
#

The tutorials from the wiki are outdated in general. Prefer using the tutorials from docs.fabricmc.net if there are any (not in this case). The error you get for the first one means that you need a RegistryKey instead of a String in the build call. You can get one using RegistryKey.of

#

Also

#

!!learnjava

sharp surgeBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .