MineLittlePony/src/main/java/com/minelittlepony/client/model/ModelWrapper.java

45 lines
1.4 KiB
Java
Raw Normal View History

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;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.api.model.IModel;
import com.minelittlepony.api.model.IModelWrapper;
import com.minelittlepony.api.model.armour.IArmour;
2020-04-03 23:54:12 +02:00
import com.minelittlepony.api.pony.IPonyData;
2019-11-29 17:26:19 +02:00
import com.minelittlepony.mson.api.ModelKey;
2015-11-17 00:09:04 -05:00
import java.util.function.Consumer;
/**
* Container class for the various models and their associated piece of armour.
*/
public record ModelWrapper<T extends LivingEntity, M extends IModel> (
M body,
IArmour<?> armor
) implements IModelWrapper {
/**
2018-08-17 23:12:40 +02:00
* Creates a new model wrapper to contain the given pony.
*/
public static <T extends LivingEntity, M extends IModel> ModelWrapper<T, M> of(ModelKey<?> key) {
return of(key, null);
}
public static <T extends LivingEntity, M extends IModel> ModelWrapper<T, M> of(ModelKey<?> key, @Nullable Consumer<M> initializer) {
2022-06-12 00:59:12 +02:00
@SuppressWarnings("unchecked")
M body = (M)key.createModel();
if (initializer != null) initializer.accept(body);
IArmour<?> armor = body.createArmour();
armor.applyMetadata(body.getMetadata());
return new ModelWrapper<>(body, armor);
2015-08-01 18:36:33 -04:00
}
2018-09-07 21:16:07 +02:00
@Override
public ModelWrapper<T, M> applyMetadata(IPonyData meta) {
body.setMetadata(meta);
armor.applyMetadata(meta);
2019-11-26 23:55:39 +02:00
return this;
2015-08-01 18:36:33 -04:00
}
}