Jump to content

Recommended Posts

Posted

As in the title... I want to make my own elytra. I found some code online for simulating the elytra but I don't know where to put it so it will work.

Here is the code I found for simulating the elytra:

/**
* An accurate simulation of the elytra item as of Minecraft 15w41b
*/
public class ElytraModel
{	
public int glideTime;
public int damageTaken;

public double posX;
public double posY;
public double posZ;

public double velX;
public double velY;
public double velZ;

/**
* Simulates a Minecraft tick (20 per second).
* The pitch and yaw are the look direction of the player.
*/
public void tick(boolean isCreative, double yaw, double pitch)
{
	if (!isCreative && (this.glideTime + 1) % 20 == 0)
	{
		this.damageTaken++;
	}

	//I did some simplifing of the folowing to reduce the number of negatives and trig functions
	double yawcos = Math.cos(-yaw - Math.PI);
	double yawsin = Math.sin(-yaw - Math.PI);
	double pitchcos = Math.cos(pitch);
	double pitchsin = Math.sin(pitch);

	double lookX = yawsin * -pitchcos;
	double lookY = -pitchsin;
	double lookZ = yawcos * -pitchcos;

	double hvel = Math.sqrt(velX * velX + velZ * velZ);
	double hlook = pitchcos; //Math.sqrt(lookX * lookX + lookZ * lookZ)
	double sqrpitchcos = pitchcos * pitchcos; //In MC this is multiplied by Math.min(1.0, Math.sqrt(lookX * lookX + lookY * lookY + lookZ * lookZ) / 0.4), don't ask me why, it should always =1

	//From here on, the code is identical to the code found in net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(float, float) or rq.g(float, float) in obfuscated 15w41b
	this.velY += -0.08 + sqrpitchcos * 0.06;

	if (this.velY < 0 && hlook > 0)
	{
		double yacc = this.velY * -0.1 * sqrpitchcos;
		this.velY += yacc;
		this.velX += lookX * yacc / hlook;
		this.velZ += lookZ * yacc / hlook;
	}
	if (pitch < 0)
	{
		double yacc = hvel * -pitchsin * 0.04;
		this.velY += yacc * 3.5;
		this.velX -= lookX * yacc / hlook;
		this.velZ -= lookZ * yacc / hlook;
	}
	if (hlook > 0)
	{
		this.velX += (lookX / hlook * hvel - this.velX) * 0.1;
		this.velZ += (lookZ / hlook * hvel - this.velZ) * 0.1;
	}

	this.velX *= 0.99;
	this.velY *= 0.98;
	this.velZ *= 0.99;

	this.posX += this.velX;
	this.posY += this.velY;
	this.posZ += this.velZ;

	this.glideTime++;
}

/** 
* Checks if the player is currently in a gliding state.
* As you can see, if the player is in creative, they will remain gliding even if on the ground. They will stop gliding once they move (but that functionality is not shown here).
*/
public boolean isGliding(boolean isCreative, boolean isOnGround, float fallDistance)
{
	if (isCreative)
	{	
		return glideTime > 0;
	}
	else
	{
		return !isOnGround && fallDistance >= 1.0f;
	}
}
}

 

And then I have a model for it(Not my model... Just a model found in forge 1.9):

 

package com.cubic_control.Models;

import com.sun.javafx.geom.Vec3d;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;

@SideOnly(Side.CLIENT)
public class ModelElytra extends ModelBiped
{
    private ModelRenderer field_187060_a;
    private ModelRenderer field_187061_b = new ModelRenderer(this, 22, 0);

    public ModelElytra()
    {
        this.field_187061_b.addBox(-10.0F, 0.0F, 0.0F, 10, 20, 2, 1.0F);
        this.field_187060_a = new ModelRenderer(this, 22, 0);
        this.field_187060_a.mirror = true;
        this.field_187060_a.addBox(0.0F, 0.0F, 0.0F, 10, 20, 2, 1.0F);
    }

    /**
     * Sets the models various rotation angles then renders the model.
     */
    public void render(Entity entityIn, float p_78088_2_, float limbSwing, float ageInTicks, float netHeadYaw, float headPitch, float scale)
    {
        this.field_187061_b.render(scale);
        this.field_187060_a.render(scale);
    }

