Jump to content

Recommended Posts

Posted

How would I go with making a texture for an EntityThrowable? I want to add a dagger that can be thrown, I have done that but it doesn't have a texture. I bet there's a Forge hook for this, could anybody show me an example?

Posted

I'd suggest you make your own render file similar to RenderArrow.

If you don't mind how silly your dagger entity would look with the standard throwable renderer, just use RenderSnowball.

Posted

I'd suggest you make your own render file similar to RenderArrow.

If you don't mind how silly your dagger entity would look with the standard throwable renderer, just use RenderSnowball.

Yea well the thing is I don't know how to change the texture file, do you? :)

Posted

Use RenderFireball code, I think it's simpler.

 

        Icon icon = Item.fireballCharge.getIconFromDamage(0);
        this.loadTexture("/gui/items.png");
        Tessellator tessellator = Tessellator.instance;
        float f3 = icon.getMinU();
        float f4 = icon.getMaxU();
        float f5 = icon.getMinV();
        float f6 = icon.getMaxV();

 

Replace the icon with what You need. Or You could use Techne, there are some tutorials I may recommend.

 

How to create models using Techne.

http://pixelmon.wikinet.org/wiki/Techne_Tutorial

 

How to texture models using Techne.

http://dragonith.deviantart.com/art/Techne-Tutorial-Texturing-I-264650065

 

http://dragonith.deviantart.com/art/Techne-Tutorial-Texturing-II-264719834

 

You would also require another tutorial, on how to use Techne generated code to render entities. I've been using it to render items so far.

Posted

Use RenderFireball code, I think it's simpler.

I used the fireball code, but it still doesn't render. Here's my code:

RenderSilverDagger:

 

 

package me.raggarcowboy.silverdagger;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.util.Icon;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderSilverDagger extends Render
{
private float field_77002_a;

public RenderSilverDagger(float par1)
{
	field_77002_a = par1;
}

public void doRenderFireball(EntityFireball par1EntityFireball, double par2, double par4, double par6, float par8, float par9)
{
	GL11.glPushMatrix();
	GL11.glTranslatef((float)par2, (float)par4, (float)par6);
	GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	float f2 = this.field_77002_a;
	GL11.glScalef(f2 / 1.0F, f2 / 1.0F, f2 / 1.0F);
	Icon icon = SilverDagger.swordSilver.getIconFromDamage(0);
	loadTexture("/textures/items/Silver_Dagger.png");
	Tessellator tessellator = Tessellator.instance;
	float f3 = icon.getMinU();
	float f4 = icon.getMaxU();
	float f5 = icon.getMinV();
	float f6 = icon.getMaxV();
	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((double)(0.0F - f8), (double)(0.0F - f9), 0.0D, (double)f3, (double)f6);
	tessellator.addVertexWithUV((double)(f7 - f8), (double)(0.0F - f9), 0.0D, (double)f4, (double)f6);
	tessellator.addVertexWithUV((double)(f7 - f8), (double)(1.0F - f9), 0.0D, (double)f4, (double)f5);
	tessellator.addVertexWithUV((double)(0.0F - f8), (double)(1.0F - f9), 0.0D, (double)f3, (double)f5);
	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)
{
	doRenderFireball((EntityFireball)par1Entity, par2, par4, par6, par8, par9);
}
}

 

 

ClientProxy:

 

 

package me.raggarcowboy.silverdagger;

import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers()
{
	MinecraftForgeClient.preloadTexture("/textures/items/Silver_Dagger.png");

	RenderingRegistry.registerEntityRenderingHandler(EntitySilverDagger.class, new RenderSilverDagger(1F));
}
}

 

 

Questions:

  • What does the float parameter in the RenderSilverDagger constructor do?
  • Do I need to register anything more?
  • Is there anything more you'd recommend?

Posted

Well, if it rendered, It would crash, as You cannot cast EntityDagger into EntityFireball in doRenderFireball. Change types used in method.

 

Second: in EntitySilverDagger class, you have to define a constructor, which takes only world as parameter. Even if You don't use it anywhere, rendering functions still need it.

 

Thirdly, you'll need also to register EntityID in EntityRegistry

 

//RegisterRenders is a fine place for this line
EntityRegistry.registerGlobalEntityID(EntitySilverDagger.class, "SilverDagger", ModLoader.getUniqueEntityId());

 

And register entity in Your load method

 

EntityRegistry.registerModEntity(EntitySilverDagger.class, "SilverDagger", 1, instance, 160, 1, false);

 

Does it work now?

 

The float is not needed. Remove it.

Posted

