Jump to content

Recommended Posts

Posted

Hey everyone,

 

I've checked everywhere, but I can't find a single thing that could be causing my issue. I'm trying to implement a basic 'fireball' using snowball as a basis but I'm not having any luck.

 

The specific problem is that while the projectile fires and impacts, it doesn't render at all.

 

I have added break points into the RenderKBFireball class but they do not fire.

 

My four classes are:

KBFireball - contains the item, it's onItemRightClick event, it's presence in creative mode, icon etc.

KBEntityFireBall - inheriting from EntityThrowable controls the onImpact

RenderKBFireball - the render class, pretty much a direct copy of RenderSnowball

KBClasses - the main mod file containing the definition and the registry etc.

 

A few things worth noting:

In KBFireball, I'm alternating between firing an actual snowball and my Fireball itself. The fact that the snowball shows is telling me this class is fine.

 

I suspect if anything, it has something to do with my registering of items, but I've tried a lot of variations and had no luck.

 

All of this compiles and runs as well, so no code errors.

 

Thanks in advance

Primalfreeze

 

KBFireball

 

 

public class KBFireball extends Item {

 

private int i = 0;

 

public KBFireball()

{

super();

setCreativeTab(CreativeTabs.tabCombat);

setUnlocalizedName(Reference.MODID + "_" + "kbfireball");

setTextureName(Reference.MODID + ":" + "kbfireball");

}

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

{

if (!par3EntityPlayer.capabilities.isCreativeMode)

{

// Consume Ammo (this will need to be use mana)

--par1ItemStack.stackSize;

}

// Play the shoot sound

par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5f, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

if (!par2World.isRemote) {

if ((i % 2) > 0) {

par2World.spawnEntityInWorld(new EntitySnowball(par2World, par3EntityPlayer));

i++;

} else {

par2World.spawnEntityInWorld(new KBEntityFireball(par2World, par3EntityPlayer));

i++;

}

}

 

 

return par1ItemStack;

}

 

}

 

 

 

KBEntityFireball

 

 

public class KBEntityFireball extends EntityThrowable

{

private float explosionRadius = 0.5f;

 

public KBEntityFireball(World par1World) {

super(par1World);

}

 

public KBEntityFireball(World par1World, EntityLivingBase par2EntityLivingBase)

{

super(par1World, par2EntityLivingBase);

}

public KBEntityFireball(World par1World, double par2, double par3, double par4)

{

super(par1World, par2, par3, par4);

}

 

protected void onImpact(MovingObjectPosition par1MovingObjectPosition)

{

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

if (!this.worldObj.isRemote)

{

this.setDead();

}

}

}

 

 

 

RenderKBFireball

 

 

public class RenderKBFireball extends Render

{

//private static ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/items/kbfireball.png");

private Item localItem;

private int dmgVal;

 

public RenderKBFireball(Item par1Item) {

this(par1Item, 0);

}

 

public RenderKBFireball(Item par1Item, int par2Int) {

localItem = par1Item;

dmgVal = par2Int;

}

 

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

{

  IIcon iicon = localItem.getIconFromDamage(dmgVal);

  if (iicon != null)

  {  

  GL11.glPushMatrix();

  GL11.glTranslatef((float)par2, (float)par4, (float)par6);

  GL11.glEnable(GL12.GL_RESCALE_NORMAL);

  this.bindEntityTexture(par1Entity);

  Tessellator tessellator = Tessellator.instance;

         

  float f = iicon.getMinU();

  float f1 = iicon.getMaxU();

  float f2 = iicon.getMinV();

  float f3 = iicon.getMaxV();

  float f4 = 1.0F;

  float f5 = 0.5F;

  float f6 = 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((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);

  tessellator.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);

  tessellator.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);

  tessellator.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);

  tessellator.draw();

  GL11.glDisable(GL12.GL_RESCALE_NORMAL);  

  GL11.glPopMatrix();

  }

}

 

@Override

protected ResourceLocation getEntityTexture(Entity par1Entity)

{

return TextureMap.locationItemsTexture;

}

}

 

 

 

KBClasses

 

 

@Mod(modid = Reference.MODID, version = Reference.VERSION)

public class KBClasses {

 

public static Item fireball;

 

    @EventHandler

    public void preinit(FMLInitializationEvent event)

    {   

    fireball =new KBFireball();

    GameRegistry.registerItem(fireball, "kbfireball");

    RenderKBFireball r = new RenderKBFireball(fireball);

   

    RenderingRegistry.registerEntityRenderingHandler(KBEntityFireball.class, r);

   

    }

   

   

 

}

 

 

Posted

@Eternaldoom - that was enough for me to figure it all out. I somehow glossed over the registering of an entity in all the examples I found. I suspect because I was looking for other problems, not chunks that were missing.

 

So thanks heaps.

 

For recordkeeping purposes, here is the added code (added in KBClasses.preInit)

 

 

    EntityRegistry.registerGlobalEntityID(KBEntityFireball.class, "KBFireball", uid);

    EntityRegistry.registerModEntity(KBEntityFireball.class, "KBFireball", uid, this, 80, 10, true);

 

 

 

This topic is now solved but I can't see anything letting me mark it as such.

 

Primalfreeze

 

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.