Posted November 24, 201311 yr I'm trying to render a custom entity, pretty simple really. but my rendering code never seems to get called, what am I doing wrong? Entity package opticraft.entitys; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class EntityBeam extends Entity { public String orientation; public EntityBeam(World par1World, String orientation) { super(par1World); this.orientation = orientation; } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound nbttagcompound) { // TODO Auto-generated method stub } @Override protected void writeEntityToNBT(NBTTagCompound nbttagcompound) { // TODO Auto-generated method stub } } Render package opticraft.render; import opticraft.entitys.EntityBeam; import opticraft.lib.ModInfo; import opticraft.lib.Names; import opticraft.models.BeamModel; import org.lwjgl.opengl.GL11; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.Entity; import net.minecraft.client.renderer.entity.Render; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class BeamRenderer extends Render{ private final BeamModel model; private String orientation = "LR"; public BeamRenderer() { this.model = new BeamModel(); System.out.println("RENDER CONSTRUCTED"); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); } //Set the lighting stuff, so it changes it's brightness properly. private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; float brightness = block.getBlockBrightness(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier); } @Override public void doRender(Entity entity, double x, double y, double z, float f, float f1) { System.out.println("RENDER CALLED"); //The PushMatrix tells the renderer to "start" doing something. GL11.glPushMatrix(); //This is setting the initial location. GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); //This is the texture of your block. It's pathed to be the same place as your other blocks here. //Outdated bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleRed.png"); //Use in 1.6.2 this ResourceLocation textures = (new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/blocks/beamTile.png")); //the ':' is very important //binding the textures Minecraft.getMinecraft().renderEngine.bindTexture(textures); //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again! GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); //A reference to your Model file. Again, very important. this.model.render((Entity)entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); //Tell it to stop rendering for both the PushMatrix's GL11.glPopMatrix(); GL11.glPopMatrix(); model.LR.isHidden = true; model.FB.isHidden = true; model.TB.isHidden = true; EntityBeam ent = (EntityBeam) entity; orientation = ent.orientation; if(orientation == "LR") model.LR.isHidden = false; else if(orientation == "FB") model.FB.isHidden = false; else if(orientation == "UD") model.TB.isHidden = false; else{ model.LR.isHidden = false; model.FB.isHidden = false; model.TB.isHidden = false; } } @Override protected ResourceLocation getEntityTexture(Entity entity) { return new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/blocks/beamTile.png"); } } Client Proxy package opticraft.proxies; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; import opticraft.Opticraft; import opticraft.entitys.EntityBeam; import opticraft.entitys.TileEntityItemLaser; import opticraft.entitys.TileEntityLaserDetector; import opticraft.entitys.TileEntitySolarCollector; import opticraft.items.ItemLaserWrench; import opticraft.lib.Ids; import opticraft.render.BeamRenderer; import opticraft.render.ItemLaserRenderer; import opticraft.render.LaserDetectorRenderer; import opticraft.render.LaserWrenchRenderer; import opticraft.render.SolarCollectorRenderer; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.registry.EntityRegistry; public class ClientProxy extends CommonProxy{ @Override public void initRenderers() { } @Override public void initSounds() { } public void registerRenderThings() { ClientRegistry.bindTileEntitySpecialRenderer(TileEntityItemLaser.class, new ItemLaserRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySolarCollector.class, new SolarCollectorRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserDetector.class, new LaserDetectorRenderer()); RenderingRegistry.registerEntityRenderingHandler(EntityBeam.class, new BeamRenderer()); MinecraftForgeClient.registerItemRenderer(Ids.laserWrench + 256, (IItemRenderer)new LaserWrenchRenderer()); } } Main class package opticraft; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; import opticraft.blocks.Blocks; import opticraft.client.gui.GuiHandler; import opticraft.entitys.EntityBeam; import opticraft.entitys.TileEntityItemLaser; import opticraft.entitys.TileEntityLaserDetector; import opticraft.entitys.TileEntitySolarCollector; import opticraft.items.Items; import opticraft.items.ItemLaserWrench; import opticraft.lib.Ids; import opticraft.lib.ModInfo; import opticraft.proxies.CommonProxy; import opticraft.render.LaserWrenchRenderer; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.Mod.EventHandler; 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.network.NetworkRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = ModInfo.ID, name = ModInfo.NAME, version = ModInfo.VERSION) @NetworkMod (channels = {ModInfo.CHANNEL}, clientSideRequired = true, serverSideRequired = true) public class Opticraft { private GuiHandler guiHandler = new GuiHandler(); @Instance public static Opticraft instance = new Opticraft(); @SidedProxy( clientSide = ModInfo.PROXY_LOCATION + ".ClientProxy", serverSide = ModInfo.PROXY_LOCATION + ".CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.initRenderers(); proxy.initSounds(); Items.init(); Items.addNames(); Blocks.init(); Blocks.addNames(); } @EventHandler public void init(FMLInitializationEvent event) { NetworkRegistry.instance().registerGuiHandler(this, guiHandler); EntityRegistry.registerModEntity(EntityBeam.class, "EntityBeam", EntityRegistry.findGlobalUniqueEntityId(), this, 128, 1, true); proxy.registerRenderThings(); GameRegistry.registerTileEntity(TileEntityItemLaser.class, "tileEntityItemLaser"); GameRegistry.registerTileEntity(TileEntitySolarCollector.class, "tileEntitySolarCollector"); GameRegistry.registerTileEntity(TileEntityLaserDetector.class, "tileEntityLaserDetector"); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }
November 24, 201311 yr Author Updated the part which actually initiates the Entity: for(int i = this.yCoord; i <= linkedDetector.y - 1; i++){ if (!worldObj.isRemote){ EntityBeam entity = new EntityBeam(worldObj, "UD"); entity.setPosition(xCoord, yCoord + i, zCoord); worldObj.spawnEntityInWorld(entity); //worldObj.playSoundEffect((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D, "random.fizz", 0.1F, worldObj.rand.nextFloat() * 0.1F + 0.9F); } } It appears from my debug line the renderer is never getting called. But it is getting initiated... No one got any idea?
November 24, 201311 yr I don't know exactly what your problem is, but here is what I have to render an entity. I was trying to copy and paste your code, but there are some classes that I needed. MagicSpellsMod.java - Main Class package codemeister88.minecraft.src; import net.minecraft.item.Item; import net.minecraftforge.common.Configuration; import codemeister88.minecraft.entity.EntityEarthGolem; import codemeister88.minecraft.item.ItemEarthSpellbook; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; 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.EntityRegistry; @Mod(modid="MagicSpellsMod", name="Magic Spells", version="1.2.1") @NetworkMod(clientSideRequired=true, serverSideRequired=false) public class MagicSpellsMod { // The instance of your mod that Forge uses. @Instance("MagicSpellsMod") public static MagicSpellsMod instance; /* * Items */ //holds the ids of the items public static int[] itemIDs = new int[1]; //Earth Spell public static Item earthSpellbook; // Says where the client and server 'proxy' code is loaded. @SidedProxy(clientSide="codemeister88.minecraft.client.ClientProxy", serverSide="codemeister88.minecraft.src.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); itemIDs[0] = config.getItem("EarthSpellbook", 5010).getInt(); config.save(); } @EventHandler public void load(FMLInitializationEvent event) { proxy.registerRenderers(); //Earth Spell earthSpellbook = new ItemEarthSpellbook(itemIDs[0], 1); EntityRegistry.registerModEntity(EntityEarthGolem.class, "EarthGolem", 3, instance, 80, 1, true); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } } CommonProxy.java package codemeister88.minecraft.src; import cpw.mods.fml.client.registry.RenderingRegistry; public class CommonProxy { public void registerRenderers() { } } ItemSpellbook.java package codemeister88.minecraft.item; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public abstract class ItemSpellbook extends Item { protected String spellName; protected int spellLevel; public ItemSpellbook(int par1, String spellName, int spellLevel) { super(par1); this.maxStackSize = 1; this.setMaxDamage(256); this.setCreativeTab(CreativeTabs.tabCombat); this.setUnlocalizedName("spellbook"); this.spellName = spellName; this.spellLevel = spellLevel; setTextureName("book_enchanted"); } public ItemSpellbook setSpellLevel(int spellLevel) { if(spellLevel > 0) { this.spellLevel = spellLevel; } else { this.spellLevel = 1; } return this; } public int getSpellLevel() { return spellLevel; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.block; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public abstract ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer); /** * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have * different names based on their damage or NBT. */ public String getUnlocalizedName(ItemStack par1ItemStack) { return super.getUnlocalizedName(par1ItemStack) + "." + spellName + spellLevel; } public String getItemDisplayName(ItemStack par1ItemStack) { return spellName + " Spellbook " + spellLevel; } } ItemEarthSpellbook.java package codemeister88.minecraft.item; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import codemeister88.minecraft.entity.EntityEarthGolem; public class ItemEarthSpellbook extends ItemSpellbook { private boolean entitySpawned = false; public ItemEarthSpellbook(int par1, int spellLevel) { super(par1, "Earth", spellLevel); } @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!par2World.isRemote) { EntityEarthGolem entityEarthGolem = new EntityEarthGolem(par2World); entityEarthGolem.setLocationAndAngles(par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ, 0.0F, 0.0F); System.out.println("Spawn Golem"); par2World.spawnEntityInWorld(entityEarthGolem); entitySpawned = true; } return par1ItemStack; } } EntityEarthGolem.java package codemeister88.minecraft.entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookAtVillager; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAIMoveTowardsTarget; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget; import net.minecraft.entity.ai.EntityAIOwnerHurtTarget; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class EntityEarthGolem extends EntityCreature { public EntityEarthGolem(World par1World) { super(par1World); // getNavigator().setEnterDoors(true); // this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true)); // this.tasks.addTask(2, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); // this.tasks.addTask(3, new EntityAIWander(this, 1.0D)); // this.tasks.addTask(4, new EntityAILookIdle(this)); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true)); this.tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 0.9D, 32.0F)); this.tasks.addTask(3, new EntityAIWander(this, 0.6D)); this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(5, new EntityAILookIdle(this)); // this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); // this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); // this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, true, true, IMob.mobSelector)); } /** * Plays step sound at given x, y, z for the entity */ protected void playStepSound(int par1, int par2, int par3, int par4) { this.playSound("gravel", 0.15F, 1.0F); } } RenderEarthGolem.java package codemeister88.minecraft.client.renderer.entity; import codemeister88.minecraft.client.model.ModelEarthGolem; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelIronGolem; import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; public class RenderEarthGolem extends RenderLiving { private static final ResourceLocation earthGolemTextures = new ResourceLocation("codemeister88:textures/entity/earth_golem.png"); public RenderEarthGolem() { super(new ModelEarthGolem(), 0.5F); } @Override protected ResourceLocation getEntityTexture(Entity entity) { return earthGolemTextures; } } ClientProxy.java package codemeister88.minecraft.client; import net.minecraft.src.ModLoader; import codemeister88.minecraft.client.renderer.entity.RenderEarthGolem; import codemeister88.minecraft.entity.EntityEarthGolem; import codemeister88.minecraft.src.CommonProxy; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.registry.EntityRegistry; public class ClientProxy extends CommonProxy { @Override public void registerRenderers() { super.registerRenderers(); EntityRegistry.registerGlobalEntityID(EntityEarthGolem.class, "EarthGolem", ModLoader.getUniqueEntityId()); RenderingRegistry.registerEntityRenderingHandler(EntityEarthGolem.class, new RenderEarthGolem()); } } ModelEarthGolem.java package codemeister88.minecraft.client.model; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; @SideOnly(Side.CLIENT) public class ModelEarthGolem extends ModelBase { /* * Model each part of the entity */ ModelRenderer body; ModelRenderer rightArm; ModelRenderer leftArm; ModelRenderer head; ModelRenderer leftLeg; ModelRenderer rightLeg; public ModelEarthGolem() { head = new ModelRenderer(this, 0, 0); head.addBox(-4F, -8F, -4F, 8, 8, ; head.setRotationPoint(0F, 0F, 0F); body = new ModelRenderer(this, 0, 16); body.addBox(-4F, 0F, -2F, 8, 12, 4); body.setRotationPoint(0F, 0F, 0F); rightArm = new ModelRenderer(this, 48, 0); rightArm.addBox(0F, 0F, -2F, 4, 12, 4); rightArm.setRotationPoint(4F, 0F, 0F); leftArm = new ModelRenderer(this, 32, 0); leftArm.addBox(-4F, 0F, -2F, 4, 12, 4); leftArm.setRotationPoint(-4F, 0F, 0F); leftLeg = new ModelRenderer(this, 24, 16); leftLeg.addBox(-2F, 0F, -2F, 4, 12, 4); leftLeg.setRotationPoint(-2F, 12F, 0F); rightLeg = new ModelRenderer(this, 40, 16); rightLeg.addBox(-2F, 0F, -2F, 4, 12, 4); rightLeg.setRotationPoint(2F, 12F, 0F); } @Override public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { setRotationAngles(f, f1, f2, f3, f4, f5, entity); body.render(f5); rightArm.render(f5); leftArm.render(f5); head.render(f5); leftLeg.render(f5); rightLeg.render(f5); } @Override public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity entity) { head.rotateAngleY = par4 / (180F / (float)Math.PI); head.rotateAngleX = par5 / (180F / (float)Math.PI); rightArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 2.0F * par2 * 0.5F; rightArm.rotateAngleZ = 0.0F; leftArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 2.0F * par2 * 0.5F; leftArm.rotateAngleZ = 0.0F; rightLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2; rightLeg.rotateAngleY = 0.0F; leftLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2; leftLeg.rotateAngleY = 0.0F; } }
November 25, 201311 yr Author Thanks for the reply, I seem to be doing similar things, but im not trying to spawn a mob so its slightly different. My code can be found here if you want a more detailed look: https://github.com/lexwebb/opticraft/
November 25, 201311 yr Okay, I have taken a small look at your code. From tracing, I found that it isn't entering the block to spawn the entity. This doesn't work out to true: if(ent.getStackInSlot(0) == null && getStackInSlot(0) != null){ } I ent.getStackInSlot(0) returns true, but getStackInSlot(0) returns false. I'm going to continue to take a look and see where you are adding them into the array.
November 25, 201311 yr Author I know for sure that this is called, as I can insert a println in there and it will output to the console
November 25, 201311 yr Yeah...sorry I was having issues getting it to work, but I have gotten past that point. Now I see where it is you are having issues, but my thought would be to use a block as the beam instead of an entity? I would make try to mimic how the redstone works when it is placed. Or is there a specific reason for using an entity?
November 25, 201311 yr Author So you know where the problem lies with the entity? I was originally going to use a tileentity for this, but then i also want it to go through transparent surfaces, e.g glass.. so an entity seemed like a better solution. If i cant get it to work ill go back to a tileentity and just make it only go through air.
November 25, 201311 yr So actually it appears that it is working...it spawns the entity; however the spawn location is clear up in the clouds. Inside TileEntityItemLaster.java: Change: entity.setPosition(xCoord, yCoord + i, zCoord); To: entity.setPosition(xCoord, i, zCoord);
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.