Well, if it rendered, It would crash, as You cannot cast EntityDagger into EntityFireball in doRenderFireball. Change types used in method.

 

Second: in EntitySilverDagger class, you have to define a constructor, which takes only world as parameter. Even if You don't use it anywhere, rendering functions still need it.

 

Thirdly, you'll need also to register EntityID in EntityRegistry

 

Does it work now?

I'm really sorry about all these questions but I really just want to add a simple snowball with another texture. Now, I followed your steps provided here and I got it to render! :D but it renders as a white cube flying in the air, I don't want it like a cube, I just want the texture flying in the air... If I remove the float, then I'll have to remove these two lines of code:

float f2 = this.field_77002_a;
GL11.glScalef(f2 / 1.0F, f2 / 1.0F, f2 / 1.0F);

It doesn't change anything so I wonder if you know what they do? Also since it doesn't render any texture, I can guess that I've put a wrong path in it. Is this correct?

Icon icon = SilverDagger.swordSilver.getIconFromDamage(0);
loadTexture("/mods/silverdagger/textures/items/Silver_Dagger.png");

Or should I change the path somehow? Thank you so much for this help

Posted

I have a similar problem as well i have a throwable snowball with a rock in it :/ i just wanted it to look like a snowball ? it currently renders as a white cube as well, i hope you find a way to solve this soon :)

Use examples, i have aspergers.

Examples make sense to me.

Posted

I'm not sure if it will work for You  - it worked when I tried some tests myself, but then You may be missing some code I'm not aware You don't have.

 

loadTexture("/mods/silverdagger/textures/items/Silver_Dagger.png");

This should rather stay

 

this.loadTexture("/gui/items.png");

 

Important is that

 

Icon icon = SilverDagger.swordSilver.getIconFromDamage(0);

 

Try it. Now, if it works, further explanation is not necessary.

 

If not:

 

1. Delete (or better comment, using ctrl+/ shortcut) the whole render code (I mean doRender function), leaving it

an empty function.

 

2.Try to run it - if

a) it still renders like white cube, that would mean that

Your render code isn't even used. You would have to double check render registering, for example using

 

the tutorial I provided. Part II and part III contain info about rendering.

 

b) the entity simply doesn't show, that the thing that needs checking is if Your getIconFromDamage returns initialized Icon. You may need to move item registration to preInit method if it doesn't.

Posted

I'm not sure if it will work for You  - it worked when I tried some tests myself, but then You may be missing some code I'm not aware You don't have.

I got it to work! The problem was in the render registration, I registered it in the registerRenderers method in ClientProxy.java at first, but then I tried to do it in the load method and it worked! Do you know why it didn't work in ClientProxy? I did initialize it in the main class... :S

 

Btw, I read some of the tutorial you provided, that seriously is a really great tutorial! I will definitely use it in the future! Thanks a lot :D

Posted

I'm glad that I helped You, Raggarcowboy.

 

As for You, ashtonr12:

 

and you use modloader. in your tutorials which makes the mod non smp compatible :/

 

Hm. I use it in my mod as well, and it works in multi, doesn't crash server. Are You sure that it causes issues?

 

As for code, this works fine. The example item is thrownItem and entitythrownitem.

 

SpaceMarineMod.class

 

 

     @Init
     public void load(FMLInitializationEvent event) throws Exception {
             proxy.registerRenderers();
    	 blasterRifle = new ItemBlasterRifle(blasterRifleId).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("BlasterRifle");
    	 
    	 
    	 thrownItem = new ItemThrown(thrownItemId).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("BlasterRifle");
    	 
    	 LanguageRegistry.addName(blasterRifle, "Blaster rifle");
             EntityRegistry.registerModEntity(EntityBlasterBolt.class, "BlasterBolt", 1, instance, 160, 1, false);
             
             
             
             LanguageRegistry.addName(thrownItem, "Thrown item");
             EntityRegistry.registerModEntity(EntityThrownItem.class, "ThrownItem", 2, instance, 160, 1, false);
             
     }

 

 

 

ClientProxy

 

        @Override
        public void registerRenderers() {
        	super.registerRenderers();	
            EntityRegistry.registerGlobalEntityID(EntityBlasterBolt.class, "BlasterBolt", ModLoader.getUniqueEntityId());
            RenderingRegistry.registerEntityRenderingHandler(EntityBlasterBolt.class, new RenderBlasterBolt());

            EntityRegistry.registerGlobalEntityID(EntityThrownItem.class, "ThrownItem", ModLoader.getUniqueEntityId());
            RenderingRegistry.registerEntityRenderingHandler(EntityThrownItem.class, new RenderThrownItem());
            
                
        }

 

 

 