    /**
     * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
     * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
     * "far" arms and legs can swing at most.
     */
    public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn)
    {
        super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);
        float f = 0.2617994F;
        float f1 = -0.2617994F;
        float f2 = 0.0F;
        float f3 = 0.0F;


        if (entityIn.isSneaking())
        {
            f = ((float)Math.PI * 2F / 9F);
            f1 = -((float)Math.PI / 4F);
            f2 = 3.0F;
            f3 = 0.08726646F;
        }

        this.field_187061_b.rotationPointX = 5.0F;
        this.field_187061_b.rotationPointY = f2;

        if (entityIn instanceof AbstractClientPlayer)
        {
            AbstractClientPlayer abstractclientplayer = (AbstractClientPlayer)entityIn;
        }
        else
        {
            this.field_187061_b.rotateAngleX = f;
            this.field_187061_b.rotateAngleZ = f1;
            this.field_187061_b.rotateAngleY = f3;
        }

        this.field_187060_a.rotationPointX = -this.field_187061_b.rotationPointX;
        this.field_187060_a.rotateAngleY = -this.field_187061_b.rotateAngleY;
        this.field_187060_a.rotationPointY = this.field_187061_b.rotationPointY;
        this.field_187060_a.rotateAngleX = this.field_187061_b.rotateAngleX;
        this.field_187060_a.rotateAngleZ = -this.field_187061_b.rotateAngleZ;
    }

    /**
     * Used for easily adding entity-dependent animations. The second and third float params here are the same second
     * and third as in the setRotationAngles method.
     */
    public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float p_78086_2_, float p_78086_3_, float partialTickTime)
    {
        super.setLivingAnimations(entitylivingbaseIn, p_78086_2_, p_78086_3_, partialTickTime);
    }
}

 

Here is my Item class for the elytra:

 

public class Ender_rite_elytra extends ItemArmor {

@SideOnly(Side.CLIENT)
private IIcon broken;

public Ender_rite_elytra() {
	super(EnumHelper.addArmorMaterial("elytra", 27, new int[] { 0, 9, 0, 0 }, 0), 0, 1);
	setMaxDamage(432);
	setMaxStackSize(1);
	setTextureName(RefStrings.MODID + ":Ender-rite_elytra");
	setUnlocalizedName("Ender_rite_elytra");
	setCreativeTab(MCreativeTabs.tabItems);
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack material) {
	return ArmorMaterial.CLOTH.func_151685_b() == material.getItem();
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
	return RefStrings.MODID + ":textures/mobs/elytra/Ender-rite_elytra.png";
}

@Override
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, int armorSlot) {
	return new ModelElytra();
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int meta) {
	return meta >= getMaxDamage() ? broken : super.getIconFromDamage(meta);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister reg) {
	super.registerIcons(reg);
	broken = reg.registerIcon(RefStrings.MODID + ":Ender-rite_elytra_broken");
}
}

 

I would just like to know how I could use this to make a working elytra... any help?

 

EDIT: Changed the ModelElytra to the one found in forge 1.9, still doesn't work.

Posted

You need a way to make the player fly.  Probably by doing something every tick while the armor is worn.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Perhaps the code in tick() in ElytraModel

I put the code in but still nothing...

heres the code just in case:

public void onArmorTick(boolean isCreative, double yaw, double pitch)
    {
	if (!isCreative && (ElytraModel.glideTime + 1) % 20 == 0)
	{
		ElytraModel.damageTaken++;
	}

	//I did some simplifing of the folowing to reduce the number of negatives and trig functions
	double yawcos = Math.cos(-yaw - Math.PI);
	double yawsin = Math.sin(-yaw - Math.PI);
	double pitchcos = Math.cos(pitch);
	double pitchsin = Math.sin(pitch);

	double lookX = yawsin * -pitchcos;
	double lookY = -pitchsin;
	double lookZ = yawcos * -pitchcos;

	double hvel = Math.sqrt(ElytraModel.velX * ElytraModel.velX + ElytraModel.velZ * ElytraModel.velZ);
	double hlook = pitchcos; //Math.sqrt(lookX * lookX + lookZ * lookZ)
	double sqrpitchcos = pitchcos * pitchcos; //In MC this is multiplied by Math.min(1.0, Math.sqrt(lookX * lookX + lookY * lookY + lookZ * lookZ) / 0.4), don't ask me why, it should always =1

	//From here on, the code is identical to the code found in net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(float, float) or rq.g(float, float) in obfuscated 15w41b
	ElytraModel.velY += -0.08 + sqrpitchcos * 0.06;

	if (ElytraModel.velY < 0 && hlook > 0)
	{
		double yacc = ElytraModel.velY * -0.1 * sqrpitchcos;
		ElytraModel.velY += yacc;
		ElytraModel.velX += lookX * yacc / hlook;
		ElytraModel.velZ += lookZ * yacc / hlook;
	}
	if (pitch < 0)
	{
		double yacc = hvel * -pitchsin * 0.04;
		ElytraModel.velY += yacc * 3.5;
		ElytraModel.velX -= lookX * yacc / hlook;
		ElytraModel.velZ -= lookZ * yacc / hlook;
	}
	if (hlook > 0)
	{
		ElytraModel.velX += (lookX / hlook * hvel - ElytraModel.velX) * 0.1;
		ElytraModel.velZ += (lookZ / hlook * hvel - ElytraModel.velZ) * 0.1;
	}

	ElytraModel.velX *= 0.99;
	ElytraModel.velY *= 0.98;
	ElytraModel.velZ *= 0.99;

	ElytraModel.posX += ElytraModel.velX;
	ElytraModel.posY += ElytraModel.velY;
	ElytraModel.posZ += ElytraModel.velZ;

	ElytraModel.glideTime++;
    }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.