Fairies are capable of rendering badly, without crashing.

This commit is contained in:
Ammon Lauritzen 2020-09-06 08:54:48 -05:00
parent e70fae38b3
commit 704b35dc1b
5 changed files with 445 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package org.mcupdater.fairies;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
@ -10,6 +11,8 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mcupdater.fairies.client.renderer.RenderFairy;
import org.mcupdater.fairies.init.Registry;
@Mod(FairyFactions.MOD_ID)
public class FairyFactions {
@ -30,5 +33,6 @@ public class FairyFactions {
public void setupClient(final FMLClientSetupEvent event) {
LOGGER.info("Setup client");
RenderingRegistry.registerEntityRenderingHandler(Registry.FAIRY_ENTITY_TYPE, RenderFairy::new);
}
}

View File

@ -0,0 +1,327 @@
package org.mcupdater.fairies.client.model;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.entity.model.IHasArm;
import net.minecraft.client.renderer.entity.model.IHasHead;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;
import org.mcupdater.fairies.entity.FairyEntity;
import javax.annotation.ParametersAreNonnullByDefault;
public class ModelFairy extends BipedModel<FairyEntity> implements IHasArm, IHasHead {
public ModelRenderer strand, strand2, strand3, strand4;
public ModelRenderer crown;
public ModelRenderer wingLeft;
public ModelRenderer wingRight;
public boolean flymode;
public boolean showCrown;
public boolean scoutWings;
public boolean rogueParts;
public boolean hairType;
public float sinage;
public ModelFairy() {
this(0.0F);
}
public ModelFairy(float modelSize) {
super(modelSize);
// not sure what this was meant to be - but it came in the original, it's some sort of rotational offset
final float f1 = 0.0f;
isSneak = false;
flymode = showCrown = false;
bipedHead = new ModelRenderer(this, 0, 0);
bipedHead.addBox(-3F, -6F, -3F, 6, 6, 6, modelSize);
bipedHead.setRotationPoint(0.0F, 0.0F + f1, 0.0F);
strand = (new ModelRenderer(this)).setTextureSize((byte)64, (byte)32);
strand.setTextureOffset(0, 20).addBox(-3F, -5F, 3F, 6, 3, 1, modelSize);
strand.setTextureOffset(24, 0).addBox(-4F, -5F, -3F, 1, 3, 6, modelSize);
strand.setTextureOffset(24, 0).addBox(3F, -5F, -3F, 1, 3, 6, modelSize);
strand.setRotationPoint(0.0F, 0.0F + f1, 0.0F);
strand2 = (new ModelRenderer(this)).setTextureSize((byte)64, (byte)32);
strand2.setTextureOffset(13, 23).addBox(-5F, -2.5F, 1.5F, 10, 3, 3, modelSize);
strand2.setRotationPoint(0F, 0F + f1, 0F);
strand.addChild(strand2);
strand3 = (new ModelRenderer(this)).setTextureSize((byte)64, (byte)32);
strand3.setTextureOffset(13, 23).addBox(-3F, -1.5F, -1.5F, 3, 3, 3, modelSize - 0.5F);
strand3.setTextureOffset(13, 23).addBox(-5.25F, -1.5F, -1.5F, 3, 3, 3, modelSize - 0.25F);
strand3.setRotationPoint(-2F, -1.75F + f1, 3F);
strand3.rotateAngleZ = -1.0F;
strand3.rotateAngleY = 0.5F;
strand3.showModel = false;
strand.addChild(strand3);
strand4 = (new ModelRenderer(this)).setTextureSize((byte)64, (byte)32);
strand4.mirror = true;
strand4.setTextureOffset(13, 23).addBox(0F, -1.5F, -1.5F, 3, 3, 3, modelSize - 0.5F);
strand4.setTextureOffset(13, 23).addBox(2.25F, -1.5F, -1.5F, 3, 3, 3, modelSize - 0.25F);
strand4.setRotationPoint(2F, -1.75F + f1, 3F);
strand4.rotateAngleZ = 1.0F;
strand4.rotateAngleY = -0.5F;
strand4.showModel = false;
strand.addChild(strand4);
crown = new ModelRenderer(this, 37, 14);
crown.addBox(-3F, -6.75F, -3F, 6, 3, 6, modelSize + 0.25F);
crown.setRotationPoint(0.0F, 0.0F + f1, 0.0F);
bipedBody = (new ModelRenderer(this)).setTextureSize((byte)64, (byte)32);
bipedBody.setTextureOffset(8, 12).addBox(-2F, 0.0F, -1F, 4, 6, 2, modelSize);
bipedBody.setTextureOffset(15, 20).addBox(-2F, 1.0F, -2F, 4, 2, 1, modelSize);
bipedBody.setRotationPoint(0.0F, 0.0F + f1, 0.0F);
wingRight = new ModelRenderer(this, 27, 9);
wingRight.addBox(0F, -0.75F, -1.0F, 5, 4, 1, modelSize + 0.25F);
wingRight.setRotationPoint(0.5F, 0.0F + f1, 1.0F);
wingLeft = new ModelRenderer(this, 27, 9);
wingLeft.mirror = true;
wingLeft.addBox(-5F, -0.75F, -1.0F, 5, 4, 1, modelSize + 0.25F);
wingLeft.setRotationPoint(-0.5F, 0.0F + f1, 1.0F);
bipedRightArm = new ModelRenderer(this, 0, 12);
bipedRightArm.addBox(-1F, -1F, -1F, 2, 6, 2, modelSize);
bipedRightArm.setRotationPoint(-5F, 1.0F + f1, 0.0F);
bipedLeftArm = new ModelRenderer(this, 0, 12);
bipedLeftArm.mirror = true;
bipedLeftArm.addBox(-1F, -1F, -1F, 2, 6, 2, modelSize);
bipedLeftArm.setRotationPoint(5F, 1.0F + f1, 0.0F);
bipedRightLeg = new ModelRenderer(this, 20, 12);
bipedRightLeg.addBox(-1F, 0.0F, -1F, 2, 6, 2, modelSize);
bipedRightLeg.setRotationPoint(-1F, 18F + f1, 0.0F);
bipedLeftLeg = new ModelRenderer(this, 20, 12);
bipedLeftLeg.mirror = true;
bipedLeftLeg.addBox(-1F, 0.0F, -1F, 2, 6, 2, modelSize);
bipedLeftLeg.setRotationPoint(1.0F, 18F + f1, 0.0F);
}
@Override
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
super.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
if (!rogueParts)
{
strand2.showModel = !hairType;
strand3.showModel = hairType;
strand4.showModel = hairType;
strand.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
}
if (showCrown && !rogueParts)
{
crown.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
}
if (!scoutWings && !rogueParts)
{
wingLeft.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
wingRight.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
}
}
@Override
public void setRotationAngles(FairyEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
// super.setRotationAngles(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
strand.rotateAngleY = bipedHead.rotateAngleY;
strand.rotateAngleX = bipedHead.rotateAngleX;
crown.rotateAngleY = bipedHead.rotateAngleY;
crown.rotateAngleX = bipedHead.rotateAngleX;
if (!flymode)
{
bipedRightArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 2.0F * limbSwingAmount * 0.5F;
bipedLeftArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 2.0F * limbSwingAmount * 0.5F;
bipedRightLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
bipedLeftLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
}
else
{
bipedRightArm.rotateAngleX = 0.0F;
bipedLeftArm.rotateAngleX = 0.0F;
bipedRightLeg.rotateAngleX = 0.0F;
bipedLeftLeg.rotateAngleX = 0.0F;
}
bipedRightArm.rotateAngleZ = 0.05F;
bipedLeftArm.rotateAngleZ = -0.05F;
bipedRightLeg.rotateAngleY = 0.0F;
bipedLeftLeg.rotateAngleY = 0.0F;
bipedRightLeg.rotateAngleZ = 0.0F;
bipedLeftLeg.rotateAngleZ = 0.0F;
if ((isSitting || isSneak) && !flymode)
{
bipedRightArm.rotateAngleX += -((float)Math.PI / 5F);
bipedLeftArm.rotateAngleX += -((float)Math.PI / 5F);
bipedRightLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
bipedLeftLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
bipedRightLeg.rotateAngleY = ((float)Math.PI / 10F);
bipedLeftLeg.rotateAngleY = -((float)Math.PI / 10F);
if (isSneak)
{
bipedRightLeg.rotateAngleX = -((float)Math.PI / 2F);
bipedLeftLeg.rotateAngleX = -((float)Math.PI / 2F);
}
}
/*
* The original version kept held items as ID's, but I don't know that they ever got set?!
* They probably did - but we'll worry about this later.
*
if (heldItemLeft != 0)
{
bipedLeftArm.rotateAngleX = bipedLeftArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F);
}
if (heldItemRight != 0)
{
bipedRightArm.rotateAngleX = bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F);
}
*/
bipedRightArm.rotateAngleY = 0.0F;
bipedLeftArm.rotateAngleY = 0.0F;
// TODO: Figure out what `onGround` actually meant
/*
if (onGround > -9990F)
{
float f6 = onGround;
bipedBody.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(f6) * (float)Math.PI * 2.0F) * 0.2F;
wingLeft.rotateAngleY = wingRight.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(f6) * (float)Math.PI * 2.0F) * 0.2F;
bipedRightArm.rotationPointZ = MathHelper.sin(bipedBody.rotateAngleY) * 5F;
bipedRightArm.rotationPointX = -MathHelper.cos(bipedBody.rotateAngleY) * 5F + 2.0F;
bipedLeftArm.rotationPointZ = -MathHelper.sin(bipedBody.rotateAngleY) * 5F;
bipedLeftArm.rotationPointX = MathHelper.cos(bipedBody.rotateAngleY) * 5F - 2.0F;
bipedRightArm.rotateAngleY += bipedBody.rotateAngleY;
bipedLeftArm.rotateAngleY += bipedBody.rotateAngleY;
bipedLeftArm.rotateAngleX += bipedBody.rotateAngleY;
f6 = 1.0F - onGround;
f6 *= f6;
f6 *= f6;
f6 = 1.0F - f6;
final float f8 = MathHelper.sin(f6 * (float)Math.PI);
final float f9 = MathHelper.sin(onGround * (float)Math.PI) * -(bipedHead.rotateAngleX - 0.7F) * 0.75F;
bipedRightArm.rotateAngleX -= f8 * 1.2D + f9;
bipedRightArm.rotateAngleY += bipedBody.rotateAngleY * 2.0F;
bipedRightArm.rotateAngleZ = MathHelper.sin(onGround * (float)Math.PI) * -0.4F;
}
*/
if (flymode)
{
final float f7 = (float)Math.PI;
bipedBody.rotateAngleX = f7 / 2.0F;
bipedBody.rotationPointY = 19F;
wingLeft.rotateAngleX = f7 / 2.0F;
wingRight.rotateAngleX = f7 / 2.0F;
wingLeft.rotationPointY = 17.5F;
wingRight.rotationPointY = 17.5F;
wingLeft.rotationPointZ = 1.0F;
wingRight.rotationPointZ = 1.0F;
bipedRightLeg.rotationPointZ = 0.0F;
bipedLeftLeg.rotationPointZ = 0.0F;
bipedRightArm.rotationPointY = 19F;
bipedLeftArm.rotationPointY = 19F;
bipedRightLeg.rotationPointY = 18F;
bipedLeftLeg.rotationPointY = 18F;
bipedRightLeg.rotationPointZ = 6F;
bipedLeftLeg.rotationPointZ = 6F;
bipedHead.rotationPointZ = -3F;
bipedHead.rotationPointY = 19.75F;
strand.rotationPointZ = -3F;
strand.rotationPointY = 19.75F;
crown.rotationPointZ = -3F;
crown.rotationPointY = 19.75F;
}
else
{
bipedBody.rotateAngleX = 0.0F;
bipedBody.rotationPointY = 12F;
wingLeft.rotateAngleX = 0.0F;
wingRight.rotateAngleX = 0.0F;
wingLeft.rotationPointY = 12.5F;
wingRight.rotationPointY = 12.5F;
wingLeft.rotationPointZ = 1.0F;
wingRight.rotationPointZ = 1.0F;
bipedRightLeg.rotationPointZ = 0.0F;
bipedLeftLeg.rotationPointZ = 0.0F;
if (isSitting)
{
bipedRightArm.rotationPointY = 13F;
bipedLeftArm.rotationPointY = 13F;
}
else
{
bipedRightArm.rotationPointY = 13F;
bipedLeftArm.rotationPointY = 13F;
}
bipedRightLeg.rotationPointY = 18F;
bipedLeftLeg.rotationPointY = 18F;
bipedRightLeg.rotationPointZ = 0.0F;
bipedLeftLeg.rotationPointZ = 0.0F;
bipedHead.rotationPointZ = 0.0F;
bipedHead.rotationPointY = 12F;
strand.rotationPointZ = 0.0F;
strand.rotationPointY = 12F;
crown.rotationPointZ = 0.0F;
crown.rotationPointY = 12F;
}
if (flymode)
{
bipedRightArm.rotateAngleZ += MathHelper.cos(ageInTicks * 0.09F) * 0.1F + 0.05F;
bipedLeftArm.rotateAngleZ -= MathHelper.cos(ageInTicks * 0.09F) * 0.1F + 0.05F;
bipedRightArm.rotateAngleX += MathHelper.sin(ageInTicks * 0.067F) * 0.1F;
bipedLeftArm.rotateAngleX -= MathHelper.sin(ageInTicks * 0.067F) * 0.1F;
bipedRightLeg.rotateAngleZ += MathHelper.cos(ageInTicks * 0.09F) * 0.1F + 0.05F;
bipedLeftLeg.rotateAngleZ -= MathHelper.cos(ageInTicks * 0.09F) * 0.1F + 0.05F;
bipedRightLeg.rotateAngleX = 0.1F;
bipedLeftLeg.rotateAngleX = 0.1F;
}
else
{
bipedRightArm.rotateAngleZ += MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
bipedLeftArm.rotateAngleZ -= MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
bipedRightArm.rotateAngleX += MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
bipedLeftArm.rotateAngleX -= MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
}
if (flymode)
{
wingLeft.rotateAngleY = 0.1F;
wingRight.rotateAngleY = -0.1F;
wingLeft.rotateAngleY += Math.sin(sinage) / 6F;
wingRight.rotateAngleY -= Math.sin(sinage) / 6F;
wingLeft.rotateAngleZ = 0.5F;
wingRight.rotateAngleZ = -0.5F;
}
else
{
wingLeft.rotateAngleY = 0.6F;
wingRight.rotateAngleY = -0.6F;
wingLeft.rotateAngleY += Math.sin(sinage) / 3F;
wingRight.rotateAngleY -= Math.sin(sinage) / 3F;
wingLeft.rotateAngleZ = 0.125F;
wingRight.rotateAngleZ = -0.125F;
}
wingLeft.rotateAngleZ += Math.cos(sinage) / (flymode ? 3F : 8F);
wingRight.rotateAngleZ -= Math.cos(sinage) / (flymode ? 3F : 8F);
}
}

