Switch the model wrappers to use records

This commit is contained in:
Sollace 2022-06-11 21:00:45 +02:00
parent 0c54bdd911
commit 89a8e36e10
16 changed files with 31 additions and 49 deletions

View file

@ -39,7 +39,7 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
@Override
public IArmour<?> createArmour() {
return new ArmourWrapper<>(PonyArmourModel::new);
return ArmourWrapper.of(PonyArmourModel::new);
}
/**

View file

@ -4,7 +4,6 @@ import net.minecraft.entity.LivingEntity;
import com.minelittlepony.api.model.IModel;
import com.minelittlepony.api.model.IModelWrapper;
import com.minelittlepony.api.model.armour.IArmourModel;
import com.minelittlepony.api.model.armour.IArmour;
import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.mson.api.ModelKey;
@ -16,7 +15,6 @@ public record ModelWrapper<T extends LivingEntity, M extends IModel> (
M body,
IArmour<?> armor
) implements IModelWrapper {
/**
* 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);
}
public M getBody() {
return body();
}
/**
* Returns the contained armour models.
*/
@SuppressWarnings("unchecked")
public <V extends IArmourModel> IArmour<V> getArmor() {
return (IArmour<V>)armor();
}
@Override
public ModelWrapper<T, M> applyMetadata(IPonyData meta) {
body.setMetadata(meta);

View file

@ -8,14 +8,15 @@ import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.mson.api.MsonModel;
public class ArmourWrapper<T extends LivingEntity> implements IArmour<PonyArmourModel<T>> {
private final PonyArmourModel<T> outerLayer;
private final PonyArmourModel<T> innerLayer;
public ArmourWrapper(MsonModel.Factory<PonyArmourModel<T>> supplier) {
outerLayer = ModelType.ARMOUR_OUTER.createModel(supplier);
innerLayer = ModelType.ARMOUR_INNER.createModel(supplier);
public record ArmourWrapper<T extends LivingEntity> (
PonyArmourModel<T> outerLayer,
PonyArmourModel<T> innerLayer
) implements IArmour<PonyArmourModel<T>> {
public static <T extends LivingEntity> ArmourWrapper<T> of(MsonModel.Factory<PonyArmourModel<T>> supplier) {
return new ArmourWrapper<>(
ModelType.ARMOUR_OUTER.createModel(supplier),
ModelType.ARMOUR_INNER.createModel(supplier)
);
}
@Override
@ -27,11 +28,6 @@ public class ArmourWrapper<T extends LivingEntity> implements IArmour<PonyArmour
@Override
public PonyArmourModel<T> getModel(ArmourLayer layer) {
if (layer == ArmourLayer.INNER) {
return innerLayer;
}
return outerLayer;
return layer == ArmourLayer.INNER ? innerLayer : outerLayer;
}
}

View file

@ -42,7 +42,7 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
@Override
public IArmour<?> createArmour() {
return new ArmourWrapper<>(Armour::new);
return ArmourWrapper.of(Armour::new);
}
@Override

View file

@ -17,7 +17,7 @@ public class ZebraModel<T extends LivingEntity> extends EarthPonyModel<T> {
@Override
public IArmour<?> createArmour() {
return new ArmourWrapper<>(Armour::new);
return ArmourWrapper.of(Armour::new);
}
@Override

View file

@ -129,7 +129,7 @@ public class EquineRenderManager<T extends LivingEntity, M extends EntityModel<T
}
public M getModel() {
return playerModel.getBody();
return playerModel.body();
}
public ModelWrapper<T, M> getModelWrapper() {

View file

@ -40,7 +40,7 @@ public interface IPonyRenderContext<T extends LivingEntity, M extends EntityMode
float yaw = MathUtil.interpolateDegress((float)entity.prevY, (float)entity.getY(), ticks);
getModelWrapper().applyMetadata(entityPony.getMetadata());
M model = getModelWrapper().getBody();
M model = getModelWrapper().body();
model.transform(BodyPart.BACK, stack);

View file

@ -50,7 +50,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
public PlayerPonyRenderer(EntityRendererFactory.Context context, boolean slim, ModelKey<? extends ClientPonyModel<AbstractClientPlayerEntity>> key) {
super(context, slim);
this.model = manager.setModel(key).getBody();
this.model = manager.setModel(key).body();
addLayers(context);
}

View file

@ -37,7 +37,7 @@ public class PlayerSeaponyRenderer extends PlayerPonyRenderer {
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 interpolated = pony.getMetadata().getInterpolator(player.getUuid()).interpolate("seapony_state", state, 5);

View file

@ -38,7 +38,7 @@ public abstract class PonyRenderer<T extends MobEntity, M extends EntityModel<T>
public PonyRenderer(EntityRendererFactory.Context context, ModelKey<? super M> key) {
super(context, null, 0.5F);
this.model = manager.setModel(key).getBody();
this.model = manager.setModel(key).body();
addLayers(context);
}

View file

@ -72,9 +72,9 @@ public class PonyStandRenderer extends ArmorStandEntityRenderer {
headPitch = 0.017453292F * entity.getHeadRotation().getPitch();
headYaw = 0.017453292F * entity.getHeadRotation().getYaw();
pony.getBody().animateModel(entity, limbDistance, limbAngle, tickDelta);
pony.getBody().setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
PonyStandRenderer.this.pony.applyAnglesTo(pony.getBody());
pony.body().animateModel(entity, limbDistance, limbAngle, tickDelta);
pony.body().setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch);
PonyStandRenderer.this.pony.applyAnglesTo(pony.body());
for (EquipmentSlot i : EquipmentSlot.values()) {
if (i.getType() == EquipmentSlot.Type.ARMOR) {

View file

@ -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(
ModelWrapper<T, ? extends IPonyModel<T>> pony, MatrixStack stack,
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);
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.getBody().getMetadata());
armour.applyMetadata(pony.body().getMetadata());
V model = armour.getModel(layer);
if (model == null) {
model = pony.<V>getArmor().getModel(layer);
model = ((IArmour<V>)pony.armor()).getModel(layer);
}
if (model.prepareToRender(armorSlot, layer)) {
pony.getBody().copyAttributes(model);
pony.body().copyAttributes(model);
model.setAngles(entity, limbAngle, limbDistance, age, headYaw, headPitch);
model.synchroniseAngles(pony.getBody());
model.synchroniseAngles(pony.body());
ArmorItem item = (ArmorItem) itemstack.getItem();

View file

@ -26,7 +26,7 @@ public class DJPon3Feature<T extends AbstractClientPlayerEntity, M extends Entit
if ("deadmau5".equals(entity.getName().getString())) {
stack.push();
M body = getModelWrapper().getBody();
M body = getModelWrapper().body();
body.transform(BodyPart.HEAD, stack);
body.getHead().rotate(stack);

View file

@ -55,7 +55,7 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & IP
}
protected void preRenderCallback(MatrixStack stack) {
M body = getModelWrapper().getBody();
M body = getModelWrapper().body();
stack.translate(0, body.getRiderYOffset(), 0.125);
body.transform(BodyPart.BODY, stack);
}

View file

@ -50,7 +50,7 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
return;
}
final M model = getModelWrapper().getBody();
final M model = getModelWrapper().body();
final Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();

View file

@ -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) {
ItemStack itemstack = entity.getEquippedStack(EquipmentSlot.HEAD);
if (!itemstack.isEmpty()) {
M model = getContext().getModelWrapper().getBody();
M model = getContext().getModelWrapper().body();
Item item = itemstack.getItem();
stack.push();