BetterEnd/src/main/java/ru/betterend/item/model/CrystaliteChestplateModel.java
2021-06-24 17:11:48 +02:00

119 lines
4.4 KiB
Java

package ru.betterend.item.model;
import java.util.Collections;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import ru.betterend.registry.EndEntitiesRenders;
public class CrystaliteChestplateModel extends HumanoidModel<LivingEntity> {
public ModelPart leftShoulder;
public ModelPart rightShoulder;
private final boolean thinArms;
public static LayerDefinition getRegularTexturedModelData(){
return getTexturedModelData(1.0f, false);
}
public static LayerDefinition getThinTexturedModelData(){
return getTexturedModelData(1.0f, true);
}
private static LayerDefinition getTexturedModelData(float scale, boolean thinArms) {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
CubeDeformation deformation = new CubeDeformation(scale + 0.25F);
PartDefinition body = modelPartData.addOrReplaceChild(PartNames.BODY, CubeListBuilder.create()
.addBox(-4.0f, 0.0f, -2.0f, 8.0f, 12.0f, 4.0f, deformation)
.texOffs(16, 16),
PartPose.ZERO);
if (thinArms) {
deformation = new CubeDeformation(scale + 0.45F);
PartDefinition leftShoulder = modelPartData.addOrReplaceChild("leftShoulder", CubeListBuilder.create()
.mirror()
.addBox(-1.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation)
.texOffs(40, 32),
PartPose.offset(5.0f, 2.0f, 0.0f));
PartDefinition rightShoulder = modelPartData.addOrReplaceChild("rightShoulder", CubeListBuilder.create()
.addBox(-3.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation)
.texOffs(40, 16),
PartPose.offset(-5.0f, 2.0f, 10.0f));
} else {
deformation = new CubeDeformation(scale + 0.45F);
PartDefinition leftShoulder = modelPartData.addOrReplaceChild("leftShoulder", CubeListBuilder.create()
.mirror()
.addBox(-1.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation)
.texOffs(40, 32),
PartPose.offset(5.0f, 2.0f, 0.0f));
PartDefinition rightShoulder = modelPartData.addOrReplaceChild("rightShoulder", CubeListBuilder.create()
.addBox(-3.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation)
.texOffs(40, 16),
PartPose.offset(-5.0f, 2.0f, 10.0f));
}
return LayerDefinition.create(modelData, 64, 48);
}
final ModelPart localBody;
public static CrystaliteChestplateModel regularModel(EntityModelSet entityModelSet){
if (entityModelSet==null) throw new RuntimeException("Need to get a ModelSet");
return new CrystaliteChestplateModel(entityModelSet.bakeLayer(EndEntitiesRenders.CRYSTALITE_CHESTPLATE), false);
}
public static CrystaliteChestplateModel thinModel(EntityModelSet entityModelSet){
if (entityModelSet==null) throw new RuntimeException("Need to get a ModelSet");
return new CrystaliteChestplateModel(entityModelSet.bakeLayer(EndEntitiesRenders.CRYSTALITE_CHESTPLATE_THIN), true);
}
protected CrystaliteChestplateModel(ModelPart modelPart, boolean thinArms) {
super(modelPart, RenderType::entityTranslucent);
this.thinArms = thinArms;
localBody = modelPart.getChild(PartNames.BODY);
leftShoulder = modelPart.getChild("leftShoulder");
rightShoulder = modelPart.getChild("rightShoulder");
}
@Override
public void copyPropertiesTo(HumanoidModel<LivingEntity> bipedEntityModel) {
super.copyPropertiesTo(bipedEntityModel);
this.leftShoulder.copyFrom(leftArm);
this.rightShoulder.copyFrom(rightArm);
}
@Override
protected Iterable<ModelPart> headParts() {
return Collections::emptyIterator;
}
@Override
protected Iterable<ModelPart> bodyParts() {
return Lists.newArrayList(localBody, leftShoulder, rightShoulder);
}
@Override
public void translateToHand(HumanoidArm arm, PoseStack matrices) {
ModelPart modelPart = this.getArm(arm);
if (this.thinArms) {
float f = 0.5F * (float)(arm == HumanoidArm.RIGHT ? 1 : -1);
modelPart.x += f;
modelPart.translateAndRotate(matrices);
modelPart.x -= f;
} else {
modelPart.translateAndRotate(matrices);
}
}
}