View File

@ -0,0 +1,67 @@
package org.mcupdater.fairies.client.renderer;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.HeldItemLayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.mcupdater.fairies.FairyFactions;
import org.mcupdater.fairies.client.model.ModelFairy;
import org.mcupdater.fairies.entity.FairyEntity;
public class RenderFairy extends MobRenderer<FairyEntity, ModelFairy> {
protected ModelFairy fairyModel, fairyModel4; //Body and withered overlay
//protected ModelFairyProps fairyModel2; //Clothes and stuff
//protected ModelFairyEyes fairyModel3; //Eyes
//protected ModelFairyProps2 fairyModel5; //Rogue Clothes
public RenderFairy(EntityRendererManager renderManagerIn, ModelFairy entityModelIn, float shadowSizeIn) {
super(renderManagerIn, entityModelIn, shadowSizeIn);
this.addLayer(new HeldItemLayer<>(this));
}
public RenderFairy(EntityRendererManager renderManagerIn) {
this(renderManagerIn, new ModelFairy(), 0.5f);
}
@Override
public ResourceLocation getEntityTexture(FairyEntity entity) {
final String texturePath;
/*
if (entity.getCustomName().equals("Steve")) {
texturePath = "textures/entities/notFairy.png";
} else {
*/
texturePath = "textures/entities/fairy"
+ ( entity.isQueen() ? "q" : "" )
+ ( entity.skinVariant()+1 )
+ ".png";
// }
return new ResourceLocation(FairyFactions.MOD_ID, texturePath);
}
@Override
protected void preRenderCallback(FairyEntity fairy, MatrixStack matrixStackIn, float partialTickTime) {
super.preRenderCallback(fairy, matrixStackIn, partialTickTime);
float f1 = 0.875F;
if (fairyModel != null) {
//fairyModel.sinage = fairy.sinage;
//fairyModel.flymode = fairy.flymode();
//fairyModel.showCrown = fairy.tamed() || fairy.queen();
fairyModel.showCrown = fairy.isQueen();
fairyModel.isSneak = fairy.isSneaking();
//fairyModel.scoutWings = fairy.scout();
//fairyModel.rogueParts = fairy.rogue();
//fairyModel.hairType = fairy.hairType();
}
GL11.glScalef(f1, f1, f1);
if (fairy.isSneaking()) {
GL11.glTranslatef(0F, (5F / 16F), 0F);
}
}
}

