This article is intended for advanced users who know how to do the simplest mod for minecraft, and here I try to tell you how to make a new mob that will protect you while standing on the spot.
So here we go:
Create a file mod_BowMan.java which we give our defender unit spawn:
package net.minecraft.src;
public class mod_BowMan extends BaseMod
{
public static final Block BowManEgg = (new BlockBowManEgg(164, 0)).setHardness(0.0F).setResistance(0.0F).setBlockName("BowManegg");
public mod_BowMan()
{
ModLoader.RegisterBlock(BowManEgg);
ModLoader.AddName(BowManEgg, "Bowman Egg");
BowManEgg.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/textures/bowmanegg.png");
ModLoader.AddRecipe(new ItemStack(BowManEgg, 1), new Object[] { "X", Character.valueOf('X'), Block.dirt});
ModLoader.RegisterEntityID(net.minecraft.src.EntityBowMan.class, "entityBowMan", ModLoader.getUniqueEntityId());
}
public String Version()
{
return "Guard Mob Tutorial by Perpetual Motion Team";
}
}
Now create a file EntityBowMan.java
Start-such as in the creation of a neutral mob:
package net.minecraft.src;
import java.util.List;
import java.util.Random;
public class EntityBowMan extends EntityAnimal
{
public EntityBowMan(World world)
{
super(world);
texture = "/mob/char.png";
moveSpeed = 0.0F;
health = 50;
isImmuneToFire = true;
}
But there is a couple of new lines in the code.
The rate of movement of the mob (0.7F - speed of the player, 0.0F - mob stand still), as we have archer, so the speed of 0.
moveSpeed = 0.0F;
Mob life (1 life - half of the heart, player have - 20 lives).
health = 50;
Immune to fire (and lava).
isImmuneToFire = true;
Now we finish.
So mob is not lost:
protected boolean canDespawn()
{
return false;
}
Now it is necessary so that the archer saw basic enemies.
Here in every variable of type "list" data is written to the enemy mob:
package net.minecraft.src;
import java.io.PrintStream;
import java.util.Random;
public class BlockBowManEgg extends Block
{
protected BlockBowManEgg(int i, int j)
{
super(i, j, Material.ground);
}
public int quantityDropped(Random random)
{
return 1;
}
public int tickRate()
{
return 30;
}
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
{
double d = i;
double d1 = j;
double d2 = k;
EntityBowMan entitybowman = new EntityBowMan(world);
entitybowman.setLocationAndAngles(d, d1, d2, world.rand.nextFloat() * 360F, 0.0F);
world.entityJoinedWorld(entitybowman);
}
}
It's simple - by pressing the left mouse button to block break (because that solidity-0) and causing it to spawn an archer.
Only the texture:
The texture of the archer - not needed (the code is entered the standard texture player).
Texture bowmanegg.png - take any file 16 * 16 and throw in a folder in the textures minecraft.jar named bowmanegg.png.
Well, that's the archer ready.
- Valentin.
Sorry for my english, I'm from Russia!
This is vodka, bear and more
I hope I helped you!
lol my NPC Guards code looks close to this wish i found this tut first so i didn't have to figure out how to make a Archer Guard on my own.
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
What are the sound files for human sounds? I am also getting this error:
== MCP v4.4 ==
> Recompiling client...
javac.exe -g -source 1.6 -target 1.6 -classpath "lib/;lib/*;jars/bin/minecraft.j
ar;jars/bin/jinput.jar;jars/bin/lwjgl.jar;jars/bin/lwjgl_util.jar" -sourcepath s
rc/minecraft -d bin/minecraft src/minecraft\com\pclewis\mcpatcher\*.java src/min
ecraft\net\minecraft\client\*.java src/minecraft\net\minecraft\isom\*.java src/m
inecraft\net\minecraft\src\*.java conf/patches/*.java failed.
Return code : 1
== ERRORS FOUND ==
warning: [options] bootstrap class path not set in conjunction with -source 1.6
src\minecraft\net\minecraft\src\EntityBowMan.java:23: error: cannot find symbol
if(playerToAttack == null)
^
symbol: variable playerToAttack
location: class EntityBowMan
src\minecraft\net\minecraft\src\EntityBowMan.java:37: error: cannot find symbol
setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
^
symbol: method setTarget(Entity)
location: class EntityBowMan
src\minecraft\net\minecraft\src\EntityBowMan.java:40: error: cannot find symbol
super.updatePlayerActionState();
^
symbol: method updatePlayerActionState()
src\minecraft\net\minecraft\src\EntityBowMan.java:50: error: no suitable constru
ctor found for EntityArrow(World,EntityBowMan)
EntityArrow entityarrow = new EntityArrow(worldObj, this);
^
constructor EntityArrow.EntityArrow(World,EntityLiving,float) is not applicable
(actual and formal argument lists differ in length)
constructor EntityArrow.EntityArrow(World,double,double,double) is not applicabl
e
(actual and formal argument lists differ in length)
constructor EntityArrow.EntityArrow(World) is not applicable
(actual and formal argument lists differ in length)
4 errors
1 warning
==================
> Done in 4.97 seconds
> Recompiling server...
!! Can not find server sources !!
Press any key to continue . . .
What are the sound files for human sounds? I am also getting this error:
== MCP v4.4 ==
> Recompiling client...
javac.exe -g -source 1.6 -target 1.6 -classpath "lib/;lib/*;jars/bin/minecraft.j
ar;jars/bin/jinput.jar;jars/bin/lwjgl.jar;jars/bin/lwjgl_util.jar" -sourcepath s
rc/minecraft -d bin/minecraft src/minecraft\com\pclewis\mcpatcher\*.java src/min
ecraft\net\minecraft\client\*.java src/minecraft\net\minecraft\isom\*.java src/m
inecraft\net\minecraft\src\*.java conf/patches/*.java failed.
Return code : 1
== ERRORS FOUND ==
warning: [options] bootstrap class path not set in conjunction with -source 1.6
src\minecraft\net\minecraft\src\EntityBowMan.java:23: error: cannot find symbol
if(playerToAttack == null)
^
symbol: variable playerToAttack
location: class EntityBowMan
src\minecraft\net\minecraft\src\EntityBowMan.java:37: error: cannot find symbol
setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
^
symbol: method setTarget(Entity)
location: class EntityBowMan
src\minecraft\net\minecraft\src\EntityBowMan.java:40: error: cannot find symbol
super.updatePlayerActionState();
^
symbol: method updatePlayerActionState()
src\minecraft\net\minecraft\src\EntityBowMan.java:50: error: no suitable constru
ctor found for EntityArrow(World,EntityBowMan)
EntityArrow entityarrow = new EntityArrow(worldObj, this);
^
constructor EntityArrow.EntityArrow(World,EntityLiving,float) is not applicable
(actual and formal argument lists differ in length)
constructor EntityArrow.EntityArrow(World,double,double,double) is not applicabl
e
(actual and formal argument lists differ in length)
constructor EntityArrow.EntityArrow(World) is not applicable
(actual and formal argument lists differ in length)
4 errors
1 warning
==================
> Done in 4.97 seconds
> Recompiling server...
!! Can not find server sources !!
Press any key to continue . . .
i don't know the sound files for the Player but if you delete the get sound methods it will default to the player's sounds. as for your error you messed something up with the first error the rest are just fall back from the first not working. If i could see code i could better help.
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
ok i see what is wrong your just using outdated code. looks as if this tutorial was made for an older minecraft/ before 1.8.1
here is newer code for the update player action state for entities. it is simpler than the other code but will cause your npc to attack all mobs near it.
also replace your attack entity code with the code the skeleton mob uses.
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
ok i see what is wrong your just using outdated code. looks as if this tutorial was made for an older minecraft/ before 1.8.1
here is newer code for the update player action state for entities. it is simpler than the other code but will cause your npc to attack all mobs near it.
This article is intended for advanced users who know how to do the simplest mod for minecraft, and here I try to tell you how to make a new mob that will protect you while standing on the spot.
So here we go:
Create a file mod_BowMan.java which we give our defender unit spawn:
Now create a file EntityBowMan.java
Start-such as in the creation of a neutral mob:
But there is a couple of new lines in the code.
The rate of movement of the mob (0.7F - speed of the player, 0.0F - mob stand still), as we have archer, so the speed of 0.
Mob life (1 life - half of the heart, player have - 20 lives).
Immune to fire (and lava).
Now we finish.
So mob is not lost:
Now it is necessary so that the archer saw basic enemies.
Here in every variable of type "list" data is written to the enemy mob:
Now process the event an attack:
If you know how to program properly, you can change this code to your treatment.
I am explain only one variable:
Time before the next attack (at the time of the skeleton = 30, and we have about 15 times faster).
And finally we finish the ending:
Now we need to make the file BlockBowManEgg.java:
It's simple - by pressing the left mouse button to block break (because that solidity-0) and causing it to spawn an archer.
Only the texture:
The texture of the archer - not needed (the code is entered the standard texture player).
Texture bowmanegg.png - take any file 16 * 16 and throw in a folder in the textures minecraft.jar named bowmanegg.png.
Well, that's the archer ready.
- Valentin.
Sorry for my english, I'm from Russia!
This is vodka, bear and more
I hope I helped you!
P.S Thanks for the correction BeastGamer!
The code will be smaller.
This code is redundant:
This is as well:
I don't mean to come across as a jerk, but this needs a few corrections. Good job for trying though.
Tutorial has been modified.
Screenshot:
This is my last post for today: (
i tried using your code for my mob creation
but it says that
super.updatePlayerActionState(); --> is not identified for the EntityAnimal according to "eclipse suggestion"
any help here?
thanks
link: The Dragon Ball Mod Alpha 1.1
i don't know the sound files for the Player but if you delete the get sound methods it will default to the player's sounds. as for your error you messed something up with the first error the rest are just fall back from the first not working. If i could see code i could better help.
here is newer code for the update player action state for entities. it is simpler than the other code but will cause your npc to attack all mobs near it.
also replace your attack entity code with the code the skeleton mob uses.
Hmm... Can I make it only attack monsters, or at least not the player with an if statement?