Skip to content

Commit 9d5b1a6

Browse files
committed
Add example animated entity using keyframe anims
1 parent 7c31207 commit 9d5b1a6

File tree

10 files changed

+518
-32
lines changed

10 files changed

+518
-32
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ org.gradle.daemon=false
55

66
minecraft_version=1.19
77
minecraft_version_range=[1.19,1.20)
8-
forge_version=41.0.30
8+
forge_version=41.0.63
99
# The forge version range can use version of forge or match the loader version range
1010
forge_version_range=[41.0.21,)
1111
# The loader version range can only be the major version of Forge/FML!
1212
loader_version_range=[41,)
1313
mappings_channel=parchment
14-
mappings_version=1.18.2-2022.06.05-1.19
14+
mappings_version=1.18.2-2022.07.03-1.19
1515

1616
mod_id=entitymodeljson
1717
mod_name=Entity Model Json

src/main/java/me/sizableshrimp/entitymodeljson/animation/EntityAnimations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class EntityAnimations {
3333
static Map<ResourceLocation, AnimationDefinition> definitions = Map.of();
3434

3535
@NotNull
36-
public Optional<AnimationDefinition> getDefinition(ResourceLocation id) {
36+
public static Optional<AnimationDefinition> getDefinition(ResourceLocation id) {
3737
return Optional.ofNullable(definitions.get(id));
3838
}
3939

4040
@NotNull
41-
public AnimationDefinition getDefinitionOrThrow(ResourceLocation id) {
41+
public static AnimationDefinition getDefinitionOrThrow(ResourceLocation id) {
4242
AnimationDefinition animationDefinition = definitions.get(id);
4343
if (animationDefinition == null)
4444
throw new IllegalArgumentException("Missing entity animation definition with id " + id);

src/test/java/me/sizableshrimp/entitymodeljsonexample/EntityModelJsonExampleMod.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222

2323
package me.sizableshrimp.entitymodeljsonexample;
2424

25+
import me.sizableshrimp.entitymodeljsonexample.animal.ExampleAnimal;
26+
import me.sizableshrimp.entitymodeljsonexample.animal.ExampleAnimalRenderer;
27+
import me.sizableshrimp.entitymodeljsonexample.animated.ExampleAnimatedEntityRenderer;
28+
import me.sizableshrimp.entitymodeljsonexample.data.ExampleEntityModelProvider;
2529
import net.minecraft.data.DataGenerator;
2630
import net.minecraft.world.entity.Entity;
2731
import net.minecraft.world.entity.EntityType;
2832
import net.minecraft.world.entity.MobCategory;
33+
import net.minecraft.world.entity.monster.warden.Warden;
2934
import net.minecraftforge.client.event.EntityRenderersEvent;
3035
import net.minecraftforge.common.data.ExistingFileHelper;
3136
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
@@ -46,6 +51,10 @@ public class EntityModelJsonExampleMod {
4651

4752
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MODID);
4853
public static final RegistryObject<EntityType<ExampleAnimal>> EXAMPLE_ANIMAL = registerEntity("animal", () -> EntityType.Builder.of(ExampleAnimal::new, MobCategory.AMBIENT));
54+
public static final RegistryObject<EntityType<Warden>> EXAMPLE_ANIMATED_ENTITY = registerEntity("animated", () -> EntityType.Builder.of(Warden::new, MobCategory.MONSTER)
55+
.sized(0.9F, 2.9F)
56+
.clientTrackingRange(16)
57+
.fireImmune());
4958

5059
public EntityModelJsonExampleMod() {
5160
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
@@ -57,11 +66,13 @@ public EntityModelJsonExampleMod() {
5766
@SubscribeEvent
5867
public void onRegisterEntityRenderers(EntityRenderersEvent.RegisterRenderers event) {
5968
event.registerEntityRenderer(EXAMPLE_ANIMAL.get(), ExampleAnimalRenderer::new);
69+
event.registerEntityRenderer(EXAMPLE_ANIMATED_ENTITY.get(), ExampleAnimatedEntityRenderer::new);
6070
}
6171

6272
@SubscribeEvent
6373
public void onEntityAttributeCreation(EntityAttributeCreationEvent event) {
6474
event.put(EXAMPLE_ANIMAL.get(), ExampleAnimal.createAttributes().build());
75+
event.put(EXAMPLE_ANIMATED_ENTITY.get(), Warden.createAttributes().build());
6576
}
6677

6778
@SubscribeEvent

src/test/java/me/sizableshrimp/entitymodeljsonexample/ExampleAnimal.java renamed to src/test/java/me/sizableshrimp/entitymodeljsonexample/animal/ExampleAnimal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 SizableShrimp
2+
* Copyright (c) 2022 SizableShrimp
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -20,7 +20,7 @@
2020
* SOFTWARE.
2121
*/
2222

23-
package me.sizableshrimp.entitymodeljsonexample;
23+
package me.sizableshrimp.entitymodeljsonexample.animal;
2424

2525
import net.minecraft.server.level.ServerLevel;
2626
import net.minecraft.world.entity.AgeableMob;
@@ -33,7 +33,7 @@
3333
import org.jetbrains.annotations.Nullable;
3434

3535
public class ExampleAnimal extends Animal {
36-
protected ExampleAnimal(EntityType<? extends Animal> entityType, Level level) {
36+
public ExampleAnimal(EntityType<? extends ExampleAnimal> entityType, Level level) {
3737
super(entityType, level);
3838
}
3939

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2022 SizableShrimp
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package me.sizableshrimp.entitymodeljsonexample.animal;
24+
25+
import net.minecraft.client.model.HierarchicalModel;
26+
import net.minecraft.client.model.geom.ModelPart;
27+
28+
public class ExampleAnimalModel extends HierarchicalModel<ExampleAnimal> {
29+
private final ModelPart root;
30+
31+
public ExampleAnimalModel(ModelPart root) {
32+
this.root = root;
33+
}
34+
35+
@Override
36+
public void setupAnim(ExampleAnimal entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {}
37+
38+
@Override
39+
public ModelPart root() {
40+
return root;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 SizableShrimp
2+
* Copyright (c) 2022 SizableShrimp
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -20,12 +20,11 @@
2020
* SOFTWARE.
2121
*/
2222

23-
package me.sizableshrimp.entitymodeljsonexample;
23+
package me.sizableshrimp.entitymodeljsonexample.animal;
2424

25+
import me.sizableshrimp.entitymodeljsonexample.EntityModelJsonExampleMod;
2526
import net.minecraft.client.model.EntityModel;
26-
import net.minecraft.client.model.HierarchicalModel;
2727
import net.minecraft.client.model.geom.ModelLayerLocation;
28-
import net.minecraft.client.model.geom.ModelPart;
2928
import net.minecraft.client.renderer.entity.EntityRendererProvider;
3029
import net.minecraft.client.renderer.entity.MobRenderer;
3130
import net.minecraft.resources.ResourceLocation;
@@ -34,9 +33,9 @@ public class ExampleAnimalRenderer extends MobRenderer<ExampleAnimal, EntityMode
3433
// The layer, in this case "main", becomes the root folder for the entity model
3534
// All JSON entity models reside in assets/modid/models/entity.
3635
// This model location translates to assets/entitymodeljsonexample/models/entity/main/example_animal.json
37-
public static final ModelLayerLocation EXAMPLE_ANIMAL_MODEL_LOCATION = new ModelLayerLocation(new ResourceLocation(EntityModelJsonExampleMod.MODID, "allay"), "main");
36+
public static final ModelLayerLocation EXAMPLE_ANIMAL_MODEL_LOCATION = new ModelLayerLocation(new ResourceLocation(EntityModelJsonExampleMod.MODID, "example_animal"), "main");
3837
// The actual texture PNG
39-
public static final ResourceLocation SQUID_LOCATION = new ResourceLocation(EntityModelJsonExampleMod.MODID, "textures/entity/allay.png");
38+
public static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/entity/armorstand/wood.png");
4039

4140
public ExampleAnimalRenderer(EntityRendererProvider.Context context) {
4241
// Bake the model location, this will get a ModelPart with the data defined in the custom JSON file
@@ -45,22 +44,6 @@ public ExampleAnimalRenderer(EntityRendererProvider.Context context) {
4544

4645
@Override
4746
public ResourceLocation getTextureLocation(ExampleAnimal entity) {
48-
return SQUID_LOCATION;
49-
}
50-
51-
public static class ExampleAnimalModel extends HierarchicalModel<ExampleAnimal> {
52-
private final ModelPart root;
53-
54-
public ExampleAnimalModel(ModelPart root) {
55-
this.root = root;
56-
}
57-
58-
@Override
59-
public void setupAnim(ExampleAnimal entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {}
60-
61-
@Override
62-
public ModelPart root() {
63-
return root;
64-
}
47+
return TEXTURE_LOCATION;
6548
}
6649
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2022 SizableShrimp
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package me.sizableshrimp.entitymodeljsonexample.animated;
24+
25+
import me.sizableshrimp.entitymodeljson.animation.EntityAnimations;
26+
import me.sizableshrimp.entitymodeljsonexample.EntityModelJsonExampleMod;
27+
import net.minecraft.client.animation.AnimationDefinition;
28+
import net.minecraft.client.animation.definitions.WardenAnimation;
29+
import net.minecraft.client.model.HierarchicalModel;
30+
import net.minecraft.client.model.geom.ModelPart;
31+
import net.minecraft.client.renderer.RenderType;
32+
import net.minecraft.resources.ResourceLocation;
33+
import net.minecraft.world.entity.monster.warden.Warden;
34+
35+
public class ExampleAnimatedEntityModel extends HierarchicalModel<Warden> {
36+
// All JSON entity animation definitions reside in assets/modid/animations/entity.
37+
// This resource location with path "warden/attack" translates to assets/entitymodeljsonexample/animations/entity/warden/attack.json
38+
private static final ResourceLocation ATTACK_LOCATION = new ResourceLocation(EntityModelJsonExampleMod.MODID, "warden/attack");
39+
private final ModelPart root;
40+
private final AnimationDefinition attackAnimation;
41+
42+
public ExampleAnimatedEntityModel(ModelPart root) {
43+
super(RenderType::entityCutoutNoCull);
44+
this.root = root;
45+
// Query the animation definition from the loaded animations
46+
this.attackAnimation = EntityAnimations.getDefinitionOrThrow(ATTACK_LOCATION);
47+
}
48+
49+
@Override
50+
public void setupAnim(Warden warden, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
51+
this.root().getAllParts().forEach(ModelPart::resetPose);
52+
53+
// Keep playing the attack animation to demo it
54+
if (warden.attackAnimationState.getAccumulatedTime() >= this.attackAnimation.lengthInSeconds() * 1000L) {
55+
warden.attackAnimationState.start(warden.tickCount);
56+
}
57+
58+
// Animate the attack animation; this should always be run and will just do nothing if the animation is not playing
59+
this.animate(warden.attackAnimationState, this.attackAnimation, ageInTicks);
60+
}
61+
62+
@Override
63+
public ModelPart root() {
64+
return this.root;
65+
}
66+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2022 SizableShrimp
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package me.sizableshrimp.entitymodeljsonexample.animated;
24+
25+
import net.minecraft.client.model.geom.ModelLayers;
26+
import net.minecraft.client.renderer.entity.EntityRendererProvider;
27+
import net.minecraft.client.renderer.entity.MobRenderer;
28+
import net.minecraft.resources.ResourceLocation;
29+
import net.minecraft.world.entity.monster.warden.Warden;
30+
31+
public class ExampleAnimatedEntityRenderer extends MobRenderer<Warden, ExampleAnimatedEntityModel> {
32+
private static final ResourceLocation TEXTURE = new ResourceLocation("textures/entity/warden/warden.png");
33+
34+
public ExampleAnimatedEntityRenderer(EntityRendererProvider.Context context) {
35+
super(context, new ExampleAnimatedEntityModel(context.bakeLayer(ModelLayers.WARDEN)), 0.9F);
36+
}
37+
38+
@Override
39+
public ResourceLocation getTextureLocation(Warden warden) {
40+
return TEXTURE;
41+
}
42+
}

src/test/java/me/sizableshrimp/entitymodeljsonexample/ExampleEntityModelProvider.java renamed to src/test/java/me/sizableshrimp/entitymodeljsonexample/data/ExampleEntityModelProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 SizableShrimp
2+
* Copyright (c) 2022 SizableShrimp
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -20,9 +20,10 @@
2020
* SOFTWARE.
2121
*/
2222

23-
package me.sizableshrimp.entitymodeljsonexample;
23+
package me.sizableshrimp.entitymodeljsonexample.data;
2424

2525
import me.sizableshrimp.entitymodeljson.datagen.EntityModelProvider;
26+
import me.sizableshrimp.entitymodeljsonexample.EntityModelJsonExampleMod;
2627
import net.minecraft.client.model.geom.ModelLayers;
2728
import net.minecraft.client.model.geom.PartPose;
2829
import net.minecraft.data.DataGenerator;

0 commit comments

Comments
 (0)