I am basing my mod tutorials around 1 main mod_ java file. I will segment the various parts (blocks, items, mobs, etc.) as best I can, but I will be keeping them all managed by 1 mod file. Things you should know:
You will need ModLoader, MCP and Eclipse if you want my help. You can post your recompile errors if you want, but I personal will not attempt to help you. 90% of recompile errors would be picked up by Eclipse. There are easy instructions on setting up Eclipse to work with the MCP.
There are several files talked about as they are created edited. Know what they are:
Main mod_ java file – This is file that extends BaseMod. This is manages all the changes you are adding to you mod. Know what it is, and in this tutorial, what I call it.
Model, Entity, Item, etc. java file – These are the files that will hold your new object definitions. If I say “your mob’s Entity java file” know what that is. If you don’t you need to start at a beginner level tutorial. I may start at the basics, but only because I am starting anew with 1.8
PNG file – your image files. Know where you keep them.
Minecraft.jar or other jar file – Though the working folder with MCP will be the temp\bin\minecraft folder, know that your PNG files must also be placed in your \jars\bin\minecraft.jar in the same folder path. I will go over this once in a tutorial. Please don’t ask about it later on
On your path to creating the greatest mod ever, do some paperwork first. These tutorials are based off of what I will be doing for my mod. I have worked most of it out on paper before starting. Know where you are going with your mod, or Start out with learning, throw that junk to the side and start over when you know what you can do. Modding is not as easy as it may seem, and seems to have a large drop off for those who are not prepared.
This may seem TEXT HEAVY, but less questions get asked this way. If I feel that a video would help the tutorial, I will add one. I will not do a video because you don’t want to read. They take quite a bit of work (to make them proper) and quiet time which I don’t get often (2 kids).
That said, welcome to inLanoche’s Minecraft 1.8 Tutorials.
I will go over this pretty quick. All the downloads can be quite easily googled.
Download:
MCP (Make sure it's for minecraft 1.8)
ModLoader (Make sure it's for minecraft 1.8)
Eclipse (I use Eclipse SDK v3.7.0).
(Also had to install jdk-6u26-windows-i586.exe after Eclipse)
Install Eclipse and then the Java JDK. I created a folder for MCP called MCP1.8.1 and unzipped the MCP files there. There is a doc folder with text files telling you how to get MCP going, as well as how to set the Eclipse workspace for ease of use. LOOK in the DOCs folder. The ModLoader site has instructions on how to get your minecraft.jar prepared for using ModLoader.
The instructions are all there. If you are still having problems, check youtube for setting up modloader. Should find all you need.
So you’ve gotten everything set up, Eclipse is loaded and you have navigated to the proper src folder. Let’s start our mod. In most cases I will have you take an existing java file, save it with a new name and use that as a template, but for this file, we will start fresh. One the Eclipse menu bar, click File>New>File. In the new file window, make sure that your file is being created in the Client>src>net>minecraft>src folder, this is where all your minecraft java files need to be stored.
Now the file name is important. All ModLoader mod files need to start with the prefix “mod_” and this (like you should treat all code) is case sensitive. Also, be sure to put the suffix .java to your file, so Eclipse will treat it like a java file. No shortcuts, do it right the first time. I will be calling my file mod_ILN.java.
One the file is opened it may have stuff in it, it may not (I think some versions of Eclipse will put the basics for a file when it’s created, I will assume that there is not). Remember that my file is called mod_ILN.java, so where I put in mod_ILN, you will put the name of your mod file. Here’s what we start with:
package net.minecraft.src;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.awt.List;
import java.lang.reflect.Constructor;
import java.util.*;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Gui;
import org.lwjgl.opengl.GL11;
import java.awt.Color;
public class mod_ILN extends BaseMod
{
//Must set the String Version string below for all modloader Mods
public String Version()
{
return "ILN v0.1 for Minecraft 1.8.1 w/ ModLoader";
}
//constructor
public mod_ILN()
{
}
}
I might have a few extra imports, but I don’t think they will hurt. Also, later on they may be used. If you don’t know the structure of a Java file, you will need to look it up elsewhere (google it). With ModLoader mods, you need to set your Version. This is the first method listed here. All it needs do is return a string.
At this point you should also notice that I have stuck in some comments. I encourage you to put your own comments, as well as type your own code. This both shows that you are understanding, and can help you to remember what you are doing. I can’t stop you from copy/pasting, but I will pass on my advice.
So now you have your foot in the door. Let’s move on to building a block.
There are 2 steps to building a block. Creating your new block class, and defining it in your mod_ java file. Let’s start by making the block class. We’ll start by opening another block class as an example. Open up BlockStone.java. After opening it, click File>Save As, and give it a new name. I like to keep my mod files together, so I will add the prefix ILN_ to all my java classes. This will be our spawn block later down the road, so I will call my file ILN_BlockSpawner.java. Those of you good boys and girls using Eclipse will notice that the class definition is showing an error. Well the class (and constructor) must match the file name. So let’s change them. In the end it will look like this:
// 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.Random;
// Referenced classes of package net.minecraft.src:
// Block, Material
public class ILN_BlockSpawner extends Block
{
public ILN_BlockSpawner(int i, int j)
{
super(i, j, Material.rock);
}
public int idDropped(int i, Random random)
{
return Block.cobblestone.blockID;
}
}
So we have made a block that has the material properties of Material.rock, and will drop a Block.cobblestone.blockID when broken. Though this is a head of its time, let’s change the object returned in idDropped() to :
return mod_ILN.ILNSpawner.blockID;
What? Errors? Well, we have not yet defined ILNSpawner in mod_ILN (that’s what the dot means, ILNSpawner in mod_ILN, and the blockID is a property of ILNSpawner… once it is made). Save this (there will be an x on the file name in the tabs, watch for it) and let’s go back to your main mod_ java file. At this point I will start to separate out the various additions our mod will be making. I do this by creating methods with “pockets” of like data around them. You can do this how you want, but this is how I will be doing it. So first off, let’s add a method call in our constructor:
//constructor
public mod_ILN()
{
//Calls to methods for various setups:
MakeBlocks();
}
Now I will also throw in a lot of commenting, so that later down the road, I won’t have to come back here myself to remember how to make a simple block. I also comment the beginning and the end of this “pocket” of data. This keeps it apart from the other stuff, so I have all the components to making a block together. Also (from FAQ styles) I put TAGs so that if this code does get big, I can do a FIND to get to my various pockets. So here is my first block definition:
//***BLCK101:START Block definition code--------------------------------------
//first define the global object for the new block
/*HINTS:
* ex:
* public static Block aBlock = (new aBlockClass(BlockID, Index for image on Terrain.png)).setBlockName("aBlock");
* look at Block.java to see .set methods available. .setBlockName("") is required
* can replace image by adding this line:
* aBlock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/16x16Image.png");
*/
public static Block ILNSpawner = (new ILN_BlockSpawner(200, 16)).setHardness(0.2F).setStepSound(Block.soundStoneFootstep).setBlockName("ILNSpawner");
//register the new blocks and add their names to the game
private void MakeBlocks()
{
ModLoader.RegisterBlock(ILNSpawner);
ModLoader.AddName(ILNSpawner, "ILNSpawner Block"); //the name that shows in the game
}
//***END Block definition code------------------------------------------------
So we define ILNSpawner (or if you are looking at all the code globally mod_ILN.ILNSpawer) here with a blockID of 200, an image index (on Terrian.png) of 16, a hardness of 0.2F, and so on. Notice that this is a global public variable definition (which is what allows it to be seen by other java files). Again, if you don’t know about the structure of java files, I would suggest looking it up, I will not go into depth on it. So after we define our Block object, we then create a method that ties things back to minecraft with some ModLoader hooks. We register the block, and we give it an name that will be displayed in game.
You may also notice that when you save this file, the red flag on your spawnblock code will disappear. The power of Eclipse. A quick hint here, again a nice touch from Eclipse, is that if you want to see other properties you can “set” for you block, go to the end of the public static definition, and before the “;” at the end type in a “.” and wait a sec. Eclipse will list off all of the property’s and methods associated with the Block class. It also gives you the types, if any, of variables that need to be passed. Nice!
You would most likely be most interested in the “.set” methods. I added the .setLightValue(1F) to mine to make it glow at night.
Well, we have define the block, but not have given it a way to find it in the game. There are 2 ways to do this (that I know of). I will show you both, though I fine the recipe way easier to see happen. First I will show you how to have it generate (as veins like ore, gold, coal, etc.). For a spawn block, you may want to leave this out, but I will still show you how it is done. Let’s go back to our main mod_ java file. Below our Block “pocket”, let’s create a new “pocket” for Surface Generation:
//***WGEN101:START World/Surface Generation definition code-----------------------------
public void GenerateSurface(World world, Random random, int chunkX, int chunkZ)
{
//how much to generate on a 16x16x128 chunk of space in the world
int posX; //16 across
int posY; //128 down
int posZ; //16 deep
int tries = 10;
int vein = 30;
for (int i = 0; i < tries; i++)
{
posX = chunkX + random.nextInt(16); //random x in the chunk from 0 - 15
posY = random.nextInt(30);
posZ = chunkZ + random.nextInt(16);
(new WorldGenMinable(ILNSpawner.blockID, vein)).generate(world, random, posX, posY, posZ);
}
}
//***WGEN101:END World/Surface Generation definition code-----------------------------
This is an existing Method (from BaseMod) so we don’t have to call it. It get’s called on it’s own.
So to go with the game’s definitions, a CHUNK is a 16x16x128 area of space. So every chunk this code wil be run. Things you may want to change are tries (how often it will attempt to create a vein is this chunk) and vein (max length a vein can be). You can also add generation for other block types with this same code.
Next we will create a recipe. First we will add a call to our soon to be recipe making method in the constructor right below the MakeBlocks() call:
MakeRecipes();
I put this section for both smelting and recipes, for now. I seem them as similar. I may be proven wrong later, but let’s leave it for now. This is kind of straight forward. On completion of this recipe we will create a new itemStack of ILNSpawner, holding 1 item. The recipe itself is defined as one object (#) of Block.dirt.
To go into more detail, the creation of the new object is define by a 3x3 matrix. If for instance we wanted this to be created from 9 blocks of dirt (needing a crafting table) the new Objet[] call would look like this:
new Object[]{"###","###","###", Character.valueOf('#'), Block.dirt});
Each row would be separated by a “,”. The # are defined at the end as Block.dirt. So to get fancy, if we wanted this recipe to be defined as an x pattern of dirt, with a sand in the middle, it would look like this:
I would suggest (for sanity) using the first single dirt block. The second example was just to show how it works. The Character value can be whatever you want, but try and be consistent. Before we actually try out the block, let’s make 1 more change to make it stand out (especially if you are testing your generate surface code).
Right now (if you look at terrain.png) we are using the 16th (it starts at 0, going left to right) image on the page, which is the cobblestone image. We don’t want our block to look like cobblestone, so lets add some color to it. Open up your new Block java file, in my case it’s ILN_BlockSpawner.java. I have added 3 more methods to the end. 2 are needed, the last is for fun:
package net.minecraft.src;
import java.util.Random;
// Referenced classes of package net.minecraft.src:
// Block, Material
public class ILN_BlockSpawner extends Block
{
public ILN_BlockSpawner(int i, int j)
{
super(i, j, Material.rock);
}
public int idDropped(int i, Random random)
{
return mod_ILN.ILNSpawner.blockID;
}
public int getRenderColor(int i)
{
//color when it's in your inventory
//Assuming i is the metadata being passed...
return 0xaa33aa; //purple color
}
public int colorMultiplier(IBlockAccess iblockaccess, int i, int j, int k)
{
//color when it is in the world
int l = iblockaccess.getBlockMetadata(i, j, k);
return 0xaa33aa; //purple color
}
public void updateTick(World world, int i, int j, int k, Random random)
{
}
}
So the break down is that I added the methods GetRenderColor(), colorMultiplier() and updateTick(). All 3 are defined in Block.java, so I can reuse them here. The first 2 set the block’s color (by returning a value). Here I have done it by setting a static value, but if you wish, you could do it based on the block’s metadata. If you know what this is, then good. Use it. If not, wait till later on. The last method is a tick update. So if you know what you are doing, you can change the color/texture/other stuff ever so many ticks. I’m not going into that now, but I leave the avenue there for those that want to experiment (check out the BlockRedStoneOre.java).
We are kind of done now. You can hit the green circle white arrow Run Client button in Eclipse and see what you have done. Start a new game, dig up a piece of dirt and craft your block. What? You placed it on the ground then smashed it with your hand and didn’t get the block back? Why is that?
Well, we defined the material as Material.rock, so it will act like a rock material. Ya, it was easy to break, but to “harvest” the block (I hope I’m using that game term right) you need to use a pickaxe, like with all rock types. Changing it to Material.wood would allow you to break it by hand.
That’s it for blocks, for now... Let’s move on to simple Items.
Items can actually be much simpler that creating blocks. Unless you are adding some fancy, you don’t need to create a class, just define it in your main mod_ java file. If it’s an item that is created/smelted, its recipe should also be created. Items have various uses (building material, tools, food), and you should be aware of its overall use before creating it. You may wish them to have several uses.
We are going to make an item that is created from smelting our previously created block (in my case ILNSpawner). We will get to the smelting afterwards, let’s first look at adding a custom texture. The rules about making textures is that they need to be base 2 x base 2. The current size of an image is 16x16 (96 pixels/inch is a must for any size). Also, when overriding the default texture map (which usually has several textures across it) the new texture will have to be the whole image. This is the way it is. So with your favorite graphics program, you can make your own “ingot” or whatever you want your smelted material to look like. Also I will be making a folder to house all the added (non-java) files for my mod. This way you know where all your changes are made. So in my MCP4.4(1.8.1)\temp\bin\minecraft\ folder, I will make a folder called ILN. In this folder I put my new PNG file CustomOre1.PNG. I must also remember to copy my ILN folder into the minecraft.jar file located in \MCP4.4(1.8.1)\jars\bin. Now that we have a texture to use, let’s write up some code. Open your main mod_ java file, in my case, its mod_ILN.java. Lets add a new method call to the constructor. Your constructor (if you are following these vids) should look something like this:
//constructor
public mod_ILN()
{
//Calls to methods for various setups:
MakeBlocks();
MakeRecipes();
MakeItems();
}
Now let’s make the Items “pocket”:
//***ITEM101:START Item definition code---------------------------------------
/*HINTS:
* ex. public static final Item = (new aItemClass(ItemID).setItemName("aItem");
* look at Item.java to see .set methods available. .setItemName("") is required
* can replace image by adding this line with 16x16 PNG file (pixels/inch must be 96):
* aItem.iconIndex = ModLoader.addOverride("/gui/items.png", "/16x16Image.png");
*/
public static final Item SpawnIngot = new Item(8000).setItemName("SpawnIngot ");
private void MakeItems()
{
ModLoader.AddName(SpawnIngot, " Spawn Ingot");
SpawnIngot.iconIndex = ModLoader.addOverride("/gui/items.png", "/ILN/CustomOre1.png");
}
//***END Item definition code-------------------------------------------------
So we have defined our static definition of SpawnIngot, as well as set the name and the iconIndex override in our MakeItems() method. Note the commentation here. I give a sample of the static definition, as well as how to use the override.
Last we can add a smelting recipe in our MakeRecipes() method. Add these lines:
//Smelting here------------------------------------------------
//original examples in FurnaceRecipes.java for blocks:
//addSmelting(Block.oreIron.blockID, new ItemStack(Item.ingotIron));
//OR for Items:
//addSmelting(Item.fishRaw.shiftedIndex, new ItemStack(Item.fishCooked));
ModLoader.AddSmelting(mod_ILN.ILNSpawner.blockID, new ItemStack(mod_ILN.SpawnIngot));
One thing to note, with recipes you can produce several of an object, while smelting can only produce 1. In any case, this is a sample of item and smelting. If you go into your game, make a furnace and smelt your block, it will make this ingot. Give it a try!
So we have a block, but it doesn’t do much right now. There are a few things you could have it do. Make it slippery, bouncy, deal damage when touched or even spawn a creature. Let’s do 2 of these things. We’re going to make any mob that steps on this block bounce up a bit. Also, if you right click on the block we’ll have it spawn a wolf.
First we will add the bounce code. Open up your block java file (in my case it’s ILN_BlockSpawner.java). We will be overriding an existing method. Add this method to your file:
public void onEntityWalking(World world, int i, int j, int k, Entity entity)
{
entity.motionY += 0.75;
}
What this will do is that any mob that “moves” on this block will get a boost of 0.75 to their Y movement. Unfortunately this is only works when the entity on it is walking. Let’s try a more complex check. So we can make this like a trampoline. Delete the onEntityWalking() method, and put these two in its place:
public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity)
{
if((int)entity.posY > j && entity.motionY < 0)
{
entity.motionY = Math.abs(entity.motionY) + 0.25;
}
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
{
float f = 0.5F;
return AxisAlignedBB.getBoundingBoxFromPool((float)i + f, j, (float)k + f, (float)(i + 1) - f, (float)(j + 1) - f, (float)(k + 1) - f);
}
So what we are doing here is first (in onEntityCollidedWithBlock()) checking if the entity is above the block and if the entity is moving down. If that’s the case, take the entity’s motion, covert it to a positive number and increase it. This gives an increasing bounce. Last, for this to work, we have to make sure that the collision bounding box is set. We do this with the second method. I may get into this a bit more later on, but this needs to be set if you want to use the onEntityCollidedWithBlock method. In any case, you can try this out. If you go on top of the block, you will begin to bounce until you get off or die from the impact of the landing.
That was fun, now let’s add some interaction to the block. Let’s start simple with it spawning a wolf when you right click the block. For that we need to add this method:
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
//mobID is String mob name
EntityLiving entityliving = (EntityLiving)EntityList.createEntityInWorld("Wolf", world);
entityliving.setLocationAndAngles(i, j+1, k, world.rand.nextFloat() * 360F, 0.0F);
world.entityJoinedWorld(entityliving);
return true;
}
So when you right click (or Activate) your block in the game, a new EntityLiving ojbect is created (using the entity named Wolf), it's location is set above the block , and it's joined to the world. Pretty simple if you know the commands. I stole this from the block BlockMobSpawner (which points to TileEntityMobSpawner), and made it work for me. :wink.gif:
This would be the end of the beginner stuff. Please make sure you are comfortable with this stuff before moving on. Next we will look at adding a new mob entity.
please never do that again, it's not even funny...
Lanoche, do know the code for making a tamed mob attack hostile mobs (with a gui perhaps) mine just attacks sheeps.. i tried to replace EntityAnimal with EntityMob / EntityCreature didnt worked either.
If you look at my sig, in my 1.7.3 tutorials, I'm sure I got that to work, but if you can wait (might be about a week) I will get to that in the advanced section of my tutorials. I'm hoping to rework that, and mounts, and a few other stuff that I have made better since my first tutorials. Want to start fresh. My sig will change in around a week as well, FYI.
Good work updating your tutorials, especially your main mod (which was a little confusing my first time through). Looking forward to reading the updated mob tutorial when it's posted.
I wasn't sure whether you would still be looking at the other thread so I decided to post in both threads. If you remember in the other thread I talked about a vendor like gui system for my mob, well I believe I have come with system. By using the same code that is used for crafting/workbench, I could create a gui to work the same way and then I could create a java named TradeValues.java with recipes that are different combinations of to work as a currency. So for example let say that the user wants to "buy" a wooden sword they would need 2 and if they wan't to "sell" their wooden sword they would get back 1 instead of 2 due to depreciation. Its not exactly what I wan't but it's a start. And of course I can see some limitations with the same i.e theirs is a limited amount of combinations etc. But it should work for now.
I replied to this in the other thread. I'll still be looking in there till the end of the week. I will be attempting vendor code later down the road, if you can wait. I like your idea, and maybe you could work it in to a GUI (page one you give it the stuff, page 2 you get what you paid for). In anycase, PM me if you want more on this. Try and keep the posts here to the tutorials listed.
Good work updating your tutorials, especially your main mod (which was a little confusing my first time through). Looking forward to reading the updated mob tutorial when it's posted.
Good to hear. Let me know if something is unclear, or just plain wrong. :smile.gif:
Intermediate Tutorials begin here. Please make sure that you have an understanding of the previous tutorials. They will be used going forward.
Creating a Simple Mob Entity
I’m not going to hash out what MOB stands for, you can look that up elsewhere. For now, know that mobs are the creatures that walk around, from chickens to the player, to Ghasts. If they move around and have some sort of AI then it’s a mob. Creating a mob is quite easy, thought there is a bit you can do where it comes to AI. For now, we’ll just make a simple biped. Later we will make it follow you around at a distance of 5 blocks. You may want to make a copy of the char.png file and create your own texture from it, so that your follower is different that you. I just took the original and shifted the HUE to blue skin tone and made the eyes yellow. I called my file char-blue.png and put it in my ILN folder, as well as put a copy (same location) in the minecraft.jar file.
Let’s start with the trusty EntityCow.java file. Open this up and save it as a new java file. I will be using the name ILN_EntityBuddy.java. What ever you set the file name to, be sure to also set the class and constructor methods to the same. I made a few changes in this file. First I changed the texture to point at my new texture. I set the setSize call to match that of the player entity. And I stripped out the drop items and interaction code (including the protected void a(Boolean flag) method, which I’m not sure how it is called, but also makes it drop steaks). It should look something like this:
I also left the cow sounds. Later I hope to go into AudioMod and add my own sounds for our buddy. For now he can sound like a cow. Save this file. We now have an entity class, but now we need to get the game to recognize it, and let us up it in the game.
Let’s go to our main mod_ java file. Add a new line to your constructor:
MakeMobs();
Now move down to some open space and make a new pocket for your mob definitions, like so:
//***MOBS101:START Mob Entity definition code-----------------------------
private void MakeMobs()
{
ModLoader.RegisterEntityID(ILN_EntityBuddy.class, "Buddy", ModLoader.getUniqueEntityId());
}
public void AddRenderer(Map map)
{ //***needed for mobs that use a different Model .java file. If not Mobs will be bipeds
//map.put(JWorld_EntityExample.class, new JWorld_RenderExample(new JWorld_ModelExample(), 0.5F));
}
//***MOBS101:END Mob Entity definition code-----------------------------
I have included what is needed for world spawning, as well as what is needed to allow you change the model from the default Biped. For now, all we need to do is to register it with a String name. I used “Buddy”. If we go back to our Spawn Block, we can change “Wolf” to “Buddy”. When you run the game and activate the spawn block, “Buddy” will appear.
If you want Buddy to spawn regularly like sheep and cows and the lot, we can add another line in the MakeMobs() method like this:
The JavaDocs are your friend, and looking at them tells me that (using one of the 4 formats for the AddSpawn method) I need the String name, the weighted Probability (low number means less chance, try not to use higher than 10), min # of entities to spawn at this point, the max(min and max set the pack size), and the Spawn list to add the entity to. In this case I made it like a standard creature. I first showed the spawn block, because the world generation of spawn often leaves you searching for days. I’ve played games where I ran around the world trying to find sheep so I could make a bed… In any case, I have tested this all and it all works. Now let’s get buddy to follow you…
Since we are still on the intermediate tutorials, I will give you a taste of AI. Nothing special, but let’s get Buddy to follow you around. To do this, we need to run some checks while time runs, or when the entity is updated. So we will look at the onEntityUpdate() method that belongs to the Entity class. Add this method to your entity:
public void onLivingUpdate()
{
super.onLivingUpdate();
Minecraft mc = ModLoader.getMinecraftInstance();
EntityPlayer player = mc.thePlayer;
PathEntity pathentity;
if(player != null)
{
float f = player.getDistanceToEntity(this);
if(f > 5F && f < 18F)
{
pathentity = worldObj.getPathToEntity(this, player, 16F);
}
else
{
pathentity = null;
}
setPathToEntity(pathentity);
}
}
A small bit of code, but there are some things I would like to talk about going forward. First off the line super.onLivingUpdate(). If you don’t know what this means, you need to understand it to go further. This call says:
Although I am overriding the method onLivingUpdate by redefining it here, still run the method from the super class (the class this class is extending, in this case EntityAnimal, taken from the class definition at the top of the file)
If you want to see what is being run, you need to look at the “super” class. In some cases, the super call is run right down to the initial super class, but always follow down the path.
Next I use a ModLoader method to get the minecraft instance. This I’m pretty sure should be left to SP mods. Multiplayer mods should look up the player list in the world object. In this case I am making this for SP mods, and this is of course is simple follow code. Later on (in advanced tutorials) we will look at tying the “pet” to the “owner”, like with the wolf. In anycase, we get the minecraft instance, and from that we can get the player entity.
Now that we have what we need we run a few simple (Entity class) methods. We get the distance between the player and this (our class). We then check if it is between 5 and 18 units. If so, we create a PathEntity. If not the PathEntity is set to null. We then apply the PathEntity object to this entity. What will happen is that any of this mob entity that are within 5 and 18 units of you will begin to follow you. So with your spawn block, you can spawn yourself a little follower army. They won’t fight, we have not given them any instructions on that, but they will follow you if in range.
The JavaDocs are your friend, and looking at them tells me that (using one of the 4 formats for the AddSpawn method) I need the String name, the weighted Probability, min # of entities to spawn at this point, the max, and the Spawn list to add the entity to. In this case I made it like a standard creature. I first showed the spawn block, because the world generation of spawn often leaves you searching for days. I’ve played games where I ran around the world trying to find sheep so I could make a bed… In any case, I have tested this all and it all works. Now let’s get buddy to follow you…
Could you explain the bolded part a bit for me? What does the weighted Probability mean? I think I understand what the min and max entities mean, but to make sure, can you explain that part too?
Could you explain the bolded part a bit for me? What does the weighted Probability mean? I think I understand what the min and max entities mean, but to make sure, can you explain that part too?
Thanks,
-Muserae
Hmmmm.
I believe weighted Probability is the radius around the block it can spawn, so if it's 20, then it will be able to spawn at the block, all the way to 20 blocks away.
Min/Max is the amount one right-click will spawn, set min to 1, and max to 10, and it can spawn 1-10 mobs per click.
I believe weighted Probability is the radius around the block it can spawn, so if it's 20, then it will be able to spawn at the block, all the way to 20 blocks away.
Min/Max is the amount one right-click will spawn, set min to 1, and max to 10, and it can spawn 1-10 mobs per click.
Almost, but not quite. As I understand it the weighted probability is the chance that it will spawn when it's time for the world to generate a new mob. The higher the number the better the chance. I would not set it above 10, as it may impact spawning of other creatures. The min and max are the spawn "pack" definition. min should never be less than 1. max should be relatively low. So if min and max are 1 and 4, then when this mob spawns it will spawn a pack size of 1 to 4 mobs.
This has nothing to do with spawning by the code in my spawn block.
Breaking away from the foreground, let’s focus on some background stuff. This will be the first part of making a fruit tree. What we will do is create the fruit, then when eaten it will drop seeds, which will be used to spawn a tree that produces fruit (instead of saplings). Ah the circle of life. First things first, let’s create a new food item. I’m going to keep this generic, because later we will do some stuff with bits. For now we will create a new java file that extends ItemFood. You can create a new java file and paste this code in there. I called my file ILN_TreeFruit.java:
package net.minecraft.src;
// Referenced classes of package net.minecraft.src:
// ItemBlock, Block, BlockCloth, ItemDye,
// ItemStack
public class ILN_ItemTreeFruit extends ItemFood
{
public ILN_ItemTreeFruit(int i, int j, float f, boolean flag)
{
/* passed vars (taken from ItemFood):
* i - shiftedIndex
* j - healAmount value
* f - field_35428_c (not sure what this does)
* flag - wolf's favourite food... waste...
*/
super(i,j,f,flag);
setMaxDamage(0);
setHasSubtypes(true);
maxStackSize = 30;
}
private int fColor = 0x00ffff;
//stolen from Item.java to reuse it, so item doesn't show damage bar
private int maxDamage;
protected Item setMaxDamage(int i)
{
fColor = i;
return this;
}
public int getColorFromDamage(int i)
{
//use this function (but not i) to set the type of fruit
return 0x00ffff; //cyan color
}
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if(entityplayer.func_35197_b(field_35431_bw))
{
entityplayer.func_35199_b(itemstack, func_35411_c(itemstack));
}
return itemstack;
}
public ItemFood func_35424_o()
{
field_35431_bw = true;
return this;
}
private boolean field_35431_bw;
}
NOTE ON MCP:
Please note that there are some methods and variables that you will come across that have generic names (like func_35424_o() or Boolean field_35431_bw). This is because the team that made the MCP have not figured out a name to be used for these items. As they find them (and you update your MCP) names will fill, and you will have to find where to update your added code. Eclipse makes it easy to find. In this case, let’s say that after you update MCP, it starts giving you an error for the call entityplayer.func_35199_b. Go into the EntityPlayer java file and look for a similar function call (requiring an ItemStack and the output from func_35411_c, which is int – from ItemFood) to find the new name. Since I am taking this from EntityFood, the short cut would be to look there first. In any case it can be done, with a bit of standard research.
This is pretty much the same as the basic ItemFood java code, with a little bit extra The fColor var, and the methods setMaxDamage and getColorFromDamage will be used later, but let’s leave them in there for now. The onItemRightClick method allows the player to eat the fruit (if hungry, I found this out later).
Half way there. Let’s set the definition now in our main mod_ java file. We already have our items pocket, let’s add to it:
//***ITEM101:START Item definition code---------------------------------------
/*HINTS:
* ex. public static final Item = (new aItemClass(ItemID).setItemName("aItem");
* look at Item.java to see .set methods available. .setItemName("") is required
* can replace image by adding this line with 16x16 PNG file (pixels/inch must be 96):
* aItem.iconIndex = ModLoader.addOverride("/gui/items.png", "/16x16Image.png");
*/
public static final Item SpawnIngot = new Item(8000).setItemName("SpawnIngot ");
public static final Item CyanFruit = new ILN_ItemTreeFruit(8001, 3, 0.5F, false).setItemName("CyanFruit").setMaxDamage(0).setIconIndex(14);
private void MakeItems()
{
ModLoader.AddName(SpawnIngot, "Spawn Ingot");
SpawnIngot.iconIndex = ModLoader.addOverride("/gui/items.png", "/ILN/CustomOre1.png");
ModLoader.AddName(CyanFruit, "Cyan Fruit");
}
//***END Item definition code-------------------------------------------------
So we have added our public static definition of CyanFruit. You will notice that using new ILN_ItemFood, there are more variables set. These are carried over from the ItemFood class. The first 2 are important as they set the Item ID and the heal amount. You will also notice that I use the .setMaxDamage() call. This will be used later. As for now, there is no way we will find this in game… yet. In your recipes, you can create your own simple recipe so that you can see it in game. I use this pattern of dirt:
###
So go and make this fruit, and run around a bit to get you hungry then eat it. Next we will make the tree, since the tree is needed before the seeds. You’ll see why.
For use with ModLoader, MCP, and Eclipse
PLEASE READ THIS BEFORE POSTING:
I am basing my mod tutorials around 1 main mod_ java file. I will segment the various parts (blocks, items, mobs, etc.) as best I can, but I will be keeping them all managed by 1 mod file. Things you should know:
Tutorials list and links:
--== Beginner Tutorials ==--
- The Main mod_ Java file
- Building a Block
- Your Block in the Game (Recipe + generation)
- Making a Simple Item ( + smelting)
- Adding Actions For your Block (collision and Activation+mob spawn)
--== Intermediate Tutorials ==--
- Adding a Basic Mob Entity (basic biped + spawning)
- Mob Follow Code (simple AI)
- Creating Fruit (part 1 of creating fruit trees)
- Making a Tree (part 2 of creating fruit trees)
- World Generation and Trees (part 3 of creating fruit trees)
- Seeds and Saplings (part 4 of creating fruit trees)
--== Advanced Tutorials ==--
- Advance Fruit Trees with Metadata(Advanced Trees Part 1)
- Fruit and Seeds (Advanced Trees Part 2)
- Mob with Inventory and GUI
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
I will go over this pretty quick. All the downloads can be quite easily googled.
Download:
MCP (Make sure it's for minecraft 1.8)
ModLoader (Make sure it's for minecraft 1.8)
Eclipse (I use Eclipse SDK v3.7.0).
(Also had to install jdk-6u26-windows-i586.exe after Eclipse)
Install Eclipse and then the Java JDK. I created a folder for MCP called MCP1.8.1 and unzipped the MCP files there. There is a doc folder with text files telling you how to get MCP going, as well as how to set the Eclipse workspace for ease of use. LOOK in the DOCs folder. The ModLoader site has instructions on how to get your minecraft.jar prepared for using ModLoader.
The instructions are all there. If you are still having problems, check youtube for setting up modloader. Should find all you need.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
So you’ve gotten everything set up, Eclipse is loaded and you have navigated to the proper src folder. Let’s start our mod. In most cases I will have you take an existing java file, save it with a new name and use that as a template, but for this file, we will start fresh. One the Eclipse menu bar, click File>New>File. In the new file window, make sure that your file is being created in the Client>src>net>minecraft>src folder, this is where all your minecraft java files need to be stored.
Now the file name is important. All ModLoader mod files need to start with the prefix “mod_” and this (like you should treat all code) is case sensitive. Also, be sure to put the suffix .java to your file, so Eclipse will treat it like a java file. No shortcuts, do it right the first time. I will be calling my file mod_ILN.java.
One the file is opened it may have stuff in it, it may not (I think some versions of Eclipse will put the basics for a file when it’s created, I will assume that there is not). Remember that my file is called mod_ILN.java, so where I put in mod_ILN, you will put the name of your mod file. Here’s what we start with:
I might have a few extra imports, but I don’t think they will hurt. Also, later on they may be used. If you don’t know the structure of a Java file, you will need to look it up elsewhere (google it). With ModLoader mods, you need to set your Version. This is the first method listed here. All it needs do is return a string.
At this point you should also notice that I have stuck in some comments. I encourage you to put your own comments, as well as type your own code. This both shows that you are understanding, and can help you to remember what you are doing. I can’t stop you from copy/pasting, but I will pass on my advice.
So now you have your foot in the door. Let’s move on to building a block.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
There are 2 steps to building a block. Creating your new block class, and defining it in your mod_ java file. Let’s start by making the block class. We’ll start by opening another block class as an example. Open up BlockStone.java. After opening it, click File>Save As, and give it a new name. I like to keep my mod files together, so I will add the prefix ILN_ to all my java classes. This will be our spawn block later down the road, so I will call my file ILN_BlockSpawner.java. Those of you good boys and girls using Eclipse will notice that the class definition is showing an error. Well the class (and constructor) must match the file name. So let’s change them. In the end it will look like this:
So we have made a block that has the material properties of Material.rock, and will drop a Block.cobblestone.blockID when broken. Though this is a head of its time, let’s change the object returned in idDropped() to :
What? Errors? Well, we have not yet defined ILNSpawner in mod_ILN (that’s what the dot means, ILNSpawner in mod_ILN, and the blockID is a property of ILNSpawner… once it is made). Save this (there will be an x on the file name in the tabs, watch for it) and let’s go back to your main mod_ java file. At this point I will start to separate out the various additions our mod will be making. I do this by creating methods with “pockets” of like data around them. You can do this how you want, but this is how I will be doing it. So first off, let’s add a method call in our constructor:
Now I will also throw in a lot of commenting, so that later down the road, I won’t have to come back here myself to remember how to make a simple block. I also comment the beginning and the end of this “pocket” of data. This keeps it apart from the other stuff, so I have all the components to making a block together. Also (from FAQ styles) I put TAGs so that if this code does get big, I can do a FIND to get to my various pockets. So here is my first block definition:
So we define ILNSpawner (or if you are looking at all the code globally mod_ILN.ILNSpawer) here with a blockID of 200, an image index (on Terrian.png) of 16, a hardness of 0.2F, and so on. Notice that this is a global public variable definition (which is what allows it to be seen by other java files). Again, if you don’t know about the structure of java files, I would suggest looking it up, I will not go into depth on it. So after we define our Block object, we then create a method that ties things back to minecraft with some ModLoader hooks. We register the block, and we give it an name that will be displayed in game.
You may also notice that when you save this file, the red flag on your spawnblock code will disappear. The power of Eclipse. A quick hint here, again a nice touch from Eclipse, is that if you want to see other properties you can “set” for you block, go to the end of the public static definition, and before the “;” at the end type in a “.” and wait a sec. Eclipse will list off all of the property’s and methods associated with the Block class. It also gives you the types, if any, of variables that need to be passed. Nice!
You would most likely be most interested in the “.set” methods. I added the .setLightValue(1F) to mine to make it glow at night.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Well, we have define the block, but not have given it a way to find it in the game. There are 2 ways to do this (that I know of). I will show you both, though I fine the recipe way easier to see happen. First I will show you how to have it generate (as veins like ore, gold, coal, etc.). For a spawn block, you may want to leave this out, but I will still show you how it is done. Let’s go back to our main mod_ java file. Below our Block “pocket”, let’s create a new “pocket” for Surface Generation:
This is an existing Method (from BaseMod) so we don’t have to call it. It get’s called on it’s own.
So to go with the game’s definitions, a CHUNK is a 16x16x128 area of space. So every chunk this code wil be run. Things you may want to change are tries (how often it will attempt to create a vein is this chunk) and vein (max length a vein can be). You can also add generation for other block types with this same code.
Next we will create a recipe. First we will add a call to our soon to be recipe making method in the constructor right below the MakeBlocks() call:
MakeRecipes();
Now let’s create our recipes pocket:
I put this section for both smelting and recipes, for now. I seem them as similar. I may be proven wrong later, but let’s leave it for now. This is kind of straight forward. On completion of this recipe we will create a new itemStack of ILNSpawner, holding 1 item. The recipe itself is defined as one object (#) of Block.dirt.
To go into more detail, the creation of the new object is define by a 3x3 matrix. If for instance we wanted this to be created from 9 blocks of dirt (needing a crafting table) the new Objet[] call would look like this:
Each row would be separated by a “,”. The # are defined at the end as Block.dirt. So to get fancy, if we wanted this recipe to be defined as an x pattern of dirt, with a sand in the middle, it would look like this:
I would suggest (for sanity) using the first single dirt block. The second example was just to show how it works. The Character value can be whatever you want, but try and be consistent. Before we actually try out the block, let’s make 1 more change to make it stand out (especially if you are testing your generate surface code).
Right now (if you look at terrain.png) we are using the 16th (it starts at 0, going left to right) image on the page, which is the cobblestone image. We don’t want our block to look like cobblestone, so lets add some color to it. Open up your new Block java file, in my case it’s ILN_BlockSpawner.java. I have added 3 more methods to the end. 2 are needed, the last is for fun:
So the break down is that I added the methods GetRenderColor(), colorMultiplier() and updateTick(). All 3 are defined in Block.java, so I can reuse them here. The first 2 set the block’s color (by returning a value). Here I have done it by setting a static value, but if you wish, you could do it based on the block’s metadata. If you know what this is, then good. Use it. If not, wait till later on. The last method is a tick update. So if you know what you are doing, you can change the color/texture/other stuff ever so many ticks. I’m not going into that now, but I leave the avenue there for those that want to experiment (check out the BlockRedStoneOre.java).
We are kind of done now. You can hit the green circle white arrow Run Client button in Eclipse and see what you have done. Start a new game, dig up a piece of dirt and craft your block. What? You placed it on the ground then smashed it with your hand and didn’t get the block back? Why is that?
Well, we defined the material as Material.rock, so it will act like a rock material. Ya, it was easy to break, but to “harvest” the block (I hope I’m using that game term right) you need to use a pickaxe, like with all rock types. Changing it to Material.wood would allow you to break it by hand.
That’s it for blocks, for now... Let’s move on to simple Items.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Items can actually be much simpler that creating blocks. Unless you are adding some fancy, you don’t need to create a class, just define it in your main mod_ java file. If it’s an item that is created/smelted, its recipe should also be created. Items have various uses (building material, tools, food), and you should be aware of its overall use before creating it. You may wish them to have several uses.
We are going to make an item that is created from smelting our previously created block (in my case ILNSpawner). We will get to the smelting afterwards, let’s first look at adding a custom texture. The rules about making textures is that they need to be base 2 x base 2. The current size of an image is 16x16 (96 pixels/inch is a must for any size). Also, when overriding the default texture map (which usually has several textures across it) the new texture will have to be the whole image. This is the way it is. So with your favorite graphics program, you can make your own “ingot” or whatever you want your smelted material to look like. Also I will be making a folder to house all the added (non-java) files for my mod. This way you know where all your changes are made. So in my MCP4.4(1.8.1)\temp\bin\minecraft\ folder, I will make a folder called ILN. In this folder I put my new PNG file CustomOre1.PNG. I must also remember to copy my ILN folder into the minecraft.jar file located in \MCP4.4(1.8.1)\jars\bin. Now that we have a texture to use, let’s write up some code. Open your main mod_ java file, in my case, its mod_ILN.java. Lets add a new method call to the constructor. Your constructor (if you are following these vids) should look something like this:
Now let’s make the Items “pocket”:
So we have defined our static definition of SpawnIngot, as well as set the name and the iconIndex override in our MakeItems() method. Note the commentation here. I give a sample of the static definition, as well as how to use the override.
Last we can add a smelting recipe in our MakeRecipes() method. Add these lines:
One thing to note, with recipes you can produce several of an object, while smelting can only produce 1. In any case, this is a sample of item and smelting. If you go into your game, make a furnace and smelt your block, it will make this ingot. Give it a try!
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
So we have a block, but it doesn’t do much right now. There are a few things you could have it do. Make it slippery, bouncy, deal damage when touched or even spawn a creature. Let’s do 2 of these things. We’re going to make any mob that steps on this block bounce up a bit. Also, if you right click on the block we’ll have it spawn a wolf.
First we will add the bounce code. Open up your block java file (in my case it’s ILN_BlockSpawner.java). We will be overriding an existing method. Add this method to your file:
What this will do is that any mob that “moves” on this block will get a boost of 0.75 to their Y movement. Unfortunately this is only works when the entity on it is walking. Let’s try a more complex check. So we can make this like a trampoline. Delete the onEntityWalking() method, and put these two in its place:
So what we are doing here is first (in onEntityCollidedWithBlock()) checking if the entity is above the block and if the entity is moving down. If that’s the case, take the entity’s motion, covert it to a positive number and increase it. This gives an increasing bounce. Last, for this to work, we have to make sure that the collision bounding box is set. We do this with the second method. I may get into this a bit more later on, but this needs to be set if you want to use the onEntityCollidedWithBlock method. In any case, you can try this out. If you go on top of the block, you will begin to bounce until you get off or die from the impact of the landing.
That was fun, now let’s add some interaction to the block. Let’s start simple with it spawning a wolf when you right click the block. For that we need to add this method:
So when you right click (or Activate) your block in the game, a new EntityLiving ojbect is created (using the entity named Wolf), it's location is set above the block , and it's joined to the world. Pretty simple if you know the commands. I stole this from the block BlockMobSpawner (which points to TileEntityMobSpawner), and made it work for me. :wink.gif:
This would be the end of the beginner stuff. Please make sure you are comfortable with this stuff before moving on. Next we will look at adding a new mob entity.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
If you look at my sig, in my 1.7.3 tutorials, I'm sure I got that to work, but if you can wait (might be about a week) I will get to that in the advanced section of my tutorials. I'm hoping to rework that, and mounts, and a few other stuff that I have made better since my first tutorials. Want to start fresh. My sig will change in around a week as well, FYI.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
I replied to this in the other thread. I'll still be looking in there till the end of the week. I will be attempting vendor code later down the road, if you can wait. I like your idea, and maybe you could work it in to a GUI (page one you give it the stuff, page 2 you get what you paid for). In anycase, PM me if you want more on this. Try and keep the posts here to the tutorials listed.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Good to hear. Let me know if something is unclear, or just plain wrong. :smile.gif:
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Creating a Simple Mob Entity
I’m not going to hash out what MOB stands for, you can look that up elsewhere. For now, know that mobs are the creatures that walk around, from chickens to the player, to Ghasts. If they move around and have some sort of AI then it’s a mob. Creating a mob is quite easy, thought there is a bit you can do where it comes to AI. For now, we’ll just make a simple biped. Later we will make it follow you around at a distance of 5 blocks. You may want to make a copy of the char.png file and create your own texture from it, so that your follower is different that you. I just took the original and shifted the HUE to blue skin tone and made the eyes yellow. I called my file char-blue.png and put it in my ILN folder, as well as put a copy (same location) in the minecraft.jar file.
Let’s start with the trusty EntityCow.java file. Open this up and save it as a new java file. I will be using the name ILN_EntityBuddy.java. What ever you set the file name to, be sure to also set the class and constructor methods to the same. I made a few changes in this file. First I changed the texture to point at my new texture. I set the setSize call to match that of the player entity. And I stripped out the drop items and interaction code (including the protected void a(Boolean flag) method, which I’m not sure how it is called, but also makes it drop steaks). It should look something like this:
I also left the cow sounds. Later I hope to go into AudioMod and add my own sounds for our buddy. For now he can sound like a cow. Save this file. We now have an entity class, but now we need to get the game to recognize it, and let us up it in the game.
Let’s go to our main mod_ java file. Add a new line to your constructor:
Now move down to some open space and make a new pocket for your mob definitions, like so:
I have included what is needed for world spawning, as well as what is needed to allow you change the model from the default Biped. For now, all we need to do is to register it with a String name. I used “Buddy”. If we go back to our Spawn Block, we can change “Wolf” to “Buddy”. When you run the game and activate the spawn block, “Buddy” will appear.
If you want Buddy to spawn regularly like sheep and cows and the lot, we can add another line in the MakeMobs() method like this:
The JavaDocs are your friend, and looking at them tells me that (using one of the 4 formats for the AddSpawn method) I need the String name, the weighted Probability (low number means less chance, try not to use higher than 10), min # of entities to spawn at this point, the max(min and max set the pack size), and the Spawn list to add the entity to. In this case I made it like a standard creature. I first showed the spawn block, because the world generation of spawn often leaves you searching for days. I’ve played games where I ran around the world trying to find sheep so I could make a bed… In any case, I have tested this all and it all works. Now let’s get buddy to follow you…
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Since we are still on the intermediate tutorials, I will give you a taste of AI. Nothing special, but let’s get Buddy to follow you around. To do this, we need to run some checks while time runs, or when the entity is updated. So we will look at the onEntityUpdate() method that belongs to the Entity class. Add this method to your entity:
A small bit of code, but there are some things I would like to talk about going forward. First off the line super.onLivingUpdate(). If you don’t know what this means, you need to understand it to go further. This call says:
If you want to see what is being run, you need to look at the “super” class. In some cases, the super call is run right down to the initial super class, but always follow down the path.
Next I use a ModLoader method to get the minecraft instance. This I’m pretty sure should be left to SP mods. Multiplayer mods should look up the player list in the world object. In this case I am making this for SP mods, and this is of course is simple follow code. Later on (in advanced tutorials) we will look at tying the “pet” to the “owner”, like with the wolf. In anycase, we get the minecraft instance, and from that we can get the player entity.
Now that we have what we need we run a few simple (Entity class) methods. We get the distance between the player and this (our class). We then check if it is between 5 and 18 units. If so, we create a PathEntity. If not the PathEntity is set to null. We then apply the PathEntity object to this entity. What will happen is that any of this mob entity that are within 5 and 18 units of you will begin to follow you. So with your spawn block, you can spawn yourself a little follower army. They won’t fight, we have not given them any instructions on that, but they will follow you if in range.
When done, your code should look like this:
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
my texture field is defined as so:
I used what the wolf does for multiple textures, like so:
But the texture isn't working; it defaults to the white missing texture thing, every time, even when I have added it correctly. :/
Could you explain the bolded part a bit for me? What does the weighted Probability mean? I think I understand what the min and max entities mean, but to make sure, can you explain that part too?
Thanks,
-Muserae
Hmmmm.
I believe weighted Probability is the radius around the block it can spawn, so if it's 20, then it will be able to spawn at the block, all the way to 20 blocks away.
Min/Max is the amount one right-click will spawn, set min to 1, and max to 10, and it can spawn 1-10 mobs per click.
Almost, but not quite. As I understand it the weighted probability is the chance that it will spawn when it's time for the world to generate a new mob. The higher the number the better the chance. I would not set it above 10, as it may impact spawning of other creatures. The min and max are the spawn "pack" definition. min should never be less than 1. max should be relatively low. So if min and max are 1 and 4, then when this mob spawns it will spawn a pack size of 1 to 4 mobs.
This has nothing to do with spawning by the code in my 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 at the very bottom where you have
Take out the last one:
Speaking of annoying, are you going to introduce Eclipse again? :tongue.gif:
Also cannot read opening posts.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Breaking away from the foreground, let’s focus on some background stuff. This will be the first part of making a fruit tree. What we will do is create the fruit, then when eaten it will drop seeds, which will be used to spawn a tree that produces fruit (instead of saplings). Ah the circle of life. First things first, let’s create a new food item. I’m going to keep this generic, because later we will do some stuff with bits. For now we will create a new java file that extends ItemFood. You can create a new java file and paste this code in there. I called my file ILN_TreeFruit.java:
NOTE ON MCP:
Please note that there are some methods and variables that you will come across that have generic names (like func_35424_o() or Boolean field_35431_bw). This is because the team that made the MCP have not figured out a name to be used for these items. As they find them (and you update your MCP) names will fill, and you will have to find where to update your added code. Eclipse makes it easy to find. In this case, let’s say that after you update MCP, it starts giving you an error for the call entityplayer.func_35199_b. Go into the EntityPlayer java file and look for a similar function call (requiring an ItemStack and the output from func_35411_c, which is int – from ItemFood) to find the new name. Since I am taking this from EntityFood, the short cut would be to look there first. In any case it can be done, with a bit of standard research.
Half way there. Let’s set the definition now in our main mod_ java file. We already have our items pocket, let’s add to it:
So we have added our public static definition of CyanFruit. You will notice that using new ILN_ItemFood, there are more variables set. These are carried over from the ItemFood class. The first 2 are important as they set the Item ID and the heal amount. You will also notice that I use the .setMaxDamage() call. This will be used later. As for now, there is no way we will find this in game… yet. In your recipes, you can create your own simple recipe so that you can see it in game. I use this pattern of dirt:
###
So go and make this fruit, and run around a bit to get you hungry then eat it. Next we will make the tree, since the tree is needed before the seeds. You’ll see why.
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE