Jump to content

Adding a New Entity - Invisible? Texture Error?


MoonMax

Recommended Posts

So, I'm basically trying to [for starters] make a mod to add a Ball of Yarn that cats will play with. I haven't added any code for the cats to actually play with it, mostly because I can't figure out how to get it to render at all. In fact, I can't even get the icon for the item used to spawn it to render; it returns to the default iron helmet icon. Any help would be much appreciated.

 

ModCatAdditions.java:

 

package CatAdditions.common;

import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.EntityList;
import net.minecraft.src.EntityEggInfo;

@Mod(modid="CatAdditions", name="CatAdditions", version="Cat Additions rev 1 for MC ver 1.4.2")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class ModCatAdditions
{
//public static final Block exampleBlock = new BlockExampleBlock(250, 0);
public static final Item yarnBall = new ItemYarnBall(6240);

@Instance("CatAdditions")
public static ModCatAdditions instance;

@SidedProxy(clientSide="CatAdditions.common.client.ClientProxy", serverSide="CatAdditions.common.CommonProxy")
public static CommonProxy proxy;

@PreInit
public void preInit(FMLPreInitializationEvent event)
{
}

@Init
public void load(FMLInitializationEvent event)
{
	proxy.registerRenderers();

	//Adding (Item)yarnBall
	LanguageRegistry.addName(yarnBall, "Ball of Yarn");

	//Adding (Entity)yarnBall
	EntityRegistry.registerModEntity(EntityYarnBall.class, "Ball of Yarn", 1, this, 80, 3, true);
	EntityList.IDtoClassMapping.put(300, EntityYarnBall.class);
	EntityList.entityEggs.put(300, new EntityEggInfo(300, 657930, 3394560));
	LanguageRegistry.instance().addStringLocalization("entity.CatAdditions.EntityYarnBall.name", "en_US", "Ball of Yarn");

	//Adding recipes
	ItemStack silkStacked = new ItemStack(Item.silk);
	GameRegistry.addRecipe(new ItemStack(yarnBall, 1),
		" A ", "AAA", " A ",
		'A', silkStacked);
}

@PostInit
public void postInit(FMLPostInitializationEvent event)
{
}
}

 

 

ItemYarnBall.java:

 

package CatAdditions.common;

import net.minecraft.src.Item;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.ItemStack;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.World;

public class ItemYarnBall extends Item
{
public int yarnBallColor = 0;

public ItemYarnBall(int id)
{
	super(id);
	this.setMaxStackSize(16);
	this.setCreativeTab(CreativeTabs.tabDecorations);
	this.setIconIndex(0);
	this.setItemName("yarnBall");
}

public ItemYarnBall(int par1, int par2)
{
	this(par1);
	yarnBallColor = par2;
}

public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
{
	switch (yarnBallColor)
	{
		default: return 16777215;
		case 0: return 2631720;
		case 1: return 12464176;
		case 2: return 4877080;
		case 3: return 9001014;
		case 4: return 5931746;
		case 5: return 10769358;
		case 6: return 3968688;
		case 7: return 13158600;
		case 8: return 8684676;
		case 9: return 14388148;
		case 10: return 7783952;
		case 11: return 14538023;
		case 12: return 9419252;
		case 13: return 13330885;
		case 14: return 15113780;
		case 15: return 16777215;
	}
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
	if(!par3World.isRemote)
	{
		par3World.spawnEntityInWorld(new EntityYarnBall(par3World, par4, par5, par6));
		--par1ItemStack.stackSize;
		return true;
	}
	else
	{
		return false;
	}
}

public String getTextureFiles()
{
	return CommonProxy.ITEMS_PNG;
}
}

 

 

EntityYarnBall.java:

 

package CatAdditions.common;

import java.util.ArrayList;

import net.minecraft.src.Entity;
import net.minecraft.src.World;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.DamageSource;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;

public class EntityYarnBall extends Entity
{
protected String texture = "/CatAdditions/common/images/ModelYarnBall.png";

public EntityYarnBall(World par1World)
{
	super(par1World);
	this.preventEntitySpawning = true;
	this.setSize(0.25F, 0.25F);
	this.yOffset = this.height / 2.0F;
}

public EntityYarnBall(World par1World, double par2, double par3, double par4)
{
	this(par1World);
	this.setPosition(par2, (double)(par3 + this.yOffset), par4);
	this.motionX = 0.0D;
	this.motionY = 0.0D;
	this.motionZ = 0.0D;
	this.prevPosX = par2;
	this.prevPosY = par3;
	this.prevPosZ = par4;
}

public String getTexture()
{
	return texture;
}

public boolean canBePushed()
{
	return true;
}

public boolean canBeCollidedWith()
{
	return !this.isDead;
}

public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
	if (!this.isDead && !this.worldObj.isRemote)
	{
		this.setDead();
		this.setBeenAttacked();
		EntityPlayer entityPlayer = null;

		if (par1DamageSource.getEntity() instanceof EntityPlayer)
		{
			entityPlayer = (EntityPlayer)par1DamageSource.getEntity();
		}

		if (entityPlayer != null && entityPlayer.capabilities.isCreativeMode)
		{
			return true;
		}

		this.dropItemStack();
	}

	return true;
}

public void dropItemStack()
{
	this.entityDropItem(new ItemStack(ModCatAdditions.yarnBall), 0.0F);
}

protected void entityInit() {}
protected void readEntityFromNBT(NBTTagCompound par1) {}
protected void writeEntityToNBT(NBTTagCompound par1) {}
}

 

 

RenderYarnBall.java:

 

package CatAdditions.common;

