Skip to content

Commit 8435de0

Browse files
committed
Fix item animation
1 parent e4fe9b5 commit 8435de0

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/main/resources/neoforge-1.21.4/templates/item/item_renderer.java.ftl

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,38 @@ package ${package}.client.renderer.item;
155155
</#list>
156156
}
157157

158-
private static final class AnimatedModel extends ${data.customModelName.split(":")[0]} {
158+
private final class AnimatedModel extends ${data.customModelName.split(":")[0]} {
159159

160-
<#list data.animations as animation>
161-
private final KeyframeAnimation keyframeAnimation${animation?index};
162-
</#list>
160+
private final ModelPart root;
161+
162+
private final BlockEntityHierarchicalModel animator = new BlockEntityHierarchicalModel();
163163

164164
public AnimatedModel(ModelPart root) {
165165
super(root);
166-
<#list data.animations as animation>
167-
this.keyframeAnimation${animation?index} = ${animation.animation}.bake(root);
168-
</#list>
166+
this.root = root;
167+
}
168+
169+
public void setupItemStackAnim(ItemStack itemstack, float ageInTicks) {
170+
animator.setupItemStackAnim(itemstack, ageInTicks);
171+
super.setupAnim(null, 0, 0, ageInTicks, 0, 0);
169172
}
170173

171-
public void setupItemStackAnim(${name}ItemRenderer renderer, ItemStack itemstack, LivingEntityRenderState state) {
172-
this.root().getAllParts().forEach(ModelPart::resetPose);
173-
<#list data.animations as animation>
174-
this.keyframeAnimation${animation?index}.apply(renderer.getAnimationState(itemstack).get(${animation?index}), state.ageInTicks, ${animation.speed}f);
175-
</#list>
176-
super.setupAnim(state);
174+
private class BlockEntityHierarchicalModel extends HierarchicalModel<Entity> {
175+
176+
@Override public ModelPart root() {
177+
return root;
178+
}
179+
180+
@Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
181+
}
182+
183+
public void setupItemStackAnim(ItemStack itemstack, float ageInTicks) {
184+
animator.root().getAllParts().forEach(ModelPart::resetPose);
185+
<#list data.animations as animation>
186+
animator.animate(getAnimationState(itemstack).get(${animation?index}), ${animation.animation}, ageInTicks, ${animation.speed}f);
187+
</#list>
188+
}
189+
177190
}
178191

179192
}

0 commit comments

Comments
 (0)