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
|
|
|
|
public Animation getAnimation(String name, IAnimatable animatable) {
|
|
|
|
Identifier location = ((CosmeticItem)animatable).getCosmetic().getAnimationFileLocation();
|
|
|
|
AnimationFile animation = CosmeticsManager.getAnimations(location);
|
|
|
|
if (animation == null) {
|
|
|
|
animation = GeckoLibCache.getInstance().getAnimations().get(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animation == null) {
|
|
|
|
throw new GeckoLibException(location,
|
|
|
|
"Could not find animation file. Please double check name.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return animation.getAnimation(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeoModel getModel(Identifier location) {
|
|
|
|
GeoModel model = CosmeticsManager.getModel(location);
|
|
|
|
if (model == null) {
|
|
|
|
model = GeckoLibCache.getInstance().getGeoModels().get(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimatedGeoModelAccessor accessor = (AnimatedGeoModelAccessor)this;
|
|
|
|
if (model != accessor.getCurrentModel()) {
|
|
|
|
accessor.getAnimationProcessor().clearModelRendererList();
|
|
|
|
accessor.setCurrentModel(model);
|
|
|
|
|
|
|
|
for (GeoBone bone : model.topLevelBones) {
|
|
|
|
registerBone(bone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
2023-10-28 18:33:26 +02:00
|
|
|
}
|