public void AddRenderer(Map map)
{ map.put(JWorld_AnibusEntity.class, new JWorld_AnibusRender(new JWorld_AnibusModel(), 0.5F));
}
The above are underlined as warning's in my Eclipse and the warning is: "Map is a raw type. References to generic type Map<K,V> should be parameterized."
And worldObj in the "public boolean OnTickInGame" has an error "worldObj cannot be resolved into a variable".
Know any fixes and is the warnings ok to go on with?
Most times the warnings are ok. In this case, don't worry about it.
At times you will need to access the Minecraft class or the World class. ModLoader has a way to get at both of these. This code can go anywhere. I do advise you to check if the world object (or others you may take from it) are already pulled from somewhere before bringing it in this way. Don't know how the resources are handled, but less use is better. In anycase, here is the code:
Minecraft mc = ModLoader.getMinecraftInstance();
World worldObj = mc.theWorld;
You should know the mc and worldObj are the variable names holding the class type objects. These names can be whatever you want, but be consistant. Also, if they are to be global in your java file, make sure that you declare them as such.
hmmm, did everything you said and it still doesn't spawn and it doesn't even show up on the spc spawn list.
(But I didn't use the "boolean OnTickInGame")
When I tried adding "boolean OnTickInGame" it gave me this error:
hmmm, did everything you said and it still doesn't spawn and it doesn't even show up on the spc spawn list.
(But I didn't use the "boolean OnTickInGame")
When I tried adding "boolean OnTickInGame" it gave me this error:
I wonder if it is not rendering properly...So it does not show up in-game?
That means that you have already declared mc some where else, or that is the name of the variable passed in the method you added that line to. Change mc to mineC or something else, but I think you could drop this line all together. I've only seen the var mc used for the minecraft class in the standard methods. You can still use the World worldObj = mc.theWrold; line since mc is already defined.
package net.minecraft.src;
import java.util.Map;
public class mod_Anibus extends BaseMod
{
public void JWorldAddMobs()
{
ModLoader.RegisterEntityID(JWorld_AnibusEntity.class, "Anibus",
ModLoader.getUniqueEntityId());
ModLoader.AddSpawn(JWorld_AnibusEntity.class, 100, EnumCreatureType.creature);
}
public void AddRenderer(Map map)
{
map.put(JWorld_AnibusEntity.class, new JWorld_AnibusRender(new JWorld_AnibusModel(), 0.5F));
}
public String Version()
{
return"Anibus V1.1 MC v1.7.3";
}
private boolean didspawn = false;
public boolean OnTickInGame(Minecraft mc)
{
worldObj = mc.theWorld;
EntityPlayer theplayer = mc.thePlayer;
if(theplayer != null && !didspawn) //wait for the player to be made, and then spawn near him
{
//spawn a char near the player
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus", worldObj);
entityliving.setLocationAndAngles(theplayer.posX + 0, theplayer.posY + 1, theplayer.posZ - 4, 0F, 0F); //x, y, z, yaw, pitch
worldObj.entityJoinedWorld(entityliving);
didspawn = !didspawn;
}
}
}
@Inlanoche....I crave to know the custom animations *drools* (Dont rush the tutorial through though!)
Ah, instead of having the line:
public void JWorldAddMobs()
Put this instead:
public mod_Anibus()
This procedure needs to be titled the same as the class name (mod_Anibus in this case) because it acts as the constructor function.
Also, inside the newly named procedure add this line: (anywhere inside, doesn't matter)
ModLoader.SetInGameHook(this, true, false);
The hook is needed to activate ModLoader functions such as OnTickInGame(..).
Keystroke Comands and Entity Control
So, right now, if I wanted my flything to fly up, I have to have a stick in my hand and activate it. Well, that kind of sucks, doesn't it? Why not just press a key to make him fly up? I could easily map it so that when you move, he goes up a bit, and when you stop he floats down, but this mighty make controlling him... not so fun... So instead, let's map the space bar to making him fly up. This will take a bit of prep work to get it going. We start in your main Java file, which in my case is mod_JWorld.java. BTW, I notice alot of code postings with JWorld in them. I really don't mind, but you should do more than just copy and paste with these tutorials. To learn it, you need to make it your own. That said, we need to add something to my mod_JWorld.java constructor:
ModLoader.SetInGameHook(this, true, false);
Don't ask me what this is for. Those that know the java lingo should understand it. You need it, let's leave it at that.
Now, I will let you in on something I do. It may not be the best practice, but I tend to like to keep the various parts of a chunk of coding together. You can add methods and global variables anywhere outside of the methods (but inside the class definition). So here I define 2 variables right before the methods for the key handling. I also surround them with comments so I can tell where this snippit starts and ends:
//register Key Clicks-----------------------
private KeyBinding powerKey = new KeyBinding("key.power", 57); //tied to spacebar (see KeyboardKEY.png file)
public static int keyDoes = 0;
public void JWorldKeyBind()
{
ModLoader.RegisterKey(this, this.powerKey, false);
ModLoader.AddLocalization("key.power", "Power key"); //key for entity Action
}
public void KeyboardEvent(KeyBinding keybinding)
{
keyDoes = 0; //reset the key
if(keybinding == this.powerKey)
{
keyDoes = 1; //this will be the entity action key
}
}
//end register Key Clicks--------------------
the private var is to set up the key binding to a keybinding class. This object is called powerKey. It needs 2 vars, a string for it's name, and and int for the key being pressed. This is the layout:
So 57 is tied to the spacebar. The public var keyDoes is something that I can use to check which key, of the ones I define, is currently being used. For our powerKey, we can set this var to 1. Maybe we'll add a powerdownKey, and make that 2. And so on.
Now let's go to the entity and use this value. I am going to use it for my flything to make it fly up. Let's go to the Entity file.
I'm not sure if I showed this before so I will go over it again. I have created a global var public boolean leap;. This will start as false (set in the constructor). We use this to tell the entity when to leap or fly up. We do this in our onLivingUpdate method like so:
These are the first lines in my onLivingUpdate code. I will show the complete code later. So when mod_JWord.keyDoes == 1 (the spacebar is pressed) we want leap to be true. We also want to reset mod_JWorld.keyDoes to 0, or it will keep leaping. Also note that I call this before super.onLivingUpdate. I want this check before the regular code is run (such as handling movement and such).
So now it knows when to leap, we need it to leap! Following the flow of this mob's behavour, we only want this to happen when it is being ridden by the player. If not, when ever you hit the spacebar to jump, all of these entities would leap.
So now we look at another super class method, moveEntity:
public void moveEntity(double d, double d1, double d2)
{
if(riddenByEntity != null)
{
stationary = true;
this.randomYawVelocity = 0;
this.rotationYaw = riddenByEntity.rotationYaw * 0.1F;
if(leap)
{//have it fly up a bit
motionX += riddenByEntity.motionX*6;
motionZ += riddenByEntity.motionZ*6;
motionY += 1F;
leap = false;
}else
{//regular run on the ground movement
motionX += riddenByEntity.motionX*8;
motionZ += riddenByEntity.motionZ*8;
if(onGround)
{
motionY = 0; //for some reason it likes to hop
}
}
if(isCollidedHorizontally)
{
motionY += 0.15F; //allows it to drift up if you are hitting an obstacle in front of you
}
super.moveEntity(motionX, motionY, motionZ);
}else
{
stationary = false;
super.moveEntity(d, d1, d2);
}
}
The first thing we do is to check if it's being ridden. Note that if you follow this if to it's else statement, we run the super.moveEntity(). If we didn't do that, the moveEntity (from the super class) would not run, and this mob would not move.
That asside, in our code here, we check if leap is true. If it is (following the train that pressing space makes keyDoes =- 1, which makes leap == true) then we adjust the motion, in this case adding to motionY.
You could easily reduce the increase to motionY, or make it a set value (= not +=) and make it so that as you hold the spacebar, you have a gentle drift up motion.
Now here is the full entity code. PLEASE NOTE: I have put in a custom flap animation, which uses my previous custom animations tutorial to make the wings flap as I want them to. Don't just copy/paste this whole thing.
One more note to this. I am finding that sometime it does not register the new key right way. Some times I have had to delete my save games, restart minecraft then it would work. Can't tell you why, but I have gotten it to work.
moveSpeed = float; : This seems to be a percentage of speed. 0.1 being 10%, 1 being 100%. I have set this over 1F (to 10F), but it did not seem to make a difference. This max speed (1) is still slower than the player
moveSpeed = 0.5F;
This is wrong..
I have made a mob with moveSpeed = 25F and it went very fast much faster than the player.
How would one go about getting a mob to create a line between it and say the player if the player is in its line of sight? By line I mean sort of the one the fishing rod uses. It would be more of a visual effect of showing where the mob is, as I have gotten my mob to slow the players motion down when the player is within range, and within the mobs line of sight.
This is wrong..
I have made a mob with moveSpeed = 25F and it went very fast much faster than the player.
Hmmm.. will have to revisit this. Thanks for the info. Do you know what mark is the player's speed? I guess I'll have to check the entities and edit my post...
Arggg >.<, I got everything working besides making it spawn but it doesnt spawn, so now i do this and i got errors....again, Help please...
It keeps referring to WorldObj and Class Minecraft...
Recompile Log
== ERRORS FOUND ==
src\minecraft\net\minecraft\src\mod_Anibus.java:31: cannot find symbol
symbol : class Minecraft
location: class net.minecraft.src.mod_Anibus
public boolean OnTickInGame(Minecraft mc)
^
src\minecraft\net\minecraft\src\mod_Anibus.java:33: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
worldObj = mc.theWorld;
^
src\minecraft\net\minecraft\src\mod_Anibus.java:38: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus
", worldObj);
^
src\minecraft\net\minecraft\src\mod_Anibus.java:40: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
worldObj.entityJoinedWorld(entityliving);
^
4 errors
Main mod file
package net.minecraft.src;
import java.util.Map;
public class mod_Anibus extends BaseMod
{
public mod_Anibus()
{
ModLoader.RegisterEntityID(JWorld_AnibusEntity.class, "Anibus",
ModLoader.getUniqueEntityId());
ModLoader.SetInGameHook(this, true, false);
ModLoader.AddSpawn(JWorld_AnibusEntity.class, 100, EnumCreatureType.creature);
}
public void AddRenderer(Map map)
{
map.put(JWorld_AnibusEntity.class, new JWorld_AnibusRender(new JWorld_AnibusModel(), 0.5F));
}
public String Version()
{
return"Anibus V1.1 MC v1.7.3";
}
private boolean didspawn = false;
public boolean OnTickInGame(Minecraft mc)
{
worldObj = mc.theWorld;
EntityPlayer theplayer = mc.thePlayer;
if(theplayer != null && !didspawn) //wait for the player to be made, and then spawn near him
{
//spawn a char near the player
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus", worldObj);
entityliving.setLocationAndAngles(theplayer.posX + 0, theplayer.posY + 1, theplayer.posZ - 4, 0F, 0F); //x, y, z, yaw, pitch
worldObj.entityJoinedWorld(entityliving);
didspawn = !didspawn;
}
}
}
Are you sure your reading the error log right? Its referring to something else >.<
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
Arggg >.<, I got everything working besides making it spawn but it doesnt spawn, so now i do this and i got errors....again, Help please...
It keeps referring to WorldObj and Class Minecraft...
Recompile Log
== ERRORS FOUND ==
src\minecraft\net\minecraft\src\mod_Anibus.java:31: cannot find symbol
symbol : class Minecraft
location: class net.minecraft.src.mod_Anibus
public boolean OnTickInGame(Minecraft mc)
^
src\minecraft\net\minecraft\src\mod_Anibus.java:33: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
worldObj = mc.theWorld;
^
src\minecraft\net\minecraft\src\mod_Anibus.java:38: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus
", worldObj);
^
src\minecraft\net\minecraft\src\mod_Anibus.java:40: cannot find symbol
symbol : variable worldObj
location: class net.minecraft.src.mod_Anibus
worldObj.entityJoinedWorld(entityliving);
^
4 errors
Main mod file
package net.minecraft.src;
import java.util.Map;
public class mod_Anibus extends BaseMod
{
public mod_Anibus()
{
ModLoader.RegisterEntityID(JWorld_AnibusEntity.class, "Anibus",
ModLoader.getUniqueEntityId());
ModLoader.SetInGameHook(this, true, false);
ModLoader.AddSpawn(JWorld_AnibusEntity.class, 100, EnumCreatureType.creature);
}
public void AddRenderer(Map map)
{
map.put(JWorld_AnibusEntity.class, new JWorld_AnibusRender(new JWorld_AnibusModel(), 0.5F));
}
public String Version()
{
return"Anibus V1.1 MC v1.7.3";
}
private boolean didspawn = false;
public boolean OnTickInGame(Minecraft mc)
{
worldObj = mc.theWorld;
EntityPlayer theplayer = mc.thePlayer;
if(theplayer != null && !didspawn) //wait for the player to be made, and then spawn near him
{
//spawn a char near the player
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus", worldObj);
entityliving.setLocationAndAngles(theplayer.posX + 0, theplayer.posY + 1, theplayer.posZ - 4, 0F, 0F); //x, y, z, yaw, pitch
worldObj.entityJoinedWorld(entityliving);
didspawn = !didspawn;
}
}
}
Are you sure your reading the error log right? Its referring to something else >.<
Here, try making OnTickInGame look like this:
public boolean OnTickInGame(Minecraft mc)
{
World worldObj;
worldObj = mc.theWorld;
EntityPlayer theplayer = mc.thePlayer;
if(theplayer != null && !didspawn) //wait for the player to be made, and then spawn near him
{
//spawn a char near the player
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus", worldObj);
entityliving.setLocationAndAngles(theplayer.posX + 0, theplayer.posY + 1, theplayer.posZ - 4, 0F, 0F); //x, y, z, yaw, pitch
worldObj.entityJoinedWorld(entityliving);
didspawn = !didspawn;
}
return true;
}
I didn't see that worldObj wasn't initialized before, so now there is a line added to create the variable worldObj and as the last line you need the return statement (I should've seen that before, sorry). Since OnTickInGame is supposed to return a boolean, just have it return true or false since it doesn't matter in this case, we just want it to do all the other code before returning.
One last thing, add:
import net.minecraft.client.Minecraft;
At the top of the file with the other imports, the reason for this is that you mod_Anibus file has no idea where to find the Minecraft references in the OnTickInGame procedure without being pointed in the right direction so to speak (because the Minecraft class lies in a separate directory). I hope this fixes everything.
One question though, How do i make it so that he still spawns, but he doesnt spawn like right next to the player. I dont want all my new creatures spawning right there when the player spawns.
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
public boolean OnTickInGame(Minecraft mc)
{
World worldObj;
worldObj = mc.theWorld;
EntityPlayer theplayer = mc.thePlayer;
if(theplayer != null && !didspawn) //wait for the player to be made, and then spawn near him
{
//spawn a char near the player
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Anibus", worldObj);
entityliving.setLocationAndAngles(theplayer.posX + 0, theplayer.posY + 1, theplayer.posZ - 4, 0F, 0F); //x, y, z, yaw, pitch
worldObj.entityJoinedWorld(entityliving);
didspawn = !didspawn;
}
return true;
}
I didn't see that worldObj wasn't initialized before, so now there is a line added to create the variable worldObj and as the last line you need the return statement (I should've seen that before, sorry). Since OnTickInGame is supposed to return a boolean, just have it return true or false since it doesn't matter in this case, we just want it to do all the other code before returning.
One last thing, add:
import net.minecraft.client.Minecraft;
At the top of the file with the other imports, the reason for this is that you mod_Anibus file has no idea where to find the Minecraft references in the OnTickInGame procedure without being pointed in the right direction so to speak (because the Minecraft class lies in a separate directory). I hope this fixes everything.
One last question, are you using Eclipse?
I have to agree with this last statement. A quick screen shot here:
I mouse over my underlined text with the error and it tells me what the problem is. Further more, clicking on create local variable 'worldObj' would actually fix the issue for you.
I reason I keep pushing for eclipse is so that you can help yourself and that (especially for syntax) I don't have to keep checking back here, and I can continue with my learning (yes I am learning this to) and share what I find. The process gets broken up if I have to fix syntax errors and the like. I do feel bad when questions on my thread go unanswered, and Im glad that there are a few like McDog3 that jump in and help out.
From this point on I will not look at compile errors. Really, I have never compiled my code, so I don't have experience doing so.
I have to agree with this last statement. A quick screen shot here:
I mouse over my underlined text with the error and it tells me what the problem is. Further more, clicking on create local variable 'worldObj' would actually fix the issue for you.
I reason I keep pushing for eclipse is so that you can help yourself and that (especially for syntax) I don't have to keep checking back here, and I can continue with my learning (yes I am learning this to) and share what I find. The process gets broken up if I have to fix syntax errors and the like. I do feel bad when questions on my thread go unanswered, and Im glad that there are a few like McDog3 that jump in and help out.
From this point on I will not look at compile errors. Really, I have never compiled my code, so I don't have experience doing so.
Finneee...I will go to eclispe then.....Going to set it up...(brb)
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
One question though, How do i make it so that he still spawns, but he doesnt spawn like right next to the player. I dont want all my new creatures spawning right there when the player spawns.
Simple. Now that you know it spawns, either get rid of the entire OnTickInGame function or just comment it out. Anibus will be spawning but you may have to search for a while to find it. The whole purpose of code inside OnTickInGame was to manuallyspawn it near the player to test that it can actually spawn. Now that it does, that code can be discarded(or commented out in case you want to use it to test other new creatures later on).
And Eclipse really is worth the time learning because it is an invaluable tool, there are plenty of tutorials on using Eclipse for Minecraft modding as well.
I have been modding for a long time but when I recompile my mod it says Map doesnt exist? I have everything like yours except different names and model(I think you can help me without seing my source code aka i dont wanna make it public)
So we can have mobs that are controlled by the player, but is it possible to make a mob that can control the player characters movements by a little bit?
Could anyone help me? The past two days I've been trying to figure out what's wrong with the mob I'm making, I don't get any errors, but he simply doesn't spawn! :sad.gif:
Here are the files I'm working with:
mod_Meatboy.java
// 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.Map;
// Referenced classes of package net.minecraft.src:
// BaseMod, ModLoader, ItemStack, Block,
// Item, EntitySuperMeatboy, ModelSuperMeatboy, EnumCreatureType,
// RenderSuperMeatboy, ItemFood
public class mod_Meatboy extends BaseMod
{
public mod_Meatboy()
{
//Items
ModLoader.AddName(meatboy, "Meatboy");
ModLoader.AddRecipe(new ItemStack(meatboy, 1), new Object[] {
"XX", "XX", Character.valueOf('X'), Block.dirt
});
meatboy.iconIndex = ModLoader.addOverride("/gui/items.png", "/meatboy/rawmeatboy.png");
ModLoader.AddName(meatboy, "Meatboy");
cookedmeatboy.iconIndex = ModLoader.addOverride("/gui/items.png", "/meatboy/cookedmeatboy.png");
ModLoader.AddName(cookedmeatboy, "Cooked Meatboy");
}
public void mod_Meatboy()
{
//Super Meatboy Mob
ModLoader.RegisterEntityID(net.minecraft.src.EntitySuperMeatboy.class, "SuperMeatboy", ModLoader.getUniqueEntityId());
ModLoader.AddSpawn(net.minecraft.src.ModelSuperMeatboy.class, 20, EnumCreatureType.creature);
}
public void AddRenderer(Map map)
{
map.put(net.minecraft.src.EntitySuperMeatboy.class, new RenderSuperMeatboy(new ModelSuperMeatboy(), 1.0F));
}
public String Version()
{
return "Meatboy Mod 1.7.3";
}
public static Item meatboy = (new ItemFood(1000, 10, true)).setItemName("Meatboy");
public static Item cookedmeatboy = (new ItemFood(1001, 15, true)).setItemName("Cooked Meatboy");
}
EntitySuperMeatboy.java
// 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;
// Referenced classes of package net.minecraft.src:
// EntityAnimal, Item, World, NBTTagCompound
public class EntitySuperMeatboy extends EntityAnimal
{
public EntitySuperMeatboy(World world)
{
super(world);
texture = "/meatboy/meatboy.png";
setSize(1.5F, 1.5F);
moveSpeed = 0.8F;
health = 10;
}
public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
super.writeEntityToNBT(nbttagcompound);
}
public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
super.readEntityFromNBT(nbttagcompound);
}
protected String getLivingSound()
{
return "mob.zombie";
}
protected String getHurtSound()
{
return "mob.cowhurt";
}
protected String getDeathSound()
{
return "mob.cowhurt";
}
protected float getSoundVolume()
{
return 0.4F;
}
protected int getDropItemId()
{
return 1256;
}
}
I have been modding for a long time but when I recompile my mod it says Map doesnt exist? I have everything like yours except different names and model(I think you can help me without seing my source code aka i dont wanna make it public)
Might as well get the simplest question answered first, do you have this line somewhere at the top of your file?
Most times the warnings are ok. In this case, don't worry about it.
At times you will need to access the Minecraft class or the World class. ModLoader has a way to get at both of these. This code can go anywhere. I do advise you to check if the world object (or others you may take from it) are already pulled from somewhere before bringing it in this way. Don't know how the resources are handled, but less use is better. In anycase, here is the code:
You should know the mc and worldObj are the variable names holding the class type objects. These names can be whatever you want, but be consistant. Also, if they are to be global in your java file, make sure that you declare them as such.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
More Hostile Dungeon's 1.0
hmmm, did everything you said and it still doesn't spawn and it doesn't even show up on the spc spawn list.
(But I didn't use the "boolean OnTickInGame")
When I tried adding "boolean OnTickInGame" it gave me this error:
Minecraft mc = ModLoader.getMinecraftInstance();
"Duplicate local variable mc" <--Error
___________________________________________________________________________________
I wonder if it is not rendering properly...So it does not show up in-game?
More Hostile Dungeon's 1.0
That means that you have already declared mc some where else, or that is the name of the variable passed in the method you added that line to. Change mc to mineC or something else, but I think you could drop this line all together. I've only seen the var mc used for the minecraft class in the standard methods. You can still use the World worldObj = mc.theWrold; line since mc is already defined.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Ah, instead of having the line:
Put this instead:
This procedure needs to be titled the same as the class name (mod_Anibus in this case) because it acts as the constructor function.
Also, inside the newly named procedure add this line: (anywhere inside, doesn't matter)
The hook is needed to activate ModLoader functions such as OnTickInGame(..).
Hopefully this solves everything.
So, right now, if I wanted my flything to fly up, I have to have a stick in my hand and activate it. Well, that kind of sucks, doesn't it? Why not just press a key to make him fly up? I could easily map it so that when you move, he goes up a bit, and when you stop he floats down, but this mighty make controlling him... not so fun... So instead, let's map the space bar to making him fly up. This will take a bit of prep work to get it going. We start in your main Java file, which in my case is mod_JWorld.java. BTW, I notice alot of code postings with JWorld in them. I really don't mind, but you should do more than just copy and paste with these tutorials. To learn it, you need to make it your own. That said, we need to add something to my mod_JWorld.java constructor:
Don't ask me what this is for. Those that know the java lingo should understand it. You need it, let's leave it at that.
Now, I will let you in on something I do. It may not be the best practice, but I tend to like to keep the various parts of a chunk of coding together. You can add methods and global variables anywhere outside of the methods (but inside the class definition). So here I define 2 variables right before the methods for the key handling. I also surround them with comments so I can tell where this snippit starts and ends:
the private var is to set up the key binding to a keybinding class. This object is called powerKey. It needs 2 vars, a string for it's name, and and int for the key being pressed. This is the layout:
So 57 is tied to the spacebar. The public var keyDoes is something that I can use to check which key, of the ones I define, is currently being used. For our powerKey, we can set this var to 1. Maybe we'll add a powerdownKey, and make that 2. And so on.
Now let's go to the entity and use this value. I am going to use it for my flything to make it fly up. Let's go to the Entity file.
I'm not sure if I showed this before so I will go over it again. I have created a global var public boolean leap;. This will start as false (set in the constructor). We use this to tell the entity when to leap or fly up. We do this in our onLivingUpdate method like so:
These are the first lines in my onLivingUpdate code. I will show the complete code later. So when mod_JWord.keyDoes == 1 (the spacebar is pressed) we want leap to be true. We also want to reset mod_JWorld.keyDoes to 0, or it will keep leaping. Also note that I call this before super.onLivingUpdate. I want this check before the regular code is run (such as handling movement and such).
So now it knows when to leap, we need it to leap! Following the flow of this mob's behavour, we only want this to happen when it is being ridden by the player. If not, when ever you hit the spacebar to jump, all of these entities would leap.
So now we look at another super class method, moveEntity:
The first thing we do is to check if it's being ridden. Note that if you follow this if to it's else statement, we run the super.moveEntity(). If we didn't do that, the moveEntity (from the super class) would not run, and this mob would not move.
That asside, in our code here, we check if leap is true. If it is (following the train that pressing space makes keyDoes =- 1, which makes leap == true) then we adjust the motion, in this case adding to motionY.
You could easily reduce the increase to motionY, or make it a set value (= not +=) and make it so that as you hold the spacebar, you have a gentle drift up motion.
Now here is the full entity code. PLEASE NOTE: I have put in a custom flap animation, which uses my previous custom animations tutorial to make the wings flap as I want them to. Don't just copy/paste this whole thing.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
This is wrong..
I have made a mob with moveSpeed = 25F and it went very fast much faster than the player.
Hmmm.. will have to revisit this. Thanks for the info. Do you know what mark is the player's speed? I guess I'll have to check the entities and edit my post...
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Arggg >.<, I got everything working besides making it spawn but it doesnt spawn, so now i do this and i got errors....again, Help please...
It keeps referring to WorldObj and Class Minecraft...
Recompile Log
Main mod file
Are you sure your reading the error log right? Its referring to something else >.<
Here, try making OnTickInGame look like this:
I didn't see that worldObj wasn't initialized before, so now there is a line added to create the variable worldObj and as the last line you need the return statement (I should've seen that before, sorry). Since OnTickInGame is supposed to return a boolean, just have it return true or false since it doesn't matter in this case, we just want it to do all the other code before returning.
One last thing, add:
At the top of the file with the other imports, the reason for this is that you mod_Anibus file has no idea where to find the Minecraft references in the OnTickInGame procedure without being pointed in the right direction so to speak (because the Minecraft class lies in a separate directory). I hope this fixes everything.
One last question, are you using Eclipse?
One question though, How do i make it so that he still spawns, but he doesnt spawn like right next to the player. I dont want all my new creatures spawning right there when the player spawns.
I have to agree with this last statement. A quick screen shot here:
I mouse over my underlined text with the error and it tells me what the problem is. Further more, clicking on create local variable 'worldObj' would actually fix the issue for you.
I reason I keep pushing for eclipse is so that you can help yourself and that (especially for syntax) I don't have to keep checking back here, and I can continue with my learning (yes I am learning this to) and share what I find. The process gets broken up if I have to fix syntax errors and the like. I do feel bad when questions on my thread go unanswered, and Im glad that there are a few like McDog3 that jump in and help out.
From this point on I will not look at compile errors. Really, I have never compiled my code, so I don't have experience doing so.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Finneee...I will go to eclispe then.....Going to set it up...(brb)
Simple. Now that you know it spawns, either get rid of the entire OnTickInGame function or just comment it out. Anibus will be spawning but you may have to search for a while to find it. The whole purpose of code inside OnTickInGame was to manuallyspawn it near the player to test that it can actually spawn. Now that it does, that code can be discarded(or commented out in case you want to use it to test other new creatures later on).
And Eclipse really is worth the time learning because it is an invaluable tool, there are plenty of tutorials on using Eclipse for Minecraft modding as well.
Before looking any further I see one major problem. In your mod_Meatboy file, take everything inside:
And put it into your other function:
This one acts as the constructor function, so the public void version is never called. Hence why its not spawning, it isn't ever being added!
Might as well get the simplest question answered first, do you have this line somewhere at the top of your file?