View File

@ -2,15 +2,60 @@ package org.mcupdater.fairies.entity;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import org.mcupdater.fairies.FairyConfig;
public class FairyEntity extends AnimalEntity {
public static final String NAME = "fairy";
private final int skinVariant;
private boolean isQueen;
public FairyEntity(EntityType<? extends FairyEntity> fairy, World world) {
super(fairy, world);
skinVariant = rand.nextInt(4);
isQueen = false;
}
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new WaterAvoidingRandomWalkingGoal(this, this.getAIMoveSpeed()));
}
@Override
public void baseTick() {
super.baseTick();
if (!world.isRemote) {
// server-side data updates here
} else {
// client-side visual/etc updates here
}
}
public int skinVariant() { return skinVariant; }
public boolean isQueen() { return isQueen; }
public static AttributeModifierMap.MutableAttribute getAttributes() {
double max_health = 15.0D;
double movement_speed = 1.0D;
// NOTE: this may not work since the attributes are only got at initial load time?
if (FairyConfig.SPEC.isLoaded()) {
max_health = FairyConfig.GENERAL.healthBase.get();
movement_speed = FairyConfig.GENERAL.speedBase.get();
}
return MobEntity.func_233666_p_()
.func_233815_a_(Attributes.field_233818_a_, max_health)
.func_233815_a_(Attributes.field_233821_d_, movement_speed);
}
@Override

View File

@ -2,6 +2,7 @@ package org.mcupdater.fairies.init;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@ -19,6 +20,7 @@ public class Registry {
.setTrackingRange(64).setUpdateInterval(1).size(0.6F, 0.85F)
.build(FairyEntity.NAME);
FAIRY_ENTITY_TYPE.setRegistryName(FairyFactions.MOD_ID, FairyEntity.NAME);
GlobalEntityTypeAttributes.put(FAIRY_ENTITY_TYPE, FairyEntity.getAttributes().func_233813_a_());
event.getRegistry().register(FAIRY_ENTITY_TYPE);
}
}