Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum MoveClass {
SPECIAL3(CooldownType.STAND_SP3),
ULTIMATE(CooldownType.STAND_ULTIMATE),
UTILITY(CooldownType.UTILITY),
//STANDBY_ON(CooldownType.STAND_STANDBY),
STANDBY_ON(CooldownType.STAND_STANDBY),
STANDBY_OFF(CooldownType.STAND_STANDBY),
TOSS(CooldownType.STAND_TOSS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.util.Mth;

import java.util.List;
import java.util.ArrayList;
import java.util.stream.IntStream;

/**
Expand Down Expand Up @@ -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);
Copy link
Copy Markdown
Member

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.

}

/**
* 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");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using type.getId().withPath

}

@Override
public void setCustomAnimations(final E animatable, final long instanceId, final AnimationState<E> animationState) {
super.setCustomAnimations(animatable, instanceId, animationState);

if (skipCustomAnimations() || !animatable.hasUser()) {
return;
}
Expand All @@ -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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
However, if you go with my suggestion of moving this to the animation state interface, this won't be necessary regardless.

}
}

/**
* Determines if the current entity state should use base model animations
*/
private boolean shouldUseBaseModelAnimations(AbstractStarPlatinumEntity<?, ?> entity) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ private static void registerMoves(MoveMap<StarPlatinumEntity, State> moves) {
moves.register(MoveClass.SPECIAL2, KNEE, State.KNEE).withAerialVariant(State.KNEE_UP);
moves.register(MoveClass.SPECIAL3, CHARGE_BARRAGE, State.BARRAGE).withCrouchingVariant(State.BARRAGE);
moves.register(MoveClass.ULTIMATE, INHALE, State.INHALE);
moves.register(MoveClass.STANDBY_ON, STANDBY_ON, State.STANDBY_IDLE);

moves.register(MoveClass.UTILITY, JUMP, State.JUMP);//.withCrouchingVariant(State.IDLE);

Expand Down Expand Up @@ -291,8 +292,9 @@ public enum State implements StandAnimationState<StarPlatinumEntity> {
GRAB_HIT(builder -> builder.setAnimation(RawAnimation.begin().thenPlayAndHold("animation.starplatinum.grabhit"))),
UPPERCUT(builder -> builder.setAnimation(RawAnimation.begin().thenPlayAndHold("animation.starplatinum.uppercut"))),
LIGHT_FOLLOWUP(builder -> builder.setAnimation(RawAnimation.begin().thenPlayAndHold("animation.starplatinum.light_followup"))),
ITEM_TOSS_CHARGE(builder -> builder.setAnimation(RawAnimation.begin().thenPlayAndHold("animation.starplatinum.itemthrow_charge"))),
ITEM_TOSS(builder -> builder.setAnimation(RawAnimation.begin().thenPlay("animation.starplatinum.itemthrow")));
STANDBY_IDLE(builder -> builder.setAnimation(RawAnimation.begin().thenLoop("standby_idle"))),
ITEM_TOSS_CHARGE(builder -> builder.setAnimation(RawAnimation.begin().thenPlayAndHold("itemthrow_charge"))),
ITEM_TOSS(builder -> builder.setAnimation(RawAnimation.begin().thenPlay("itemthrow")));

private final BiConsumer<StarPlatinumEntity, AnimationState<StarPlatinumEntity>> animator;

Expand Down
Loading