Jump to content

Recommended Posts

Posted

The weapons shoots fine but the projectile is invisible. Also, is it possible to scale up the size of an item (weapon) the player is holding, and if so, how?

 

Entity Code:

 

 

package com.darkCaves.projectiles;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

 

public class EntityShot extends EntityThrowable{

public EntityShot(World par1World){

super(par1World);

}

public EntityShot(World par1World, EntityPlayer par3EntityPlayer){

super(par1World, par3EntityPlayer);

setThrowableHeading(this.motionX, this.motionY, this.motionZ, 3.0F, 1.0F);

}

public EntityeShot(World par1World, double par2, double par4, double par6){

super(par1World, par2, par4, par6);

}

 

@Override

protected float getGravityVelocity(){

return 0F;

}

public static float explosionRadius = 2.0F;

@Override

protected void onImpact(MovingObjectPosition movingobjectposition){

this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, (float)this.explosionRadius, false);

this.setDead();

}

 

 

}

 

 

Render Code:

 

 

package com.darkCaves.projectiles;

 

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL12;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.entity.Entity;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.util.ResourceLocation;

 

@SideOnly(Side.CLIENT)

public class RenderShot extends Render {

private static ResourceLocation EntityTexture = new ResourceLocation("darkcaves:textures/projectiles/darkShot.png");

private float scale;

 

 

    public void renderProjectile(EntityThrowable projectile, double x, double y, double z) {

        GL11.glPushMatrix();

        this.bindEntityTexture(projectile);

        GL11.glTranslatef((float)x, (float)y, (float)z);

        GL11.glEnable(GL12.GL_RESCALE_NORMAL);

        GL11.glScalef(scale * 0.5F, scale * 0.5F, scale * 0.5F);

        Tessellator tessellator = Tessellator.instance;

        float minU = 0;

        float maxU = 1;

        float minV = 0;

        float maxV = 1;

        float f7 = 1.0F;

        float f8 = 0.5F;

        float f9 = 0.25F;

        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);

        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);

        tessellator.startDrawingQuads();

        tessellator.setNormal(0.0F, 1.0F, 0.0F);

        tessellator.addVertexWithUV(0.0F - f8, 0.0F - f9, 0.0D, minU, maxV);

        tessellator.addVertexWithUV(f7 - f8, 0.0F - f9, 0.0D, maxU, maxV);

        tessellator.addVertexWithUV(f7 - f8, 1.0F - f9, 0.0D, maxU, minV);

        tessellator.addVertexWithUV(0.0F - f8, 1.0F - f9, 0.0D, minU, minV);

        tessellator.draw();

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);

        GL11.glPopMatrix();

    }

 

    @Override

    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {

        this.renderProjectile((EntityThrowable)par1Entity, par2, par4, par6);

    }

 

@Override

protected ResourceLocation getEntityTexture(Entity entity) {

return EntityTexture;

}

 

 

}

 

 

 

Main Class Code:

 

 

@EventHandler

public void PreInit(FMLPreInitializationEvent event){

EntityRegistry.registerModEntity(EntityShot.class, "Shot", 200, this, 120, 3, true );

      }

 

 

Client Proxy Code:

 

 

~~Preinit statement above~~

public void RenderInformation(){

 

RenderingRegistry.registerEntityRenderingHandler(EntityShot.class, new RenderShot());

}

 

 

Posted

Can I see your entire main class - as of now?

It's very extensive, but everything related to the projectile can be found here:

 

public class darkCaves {
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
	EntityRegistry.registerModEntity(EntityDischargeShot.class, "DischargeShot", 200, this, 120, 3, true );

	proxy.RenderInformation();
}
}

Posted

private float scale; // default value is zero...

// uh oh...
GL11.glScalef(scale * 0.5F, scale * 0.5F, scale * 0.5F);

 

You need to initialize your variable.

Fixed it, thanks a bunch!

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.