Selacstellap Posted July 24, 2013 Share Posted July 24, 2013 (Updated 2013/7/25) Solved I use EntityRegistry.registerModEntity(params) instead of EntityRegistry.registerGlobalEntityID(params) and it works! Thanks to the OP of http://www.minecraftforge.net/forum/index.php/topic,10285.msg52206.html#msg52206 whose post inspires me. Thank you guys who replied me. Feel free to lock this thread. --- Hi everyone. I'm designing a shooter shooting healing ball and the ball is nothing but a snowball with a different texture (original snowball.png painted yellow). Then I copy-paste the renderer and entity code for snowball and customize it. Of course I have registered the item, the entity and the renderer and bind them together, but it just doesn't work: the rendering methods inside the customized class are never called. As the following code shows, I add some console output into the methods. When my shooter shoots a EntitySnowball, the message is displayed, but when it shoots EntityHealingBall, console shows nothing related. However, what makes it more strange is, every time the game is initialized, the messages "Entity Reged" and "Renderer Reged" are posted onto the console. That confuses me: why it just doesn't work, even if the renderer and the entity are registered successfully? Any help would be appreciated. ItemBlasterRifle.java package tutorial.generic; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityFireball; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemBlasterRifle extends Item { public ItemBlasterRifle(int par1) { super(par1); // TODO Auto-generated constructor stub } @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if(par3EntityPlayer.inventory.consumeInventoryItem(Generic.healingBall.itemID)) { par2World.playSoundAtEntity(par3EntityPlayer, "generic:blasterShot", 1.0F, 1.0F); if(!par2World.isRemote) { par2World.spawnEntityInWorld(new EntityHealingBall(par2World, par3EntityPlayer)); } } return par1ItemStack; } } ItemHealingBall.java package tutorial.generic; 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.ItemSnowball; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemHealingBall extends Item { public ItemHealingBall(int par1) { super(par1); // TODO Auto-generated constructor stub this.setCreativeTab(CreativeTabs.tabCombat); this.setMaxStackSize(64); this.setUnlocalizedName("HealingBall"); } } EntityHealingBall.java package tutorial.generic; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityBlaze; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.util.DamageSource; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class EntityHealingBall extends EntityThrowable { public EntityHealingBall(World par1World) { super(par1World); } public EntityHealingBall(World par1World, EntityLivingBase par2EntityLivingBase) { super(par1World, par2EntityLivingBase); } public EntityHealingBall(World par1World, double par2, double par4, double par6) { super(par1World, par2, par4, par6); } @Override protected void onImpact(MovingObjectPosition par1MovingObjectPosition) { if (par1MovingObjectPosition.entityHit != null) { byte b0 = 0; if (par1MovingObjectPosition.entityHit instanceof EntityPlayer) { b0 = 1; ((EntityPlayer) par1MovingObjectPosition.entityHit).heal((float) b0); } } for (int i = 0; i < 8; ++i) { this.worldObj.spawnParticle("HealingBallpoof", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); } if (!this.worldObj.isRemote) { this.setDead(); } } } RenderHealingBall.java (copy-pasted from RenderSnowball.java) package tutorial.generic; 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.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.EntityPotion; import net.minecraft.item.Item; import net.minecraft.item.ItemPotion; import net.minecraft.potion.PotionHelper; import net.minecraft.util.Icon; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @SideOnly(Side.CLIENT) public class RenderHealingBall extends Render { private Item field_94151_a; private int field_94150_f; public RenderHealingBall(Item par1Item, int par2) { this.field_94151_a = par1Item; this.field_94150_f = par2; } public RenderHealingBall(Item par1Item) { this(par1Item, 0); } /** * 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) { Icon icon = this.field_94151_a.getIconFromDamage(this.field_94150_f); if (icon != null) { GL11.glPushMatrix(); GL11.glTranslatef((float)par2, (float)par4, (float)par6); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glScalef(0.5F, 0.5F, 0.5F); this.func_110777_b(par1Entity); Tessellator tessellator = Tessellator.instance; if (icon == ItemPotion.func_94589_d("bottle_splash")) { int i = PotionHelper.func_77915_a(((EntityPotion)par1Entity).getPotionDamage(), false); float f2 = (float)(i >> 16 & 255) / 255.0F; float f3 = (float)(i >> 8 & 255) / 255.0F; float f4 = (float)(i & 255) / 255.0F; GL11.glColor3f(f2, f3, f4); GL11.glPushMatrix(); this.func_77026_a(tessellator, ItemPotion.func_94589_d("overlay")); GL11.glPopMatrix(); GL11.glColor3f(1.0F, 1.0F, 1.0F); } this.func_77026_a(tessellator, icon); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); } } protected ResourceLocation func_110775_a(Entity par1Entity) { System.out.println("will return resource location - healing ball."); return TextureMap.field_110576_c; } private void func_77026_a(Tessellator par1Tessellator, Icon par2Icon) { float f = par2Icon.getMinU(); float f1 = par2Icon.getMaxU(); float f2 = par2Icon.getMinV(); float f3 = par2Icon.getMaxV(); System.out.println("will draw texture - healing ball." + ' ' + f + ' ' + f1 + ' ' + f2 + ' ' + f3); 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); par1Tessellator.startDrawingQuads(); par1Tessellator.setNormal(0.0F, 1.0F, 0.0F); par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3); par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3); par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2); par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2); par1Tessellator.draw(); } } Generic.java package tutorial.generic; import java.io.File; import tutorial.generic.client.GuiBuffBar; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; 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.Mod.EventHandler; @Mod(modid="Generic", name="Generic", version="0.0.0") @NetworkMod(clientSideRequired=true, serverSideRequired=false) public class Generic { private static Item genericItem = new GenericItem(5000).func_111206_d("generic:genericItem"); private static Item genericIngot = new GenericItem(5001).setMaxStackSize(16).setUnlocalizedName("genericIngot").func_111206_d("generic:genericIngot"); private static Block genericDirt = new GenericBlock(500, Material.ground).func_111022_d("generic:genericDirt").setCreativeTab(CreativeTabs.tabBlock).setHardness(0.5F).setUnlocalizedName("genericDirt").setStepSound(Block.soundGravelFootstep); private static Item blasterRifle = new ItemBlasterRifle(5002).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("blasterRifle").func_111206_d("generic:gun"); public static Item healingBall = new ItemHealingBall(5003).func_111206_d("generic:healingball"); @Instance("Generic") public static Generic instance; @SidedProxy(clientSide="tutorial.generic.client.ClientProxy", serverSide="tutorial.generic.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { } @EventHandler public void load(FMLInitializationEvent event) { proxy.registerRenderers(); GameRegistry.addShapelessRecipe(new ItemStack(blasterRifle), new ItemStack(net.minecraft.block.Block.dirt)); GameRegistry.addShapedRecipe(new ItemStack(net.minecraft.item.Item.axeDiamond), "xxx", "xxx", "yyy", 'x', net.minecraft.block.Block.dirt, 'y', net.minecraft.item.Item.diamond); GameRegistry.addSmelting(net.minecraft.block.Block.dirt.blockID, new ItemStack(net.minecraft.item.Item.swordDiamond), 1.0f); GameRegistry.registerBlock(genericDirt, "genericDirt"); LanguageRegistry.addName(genericItem, "Generic Item"); LanguageRegistry.addName(genericIngot, "Generic Ingot"); LanguageRegistry.addName(genericDirt, "Generic Dirt"); LanguageRegistry.addName(blasterRifle, "Blaster Rifle"); LanguageRegistry.addName(healingBall, "Healing Ball"); MinecraftForge.setBlockHarvestLevel(genericDirt, "shovel", 0); } @EventHandler public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new GuiBuffBar(Minecraft.getMinecraft())); } } ClientProxy.java package tutorial.generic.client; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import tutorial.generic.CommonProxy; import tutorial.generic.EntityBlasterRifleAmmo; import tutorial.generic.EntityHealingBall; import tutorial.generic.Generic; import tutorial.generic.RenderBlasterRifleAmmo; import tutorial.generic.RenderHealingBall; import tutorial.generic.SoundRegHandler; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; public class ClientProxy extends CommonProxy { @Override public void registerRenderers() { EntityRegistry.registerGlobalEntityID(EntityHealingBall.class, "HealingBall", EntityRegistry.findGlobalUniqueEntityId()); System.out.println("Entity Reged"); RenderingRegistry.registerEntityRenderingHandler(EntityHealingBall.class, new RenderHealingBall(Generic.healingBall)); System.out.println("Renderer Reged"); MinecraftForge.EVENT_BUS.register(new SoundRegHandler()); } } Quote Link to comment Share on other sites More sharing options...
ralphyrafa Posted July 24, 2013 Share Posted July 24, 2013 put a println in the render class instead of the proxy and check if it appears Quote I like helping people because i was also in a same problem and i do not like unfinished work, so a thank you will be enough for the people im helping and a thank you to the people that helped me Link to comment Share on other sites More sharing options...
hydroflame Posted July 24, 2013 Share Posted July 24, 2013 put a println in the render class instead of the proxy and check if it appears YES!!!!!! but to come to the actual problem, you are registering your entity CLIENT side only, the server doesnt know that theres a new entity and so it never makes it appear EntityRegistry.registerGlobalEntityID(EntityHealingBall.class, "HealingBall", EntityRegistry.findGlobalUniqueEntityId()); System.out.println("Entity Reged"); try placing that code in you Generic main mod file because both client side and server side will run this Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution- Link to comment Share on other sites More sharing options...
Selacstellap Posted July 25, 2013 Author Share Posted July 25, 2013 Thank you, but actually I would not like the texture to be rendered on server side. My solution is to switch to another method. Quote Link to comment Share on other sites More sharing options...
hydroflame Posted July 25, 2013 Share Posted July 25, 2013 no i dont think you understand that the entity need to exists on both side but the renderer only exists client side Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution- Link to comment Share on other sites More sharing options...
Selacstellap Posted July 25, 2013 Author Share Posted July 25, 2013 Oh! I did not realize that. Fortunately I put my entity registration in preInit() of the mod file now... by coincidence.. Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.