mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 12:37:59 +01:00
Added support for rendering legacy (vanilla) armour textures
This commit is contained in:
parent
85791a8d8c
commit
aff5920b0e
10 changed files with 116 additions and 16 deletions
|
@ -39,7 +39,7 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEquestrianArmour<?> createArmour() {
|
public IEquestrianArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(new ModelPonyArmour<>(), new ModelPonyArmour<>());
|
return new ArmourWrapper<>(ModelPonyArmour::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,7 +208,6 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
|
||||||
* @param y New rotation Y
|
* @param y New rotation Y
|
||||||
*/
|
*/
|
||||||
private void updateHeadRotation(float headYaw, float headPitch) {
|
private void updateHeadRotation(float headYaw, float headPitch) {
|
||||||
|
|
||||||
head.yaw = attributes.isSleeping ? (Math.abs(attributes.interpolatorId.getMostSignificantBits()) % 2.8F) - 1.9F : headYaw / 57.29578F;
|
head.yaw = attributes.isSleeping ? (Math.abs(attributes.interpolatorId.getMostSignificantBits()) % 2.8F) - 1.9F : headYaw / 57.29578F;
|
||||||
|
|
||||||
headPitch = attributes.isSleeping ? 0.1f : headPitch / 57.29578F;
|
headPitch = attributes.isSleeping ? 0.1f : headPitch / 57.29578F;
|
||||||
|
@ -647,22 +646,22 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
|
||||||
|
|
||||||
leftArm .setRotationPoint( rarmX, yOffset + rarmY, 0);
|
leftArm .setRotationPoint( rarmX, yOffset + rarmY, 0);
|
||||||
rightArm .setRotationPoint(-rarmX, yOffset + rarmY, 0);
|
rightArm .setRotationPoint(-rarmX, yOffset + rarmY, 0);
|
||||||
leftArmOverlay .setRotationPoint(rarmX, yOffset + rarmY, 0);
|
leftArmOverlay .setRotationPoint( rarmX, yOffset + rarmY, 0);
|
||||||
rightArmOverlay.setRotationPoint(-rarmX, yOffset + rarmY, 0);
|
rightArmOverlay.setRotationPoint(-rarmX, yOffset + rarmY, 0);
|
||||||
|
|
||||||
leftLeg .setRotationPoint( rarmX, yOffset, 0);
|
leftLeg .setRotationPoint( rarmX, yOffset, 0);
|
||||||
rightLeg .setRotationPoint(-rarmX, yOffset, 0);
|
rightLeg .setRotationPoint(-rarmX, yOffset, 0);
|
||||||
leftLegOverlay .setRotationPoint(rarmX, yOffset, 0);
|
leftLegOverlay .setRotationPoint( rarmX, yOffset, 0);
|
||||||
rightLegOverlay.setRotationPoint(-rarmX, yOffset, 0);
|
rightLegOverlay.setRotationPoint(-rarmX, yOffset, 0);
|
||||||
|
|
||||||
leftArm .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch);
|
leftArm .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
rightArm .addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch);
|
rightArm .addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
leftArmOverlay .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
leftArmOverlay .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
||||||
rightArmOverlay.addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
rightArmOverlay.addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
||||||
|
|
||||||
leftLeg .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch);
|
leftLeg .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
rightLeg .addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch);
|
rightLeg .addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
leftLegOverlay .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
leftLegOverlay .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
||||||
rightLegOverlay.addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
rightLegOverlay.addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch + 0.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,16 @@ import com.minelittlepony.model.armour.ArmourLayer;
|
||||||
import com.minelittlepony.model.armour.IEquestrianArmour;
|
import com.minelittlepony.model.armour.IEquestrianArmour;
|
||||||
import com.minelittlepony.pony.IPonyData;
|
import com.minelittlepony.pony.IPonyData;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ArmourWrapper<T extends LivingEntity> implements IEquestrianArmour<ModelPonyArmour<T>> {
|
public class ArmourWrapper<T extends LivingEntity> implements IEquestrianArmour<ModelPonyArmour<T>> {
|
||||||
|
|
||||||
private final ModelPonyArmour<T> outerLayer;
|
private final ModelPonyArmour<T> outerLayer;
|
||||||
private final ModelPonyArmour<T> innerLayer;
|
private final ModelPonyArmour<T> innerLayer;
|
||||||
|
|
||||||
public ArmourWrapper(ModelPonyArmour<T> outer, ModelPonyArmour<T> inner) {
|
public ArmourWrapper(Supplier<ModelPonyArmour<T>> supplier) {
|
||||||
outerLayer = outer;
|
outerLayer = supplier.get();
|
||||||
innerLayer = inner;
|
innerLayer = supplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.util.Identifier;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.minelittlepony.client.ForgeProxy;
|
import com.minelittlepony.client.ForgeProxy;
|
||||||
import com.minelittlepony.model.armour.ArmourLayer;
|
import com.minelittlepony.model.armour.ArmourLayer;
|
||||||
|
import com.minelittlepony.model.armour.ArmourVariant;
|
||||||
import com.minelittlepony.model.armour.IArmourTextureResolver;
|
import com.minelittlepony.model.armour.IArmourTextureResolver;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -77,4 +78,12 @@ public class DefaultArmourTextureResolver<T extends LivingEntity> implements IAr
|
||||||
private Identifier getArmorTexture(T entity, ItemStack item, String def, EquipmentSlot slot, @Nullable String type) {
|
private Identifier getArmorTexture(T entity, ItemStack item, String def, EquipmentSlot slot, @Nullable String type) {
|
||||||
return HUMAN_ARMOUR.computeIfAbsent(ForgeProxy.getArmorTexture(entity, item, def, slot, type), Identifier::new);
|
return HUMAN_ARMOUR.computeIfAbsent(ForgeProxy.getArmorTexture(entity, item, def, slot, type), Identifier::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArmourVariant getArmourVariant(ArmourLayer layer, Identifier resolvedTexture) {
|
||||||
|
if (resolvedTexture.getPath().endsWith("_pony.png")) {
|
||||||
|
return ArmourVariant.NORMAL;
|
||||||
|
}
|
||||||
|
return ArmourVariant.LEGACY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
package com.minelittlepony.client.model.armour;
|
package com.minelittlepony.client.model.armour;
|
||||||
|
|
||||||
|
import net.minecraft.client.model.Cuboid;
|
||||||
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
|
||||||
import com.minelittlepony.client.model.AbstractPonyModel;
|
import com.minelittlepony.client.model.AbstractPonyModel;
|
||||||
import com.minelittlepony.client.util.render.PonyRenderer;
|
import com.minelittlepony.client.util.render.PonyRenderer;
|
||||||
|
import com.minelittlepony.client.util.render.plane.PlaneRenderer;
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
|
import com.minelittlepony.model.armour.ArmourVariant;
|
||||||
import com.minelittlepony.model.armour.IArmour;
|
import com.minelittlepony.model.armour.IArmour;
|
||||||
|
|
||||||
public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T> implements IArmour {
|
public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T> implements IArmour {
|
||||||
|
|
||||||
public PonyRenderer chestPiece;
|
public PonyRenderer chestPiece;
|
||||||
|
|
||||||
|
public Cuboid steveRightLeg;
|
||||||
|
public Cuboid steveLeftLeg;
|
||||||
|
|
||||||
|
private ArmourVariant variant = ArmourVariant.NORMAL;
|
||||||
|
|
||||||
public ModelPonyArmour() {
|
public ModelPonyArmour() {
|
||||||
super(false);
|
super(false);
|
||||||
textureHeight = 32;
|
textureHeight = 32;
|
||||||
|
@ -28,7 +36,24 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBody(float scale) {
|
protected void renderBody(float scale) {
|
||||||
chestPiece.render(scale);
|
if (variant == ArmourVariant.LEGACY) {
|
||||||
|
body.render(scale);
|
||||||
|
upperTorso.render(scale);
|
||||||
|
} else {
|
||||||
|
chestPiece.render(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderLegs(float scale) {
|
||||||
|
super.renderLegs(scale);
|
||||||
|
steveLeftLeg.render(scale);
|
||||||
|
steveRightLeg.render(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVariant(ArmourVariant variant) {
|
||||||
|
this.variant = variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,6 +67,9 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
leftArm.copyRotation(mainModel.leftArm);
|
leftArm.copyRotation(mainModel.leftArm);
|
||||||
rightLeg.copyRotation(mainModel.rightLeg);
|
rightLeg.copyRotation(mainModel.rightLeg);
|
||||||
leftLeg.copyRotation(mainModel.leftLeg);
|
leftLeg.copyRotation(mainModel.leftLeg);
|
||||||
|
|
||||||
|
steveLeftLeg.copyRotation(mainModel.leftLeg);
|
||||||
|
steveRightLeg.copyRotation(mainModel.rightLeg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +87,16 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
chestPiece = new PonyRenderer(this, 16, 8)
|
chestPiece = new PonyRenderer(this, 16, 8)
|
||||||
.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z)
|
.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z)
|
||||||
.box(-4, 4, -2, 8, 8, 16, stretch);
|
.box(-4, 4, -2, 8, 8, 16, stretch);
|
||||||
|
|
||||||
|
// fits the legacy player's torso to our pony bod.
|
||||||
|
upperTorso = new PlaneRenderer(this, 24, 0);
|
||||||
|
upperTorso.offset(BODY_CENTRE_X, BODY_CENTRE_Y, BODY_CENTRE_Z)
|
||||||
|
.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z)
|
||||||
|
.tex(32, 23).east( 4, -4, -4, 8, 8, stretch)
|
||||||
|
.west(-4, -4, -4, 8, 8, stretch)
|
||||||
|
.tex(32, 23).south(-4, -4, 4, 8, 8, stretch)
|
||||||
|
.tex(32, 23).top(-4, -4, -8, 8, 12, stretch);
|
||||||
|
// it's a little short, so the butt tends to show. :/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,6 +106,30 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
|
|
||||||
leftLeg = new PonyRenderer(this, 48, 8).flip();
|
leftLeg = new PonyRenderer(this, 48, 8).flip();
|
||||||
rightLeg = new PonyRenderer(this, 48, 8);
|
rightLeg = new PonyRenderer(this, 48, 8);
|
||||||
|
|
||||||
|
steveLeftLeg = new PonyRenderer(this, 0, 16).flip();
|
||||||
|
steveRightLeg = new PonyRenderer(this, 0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initLegs(float yOffset, float stretch) {
|
||||||
|
super.initLegs(yOffset, stretch);
|
||||||
|
|
||||||
|
int armLength = attributes.armLength;
|
||||||
|
int armWidth = attributes.armWidth;
|
||||||
|
int armDepth = attributes.armDepth;
|
||||||
|
|
||||||
|
float rarmX = attributes.armRotationX;
|
||||||
|
|
||||||
|
float armX = THIRDP_ARM_CENTRE_X;
|
||||||
|
float armY = THIRDP_ARM_CENTRE_Y;
|
||||||
|
float armZ = BODY_CENTRE_Z / 2 - 1 - armDepth;
|
||||||
|
|
||||||
|
steveLeftLeg .setRotationPoint( rarmX, yOffset, 0);
|
||||||
|
steveRightLeg.setRotationPoint(-rarmX, yOffset, 0);
|
||||||
|
|
||||||
|
steveLeftLeg .addBox(armX, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
|
steveRightLeg.addBox(armX - armWidth, armY, armZ, armWidth, armLength, armDepth, stretch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,14 +142,18 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
tail.setVisible(false);
|
tail.setVisible(false);
|
||||||
upperTorso.field_3664 = true;
|
upperTorso.field_3664 = true;
|
||||||
snout.isHidden = true;
|
snout.isHidden = true;
|
||||||
|
steveLeftLeg.visible = false;
|
||||||
|
steveRightLeg.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showBoots() {
|
public void showBoots() {
|
||||||
rightArm.visible = true;
|
rightArm.visible = true;
|
||||||
leftArm.visible = true;
|
leftArm.visible = true;
|
||||||
rightLeg.visible = true;
|
rightLeg.visible = variant == ArmourVariant.NORMAL;
|
||||||
leftLeg.visible = true;
|
leftLeg.visible = variant == ArmourVariant.NORMAL;
|
||||||
|
steveLeftLeg.visible = variant == ArmourVariant.LEGACY;
|
||||||
|
steveRightLeg.visible = variant == ArmourVariant.LEGACY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,6 +171,11 @@ public class ModelPonyArmour<T extends LivingEntity> extends AbstractPonyModel<T
|
||||||
public void showSaddle() {
|
public void showSaddle() {
|
||||||
chestPiece.visible = true;
|
chestPiece.visible = true;
|
||||||
neck.visible = true;
|
neck.visible = true;
|
||||||
|
|
||||||
|
if (variant == ArmourVariant.LEGACY) {
|
||||||
|
upperTorso.field_3664 = false;
|
||||||
|
upperTorso.visible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class ModelSeapony<T extends LivingEntity> extends ModelUnicorn<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEquestrianArmour<?> createArmour() {
|
public IEquestrianArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(new Armour(), new Armour());
|
return new ArmourWrapper<>(Armour::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class ModelZebra<T extends LivingEntity> extends ModelEarthPony<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEquestrianArmour<?> createArmour() {
|
public IEquestrianArmour<?> createArmour() {
|
||||||
return new ArmourWrapper<>(new Armour(), new Armour());
|
return new ArmourWrapper<>(Armour::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,6 +61,7 @@ public class LayerPonyArmor<T extends LivingEntity, M extends EntityModel<T> & I
|
||||||
IArmourTextureResolver<T> resolver = armour instanceof IArmourTextureResolver ? (IArmourTextureResolver<T>)armour : (IArmourTextureResolver<T>)textures;
|
IArmourTextureResolver<T> resolver = armour instanceof IArmourTextureResolver ? (IArmourTextureResolver<T>)armour : (IArmourTextureResolver<T>)textures;
|
||||||
|
|
||||||
Identifier armourTexture = resolver.getArmourTexture(entity, itemstack, armorSlot, layer, null);
|
Identifier armourTexture = resolver.getArmourTexture(entity, itemstack, armorSlot, layer, null);
|
||||||
|
armour.setVariant(resolver.getArmourVariant(layer, armourTexture));
|
||||||
|
|
||||||
getContext().bindTexture(armourTexture);
|
getContext().bindTexture(armourTexture);
|
||||||
|
|
||||||
|
@ -73,6 +74,8 @@ public class LayerPonyArmor<T extends LivingEntity, M extends EntityModel<T> & I
|
||||||
|
|
||||||
armour.render(entity, move, swing, ticks, headYaw, headPitch, scale);
|
armour.render(entity, move, swing, ticks, headYaw, headPitch, scale);
|
||||||
armourTexture = resolver.getArmourTexture(entity, itemstack, armorSlot, layer, "overlay");
|
armourTexture = resolver.getArmourTexture(entity, itemstack, armorSlot, layer, "overlay");
|
||||||
|
armour.setVariant(resolver.getArmourVariant(layer, armourTexture));
|
||||||
|
|
||||||
getContext().bindTexture(armourTexture);
|
getContext().bindTexture(armourTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.minelittlepony.model.armour;
|
||||||
|
|
||||||
|
public enum ArmourVariant {
|
||||||
|
NORMAL,
|
||||||
|
LEGACY
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ public interface IArmour {
|
||||||
*/
|
*/
|
||||||
void setInVisible();
|
void setInVisible();
|
||||||
|
|
||||||
|
void setVariant(ArmourVariant variant);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares an armour model for rendering, first hiding all the pieces and then incrementally showing them as appropriate.
|
* Prepares an armour model for rendering, first hiding all the pieces and then incrementally showing them as appropriate.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,4 +13,12 @@ public interface IArmourTextureResolver<T extends LivingEntity> {
|
||||||
* Gets the armour texture to be used for the given entity, armour piece, slot, and render layer.
|
* Gets the armour texture to be used for the given entity, armour piece, slot, and render layer.
|
||||||
*/
|
*/
|
||||||
Identifier getArmourTexture(T entity, ItemStack itemstack, EquipmentSlot slot, ArmourLayer layer, @Nullable String type);
|
Identifier getArmourTexture(T entity, ItemStack itemstack, EquipmentSlot slot, ArmourLayer layer, @Nullable String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the armour variant for the identified texture.
|
||||||
|
* Either normal for pony-style textures, or legacy for other textures.
|
||||||
|
*/
|
||||||
|
default ArmourVariant getArmourVariant(ArmourLayer layer, Identifier resolvedTexture) {
|
||||||
|
return ArmourVariant.NORMAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue