User Tools

Site Tools


tutorial:entity

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:entity [2021/07/17 20:25] – [Creating a Model and Texture] logdawg970tutorial:entity [2023/09/13 20:30] (current) – ↷ Links adapted because of a move operation nebelnidas
Line 1: Line 1:
 ===== Creating an Entity ===== ===== Creating an Entity =====
  
-//The source code for this project can be found [[https://github.com/Draylar/entity-testing|here]] on the entity branch.//+//The source code for this project can be found [[https://github.com/Draylar/entity-testing/tree/entity|here]].//
  
 Entities are a movable object in a world with logic attached to them. A few examples include: Entities are a movable object in a world with logic attached to them. A few examples include:
Line 10: Line 10:
 Living Entities are Entities that have health and can deal damage.  Living Entities are Entities that have health and can deal damage. 
 There are various classes that branch off `LivingEntity` for different purposes, including: There are various classes that branch off `LivingEntity` for different purposes, including:
-  * ''HostileEntity'' for Zombies, Creepersand Skeletons +  * ''HostileEntity'' for Zombies, Creepers and Skeletons 
-  * ''AnimalEntity'' for Sheep, Cowsand Pigs+  * ''AnimalEntity'' for Sheep, Cows and Pigs
   * ''WaterCreatureEntity'' for things that swim   * ''WaterCreatureEntity'' for things that swim
-  * ''FishEntity'' for fishies+  * ''FishEntity'' for fishies (use instead of ''WaterCreatureEntity'' for schooling behavior)
    
-What you extend depends on your needs and goals are. +What you extend depends on what your needs and goals are. 
 As you get further down the chain, the entity logic becomes more specific and curated to certain tasks. As you get further down the chain, the entity logic becomes more specific and curated to certain tasks.
 The two generic entity classes that come after ''LivingEntity'' are: The two generic entity classes that come after ''LivingEntity'' are:
Line 61: Line 61:
      */      */
     public static final EntityType<CubeEntity> CUBE = Registry.register(     public static final EntityType<CubeEntity> CUBE = Registry.register(
-            Registry.ENTITY_TYPE,+            Registries.ENTITY_TYPE,
             new Identifier("entitytesting", "cube"),             new Identifier("entitytesting", "cube"),
             FabricEntityTypeBuilder.create(SpawnGroup.CREATURE, CubeEntity::new).dimensions(EntityDimensions.fixed(0.75f, 0.75f)).build()             FabricEntityTypeBuilder.create(SpawnGroup.CREATURE, CubeEntity::new).dimensions(EntityDimensions.fixed(0.75f, 0.75f)).build()
Line 151: Line 151:
             return new CubeEntityRenderer(context);             return new CubeEntityRenderer(context);
         });         });
-        EntityModelLayerRegistry.registerModelLayer(MODEL_CUBE_LAYER, ModelCube::getTexturedModelData);+        // In 1.17, use EntityRendererRegistry.register (seen below) instead of EntityRendererRegistry.INSTANCE.register (seen above) 
 +        EntityRendererRegistry.register(EntityTesting.CUBE, (context) -> { 
 +            return new CubeEntityRenderer(context); 
 +        }); 
 +         
 +        EntityModelLayerRegistry.registerModelLayer(MODEL_CUBE_LAYER, CubeEntityModel::getTexturedModelData);
     }     }
 } }
Line 192: Line 197:
     }     }
          
 +    // You can use BlockBench, make your model and export it to get this method for your entity model.
     public static TexturedModelData getTexturedModelData() {     public static TexturedModelData getTexturedModelData() {
         ModelData modelData = new ModelData();         ModelData modelData = new ModelData();
     ModelPartData modelPartData = modelData.getRoot();     ModelPartData modelPartData = modelData.getRoot();
-        modelPartData.addChild(EntityModelPartNames.CUBE, ModelPartBuilder.create().uv(0, 0).cuboid(-6F, 12F, -6F, 12F, 12F, 12F), ModelTransform.pivot(0F, 0F, 0F);+        modelPartData.addChild(EntityModelPartNames.CUBE, ModelPartBuilder.create().uv(0, 0).cuboid(-6F, 12F, -6F, 12F, 12F, 12F), ModelTransform.pivot(0F, 0F, 0F));
     }     }
 </code> </code>
Line 220: Line 226:
     public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {     public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
         ImmutableList.of(this.base).forEach((modelRenderer) -> {         ImmutableList.of(this.base).forEach((modelRenderer) -> {
-            modelRenderer.render(matrixStackInbufferInpackedLightInpackedOverlayIn, red, green, blue, alpha);+            modelRenderer.render(matricesverticeslightoverlay, red, green, blue, alpha);
         });         });
     }     }
Line 269: Line 275:
 ===== Adding tasks & activities ===== ===== Adding tasks & activities =====
  
-To add activities see [[:villager_activities|here]].+To add activities see [[tutorial:villager_activities|here]].
  
tutorial/entity.1626553521.txt.gz · Last modified: 2021/07/17 20:25 by logdawg970