-
Notifications
You must be signed in to change notification settings - Fork 12
reworking stand animation stuff #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: arch/1.20.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import net.minecraft.util.Mth; | ||
|
|
||
| import java.util.List; | ||
| import java.util.ArrayList; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| /** | ||
|
|
@@ -58,12 +59,77 @@ public ResourceLocation getTextureResource(final E entity) { | |
|
|
||
| @Override | ||
| public ResourceLocation getAnimationResource(final E entity) { | ||
| return animation; | ||
| // Get all animation resources this stand can use | ||
| List<ResourceLocation> allAnimations = getAllAnimationResources(entity); | ||
|
|
||
| // Return the primary animation resource (first in the list) | ||
| return allAnimations.isEmpty() ? animation : allAnimations.get(0); | ||
| } | ||
|
|
||
| /** | ||
| * Gets all animation resources that this stand can use. | ||
| * Override this method in subclasses to provide multiple animation JSONs. | ||
| * The first animation in the list will be used as the primary animation resource. | ||
| * | ||
| * @param entity the entity to get animation resources for | ||
| * @return list of all animation resources this stand can use | ||
| */ | ||
| protected List<ResourceLocation> getAllAnimationResources(final E entity) { | ||
| // Check if subclass wants to completely control animation order | ||
| List<ResourceLocation> customOrder = getCustomAnimationOrder(entity); | ||
| if (customOrder != null) { | ||
| return customOrder; | ||
| } | ||
|
|
||
| // Default behavior: default animation first, then additional ones | ||
| List<ResourceLocation> animations = new ArrayList<>(); | ||
| animations.add(animation); // Always include the default animation | ||
|
|
||
| // Add any additional animations from subclasses | ||
| List<ResourceLocation> additionalAnimations = getAdditionalAnimationResources(entity); | ||
| if (additionalAnimations != null) { | ||
| animations.addAll(additionalAnimations); | ||
| } | ||
|
|
||
| return animations; | ||
| } | ||
|
|
||
| /** | ||
| * Override this method in subclasses to completely control the animation loading order. | ||
| * If this returns non-null, it will be used instead of the default + additional pattern. | ||
| * | ||
| * @param entity the entity to get custom animation order for | ||
| * @return list of animation resources in desired order, or null to use default behavior | ||
| */ | ||
| protected List<ResourceLocation> getCustomAnimationOrder(final E entity) { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Override this method in subclasses to provide additional animation resources. | ||
| * This allows stands to use multiple animation JSONs from other stands. | ||
| * | ||
| * @param entity the entity to get additional animation resources for | ||
| * @return list of additional animation resources, or null if none | ||
| */ | ||
| protected List<ResourceLocation> getAdditionalAnimationResources(final E entity) { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to create an animation resource for any stand by name. | ||
| * | ||
| * @param standName the name of the stand (e.g., "white_snake", "star_platinum") | ||
| * @return the animation resource for that stand | ||
| */ | ||
| protected ResourceLocation createAnimationResource(final String standName) { | ||
| return new ResourceLocation(type.getId().getNamespace(), "animations/" + standName + ".animation.json"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using |
||
| } | ||
|
|
||
| @Override | ||
| public void setCustomAnimations(final E animatable, final long instanceId, final AnimationState<E> animationState) { | ||
| super.setCustomAnimations(animatable, instanceId, animationState); | ||
|
|
||
| if (skipCustomAnimations() || !animatable.hasUser()) { | ||
| return; | ||
| } | ||
|
|
@@ -76,4 +142,4 @@ public void setCustomAnimations(final E animatable, final long instanceId, final | |
| protected boolean skipCustomAnimations() { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,40 @@ | ||
| package net.arna.jcraft.client.model.entity.stand; | ||
|
|
||
| import net.arna.jcraft.JCraft; | ||
| import net.arna.jcraft.common.entity.stand.AbstractStarPlatinumEntity; | ||
| import net.arna.jcraft.api.registry.JStandTypeRegistry; | ||
| import net.minecraft.resources.ResourceLocation; | ||
|
|
||
| /** | ||
| * The {@link StandEntityModel} for {@link net.arna.jcraft.common.entity.stand.StarPlatinumEntity StarPlatinumEntity} | ||
| * and {@link net.arna.jcraft.common.entity.stand.SPTWEntity SPTWEntity}. | ||
| * @see net.arna.jcraft.client.renderer.entity.stands.StarPlatinumRenderer StarPlatinumRenderer | ||
| * @see net.arna.jcraft.client.renderer.entity.stands.SPTWRenderer SPTWRenderer | ||
| * The {@link StandEntityModel} for {@link AbstractStarPlatinumEntity}. | ||
| * This uses base model animations for standby mode. | ||
| */ | ||
| public class StarPlatinumModel extends StandEntityModel<AbstractStarPlatinumEntity<?, ?>> { | ||
| private static final ResourceLocation MODEL = JCraft.id("geo/star_platinum.geo.json"); | ||
|
|
||
| public StarPlatinumModel(final boolean theWorld) { | ||
| super(theWorld ? JStandTypeRegistry.STAR_PLATINUM_THE_WORLD.get() : JStandTypeRegistry.STAR_PLATINUM.get()); | ||
| public StarPlatinumModel(boolean someCondition) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this parameter is no longer needed, please delete it. |
||
| super(JStandTypeRegistry.STAR_PLATINUM.get(), 0f, 0f); | ||
| } | ||
|
|
||
| @Override | ||
| public ResourceLocation getModelResource(final AbstractStarPlatinumEntity<?, ?> object) { | ||
| return MODEL; | ||
| public ResourceLocation getAnimationResource(final AbstractStarPlatinumEntity<?, ?> entity) { | ||
| // Check if the entity is in standby mode and should use base model animations | ||
| if (shouldUseBaseModelAnimations(entity)) { | ||
| return createAnimationResource("base_model"); | ||
| } else { | ||
| return createAnimationResource("star_platinum"); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This creates a new instance of ResourceLocation every time its called (which probably happens a lot), consider caching it in a field instead. |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Determines if the current entity state should use base model animations | ||
| */ | ||
| private boolean shouldUseBaseModelAnimations(AbstractStarPlatinumEntity<?, ?> entity) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge fan of this way of doing the separate animation sources. I think it'd be better to modify the interface state enums implement so that each state includes the source of its animation. More versatile and less prone to breaking. |
||
| if (entity.getState() == null) return false; | ||
|
|
||
| String stateName = entity.getState().toString(); | ||
|
|
||
| // Use base model animations for these specific states | ||
| return stateName.equals("STANDBY_IDLE") || | ||
| stateName.equals("ITEM_TOSS_CHARGE") || | ||
| stateName.equals("ITEM_TOSS"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much use to creating a list with all the additional animation sources if this method always simply uses the first one.
Classes that choose to override just this method can override it to implement all logic needed and wouldn't need to rely on getAllAnimationResources.