mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 15:37:59 +01:00
Switch the model wrappers to use records
This commit is contained in:
parent
0c54bdd911
commit
89a8e36e10
16 changed files with 31 additions and 49 deletions
|
@ -39,7 +39,7 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IArmour<?> createArmour() {
|
public IArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(PonyArmourModel::new);
|
return ArmourWrapper.of(PonyArmourModel::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.entity.LivingEntity;
|
||||||
|
|
||||||
import com.minelittlepony.api.model.IModel;
|
import com.minelittlepony.api.model.IModel;
|
||||||
import com.minelittlepony.api.model.IModelWrapper;
|
import com.minelittlepony.api.model.IModelWrapper;
|
||||||
import com.minelittlepony.api.model.armour.IArmourModel;
|
|
||||||
import com.minelittlepony.api.model.armour.IArmour;
|
import com.minelittlepony.api.model.armour.IArmour;
|
||||||
import com.minelittlepony.api.pony.IPonyData;
|
import com.minelittlepony.api.pony.IPonyData;
|
||||||
import com.minelittlepony.mson.api.ModelKey;
|
import com.minelittlepony.mson.api.ModelKey;
|
||||||
|
@ -16,7 +15,6 @@ public record ModelWrapper<T extends LivingEntity, M extends IModel> (
|
||||||
M body,
|
M body,
|
||||||
IArmour<?> armor
|
IArmour<?> armor
|
||||||
) implements IModelWrapper {
|
) implements IModelWrapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new model wrapper to contain the given pony.
|
* Creates a new model wrapper to contain the given pony.
|
||||||
*/
|
*/
|
||||||
|
@ -27,18 +25,6 @@ public record ModelWrapper<T extends LivingEntity, M extends IModel> (
|
||||||
return new ModelWrapper<>(body, armor);
|
return new ModelWrapper<>(body, armor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public M getBody() {
|
|
||||||
return body();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contained armour models.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <V extends IArmourModel> IArmour<V> getArmor() {
|
|
||||||
return (IArmour<V>)armor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelWrapper<T, M> applyMetadata(IPonyData meta) {
|
public ModelWrapper<T, M> applyMetadata(IPonyData meta) {
|
||||||
body.setMetadata(meta);
|
body.setMetadata(meta);
|
||||||
|
|
|
@ -8,14 +8,15 @@ import com.minelittlepony.api.pony.IPonyData;
|
||||||
import com.minelittlepony.client.model.ModelType;
|
import com.minelittlepony.client.model.ModelType;
|
||||||
import com.minelittlepony.mson.api.MsonModel;
|
import com.minelittlepony.mson.api.MsonModel;
|
||||||
|
|
||||||
public class ArmourWrapper<T extends LivingEntity> implements IArmour<PonyArmourModel<T>> {
|
public record ArmourWrapper<T extends LivingEntity> (
|
||||||
|
PonyArmourModel<T> outerLayer,
|
||||||
private final PonyArmourModel<T> outerLayer;
|
PonyArmourModel<T> innerLayer
|
||||||
private final PonyArmourModel<T> innerLayer;
|
) implements IArmour<PonyArmourModel<T>> {
|
||||||
|
public static <T extends LivingEntity> ArmourWrapper<T> of(MsonModel.Factory<PonyArmourModel<T>> supplier) {
|
||||||
public ArmourWrapper(MsonModel.Factory<PonyArmourModel<T>> supplier) {
|
return new ArmourWrapper<>(
|
||||||
outerLayer = ModelType.ARMOUR_OUTER.createModel(supplier);
|
ModelType.ARMOUR_OUTER.createModel(supplier),
|
||||||
innerLayer = ModelType.ARMOUR_INNER.createModel(supplier);
|
ModelType.ARMOUR_INNER.createModel(supplier)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,11 +28,6 @@ public class ArmourWrapper<T extends LivingEntity> implements IArmour<PonyArmour
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PonyArmourModel<T> getModel(ArmourLayer layer) {
|
public PonyArmourModel<T> getModel(ArmourLayer layer) {
|
||||||
|
return layer == ArmourLayer.INNER ? innerLayer : outerLayer;
|
||||||
if (layer == ArmourLayer.INNER) {
|
|
||||||
return innerLayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return outerLayer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IArmour<?> createArmour() {
|
public IArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(Armour::new);
|
return ArmourWrapper.of(Armour::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class ZebraModel<T extends LivingEntity> extends EarthPonyModel<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IArmour<?> createArmour() {
|
public IArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(Armour::new);
|
return ArmourWrapper.of(Armour::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
|
||||||
}
|
}
|
||||||
|
|
||||||
public M getModel() {
|
public M getModel() {
|
||||||
return playerModel.getBody();
|
return playerModel.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModelWrapper<T, M> getModelWrapper() {
|
public ModelWrapper<T, M> getModelWrapper() {
|
||||||
|
|
|
@ -40,7 +40,7 @@ public interface IPonyRenderContext<T extends LivingEntity, M extends EntityMode
|
||||||
float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);
|
float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);
|
||||||
|
|
||||||
getModelWrapper().applyMetadata(entityPony.getMetadata());
|
getModelWrapper().applyMetadata(entityPony.getMetadata());
|
||||||
M model = getModelWrapper().getBody();
|
M model = getModelWrapper().body();
|
||||||
|
|
||||||
model.transform(BodyPart.BACK, stack);
|
model.transform(BodyPart.BACK, stack);
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
|
||||||
public PlayerPonyRenderer(EntityRendererFactory.Context context, boolean slim, ModelKey<? extends ClientPonyModel<AbstractClientPlayerEntity>> key) {
|
public PlayerPonyRenderer(EntityRendererFactory.Context context, boolean slim, ModelKey<? extends ClientPonyModel<AbstractClientPlayerEntity>> key) {
|
||||||
super(context, slim);
|
super(context, slim);
|
||||||
|
|
||||||
this.model = manager.setModel(key).getBody();
|
this.model = manager.setModel(key).body();
|
||||||
|
|
||||||
addLayers(context);
|
addLayers(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class PlayerSeaponyRenderer extends PlayerPonyRenderer {
|
||||||
|
|
||||||
boolean wet = pony.isPartiallySubmerged(player);
|
boolean wet = pony.isPartiallySubmerged(player);
|
||||||
|
|
||||||
model = manager.setModel(wet ? seapony : normalPony).getBody();
|
model = manager.setModel(wet ? seapony : normalPony).body();
|
||||||
|
|
||||||
float state = wet ? 100 : 0;
|
float state = wet ? 100 : 0;
|
||||||
float interpolated = pony.getMetadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);
|
float interpolated = pony.getMetadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);
|
||||||
|
|
|
@ -38,7 +38,7 @@ public abstract class PonyRenderer<T extends MobEntity, M extends EntityModel<T>
|
||||||
public PonyRenderer(EntityRendererFactory.Context context, ModelKey<? super M> key) {
|
public PonyRenderer(EntityRendererFactory.Context context, ModelKey<? super M> key) {
|
||||||
super(context, null, 0.5F);
|
super(context, null, 0.5F);
|
||||||
|
|
||||||
this.model = manager.setModel(key).getBody();
|
this.model = manager.setModel(key).body();
|
||||||
|
|
||||||
addLayers(context);
|
addLayers(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,9 @@ public class PonyStandRenderer extends ArmorStandEntityRenderer {
|
||||||
headPitch = 0.017453292F * entity.getHeadRotation().getPitch();
|
headPitch = 0.017453292F * entity.getHeadRotation().getPitch();
|
||||||
headYaw = 0.017453292F * entity.getHeadRotation().getYaw();
|
headYaw = 0.017453292F * entity.getHeadRotation().getYaw();
|
||||||
|
|
||||||
pony.getBody().animateModel(entity, limbDistance, limbAngle, tickDelta);
|
pony.body().animateModel(entity, limbDistance, limbAngle, tickDelta);
|
||||||
pony.getBody().setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
|
pony.body().setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
|
||||||
PonyStandRenderer.this.pony.applyAnglesTo(pony.getBody());
|
PonyStandRenderer.this.pony.applyAnglesTo(pony.body());
|
||||||
|
|
||||||
for (EquipmentSlot i : EquipmentSlot.values()) {
|
for (EquipmentSlot i : EquipmentSlot.values()) {
|
||||||
if (i.getType() == EquipmentSlot.Type.ARMOR) {
|
if (i.getType() == EquipmentSlot.Type.ARMOR) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & IP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends LivingEntity, V extends BipedEntityModel<T> & IArmourModel> void renderArmor(
|
public static <T extends LivingEntity, V extends BipedEntityModel<T> & IArmourModel> void renderArmor(
|
||||||
ModelWrapper<T, ? extends IPonyModel<T>> pony, MatrixStack stack,
|
ModelWrapper<T, ? extends IPonyModel<T>> pony, MatrixStack stack,
|
||||||
VertexConsumerProvider renderContext, int lightUv, T entity,
|
VertexConsumerProvider renderContext, int lightUv, T entity,
|
||||||
|
@ -56,20 +57,19 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & IP
|
||||||
ItemStack itemstack = entity.getEquippedStack(armorSlot);
|
ItemStack itemstack = entity.getEquippedStack(armorSlot);
|
||||||
|
|
||||||
if (!itemstack.isEmpty() && itemstack.getItem() instanceof ArmorItem) {
|
if (!itemstack.isEmpty() && itemstack.getItem() instanceof ArmorItem) {
|
||||||
|
IArmour<V> armour = ArmourRegistry.getArmour(itemstack, (IArmour<V>)pony.armor());
|
||||||
|
|
||||||
IArmour<V> armour = ArmourRegistry.getArmour(itemstack, pony.<V>getArmor());
|
armour.applyMetadata(pony.body().getMetadata());
|
||||||
|
|
||||||
armour.applyMetadata(pony.getBody().getMetadata());
|
|
||||||
|
|
||||||
V model = armour.getModel(layer);
|
V model = armour.getModel(layer);
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
model = pony.<V>getArmor().getModel(layer);
|
model = ((IArmour<V>)pony.armor()).getModel(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.prepareToRender(armorSlot, layer)) {
|
if (model.prepareToRender(armorSlot, layer)) {
|
||||||
pony.getBody().copyAttributes(model);
|
pony.body().copyAttributes(model);
|
||||||
model.setAngles(entity, limbAngle, limbDistance, age, headYaw, headPitch);
|
model.setAngles(entity, limbAngle, limbDistance, age, headYaw, headPitch);
|
||||||
model.synchroniseAngles(pony.getBody());
|
model.synchroniseAngles(pony.body());
|
||||||
|
|
||||||
ArmorItem item = (ArmorItem) itemstack.getItem();
|
ArmorItem item = (ArmorItem) itemstack.getItem();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class DJPon3Feature<T extends AbstractClientPlayerEntity, M extends Entit
|
||||||
if ("deadmau5".equals(entity.getName().getString())) {
|
if ("deadmau5".equals(entity.getName().getString())) {
|
||||||
stack.push();
|
stack.push();
|
||||||
|
|
||||||
M body = getModelWrapper().getBody();
|
M body = getModelWrapper().body();
|
||||||
|
|
||||||
body.transform(BodyPart.HEAD, stack);
|
body.transform(BodyPart.HEAD, stack);
|
||||||
body.getHead().rotate(stack);
|
body.getHead().rotate(stack);
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & IP
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void preRenderCallback(MatrixStack stack) {
|
protected void preRenderCallback(MatrixStack stack) {
|
||||||
M body = getModelWrapper().getBody();
|
M body = getModelWrapper().body();
|
||||||
stack.translate(0, body.getRiderYOffset(), 0.125);
|
stack.translate(0, body.getRiderYOffset(), 0.125);
|
||||||
body.transform(BodyPart.BODY, stack);
|
body.transform(BodyPart.BODY, stack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final M model = getModelWrapper().getBody();
|
final M model = getModelWrapper().body();
|
||||||
|
|
||||||
final Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
final Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class SkullFeature<T extends LivingEntity, M extends EntityModel<T> & IPo
|
||||||
public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {
|
public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {
|
||||||
ItemStack itemstack = entity.getEquippedStack(EquipmentSlot.HEAD);
|
ItemStack itemstack = entity.getEquippedStack(EquipmentSlot.HEAD);
|
||||||
if (!itemstack.isEmpty()) {
|
if (!itemstack.isEmpty()) {
|
||||||
M model = getContext().getModelWrapper().getBody();
|
M model = getContext().getModelWrapper().body();
|
||||||
Item item = itemstack.getItem();
|
Item item = itemstack.getItem();
|
||||||
|
|
||||||
stack.push();
|
stack.push();
|
||||||
|
|
Loading…
Reference in a new issue