import net.minecraft.src.Render;
import net.minecraft.src.ModelBase;
import net.minecraft.src.Entity;

public class RenderYarnBall extends Render
{
private ModelBase modelYarnBall;

public RenderYarnBall(ModelBase modelBase)
{
	this.shadowSize = 0.5F;
	modelYarnBall = modelBase;
}

public void doRenderYarnBall(EntityYarnBall par1EntityYarnBall, double par2, double par3, double par4, float par5, float par6)
{
	this.loadTexture("/CatAdditions/common/images/ModelYarnBall.png");
	modelYarnBall.render(par1EntityYarnBall, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
}

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

 

 

ModelYarnBall.java:

 

// Date: 11/6/2012 5:24:24 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX
package CatAdditions.common;

import net.minecraft.src.ModelBase;
import net.minecraft.src.ModelRenderer;
import net.minecraft.src.Entity;

public class ModelYarnBall extends ModelBase
{
    ModelRenderer base;
    ModelRenderer front;
    ModelRenderer back;
    ModelRenderer right;
    ModelRenderer left;
    ModelRenderer top;
    ModelRenderer bottom;

public ModelYarnBall()
{
	textureWidth = 32;
	textureHeight = 16;

	base = new ModelRenderer(this, 0, 0);
	base.addBox(0F, 0F, 0F, 4, 4, 4);
	base.setRotationPoint(-2F, 19F, -2F);
	base.setTextureSize(32, 16);
	base.mirror = true;
	setRotation(base, 0F, 0F, 0F);
	front = new ModelRenderer(this, 16, 0);
	front.addBox(0F, 0F, 0F, 2, 2, 1);
	front.setRotationPoint(-1F, 20F, -3F);
	front.setTextureSize(32, 16);
	front.mirror = true;
	setRotation(front, 0F, 0F, 0F);
	back = new ModelRenderer(this, 16, 0);
	back.addBox(0F, 0F, 0F, 2, 2, 1);
	back.setRotationPoint(-1F, 20F, 2F);
	back.setTextureSize(32, 16);
	back.mirror = true;
	setRotation(back, 0F, 0F, 0F);
	right = new ModelRenderer(this, 16, 3);
	right.addBox(0F, 0F, 0F, 1, 2, 2);
	right.setRotationPoint(-3F, 20F, -1F);
	right.setTextureSize(32, 16);
	right.mirror = true;
	setRotation(right, 0F, 0F, 0F);
	left = new ModelRenderer(this, 16, 3);
	left.addBox(0F, 0F, 0F, 1, 2, 2);
	left.setRotationPoint(2F, 20F, -1F);
	left.setTextureSize(32, 16);
	left.mirror = true;
	setRotation(left, 0F, 0F, 0F);
	top = new ModelRenderer(this, 22, 0);
	top.addBox(0F, 0F, 0F, 2, 1, 2);
	top.setRotationPoint(-1F, 18F, -1F);
	top.setTextureSize(32, 16);
	top.mirror = true;
	setRotation(top, 0F, 0F, 0F);
	bottom = new ModelRenderer(this, 22, 0);
	bottom.addBox(0F, 0F, 0F, 2, 1, 2);
	bottom.setRotationPoint(-1F, 23F, -1F);
	bottom.setTextureSize(32, 16);
	bottom.mirror = true;
	setRotation(bottom, 0F, 0F, 0F);
}

public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
	super.render(entity, f, f1, f2, f3, f4, f5);
	setRotationAngles(f, f1, f2, f3, f4, f5, entity);
	base.render(f5);
	front.render(f5);
	back.render(f5);
	right.render(f5);
	left.render(f5);
	top.render(f5);
	bottom.render(f5);
}

private void setRotation(ModelRenderer model, float x, float y, float z)
{
	model.rotateAngleX = x;
	model.rotateAngleY = y;
	model.rotateAngleZ = z;
}

public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
{
	super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}

 

 

CommonProxy.java:

 

package CatAdditions.common;

public class CommonProxy
{
public static String ITEMS_PNG = "/CatAdditions/common/images/items.png";
public static String BLOCK_PNG = "/CatAdditions/common/images/block.png";

public void registerRenderers()
{
}
}

 

 

ClientProxy.java:

 

package CatAdditions.common.client;

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

import CatAdditions.common.CommonProxy;
import CatAdditions.common.EntityYarnBall;
import CatAdditions.common.RenderYarnBall;
import CatAdditions.common.ModelYarnBall;

public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers()
{
	MinecraftForgeClient.preloadTexture(ITEMS_PNG);
	MinecraftForgeClient.preloadTexture(BLOCK_PNG);
	RenderingRegistry.registerEntityRenderingHandler(EntityYarnBall.class, new RenderYarnBall(new ModelYarnBall()));
}
}

 

 

Images:

 

 

ModelYarnBall.png

51n6c.png

yarnBall.png

0Ngxl.png

 

The block.png and items.png are just generic testing sheets, I shouldn't have them referenced anywhere.

 

 

↑It makes sense if you don't think about it.↑

 

Creepers only explode because they want to hug you, but when they reach you, they realize they have no arms, and then explode with anger.

Link to comment
Share on other sites

  • 3 weeks later...

In the item.java u add an extra 's' at the method name:

 

public String getTextureFiles()
{
  return CommonProxy.ITEMS_PNG;
}

 

Try:

 

public String getTextureFile()
{
  return CommonProxy.ITEMS_PNG;
}

 

Also you didn't call the right image files in the commonProxy.java. I'm sure this will fix the "texture not loading" problem... at least for forge 6.3.0 (mc 1.4.4).

Link to comment
Share on other sites

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.