Flenix Posted November 23, 2013 Posted November 23, 2013 Hey guys, I've been trying to learn how to make Entities properly. I've been following vswe's tutorial after some advice from IRC users ( ), but when I reached the first test point, there was an issue. In the video he loads up just fine, spawns one and it's all good. However, in mine, the entity only renders when I'm looking at it from a specific angle - anything else and it vanishes. It's a very narrow angle too. I tried continuing the tutorial a little further to see if I'd notice a mistake anywhere, but I didn't. When it came to the second test (mounting the entity), I also couldn't do that, and gave up and cried for help on IRC. No one seemed to know, so posting here! Can anyone spot my mistake? Note, I'm using the supplied Render class (with slight alterations as the 1.6.1 version provided didn't work), and I've tried both the supplied model file and my own one. Here's the classes, let me know if you need anything else. [spoiler=Entity] package co.uk.silvania.roads.entity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; public class EntityBasicCar extends Entity { public EntityBasicCar(World world) { super(world); setSize(4.0F, 2.0F); } @Override public AxisAlignedBB getBoundingBox() { return boundingBox; } @Override public AxisAlignedBB getCollisionBox(Entity entity) { if (entity != riddenByEntity) { return entity.boundingBox; } else { return null; } } @Override public boolean canBeCollidedWith() { return !isDead; } @Override public boolean interactFirst(EntityPlayer player) { if (!worldObj.isRemote && riddenByEntity == null) { player.mountEntity(this); } return true; } @Override public double getMountedYOffset() { return -0.15; } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound nbt) { } @Override protected void writeEntityToNBT(NBTTagCompound nbt) { } } [spoiler=Entity Registry] package co.uk.silvania.roads.entity; import co.uk.silvania.roads.Roads; import cpw.mods.fml.common.registry.EntityRegistry; public class Entities { public static void init() { EntityRegistry.registerModEntity(EntityBasicCar.class, "EntityBasicCar", 0, Roads.instance, 80, 3, true); } } [spoiler=Render] package co.uk.silvania.roads.client.vehicles; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBoat; import net.minecraft.client.renderer.entity.Render; import net.minecraft.util.ResourceLocation; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; import org.lwjgl.opengl.GL11; import co.uk.silvania.roads.entity.EntityBasicCar; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderBasicCar extends Render { private static final ResourceLocation texture = new ResourceLocation("roads", "textures/vehicles/BasicCar.png"); private static final ResourceLocation chargedTexture = new ResourceLocation("roads", "textures/vehicles/BasicCar_red.png"); protected ModelBasicCar model; public RenderBasicCar() { shadowSize = 0.5F; model = new ModelBasicCar(); } public void renderBasicCar(EntityBasicCar car, double x, double y, double z, float yaw, float partialTickTime) { GL11.glPushMatrix(); GL11.glTranslatef((float)x, (float)y, (float)z); GL11.glRotatef(180.0F - yaw, 0.0F, 1.0F, 0.0F); GL11.glScalef(-1.0F, -1.0F, 1.0F); bindEntityTexture(car); model.render(car, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); } @Override public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTickTime) { this.renderBasicCar((EntityBasicCar)entity, x, y, z, yaw, partialTickTime); } protected ResourceLocation getCarTextures(EntityBasicCar entity) { return texture; } @Override protected ResourceLocation getEntityTexture(Entity entity) { return (this.getCarTextures((EntityBasicCar)entity)); //Originally had a check if it was charged here, but as my Entity doesn't have the charged methods yet, I changed it to match "RenderCow" } } [spoiler=My Model (Techne export)] package co.uk.silvania.roads.client.vehicles; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; public class ModelBasicCar extends ModelBase { //fields ModelRenderer Front; ModelRenderer Windscreen; ModelRenderer Wheel_1; ModelRenderer Wheel_2; ModelRenderer Wheel_3; ModelRenderer Wheel_4; ModelRenderer Right; ModelRenderer Back; ModelRenderer Left; ModelRenderer Floor; ModelRenderer Steering_Wheel; ModelRenderer Steering_Column; ModelRenderer Chair_Base; ModelRenderer Chair_Top; ModelRenderer Wiper_Right; ModelRenderer Wiper_Left; public ModelBasicCar() { textureWidth = 512; textureHeight = 512; Front = new ModelRenderer(this, 0, 0); Front.addBox(0F, 0F, 0F, 48, 16, 20); Front.setRotationPoint(-24F, 2F, -32F); Front.setTextureSize(512, 512); Front.mirror = true; setRotation(Front, 0F, 0F, 0F); Windscreen = new ModelRenderer(this, 0, 53); Windscreen.addBox(0F, 0F, 0F, 48, 16, 1); Windscreen.setRotationPoint(-24F, -14F, -13F); Windscreen.setTextureSize(512, 512); Windscreen.mirror = true; setRotation(Windscreen, 0F, 0F, 0F); Wheel_1 = new ModelRenderer(this, 0, 0); Wheel_1.addBox(0F, -4F, -4F, 1, 8, ; Wheel_1.setRotationPoint(-25F, 20F, -21F); Wheel_1.setTextureSize(512, 512); Wheel_1.mirror = true; setRotation(Wheel_1, 0F, 0F, 0F); Wheel_2 = new ModelRenderer(this, 0, 0); Wheel_2.addBox(-1F, -4F, -4F, 1, 8, ; Wheel_2.setRotationPoint(25F, 20F, -21F); Wheel_2.setTextureSize(512, 512); Wheel_2.mirror = true; setRotation(Wheel_2, 0F, 0F, 0F); Wheel_3 = new ModelRenderer(this, 0, 0); Wheel_3.addBox(0F, -4F, -4F, 1, 8, ; Wheel_3.setRotationPoint(-25F, 20F, 35F); Wheel_3.setTextureSize(512, 512); Wheel_3.mirror = true; setRotation(Wheel_3, 0F, 0F, 0F); Wheel_4 = new ModelRenderer(this, 0, 0); Wheel_4.addBox(-1F, -4F, -4F, 1, 8, ; Wheel_4.setRotationPoint(25F, 20F, 35F); Wheel_4.setTextureSize(512, 512); Wheel_4.mirror = true; setRotation(Wheel_4, 0F, 0F, 0F); Right = new ModelRenderer(this, 0, 0); Right.addBox(0F, 0F, 0F, 1, 16, 35); Right.setRotationPoint(-24F, 2F, -12F); Right.setTextureSize(512, 512); Right.mirror = true; setRotation(Right, 0F, 0F, 0F); Back = new ModelRenderer(this, 0, 0); Back.addBox(0F, 0F, 0F, 48, 16, 20); Back.setRotationPoint(-24F, 2F, 23F); Back.setTextureSize(512, 512); Back.mirror = true; setRotation(Back, 0F, 0F, 0F); Left = new ModelRenderer(this, 0, 0); Left.addBox(0F, 0F, 0F, 1, 16, 35); Left.setRotationPoint(23F, 2F, -12F); Left.setTextureSize(512, 512); Left.mirror = true; setRotation(Left, 0F, 0F, 0F); Floor = new ModelRenderer(this, 105, 5); Floor.addBox(0F, 0F, 0F, 46, 1, 35); Floor.setRotationPoint(-23F, 17F, -12F); Floor.setTextureSize(512, 512); Floor.mirror = true; setRotation(Floor, 0F, 0F, 0F); Steering_Wheel = new ModelRenderer(this, 75, 40); Steering_Wheel.addBox(-4F, -4F, -1F, 8, 8, 1); Steering_Wheel.setRotationPoint(14F, 0F, -5.8F); Steering_Wheel.setTextureSize(512, 512); Steering_Wheel.mirror = true; setRotation(Steering_Wheel, 0F, 0F, 0F); Steering_Column = new ModelRenderer(this, 97, 43); Steering_Column.addBox(-1F, -1F, -8F, 2, 2, ; Steering_Column.setRotationPoint(14F, 0F, -6.5F); Steering_Column.setTextureSize(512, 512); Steering_Column.mirror = true; setRotation(Steering_Column, 0.6108652F, 0F, 0F); Chair_Base = new ModelRenderer(this, 0, 80); Chair_Base.addBox(0F, 0F, 0F, 12, 2, 14); Chair_Base.setRotationPoint(8F, 11F, -2F); Chair_Base.setTextureSize(512, 512); Chair_Base.mirror = true; setRotation(Chair_Base, -0.122173F, 0F, 0F); Chair_Top = new ModelRenderer(this, 80, 80); Chair_Top.addBox(0F, -6F, 0F, 12, 20, 2); Chair_Top.setRotationPoint(8F, 0F, 13F); Chair_Top.setTextureSize(512, 512); Chair_Top.mirror = true; setRotation(Chair_Top, -0.2617994F, 0F, 0F); Wiper_Right = new ModelRenderer(this, 0, 100); Wiper_Right.addBox(-20F, 0F, 0F, 20, 1, 1); Wiper_Right.setRotationPoint(-1F, 1F, -13.5F); Wiper_Right.setTextureSize(512, 512); Wiper_Right.mirror = true; setRotation(Wiper_Right, 0F, 0F, 0F); Wiper_Left = new ModelRenderer(this, 0, 97); Wiper_Left.addBox(-20F, 0F, 0F, 20, 1, 1); Wiper_Left.setRotationPoint(20F, 1F, -13.5F); Wiper_Left.setTextureSize(512, 512); Wiper_Left.mirror = true; setRotation(Wiper_Left, 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); Front.render(f5); Windscreen.render(f5); Wheel_1.render(f5); Wheel_2.render(f5); Wheel_3.render(f5); Wheel_4.render(f5); Right.render(f5); Back.render(f5); Left.render(f5); Floor.render(f5); Steering_Wheel.render(f5); Steering_Column.render(f5); Chair_Base.render(f5); Chair_Top.render(f5); Wiper_Right.render(f5); Wiper_Left.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); } } [spoiler=Official Model (not being used right now, provided for completeness)] package example.client; import java.util.ArrayList; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class ModelSpaceship extends ModelBase { private ArrayList<ModelRenderer> parts = new ArrayList<ModelRenderer>(); public ModelSpaceship() { textureWidth = 128; textureHeight = 64; ModelRenderer bot = new ModelRenderer(this, 0, 0); parts.add(bot); bot.addBox( -14, -8, -2, 28, 16, 4, 0.0F); bot.setRotationPoint(0, 4, 0); bot.rotateAngleX = (float)Math.PI / 2F; ModelRenderer side1 = new ModelRenderer(this, 0, 20); parts.add(side1); side1.addBox( -14, -1.5F, -2, 28, 3, 4, 0.0F); side1.setRotationPoint(0, 0, -9); side1.rotateAngleX = (float)Math.PI / 2F; ModelRenderer side2 = new ModelRenderer(this, 0, 20); parts.add(side2); side2.addBox( -14, -1.5F, -2, 28, 3, 4, 0.0F); side2.setRotationPoint(0, 0, 9); side2.rotateAngleX = (float)Math.PI / 2F; ModelRenderer back = new ModelRenderer(this, 0, 27); parts.add(back); back.addBox( -10.5F, -1.5F, -2, 21, 3, 4, 0.0F); back.setRotationPoint(15.5F, 0, 0); back.rotateAngleX = (float)Math.PI / 2F; back.rotateAngleY = (float)Math.PI / 2F; ModelRenderer wing1 = new ModelRenderer(this, 0, 34); parts.add(wing1); wing1.addBox( -13, -0.5F, -4, 26, 1, 8, 0.0F); wing1.setRotationPoint(0, -1, -14); ModelRenderer wing2 = new ModelRenderer(this, 0, 34); parts.add(wing2); wing2.addBox( -13, -0.5F, -4, 26, 1, 8, 0.0F); wing2.setRotationPoint(0, -1, 14); ModelRenderer front = new ModelRenderer(this, 0, 43); parts.add(front); front.addBox( -7.5F, -2.5F, -3, 15, 5, 6, 0.0F); front.setRotationPoint(-16, 1, 0); front.rotateAngleX = (float)Math.PI / 2F; front.rotateAngleY = (float)Math.PI / 2F; ModelRenderer window = new ModelRenderer(this, 0, 54); parts.add(window); window.addBox( -7.5F, -0.5F, -2, 15, 1, 4, 0.0F); window.setRotationPoint(-14.5F, -4, 0); window.rotateAngleX = (float)Math.PI / 2F; window.rotateAngleY = (float)Math.PI / 2F; } public void render(Entity entity, float val1, float val2, float val3, float val4, float val5, float mult) { for (ModelRenderer part : parts) { part.render(mult); } } } [spoiler=Item (to spawn the vehicle)] package co.uk.silvania.roads.entity; import co.uk.silvania.roads.Roads; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ItemBasicCar extends Item { public ItemBasicCar(int id) { super(id); this.setCreativeTab(Roads.tabRoads); } //TODO resource stuff @Override public boolean onItemUseFirst(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) { EntityBasicCar car = new EntityBasicCar(world); car.posX = x + 0.5; car.posY = y + 1.5; car.posZ = z + 0.5; world.spawnEntityInWorld(car); return true; } else { return false; } } } [spoiler=And this is in my client proxy] RenderingRegistry.registerEntityRenderingHandler(EntityBasicCar.class, new RenderBasicCar()); I'm guessing the error is probably due to some sort of change between the version of forge when the video was made, and the version we're using now. Note, I'm still on the previous recommended build (916 I think?) - I didn't want to dive into Gradle until after I've done this. Quote http://s13.postimg.org/z9mlly2av/siglogo.png[/img] My mods (Links coming soon) Cities | Roads | Remula | SilvaniaMod | MoreStats
Flenix Posted November 25, 2013 Author Posted November 25, 2013 Anyone able to help with this? Quote http://s13.postimg.org/z9mlly2av/siglogo.png[/img] My mods (Links coming soon) Cities | Roads | Remula | SilvaniaMod | MoreStats
Flenix Posted November 27, 2013 Author Posted November 27, 2013 Anyone at all? There must be someone who can spot my error? Even just redirecting me to another place I might be able to get help would be great... Quote http://s13.postimg.org/z9mlly2av/siglogo.png[/img] My mods (Links coming soon) Cities | Roads | Remula | SilvaniaMod | MoreStats
GotoLink Posted November 27, 2013 Posted November 27, 2013 if (world.isRemote) { EntityBasicCar car = new EntityBasicCar(world); car.posX = x + 0.5; car.posY = y + 1.5; car.posZ = z + 0.5; world.spawnEntityInWorld(car); Error in server side check. You might want to use Entity#setPosition(double,double,double) Quote
Flenix Posted November 29, 2013 Author Posted November 29, 2013 That fixed it, I just missed the !. That's the second time I've done that in two days, damnit... Thanks Quote http://s13.postimg.org/z9mlly2av/siglogo.png[/img] My mods (Links coming soon) Cities | Roads | Remula | SilvaniaMod | MoreStats
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.