I might have an idea but it is crazy enough to apply, here it goes:
Premise:
My tamed mob only attacks evil mobs on sight and not neutral mobs (EntityAnimal).
So what if I can apply this to coding
1. During my attack on any entityanimal, its normal health would decrease and hence that can be used as a key command
2. Let us say i will do this specifically for a sheep mob
3. on the method updateEntityActionState() i will add this lines
EntitySheep entitysheep = new EntitySheep();
EntityPlayer entityplayer = new EntityPlayer();
if(entitysheep.health < entitysheep.maxhealth && entitysheep.canBeSeen && entitplayer != null)
setTarget(entitysheep);
please comment on this i dont know if this will work :sad.gif:
**I was thinking if there is a possible way to make my Entitymob extend Entitywolf so the function of entitywolf will be carried over to it? (Edit, I tried as expected it crashed minecraft)
**Or can the method alertWolves be placed in my Etitymob class and fashion/customize it in a way that it will work?
*Also i dont comprehend how this piece of code will tell the wolf to attack which ever the player attacks. (I do see isWolfTamed and .owner) so this gives me a clue, but setting wolf settarget as entityliving at the last part of this code seems odd to me :sad.gif:.
Thanks again sir. Hope we can figure a work around for this !!!! :smile.gif:
We, knowing what is called is only half of the answer. You also have to look WHERE it is called. This will tell you what vars a being put to it. If you search the code some more for "alertWolves" you will find it is called in both attackTargetEntityWithCurrentItem(Entity entity) and attackEntityFrom(Entity entity, int i). The former is when you hit an entity, the latter is when you are hit by an entity. What there needs to be is a global entity var called enemy or something like that. Then when you attack, or are attacked, you set this to the entity in question. This could be monitored by your new entity, and when it's not null, there is your target.
Just checking but are you sure (case sensitive) that you defined your new mob as "Cometmob1"? I would think that this would be were the error lies. it would be defined in your main mod_ file with a line like this:
I think it's time I go back to some step by step instructions in this tutorial. The only thing I will assume you have created a model already. You can always use my which will be posted. First we will go over the parts of the entity that are needed. Then the model file. Last will be the render file, with a touch on getting it into the game (in the mod_ file).
But before we start we will need a way to check when the player applies gas or breaks. So we first have to add some stuff to check for key inputs. Luckily ModLoader has hooks for this. now in your constructor for your mod_ java file, you need to add this:
JWorldKeyBind(); //sets up new key bindings
ModLoader.SetInGameHook(this, true, false);
Note that the name JWorldKeyBind() is what I called the method. You can call it whatever you like, but just make sure that you call the KeyBind method and SetInGameHook in your constructor.
//register Key Clicks-----------------------
private KeyBinding power1Key;
private KeyBinding power2Key;
public static int keyIs = 0;
public void JWorldKeyBind()
{
power1Key = new KeyBinding("key.power1", 47); //bind this to v key (47) (see KeyboardKEY.png file)
ModLoader.RegisterKey(this, this.power1Key, false);
ModLoader.AddLocalization("key.power1", "Mount Power1"); //Label the key in the options menu
power2Key = new KeyBinding("key.power2", 48); //bind this to b key (48)
ModLoader.RegisterKey(this, this.power2Key, false);
ModLoader.AddLocalization("key.power2", "Mount Power2"); //Label the key in the options menu
}
public void KeyboardEvent(KeyBinding keybinding)
{
//keyIs = 0; //reset the key
if(keybinding == this.power1Key)
{
keyIs = 1; //this will be the entity action key
return;
}
if(keybinding == this.power2Key)
{
keyIs = 2; //this will be the entity secondary action key
return;
}
//keyIs = 0;
}
//end register Key Clicks--------------------
Going over this quickly, what we did was set keybinding variables to power1Key and power2Key. The ModLoader.AddLocalization add the discription Mount Power1 to the options menu in game. After that we call the keyboardEvent watcher to check for when the key keybinding is passed to see if it equals power1Key or power2Key, if so it sets our int variable to a flagged number. 1 or 2 corresponding to either power 1 or 2 key being pressed. Now that we are watching for the key press let's start on the entity file.
Car Entity file
Waht I did was start again with something pretty generic, the EntityCow. Change the name of the file (and contructor method) and at the bottom we are going to add a few global vars:
public float driveSpeed; //will also manage the wheel rotations
public int carSounder = 8000; //time interval for sound with the car. Should be really high when not running
private float throttle = 0.05F;
these should be self explainitory. You will still, in the constructor, want to set up things like the texture, the setSize(), and even the health. Anything extra I will leave up to you. Next we make an important behavioral change:
protected void updateEntityActionState()
{
}
Normally you'd want your mob to do something while just sitting there. Here we don't. This mob must be controlled. By adding this code, we have nullified the super.updateEntityActionSate() call. When the game engine goes to call this method, nothing will happen.
Next we need to make sure that the rider code is overwriten as well:
Just the basics needed here. Set no motion, check that there is a rider. Now we have to handle the onLivingUpdate():
public void onLivingUpdate()
{
if (riddenByEntity == null)
{
driveSpeed = 0.0F; //stop the wheels going.
carSounder = 8000; //car sounds should be really infrequent
}
if (riddenByEntity != null)
{
carSounder = 5;
if(mod_JWorld.keyIs == 1) //throttle up
{
driveSpeed += throttle;
mod_JWorld.keyIs = 0;
}
if(mod_JWorld.keyIs == 2) //throttle down
{
driveSpeed -= throttle;
mod_JWorld.keyIs = 0;
}
if(Math.abs(rotationYaw - riddenByEntity.rotationYaw) > 3)
{
rotationYaw = riddenByEntity.rotationYaw; //set rotation as you move.
}
moveEntityWithHeading(moveStrafing, moveForward); //values seem to do nothing...
}
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
if(list != null && list.size() > 0)
{
for(int i = 0; i < list.size(); i++)
{
Entity entity = (Entity)list.get(i);
if(entity.canBePushed())
{
entity.applyEntityCollision(this);
if(driveSpeed > 0.3)
{
//should deal damage from collision
}
}
}
}
if(onGround)
{
motionY = 0;
}
}
So basically if there is no rider, set the drive speed to 0, and set the carSound to a long wait number. The latter is your own discression. Now if it's ridden, we get the car sounds going often, and we check if the power keys (set above) are in use. If so, throttle up/down.
Next I do something to help slow the gitter move of my mount code. I check if the difference of the rider's yaw and the mount's yaw. If it's more than 3 degrees (dead space of 6 degrees left to right) then the mount follows the rider's yaw.
We leave in the collision checks, but later we can add damage delt to mob you hit based on your speed, if you want.
Netxt we work on the player interaction. We will change (if you used the EntityCow)the existing interact() method:
public boolean interact(EntityPlayer entityplayer)
{
ItemStack itemstack = entityplayer.inventory.getCurrentItem(); //see what the interacting player is holding
//Should maka e key item, that could be specific to each car.
if(itemstack == null &&(riddenByEntity == null || riddenByEntity == entityplayer))
{
entityplayer.mountEntity(this);
return true;
}
return false;
}
public void mountThis(Entity entity) //use this for mounting from GUI or direct mount
{
if (riddenByEntity == null || riddenByEntity == entity)
{
rotationYaw = entity.rotationYaw;
entity.mountEntity(this); //climb on/get off
}
}
Simplely, if you have nothing in hand and right click this, you will mount it. Because I have often had to call this elsewhere (like in a GUI), so I made my own method for calling the mount code. Also, I force the mount's rotation to match the rider's. Could go the otherway, but might lead to some disorientation. You can do as you please.
last some adjustments to the moveEntity method:
public void moveEntity(double d, double d1, double d2)
{
if(riddenByEntity != null)
{
motionZ = Math.cos(rotationYaw * 0.0174532925) * driveSpeed;
motionX = Math.sin(rotationYaw * 0.0174532925) * -driveSpeed;
if(isCollidedHorizontally) //need to check the height of the collision.
{
motionY += 0.15F; //allows it to drift up if you are hitting an obstacle in front of you
}
super.moveEntity(motionX, motionY, motionZ);
}
}
Here we move based on the heading (trig fun with the yaw and speed). Also, some code to make it go over hills. Right now it will drive up a flat wall. Need to edit this to check the hieght of the obsticle in front of it. For now this works good enough.
That's the important stuff. Here's what my code looks like:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
package net.minecraft.src;
import java.util.List;
// Referenced classes of package net.minecraft.src:
// EntityAnimal, Item, EntityPlayer, InventoryPlayer,
// ItemStack, World, NBTTagCompound
public class JWorld_CarEntity extends EntityLiving
{
public JWorld_CarEntity(World world)
{
super(world);
texture = "/mods/car1.png";
setSize(1F, 0.5F);
//test
driveSpeed = 0F;
}
protected void updateEntityActionState()
{
}
public void updateRidden()
{
if(ridingEntity.isDead)
{
ridingEntity = null;
return;
}
motionX = 0.0D;
motionY = 0.0D;
motionZ = 0.0D;
//onUpdate();
if(ridingEntity == null)
{
return;
}
}
public void onLivingUpdate()
{
if (riddenByEntity == null)
{
driveSpeed = 0.0F; //stop the wheels going.
carSounder = 8000; //car sounds should be really infrequent
}
if (riddenByEntity != null)
{
carSounder = 5;
if(mod_JWorld.keyIs == 1) //throttle up
{
driveSpeed += throttle;
mod_JWorld.keyIs = 0;
}
if(mod_JWorld.keyIs == 2) //throttle down
{
driveSpeed -= throttle;
mod_JWorld.keyIs = 0;
}
if(Math.abs(rotationYaw = riddenByEntity.rotationYaw) > 3)
{
rotationYaw = riddenByEntity.rotationYaw; //set rotation as you move.
}
mod_JWorld.mountYaw = this.rotationYaw;
mod_JWorld.mountSpeed = this.driveSpeed;
mod_JWorld.mountY = (float)this.motionY;
moveEntityWithHeading(moveStrafing, moveForward); //values seem to do nothing...
}
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
if(list != null && list.size() > 0)
{
for(int i = 0; i < list.size(); i++)
{
Entity entity = (Entity)list.get(i);
if(entity.canBePushed())
{
entity.applyEntityCollision(this);
if(driveSpeed > 0.3)
{
//should deal damage from collision
}
}
}
}
if(onGround)
{
motionY = 0;
}
}
public boolean interact(EntityPlayer entityplayer)
{
ItemStack itemstack = entityplayer.inventory.getCurrentItem(); //see what the interacting player is holding
//Should maka e key item, that could be specific to each car.
if(itemstack == null &&(riddenByEntity == null || riddenByEntity == entityplayer))
{
entityplayer.mountEntity(this);
return true;
}
return false;
}
public void moveEntity(double d, double d1, double d2)
{
if(riddenByEntity != null)
{
motionZ = Math.cos(rotationYaw * 0.0174532925) * driveSpeed;
motionX = Math.sin(rotationYaw * 0.0174532925) * -driveSpeed;
if(isCollidedHorizontally) //need to check the height of the collision.
{
motionY += 0.15F; //allows it to drift up if you are hitting an obstacle in front of you
}
super.moveEntity(motionX, motionY, motionZ);
}
}
public void mountThis(Entity entity) //use this for mounting from GUI or direct mount
{
if (riddenByEntity == null || riddenByEntity == entity)
{
rotationYaw = entity.rotationYaw;
entity.mountEntity(this); //climb on/get off
}
}
public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
super.writeEntityToNBT(nbttagcompound);
}
public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
super.readEntityFromNBT(nbttagcompound);
}
public int getTalkInterval()
{
return carSounder;
}
protected String getLivingSound()
{
return "mob.cow";
}
protected String getHurtSound()
{
return "mob.cowhurt";
}
protected String getDeathSound()
{
return "mob.cowhurt";
}
protected float getSoundVolume()
{
return 0.4F;
}
protected int getDropItemId()
{
return Item.leather.shiftedIndex;
}
public float driveSpeed; //will also manage the wheel rotations
public int carSounder = 8000; //time interval for sound with the car. Should be really high when not running
private float throttle = 0.05F;
}
***THIS CURRENT CODE WORKS, BUT A BETTER UPDATE TO THIS IS PLACED HERE:
Model file
For the most part, this will be just like any other model file. The only change will be for managing the wheel rotations. Here is the full code:
Pretty straigh forward if you've done my other tuts. We add one more method, RotateWheels(float f). I kept with thier naming structure, but f will be passed as the new rotation angle for the wheel, or it's spin rotation if you will. Nothing special, just incrementing the rotation by the value passed. Yup done.
The render file
Here's were some new magic happens. I'm going to do 2 things here. You know that I need to manage the wheel rotation, but I'm also going to handle the driving up and down hills/jumping/etc. pitch for the whole mob. This won't affect the rider (as is), but it's good enough to pass along.
Again, I will throw the whole code at you. Now I build my model at half size, so I scale it by 2. IF you built yours to scale, change the scale values to 1:
One thing to point out is that I need to know the model file. So in the constructor, I assign it to a global var called carmodel. Now I can use it where I need it.
You need the preRenderCallback method (or at least this is how it's done elsewhere) to call your new animations. I called my animation method animateCar(). So I check the value of driveSpeed from the entity. Don't want to process the rotate, unless it's rotating. If it is I pass it to the model file. positive for forward, negative for backwards. This is handled in the entity, so we're good.
Next might be something new for most. I watch the entity's motionY. Becuase when it goes up hill the motionY is > 0, when it goes down hill (falling) the motionY is < 0. Now if you watch my vid, even though I try to control the motion, the car shakes a bit. If you watch the motionY of a mob, it bounces below 0. I clocked it at -0.0784, but that's what I could see. Any how, a base the change in pitch off the motionY value, * 90 (tested to get this. Works well). I also make sure that the pitch never goes more than 45 degrees (+/-). So if you fall a long distance, or jump high from a boost or something, it doesn't flip around.
You can always base this off something else, but on a quick fix, this worked well for me.
Last we need to add or mob to the game. I personally don't want it to spawn, so I leave that part out. Instead, I added it to my spawn block(GUI). You can add it any way you want. Heck, make a recipe for it if you'd like. Here is my mod_ java code with my other mobs:
//used to render added MOBs ------------------------------------------------------------------
public void JWorldAddMobs()
{
//ModLoader.RegisterEntityID(JWorld_EntityExample.class, "centuar", ModLoader.getUniqueEntityId());
ModLoader.RegisterEntityID(JWorld_GnomeEntity.class, "gnome", ModLoader.getUniqueEntityId());
myMobList.add("gnome");
ModLoader.RegisterEntityID(JWorld_AnibusEntity.class, "Anibus", ModLoader.getUniqueEntityId());
myMobList.add("Anibus");
ModLoader.RegisterEntityID(JWorld_FlythingEntity.class, "Flything", ModLoader.getUniqueEntityId());
myMobList.add("Flything");
ModLoader.RegisterEntityID(JWorld_HorseEntity.class, "Horse", ModLoader.getUniqueEntityId());
myMobList.add("Horse");
ModLoader.RegisterEntityID(JWorld_DomoEntity.class, "Domo", ModLoader.getUniqueEntityId());
myMobList.add("Domo");
ModLoader.RegisterEntityID(JWorld_CarEntity.class, "Car", ModLoader.getUniqueEntityId());
myMobList.add("Car");
//testing
myMobList.add("Wolf");
myMobList.add("Zombie");
//***this is the spawn rate for exmaple if you put 3 the mobs is very rare to spawn,
//***The EnumCreatureType is what type of mob it is , mobs that you want to spawn in water are "waterCreature", enemies are "monster", and animals are "creature".
ModLoader.AddSpawn(JWorld_GnomeEntity.class, 2, EnumCreatureType.creature);
ModLoader.AddSpawn(JWorld_AnibusEntity.class, 2, EnumCreatureType.creature);
ModLoader.AddSpawn(JWorld_FlythingEntity.class, 2, EnumCreatureType.creature);
ModLoader.AddSpawn(JWorld_HorseEntity.class, 4, EnumCreatureType.creature);
ModLoader.AddSpawn(JWorld_DomoEntity.class, 3, EnumCreatureType.creature);
//ModLoader.AddSpawn(JWorld_CarEntity.class, 3, EnumCreatureType.creature); //no spawn for the car
}
And there you have it. Next post will have a sample vid :wink.gif:
@Inlanoche Hey I got my tameable mob setup and all, he can eat custom items and be healed with custom items, he follows, but i liked to see if you could put up a a tutorial on how to rename mobs, get a healthbar, and possibily a level up/experience system. Yes i know, alot to ask, Im patient so PLEASE dont rush the tutorial to where it doesnt make too much sense o_o, take your time(Kinda like the tameable classes tutorial, I couldnt understand much of it so i did it a different way and it worked out nicely)
Thank you :smile.gif:
EDIT: Someone should seriously make a banner referring to this so we can advertise this on our signatures. It could mean more awesome mods in the future, you never know, this tutorial thread isnt all that popular so not too many people have seen it yet....
Rollback Post to RevisionRollBack
Famous Nyan seed has caves now along with 3 other special maps for MCPE! Check here for downloads: http://tinyurl.com/c75ax6y
src\minecraft\net\minecraft\src\mod_spiders.java:20: error: constructor
RenderSpidermod1 in class RenderSpidermod1 cannot be applied to given types;
map.put(EnntitySpider1.class, new RenderSpidermod1(new ModelSpidermod1(), 0.5F));
required: no arguments
found: ModelSpidermod1,float
reason: actual and formal argument lists differ in length
src\minecraft\net\minecraft\src\ModelSpidermod1.java:15: error: constructor
ModelBase in class ModelBase cannot be applied to given types;
super(1, 0.0F);
required: no arguments
found: int,float
reason: actual and formal argument lists differ in length
2 errors
src\minecraft\net\minecraft\src\mod_spiders.java:20: error: constructor
RenderSpidermod1 in class RenderSpidermod1 cannot be applied to given types;
map.put(EnntitySpider1.class, new RenderSpidermod1(new ModelSpidermod1(), 0.5F));
required: no arguments
found: ModelSpidermod1,float
reason: actual and formal argument lists differ in length
src\minecraft\net\minecraft\src\ModelSpidermod1.java:15: error: constructor
ModelBase in class ModelBase cannot be applied to given types;
super(1, 0.0F);
required: no arguments
found: int,float
reason: actual and formal argument lists differ in length
2 errors
If you need more, I will post required classes.
The more I would ask is to use Eclipse. Seems like (what the error says) is that you have syntax errors in your model file that eclipse would point out:
reason: actual and formal argument lists differ in length
src\minecraft\net\minecraft\src\ModelSpidermod1.java:15: error: constructor
ModelBase in class ModelBase cannot be applied to given types; super(1, 0.0F);
required: no arguments found: int,float reason: actual and formal argument lists differ in length
2 errors
I've followed the "flying" tutorial but that only makes the npcs falling down very slow, but what I wanted was that the npcs fly around like Ghasts could anyone explain please how to do that?
That tutorial on tameble animal, it seems really hard to remove stuff i dont want, like riding.
I want it to be tamed with a specific item, so you can put it on your head and so you can make it follow/stay. Can some one make a entity code like this if its not too hard and i would love you forever and click the button on many of your posts.
It's not really hard to remove the riding code. Just stop it from being accessed. For example. In my code, to mount/ride a mob, you have to click it and then select mount from the GUI. Well, just don't have the IF statement (in the interaction) that allows to mount. I made this class to show numerous things you can do. You can copy the entity class, then delete the stuff you don't want. You will of course (Eclipse helps LOTS in these cases) have to clean up any errors due to referencing these parts.
If you look back at all the classes down the chain of the class extensions, the riding code is there. You just have to turn it on. And by the way, having the mob sit on your head would need the mount code, unless you feel like coding that yourself. I'm sure that is more complex than what I have put together here.
This is the problem I was referring too:
As you can see the npc's name appears inside his head instead of above it. Any help in fix this will be very much appreciated.
could be due to the bounding box (setSize() in constructor ). Is this set to the right size? You could try making the second number larger.
aight I increased the motionY but I wasn't sure where the move coding was, I put it in the public void onLivingUpdate()
So there weren't any errors or anything but the NPC flys straight in the air! 'cause I wanted them to hover over the world a bit and now I'm not sure if I made something wrong or not...
My code:
public void onLivingUpdate()
{
super.onLivingUpdate();
motionY = -0.5;
}
You might try motionY = -1 * motionY;. Might make it bob up and down. Thing is, you need to find out what the gravity is (what is added to motionY each tick) and counter it. It's in the game engine. Well, maybe set the motionY = 0; This would mean it doesn't fall or float up. Then you can run another check to make it go up when needed.
I might have an idea but it is crazy enough to apply, here it goes:
Premise:
My tamed mob only attacks evil mobs on sight and not neutral mobs (EntityAnimal).
So what if I can apply this to coding
1. During my attack on any entityanimal, its normal health would decrease and hence that can be used as a key command
2. Let us say i will do this specifically for a sheep mob
3. on the method updateEntityActionState() i will add this lines
EntitySheep entitysheep = new EntitySheep();
EntityPlayer entityplayer = new EntityPlayer();
if(entitysheep.health < entitysheep.maxhealth && entitysheep.canBeSeen && entitplayer != null)
setTarget(entitysheep);
please comment on this i dont know if this will work :sad.gif:
thanks
link: The Dragon Ball Mod Alpha 1.1
We, knowing what is called is only half of the answer. You also have to look WHERE it is called. This will tell you what vars a being put to it. If you search the code some more for "alertWolves" you will find it is called in both attackTargetEntityWithCurrentItem(Entity entity) and attackEntityFrom(Entity entity, int i). The former is when you hit an entity, the latter is when you are hit by an entity. What there needs to be is a global entity var called enemy or something like that. Then when you attack, or are attacked, you set this to the entity in question. This could be monitored by your new entity, and when it's not null, there is your target.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
link: The Dragon Ball Mod Alpha 1.1
Just checking but are you sure (case sensitive) that you defined your new mob as "Cometmob1"? I would think that this would be were the error lies. it would be defined in your main mod_ file with a line like this:
But instead of "gnome" it should be "Cometmob1" to match your call to create it in the spawn block.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
I think it's time I go back to some step by step instructions in this tutorial. The only thing I will assume you have created a model already. You can always use my which will be posted. First we will go over the parts of the entity that are needed. Then the model file. Last will be the render file, with a touch on getting it into the game (in the mod_ file).
But before we start we will need a way to check when the player applies gas or breaks. So we first have to add some stuff to check for key inputs. Luckily ModLoader has hooks for this. now in your constructor for your mod_ java file, you need to add this:
Note that the name JWorldKeyBind() is what I called the method. You can call it whatever you like, but just make sure that you call the KeyBind method and SetInGameHook in your constructor.
Next we will create the JWorldKeyBind() method as well as the variables to track it and the supporting keyboardEvent() method. Here I create 2 keybindings for keys v and b:
(you can view the keymap here: http://i634.photobucket.com/albums/uu70/jik_ff/keyboardKEYnumbers.png )
Car Entity file
Waht I did was start again with something pretty generic, the EntityCow. Change the name of the file (and contructor method) and at the bottom we are going to add a few global vars:
these should be self explainitory. You will still, in the constructor, want to set up things like the texture, the setSize(), and even the health. Anything extra I will leave up to you. Next we make an important behavioral change:
Normally you'd want your mob to do something while just sitting there. Here we don't. This mob must be controlled. By adding this code, we have nullified the super.updateEntityActionSate() call. When the game engine goes to call this method, nothing will happen.
Next we need to make sure that the rider code is overwriten as well:
Just the basics needed here. Set no motion, check that there is a rider. Now we have to handle the onLivingUpdate():
So basically if there is no rider, set the drive speed to 0, and set the carSound to a long wait number. The latter is your own discression. Now if it's ridden, we get the car sounds going often, and we check if the power keys (set above) are in use. If so, throttle up/down.
Next I do something to help slow the gitter move of my mount code. I check if the difference of the rider's yaw and the mount's yaw. If it's more than 3 degrees (dead space of 6 degrees left to right) then the mount follows the rider's yaw.
We leave in the collision checks, but later we can add damage delt to mob you hit based on your speed, if you want.
Netxt we work on the player interaction. We will change (if you used the EntityCow)the existing interact() method:
Simplely, if you have nothing in hand and right click this, you will mount it. Because I have often had to call this elsewhere (like in a GUI), so I made my own method for calling the mount code. Also, I force the mount's rotation to match the rider's. Could go the otherway, but might lead to some disorientation. You can do as you please.
last some adjustments to the moveEntity method:
Here we move based on the heading (trig fun with the yaw and speed). Also, some code to make it go over hills. Right now it will drive up a flat wall. Need to edit this to check the hieght of the obsticle in front of it. For now this works good enough.
That's the important stuff. Here's what my code looks like:
***THIS CURRENT CODE WORKS, BUT A BETTER UPDATE TO THIS IS PLACED HERE:
UPDATED CAR MOB LINK
(will be set soon)
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Model file
For the most part, this will be just like any other model file. The only change will be for managing the wheel rotations. Here is the full code:
Pretty straigh forward if you've done my other tuts. We add one more method, RotateWheels(float f). I kept with thier naming structure, but f will be passed as the new rotation angle for the wheel, or it's spin rotation if you will. Nothing special, just incrementing the rotation by the value passed. Yup done.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
The render file
Here's were some new magic happens. I'm going to do 2 things here. You know that I need to manage the wheel rotation, but I'm also going to handle the driving up and down hills/jumping/etc. pitch for the whole mob. This won't affect the rider (as is), but it's good enough to pass along.
Again, I will throw the whole code at you. Now I build my model at half size, so I scale it by 2. IF you built yours to scale, change the scale values to 1:
One thing to point out is that I need to know the model file. So in the constructor, I assign it to a global var called carmodel. Now I can use it where I need it.
You need the preRenderCallback method (or at least this is how it's done elsewhere) to call your new animations. I called my animation method animateCar(). So I check the value of driveSpeed from the entity. Don't want to process the rotate, unless it's rotating. If it is I pass it to the model file. positive for forward, negative for backwards. This is handled in the entity, so we're good.
Next might be something new for most. I watch the entity's motionY. Becuase when it goes up hill the motionY is > 0, when it goes down hill (falling) the motionY is < 0. Now if you watch my vid, even though I try to control the motion, the car shakes a bit. If you watch the motionY of a mob, it bounces below 0. I clocked it at -0.0784, but that's what I could see. Any how, a base the change in pitch off the motionY value, * 90 (tested to get this. Works well). I also make sure that the pitch never goes more than 45 degrees (+/-). So if you fall a long distance, or jump high from a boost or something, it doesn't flip around.
You can always base this off something else, but on a quick fix, this worked well for me.
Last we need to add or mob to the game. I personally don't want it to spawn, so I leave that part out. Instead, I added it to my spawn block(GUI). You can add it any way you want. Heck, make a recipe for it if you'd like. Here is my mod_ java code with my other mobs:
And there you have it. Next post will have a sample vid :wink.gif:
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
It says "The method contract(double, double, double) is undefined for the type AxisAlignedBB"
help? It's for the tamable entity part.
That's odd, because if I open up the java file for AxisAlignedBB I can see it:
Check yours.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Not sure what to say... Right now I am doing my tut on vehicles... post your code to set up the mob from your mod_ java file.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Thank you :smile.gif:
EDIT: Someone should seriously make a banner referring to this so we can advertise this on our signatures. It could mean more awesome mods in the future, you never know, this tutorial thread isnt all that popular so not too many people have seen it yet....
src\minecraft\net\minecraft\src\mod_spiders.java:20: error: constructor
RenderSpidermod1 in class RenderSpidermod1 cannot be applied to given types;
map.put(EnntitySpider1.class, new RenderSpidermod1(new ModelSpidermod1(), 0.5F));
required: no arguments
found: ModelSpidermod1,float
reason: actual and formal argument lists differ in length
src\minecraft\net\minecraft\src\ModelSpidermod1.java:15: error: constructor
ModelBase in class ModelBase cannot be applied to given types;
super(1, 0.0F);
required: no arguments
found: int,float
reason: actual and formal argument lists differ in length
2 errors
link: The Dragon Ball Z Mod : Add mobs to your minecraft
Thanks again, a more to you :smile.gif:
link: The Dragon Ball Mod Alpha 1.1
The more I would ask is to use Eclipse. Seems like (what the error says) is that you have syntax errors in your model file that eclipse would point out:
reason: actual and formal argument lists differ in length
src\minecraft\net\minecraft\src\ModelSpidermod1.java:15: error: constructor
ModelBase in class ModelBase cannot be applied to given types;
super(1, 0.0F);
required: no arguments
found: int,float
reason: actual and formal argument lists differ in length
2 errors
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Increase thier motionY when they move.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
It's not really hard to remove the riding code. Just stop it from being accessed. For example. In my code, to mount/ride a mob, you have to click it and then select mount from the GUI. Well, just don't have the IF statement (in the interaction) that allows to mount. I made this class to show numerous things you can do. You can copy the entity class, then delete the stuff you don't want. You will of course (Eclipse helps LOTS in these cases) have to clean up any errors due to referencing these parts.
If you look back at all the classes down the chain of the class extensions, the riding code is there. You just have to turn it on. And by the way, having the mob sit on your head would need the mount code, unless you feel like coding that yourself. I'm sure that is more complex than what I have put together here.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
That's not in mine! I don't know why but it isn't there!
could be due to the bounding box (setSize() in constructor ). Is this set to the right size? You could try making the second number larger.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
You might try motionY = -1 * motionY;. Might make it bob up and down. Thing is, you need to find out what the gravity is (what is added to motionY each tick) and counter it. It's in the game engine. Well, maybe set the motionY = 0; This would mean it doesn't fall or float up. Then you can run another check to make it go up when needed.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE