anvillib/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticModel.java

68 lines
2.4 KiB
Java
Raw Normal View History

2023-10-28 18:33:26 +02:00
package net.anvilcraft.anvillib.cosmetics;
2023-11-19 15:44:13 +01:00
import net.anvilcraft.anvillib.mixin.accessor.AnimatedGeoModelAccessor;
2023-10-28 18:33:26 +02:00
import net.minecraft.util.Identifier;
2023-11-19 15:44:13 +01:00
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.builder.Animation;
import software.bernie.geckolib3.file.AnimationFile;
import software.bernie.geckolib3.geo.exception.GeckoLibException;
import software.bernie.geckolib3.geo.render.built.GeoBone;
import software.bernie.geckolib3.geo.render.built.GeoModel;
2023-10-28 18:33:26 +02:00
import software.bernie.geckolib3.model.AnimatedGeoModel;
2023-11-19 15:44:13 +01:00
import software.bernie.geckolib3.resource.GeckoLibCache;
2023-10-28 18:33:26 +02:00
public class CosmeticModel extends AnimatedGeoModel<CosmeticItem> {
@Override
public Identifier getAnimationFileLocation(CosmeticItem animatable) {
return animatable.getCosmetic().getAnimationFileLocation();
}
@Override
public Identifier getModelLocation(CosmeticItem animatable) {
return animatable.getCosmetic().getModelLocation();
}
@Override
public Identifier getTextureLocation(CosmeticItem animatable) {
return animatable.getCosmetic().getTextureLocation();
}
2023-11-19 15:44:13 +01:00
@Override
2023-11-24 18:52:05 +01:00
public Animation getAnimation(String name, IAnimatable animatable) {
Identifier location
= ((CosmeticItem) animatable).getCosmetic().getAnimationFileLocation();
AnimationFile animation = CosmeticsManager.getAnimations(location);
2023-11-19 15:44:13 +01:00
if (animation == null) {
animation = GeckoLibCache.getInstance().getAnimations().get(location);
}
2023-11-24 18:52:05 +01:00
if (animation == null) {
throw new GeckoLibException(
location, "Could not find animation file. Please double check name."
);
}
return animation.getAnimation(name);
}
2023-11-19 15:44:13 +01:00
@Override
public GeoModel getModel(Identifier location) {
GeoModel model = CosmeticsManager.getModel(location);
if (model == null) {
model = GeckoLibCache.getInstance().getGeoModels().get(location);
}
2023-11-24 18:52:05 +01:00
AnimatedGeoModelAccessor accessor = (AnimatedGeoModelAccessor) this;
2023-11-19 15:44:13 +01:00
if (model != accessor.getCurrentModel()) {
2023-11-24 18:52:05 +01:00
accessor.getAnimationProcessor().clearModelRendererList();
accessor.setCurrentModel(model);
2023-11-19 15:44:13 +01:00
2023-11-24 18:52:05 +01:00
for (GeoBone bone : model.topLevelBones) {
registerBone(bone);
}
}
2023-11-19 15:44:13 +01:00
2023-11-24 18:52:05 +01:00
return model;
2023-11-19 15:44:13 +01:00
}
2023-10-28 18:33:26 +02:00
}