ThrownItemEntity

 

 

public class EntityThrownItem extends EntityThrowable{

public EntityThrownItem(World par1World) {
	super(par1World);
	// TODO Auto-generated constructor stub
}

public EntityThrownItem(World par2World, EntityPlayer par3EntityPlayer) {
	super(par2World,par3EntityPlayer);
}

@Override
protected void entityInit() {

}

@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound) {

}

@Override
public void writeEntityToNBT(NBTTagCompound nbttagcompound) {

}

@Override
protected void onImpact(MovingObjectPosition movingobjectposition) {
	this.setDead();

}

}

 

 

 

RenderThrownItem

 

 

public class RenderThrownItem extends Render
{

public RenderThrownItem()
{
}	

public void doRenderThrownItem(EntityThrownItem par1EntityThrownItem, double par2, double par4, double par6, float par8, float par9)
{
    GL11.glPushMatrix();
    GL11.glTranslatef((float)par2, (float)par4, (float)par6);
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    float f2 = 1.0F;
    GL11.glScalef(f2 / 1.0F, f2 / 1.0F, f2 / 1.0F);
    Icon icon = SenitielsSpaceMarineMod.blasterRifle.getIconFromDamage(0);
    this.loadTexture("/gui/items.png");
    Tessellator tessellator = Tessellator.instance;
    float f3 = icon.getMinU();
    float f4 = icon.getMaxU();
    float f5 = icon.getMinV();
    float f6 = icon.getMaxV();
    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((double)(0.0F - f8), (double)(0.0F - f9), 0.0D, (double)f3, (double)f6);
    tessellator.addVertexWithUV((double)(f7 - f8), (double)(0.0F - f9), 0.0D, (double)f4, (double)f6);
    tessellator.addVertexWithUV((double)(f7 - f8), (double)(1.0F - f9), 0.0D, (double)f4, (double)f5);
    tessellator.addVertexWithUV((double)(0.0F - f8), (double)(1.0F - f9), 0.0D, (double)f3, (double)f5);
    tessellator.draw();
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}

/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
* (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
    this.doRenderThrownItem((EntityThrownItem)par1Entity, par2, par4, par6, par8, par9);
}

}

 

 

 

 

Posted

please post our working code, PLEASE!...

<3

I would go ahead and follow Senitiels code, however if it still doesn't work, the part that fixed it for me was switching place of...

RenderingRegistry.registerEntityRenderingHandler(EntitySilverDagger.class, new RenderSilverDagger());

from ClientProxy.java to your load/init-method in your main mod-class, like so

@Init
public void load(FMLPreInitializationEvent event)
{
     RenderingRegistry.registerEntityRenderingHandler(EntityBlasterBolt.class, new RenderBlasterBolt());
}

Good luck! :)

Posted

ok so i added and followed the tutorials twice but the entity doesnt seem to render, i have it so that its basiccaly exactly the same as a snowball, i think i must have missed a line of code :( whne i right click the RockSnowball is consumed (good) but the entity doesnt show(bab) but when i shoot it at water i can hear it splash (good) so its obvoisely there but not rendering also nothing happens when i shoot it at living entities such as cows.

 

Main Class;

EntityRegistry.registerModEntity(EntityRockSnowball.class, "RockSnowball", 2, this , 250, 1, false);

Item Class;

package ashtonsmod.common;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class RockSnowball extends Item
{
    public RockSnowball(int par1)
    {
        super(par1);
        this.maxStackSize = 64;
    }
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        if (!par3EntityPlayer.capabilities.isCreativeMode)
        {
            --par1ItemStack.stackSize;
        }

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

        if (!par2World.isRemote)
        {
            par2World.spawnEntityInWorld(new EntityRockSnowball(par2World, par3EntityPlayer));
        }

        return par1ItemStack;
    }
    
    @Override
   	public void updateIcons(IconRegister par1IconRegister)
    {
        this.iconIndex = par1IconRegister.registerIcon("ashtonsmod:RockSnowball");
    }}

Entity Class

package ashtonsmod.common;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityRockSnowball extends EntityThrowable{

public EntityRockSnowball(World par1World) {
  super(par1World);
  // TODO Auto-generated constructor stub
}

public EntityRockSnowball(World par2World, EntityPlayer par3EntityPlayer) {
  super(par2World,par3EntityPlayer);
}

@Override
protected void entityInit() {

}

@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound) {

}

@Override
public void writeEntityToNBT(NBTTagCompound nbttagcompound) {

}

@Override
protected void onImpact(MovingObjectPosition movingobjectposition) {
  this.setDead();
  
}

}

Render Class;

