2019-03-23 21:49:34 +02:00
|
|
|
package com.minelittlepony.client.model;
|
2015-08-01 18:36:33 -04:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2023-02-15 19:09:59 +00:00
|
|
|
import net.minecraft.item.ArmorItem;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2019-05-27 17:59:15 +02:00
|
|
|
|
2022-07-06 12:53:31 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2021-02-06 16:52:06 +02:00
|
|
|
import com.minelittlepony.api.model.IModel;
|
|
|
|
import com.minelittlepony.api.model.IModelWrapper;
|
2023-02-15 19:09:59 +00:00
|
|
|
import com.minelittlepony.api.model.armour.*;
|
2020-04-03 23:54:12 +02:00
|
|
|
import com.minelittlepony.api.pony.IPonyData;
|
2023-02-15 19:09:59 +00:00
|
|
|
import com.minelittlepony.client.model.armour.PonyArmourModel;
|
|
|
|
import com.minelittlepony.mson.api.*;
|
2015-11-17 00:09:04 -05:00
|
|
|
|
2023-02-15 19:09:59 +00:00
|
|
|
import java.util.*;
|
2022-07-06 12:53:31 +02:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Container class for the various models and their associated piece of armour.
|
|
|
|
*/
|
2023-02-15 19:09:59 +00:00
|
|
|
public class ModelWrapper<T extends LivingEntity, M extends IModel> implements IModelWrapper {
|
|
|
|
@Nullable
|
|
|
|
private final MsonModel.Factory<PonyArmourModel<T>> armorFactory;
|
|
|
|
private final Map<ModelKey<PonyArmourModel<?>>, PonyArmourModel<T>> armor = new HashMap<>();
|
|
|
|
|
|
|
|
private final M body;
|
|
|
|
|
2023-02-15 20:35:48 +00:00
|
|
|
public ModelWrapper(PlayerModelKey<T, ? super M> playerModelKey, boolean slimArms, @Nullable Consumer<M> initializer) {
|
2023-02-15 19:09:59 +00:00
|
|
|
this.armorFactory = playerModelKey.armorFactory();
|
|
|
|
this.body = playerModelKey.getKey(slimArms).createModel();
|
|
|
|
if (initializer != null) {
|
|
|
|
initializer.accept(this.body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ModelWrapper(ModelKey<M> key) {
|
|
|
|
this.armorFactory = null;
|
|
|
|
this.body = key.createModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public M body() {
|
|
|
|
return body;
|
2022-07-06 12:53:31 +02:00
|
|
|
}
|
|
|
|
|
2023-02-15 19:09:59 +00:00
|
|
|
public Optional<PonyArmourModel<T>> getArmourModel(ItemStack stack, ArmourLayer layer) {
|
|
|
|
return ArmorModelRegistry.getModelKey(stack.getItem(), layer).or(() -> ArmorModelRegistry.getDefault(layer).filter(l -> stack.getItem() instanceof ArmorItem))
|
|
|
|
.map(key -> armor.computeIfAbsent(key, k -> {
|
|
|
|
return armorFactory == null ? k.createModel() : k.createModel(armorFactory);
|
|
|
|
}));
|
2015-08-01 18:36:33 -04:00
|
|
|
}
|
|
|
|
|
2018-09-07 21:16:07 +02:00
|
|
|
@Override
|
2021-02-06 16:52:06 +02:00
|
|
|
public ModelWrapper<T, M> applyMetadata(IPonyData meta) {
|
|
|
|
body.setMetadata(meta);
|
2023-02-15 19:09:59 +00:00
|
|
|
armor.values().forEach(a -> a.setMetadata(meta));
|
2019-11-26 23:55:39 +02:00
|
|
|
return this;
|
2015-08-01 18:36:33 -04:00
|
|
|
}
|
|
|
|
}
|