package ashtonsmod.common;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.Icon;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class RenderRockSnowball extends Render
{

public RenderRockSnowball()
{
} 

public void doRenderThrownItem(EntityRockSnowball par1EntityThrownItem, double par2, double par4, double par6, float par8, float par9)
{
    GL11.glPushMatrix();
    GL11.glTranslatef((float)par2, (float)par4, (float)par6);
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    float f2 = 1.0F;
    GL11.glScalef(f2 / 1.0F, f2 / 1.0F, f2 / 1.0F);
    Icon icon = ashtonsmod.RockSnowball.getIconFromDamage(0);
    this.loadTexture("ashtonsmod:RockSnowball");
    Tessellator tessellator = Tessellator.instance;
    float f3 = icon.getMinU();
    float f4 = icon.getMaxU();
    float f5 = icon.getMinV();
    float f6 = icon.getMaxV();
    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((double)(0.0F - f8), (double)(0.0F - f9), 0.0D, (double)f3, (double)f6);
    tessellator.addVertexWithUV((double)(f7 - f8), (double)(0.0F - f9), 0.0D, (double)f4, (double)f6);
    tessellator.addVertexWithUV((double)(f7 - f8), (double)(1.0F - f9), 0.0D, (double)f4, (double)f5);
    tessellator.addVertexWithUV((double)(0.0F - f8), (double)(1.0F - f9), 0.0D, (double)f3, (double)f5);
    tessellator.draw();
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}

/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
* (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
    this.doRenderRockSnowball((EntityRockSnowball)par1Entity, par2, par4, par6, par8, par9);
}

private void doRenderRockSnowball(EntityRockSnowball par1Entity, double par2,
	double par4, double par6, float par8, float par9) {

}

}

 

Client Proxy Class;

package ashtonsmod.client;

import ashtonsmod.common.EntityRockSnowball;
import ashtonsmod.common.RenderRockSnowball;
import ashtonsmod.common.RockSnowball;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.src.ModLoader;
import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxyashtonsmod extends ashtonsmod.common.CommonProxy {
        	 @Override
             public void registerRenderers() {
              super.registerRenderers(); 
                 EntityRegistry.registerGlobalEntityID(EntityRockSnowball.class, "RockSnoball", ModLoader.getUniqueEntityId());
                 RenderingRegistry.registerEntityRenderingHandler(EntityRockSnowball.class, new RenderRockSnowball());
        }
        
        public void renderRegistry() {
        }
}

 

why these problems?

Use examples, i have aspergers.

Examples make sense to me.

Posted

Well, You were supposed to use RenderThrownItem it as the body for

 

private void doRenderRockSnowball(EntityRockSnowball par1Entity, double par2,
	double par4, double par6, float par8, float par9) {

}

 

Remember, there's no magic here - if a method isn't called anywhere, then it won't do anything. You may check it using Eclipse right click->show references

Posted

did you mean this part?

public void doRenderRockSnowball(EntityRockSnowball par1EntityRockSnowball, double par2, double par4, double par6, float par8, float par9)
{

i missed some words there but now it just shoots a white square that does not interact with the world

Use examples, i have aspergers.

Examples make sense to me.

Posted

i was meant to use what as what?

Seems as your code has quite a lot of flaws... First of all, instead of "this.setDead();" in onImpact in your EntityRockSnowball class, use this code:

 

 

if (par1MovingObjectPosition.entityHit != null)
	{
		par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), ; // <-- change 8 to whatever damage you'd like to cause
	}

	if (!this.worldObj.isRemote && this.rand.nextInt( == 0)
	{
		byte b0 = 1;

		if (this.rand.nextInt(32) == 0)
		{
			b0 = 4;
		}
	}

	for (int j = 0; j < 8; j++)
	{
		this.worldObj.spawnParticle("snowballpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
	}

	if (!this.worldObj.isRemote)
	{
		this.setDead();
	}

 

 

That will damage the target and also spawn a snowball particle. You can change the number I've commented by to change the damage.

Second of all, in the doRenderThrownItem, replace...

this.loadTexture("ashtonsmod:RockSnowball");

... with...

this.loadTexture("/gui/items.png");

Third thing, inside the doRender function, put doRenderThrownItem(etc...) instead of doRenderRockSnowball(etc...) since this function is completely empty. Also you can delete the doRenderRockSnowball function (the last function of the render class) since it only takes unnecessary space.

 

Now if all of this still doesn't work, then take away the RenderingRegistry.registerEntityRenderingHandler(EntityRockSnowball.class, new RenderRockSnowball()); line from your ClientProxy and put it in the load/init function of your main class.

 

Hope this helped ;)

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.