Thank you so much for these tutorials. They have been helping me so much and thanks for doing the modleader tutorial since I never really understood that.
I'm trying to make a blueprints item that store some part of the world defined by the item user in it and then build a replicate in an empty space.
At least it works but it seems that each blueprint are linked together. They use the same variables and I can't have one storing a tavern for example and another one storing a TNT cannon...
Some items have some values of their own - lifebar for tools - but I don't catch how they instantiate it...
Could someone help me for?
Here's the sourcecode. I don't think it's about functions, more about the constructor...
package net.minecraft.src;
/**
* Summary description for Redprints.
*/
import java.util.Random;
public class ItemRedprints extends Item
{
public ItemRedprints(int i)
{
super(i);
maxStackSize = 1;
Step = 0;
MaxSize = 10;
this.Data = new int[MaxSize][MaxSize][MaxSize];
this.StartBlock = new int[3];
this.EndBlock = new int[3];
this.Size = new int[3];
this.Direction = new byte[3]; // Direction is of no use for now
}
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
{
switch (Step)
{
// // Get the starting spot coordinate and go to Step 2
case 0:
StartBlock[0] = i;
StartBlock[1] = j;
StartBlock[2] = k;
Step = 1;
return true;
// Get the ending spot coordinate. If the size is too huge, reinitialize. If it isn't, save the area between the spots.
case 1:
EndBlock[0] = i;
EndBlock[1] = j;
EndBlock[2] = k;
int roll = 0;
for (int n = 0; n < 3; n++)
{
if (EndBlock[n] > StartBlock[n])
{
Direction[n] = 1;
}
else
{
roll = EndBlock[n];
EndBlock[n] = StartBlock[n];
StartBlock[n] = roll;
Direction[n] = 0;
}
Size[n] = EndBlock[n] - StartBlock[n];
}
// Is the area too huge?
if (Size[0] < MaxSize)
{
if (Size[1] < MaxSize)
{
if (Size[2] < MaxSize)
{
// Getting the area ID.
for (int n1 = 0; n1 < Size[0]; ++n1)
{
for (int n2 = 0; n2 < Size[1]; ++n2)
{
for (int n3 = 0; n3 < Size[2]; ++n3)
{
Data[n1][n2][n3] = world.getBlockId(StartBlock[0] + n1, n2 + StartBlock[1], n3 + StartBlock[2]);
world.setBlockWithNotify(StartBlock[0] + n1, n2 + StartBlock[1],n3 + StartBlock[2], 0);
}
}
}
// Moving to step 3.
Step = 2;
return true;
}
}
}
// Unsuccesful, then go back to step 0.
StartBlock[0] = 0;
StartBlock[1] = 0;
StartBlock[2] = 0;
Step = 0;
world.setBlockWithNotify(StartBlock[0],StartBlock[1],StartBlock[2], Block.wood.blockID);
return false;
//Construction step.
case 2 :
if (l == 0)
{
j--;
}
if (l == 1)
{
j++;
}
if (l == 2)
{
k--;
}
if (l == 3)
{
k++;
}
if (l == 4)
{
i--;
}
if (l == 5)
{
i++;
}
//Seeing if the building area is empty
for (int n1 = 0; n1 < Size[0]; ++n1)
{
for (int n2 = 0; n2 < Size[1]; ++n2)
{
for (int n3 = 0; n3 < Size[2]; ++n3)
{
if (world.getBlockId(n1 + i, n2 + j, n3 + k) != 0)
{
return false;
}
}
}
}
// Then building
for (int n1 = 0; n1 < Size[0]; ++n1)
{
for (int n2 = 0; n2 < Size[1]; ++n2)
{
for (int n3 = 0; n3 < Size[2]; ++n3)
{
world.setBlockWithNotify(n1 + i, n2 + j, n3 + k,Data[n1][n2][n3]);
}
}
}
return true;
default:
Step = 0;
return false;
}
}
private int[][][] Data;
private int MaxSize;
private int[] Size;
private int Step;
private int[] StartBlock;
private int[] EndBlock;
private byte Direction[];
I'm new to Java, Object-Oriented Prog and Modding in general (I've only played with Basic before.) So if someone see something awful, please tell me.
Thx.
Edit :
I've looked into the itemstack.java, it seems that it's the inventory box that is "taking damage" and not the item directly... Then I can't link each blueprint to the dynamic datas, only the whole stuff... Waste of time?
Ok cool idea! Basically "item" and "block" classes are only instantiated ONCE therefore any instance variables that are set would affect all the same blocks/items. The way around this is to use an Entity class. Entity classes can have multiple instances and will achieve what you are after. Although I have not provided a tutorial on this yet, you may use parts of the NPC tutorial to help you.
The downside of using an Entity rather than an Item/Block is that it requires a lot more coding and is more complex :sad.gif:
To change your code to use an entity, create a new entity object where the logic is; in this case "onItemUse". Hope this helps..
Thanks, I have about 6 mods that I need to work out how to combine the bk class so a basic tut on joining would be great! As for the block ids I am pretty sure mod loader doesn't assign them. If I'm understanding the code I am seeing in jd-gui (just learned how to use that), then each modder assigns the the block ids they use under "mod_" class file. This would account for the error with human only pressure plate and controller blocks (as both use id 105). If (and this is a big if) what I just said is right, then what I really need is someone to hold my hand and walk me through how to decompile and recompile someone elses mod. Thanks for all the help in taking the time to help us noobs.
Ah ok. I will write a tutorial in the next few days for this then.
This is the code i used, and it keeps giving me the error above ^^^
package net.minecraft.src;
import java.util.Random;
public class WorldGenExample extends WorldGenerator
{
public WorldGenExample()
{
}
public boolean generate(World world, Random random, int i, int j, int k)
{
}
}
// Gives this a 1 in 10 chance of generating
if (random.nextInt(10) == 0)
{
// Loops 64 times, this could create up to 64 TNT
for (int z = 0; z < 64; z++)
{
int i1 = i + random.nextInt(8) - random.nextInt(8);
int j1 = j + random.nextInt(8) - random.nextInt(8);
int k1 = k + random.nextInt(8) - random.nextInt(8);
// Checks that there is nothing in the current location and there is grass beneath.
if(world.getBlockId(i1, j1, k1) == 0 && world.getBlockId(i1, j1 - 1, k1) == Block.grass.blockID && Block.tnt.canPlaceBlockAt(world, i1, j1, k1))
{
world.setBlockAndMetadata(i1, j1, k1, Block.tnt.blockID, random.nextInt(4));
}
}
}
Im starting to get really mad, iv looked it over, there are no missing brackets, and its what the create a Biome says to do (I hope).
Here is the fixed code... see the difference?
package net.minecraft.src;
import java.util.Random;
public class WorldGenExample extends WorldGenerator
{
public WorldGenExample()
{
}
public boolean generate(World world, Random random, int i, int j, int k)
{
// Gives this a 1 in 10 chance of generating
if (random.nextInt(10) == 0)
{
// Loops 64 times, this could create up to 64 TNT
for (int z = 0; z < 64; z++)
{
int i1 = i + random.nextInt(8) - random.nextInt(8);
int j1 = j + random.nextInt(8) - random.nextInt(8);
int k1 = k + random.nextInt(8) - random.nextInt(8);
// Checks that there is nothing in the current location and there is grass beneath.
if(world.getBlockId(i1, j1, k1) == 0 && world.getBlockId(i1, j1 - 1, k1) == Block.grass.blockID && Block.tnt.canPlaceBlockAt(world, i1, j1, k1))
{
world.setBlockAndMetadata(i1, j1, k1, Block.tnt.blockID, random.nextInt(4));
}
}
}
}
}
Would you happen to have a list of all the texture numbers, i would like to give an item a custom texture, but i can figure out whats used and whats not
The texture numbers come out of textures.png the numbers go from left to right, up to down, starting from 0 going to 255. There are 16 textures per line and 16 lines. Hope this helps.
i just finished making a new block, ore, and custom recipe. testgame won't run and when i checked the compile log thing the ^ symbol is on everything... here is what i have changed
public static Item paper = (new Item(83)).setIconIndex(58);
public static Item RubyOre = (new ItemExample(95)).setIconIndex(13);
public static Item book = (new Item(84)).setIconIndex(59);
(in the middle) this is the item file and yes i made a new texture
oreRedstoneGlowing = (new BlockRedstoneOre(74, 51, true)).setLightValue(0.625F).setHardness(3F).setResistance(5F).setStepSound(soundStoneFootstep);
RubyBlock = (new BlockRubyBlock(92, 106)).setHardness(3F).setResistance(5F).setStepSound(soundStoneFootstep).setLightValue(1.0F);
torchRedstoneIdle = (new BlockRedstoneTorch(75, 115, false)).setHardness(0.0F).setStepSound(soundWoodFootstep);
the block (it's in the middle again) i made a custom texture
all the other codes i put in are exactly copy pasted from yours but with RubyOre or RubyBlock
note; (what i think it might be) if i use the space bar to get to the right adjacent area for coding will that screw things up? i tried pressing tab but it isn't in the right space. i really hope someone will respond i urgently need help
Ok if the ^ character is on everything then there are more generic problems, backup your classes you have changed, then run 'decompile.bat', 'update_names.bat' and then run 'recompile.bat'. See if this results in any errors, if it does please post some of the errors here and I will try and help you out.
i tried to just finish it off and add it to the game and see if it works and when i run reobf or whatever it's called this is what came up...
Minecraft coder pack version 2.5
MCP 2.5 running in C:\MCP
+obfuscating client
Traceback (most recent call last):
File "obfuscathon.py", line 89, in <module>
File "obfuscathon.py", line 65, in main
File def_project.pyc", line 229,in normlize_mapping_table
File "def_project.pyc", line 79, in get_classesref
KeyError: 'net/minecraft/src/Block'
that repeats twice i know that it has something to do with Block but i can't figure out what someone plz help
edit: there was no clent_conf file so i added that in myself, does that matter?
Those errors are due to class files not found - this is USUALLY ok. You need to compile the classes first BEFORE running reobf.bat though.
There should be a file:
/conf/client_obfuscation.txt
If this doesn't exist then I guess you should add it in then...
This is a very helpful guide to anyone willing to become a Minecraft modder! Thanks to this guide I have built my first mod, "The Velvokay Food Variety Mod".
hy i have problem with new npc/item adding .
when i try to add npc like your madcow(from tutorial) after recompile i look in the log an see error with mobspawnbase.java :the first error is something like illegal class used.i have 66 errors in that log.
with items :i just didnt under stand where to put 2 first tutorial codes for grenades.
Please post the errors you received - I can't help you otherwise.
I'm posting cause I'm having some problems with test_game.bat...
I followed your tutorial for adding new blocks, and I did everything exactly as you said, but when I try to run test_game.bat , the window just disappears and nothing happens.
I don't know where I screwed up. Maybe because I didn't add minecraft_server.jar to MCP/jars (I don't have it), or maybe I copied the .minecraft/bin and .minecraft/resources to MCP/jars wrong? I followed every step for your tutorial twice but test_game.bat won't run.
Can you tell me what to do guys?
thanks in advance...
Quote from Knaren »
Check java. I had this problem too but i have deleted the mcp and reinstalled java.
Also check your logs... Make sure you recompile the code BEFORE trying to run test_game.bat
Adding explanations for nearly everything in there, for these of us who have no experience with Java, what-so-ever. Please tell me if anything is wrong, and I will fix it.
Nice, I will link it to the original post shortly. I have a programmers background and clearly stated at the start that I was writing these tutorials for people who have Java/programming experience so assumed that those people would know what most of the code was, so I guess further explanation would help.
- Edit the Health
- Make something like a lvl up system (lvl up add's 1 health for example)
- Monsters giv exp (editable, and exp need editable) ?
thanks =)
Possibly, but then you are venturing into "non-standard" game play, this means that there are a number of ways to do these things and tutorials only cover one way, which may not be the "best" way to do it...
If I was going to implement a "leveling" system I would add an experience gained variable to the EntityPlayer class which saves to the level.dat (for later use), add a experience variable in EntityLiving which is a static variable which provides the amount of experience gained for killing the NPC then probably add calls in the attackEntity methods which add to the experience gained variable.. Something along those lines anyway.
So, I ran into an error the first time I tried to compile my custom item. It began giving me this error, and all of the code I would then attempt to compile wouldn't work. I tried doing a clean install of MCP, but it would still give me the error. Anyway, here it comes.
Failed to load options
java.lang.ArrayIndexOutOfBoundsException: 1
at net.minecraft.src.GameSettings.loadOptions(GameSettings.java:289)
at net.minecraft.src.GameSettings.(init)(GameSettings.java:44)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:182)
at net.minecraft.client.Minecraft.run(Minecraft.java:458)
at java.lang.Thread.run(Unknown Source)
And then some **** about Windows 7, but it worked perfectly well even with that, before the above code popped up.
I get the same error on Windows 7, not sure exactly what does it (probably a settings file) but it doesn't seem to effect any game play.
I was wondering if you could teach someone how to do two things.
1) Make new weapons, Eg. Spears, Battleaxes, Knives.
2) Make mobs spawn in a certain type of biome and stay in that biome. Eg. Fish, sharks, octopi
Thank you so much for the tutorial.
I was just wondering if you could make a tutorial for adding server commands, thanks!
Probably the best way to do this would be using the Hey0 mod kit. I have never used it, or modded for it, but there are heaps of plugins for it so it must be pretty straight forward to do.
Client commands on the other hand can be achieved through editing the EntityPlayerSP class.
Sorry, I don't understand what you are after - you will have to confirm.
Thanks should go to club559 not me
Ok cool idea! Basically "item" and "block" classes are only instantiated ONCE therefore any instance variables that are set would affect all the same blocks/items. The way around this is to use an Entity class. Entity classes can have multiple instances and will achieve what you are after. Although I have not provided a tutorial on this yet, you may use parts of the NPC tutorial to help you.
The downside of using an Entity rather than an Item/Block is that it requires a lot more coding and is more complex :sad.gif:
To change your code to use an entity, create a new entity object where the logic is; in this case "onItemUse". Hope this helps..
Ah ok. I will write a tutorial in the next few days for this then.
Read the original post about compiling, testing and re-obfuscating. If you are still having troubles after reading it, just let me know.
Here is the fixed code... see the difference?
The texture numbers come out of textures.png the numbers go from left to right, up to down, starting from 0 going to 255. There are 16 textures per line and 16 lines. Hope this helps.
Ok if the ^ character is on everything then there are more generic problems, backup your classes you have changed, then run 'decompile.bat', 'update_names.bat' and then run 'recompile.bat'. See if this results in any errors, if it does please post some of the errors here and I will try and help you out.
Those errors are due to class files not found - this is USUALLY ok. You need to compile the classes first BEFORE running reobf.bat though.
There should be a file:
/conf/client_obfuscation.txt
If this doesn't exist then I guess you should add it in then...
Using the Item tutorial you should be able to work out how to make it food. If not post again and I will add it to the list of tutorials I have to do.
Glad to hear =)
Please post the errors you received - I can't help you otherwise.
Also check your logs... Make sure you recompile the code BEFORE trying to run test_game.bat
http://www.google.com.au/search?q=learn+java
Nice, I will link it to the original post shortly. I have a programmers background and clearly stated at the start that I was writing these tutorials for people who have Java/programming experience so assumed that those people would know what most of the code was, so I guess further explanation would help.
Possibly, but then you are venturing into "non-standard" game play, this means that there are a number of ways to do these things and tutorials only cover one way, which may not be the "best" way to do it...
If I was going to implement a "leveling" system I would add an experience gained variable to the EntityPlayer class which saves to the level.dat (for later use), add a experience variable in EntityLiving which is a static variable which provides the amount of experience gained for killing the NPC then probably add calls in the attackEntity methods which add to the experience gained variable.. Something along those lines anyway.
I get the same error on Windows 7, not sure exactly what does it (probably a settings file) but it doesn't seem to effect any game play.
1. That is going to be one of the next tutorials.
2. I won't do a tutorial on this, simply add the NPCs name to the MobSpawner[TYPE] classes.
Probably the best way to do this would be using the Hey0 mod kit. I have never used it, or modded for it, but there are heaps of plugins for it so it must be pretty straight forward to do.
Client commands on the other hand can be achieved through editing the EntityPlayerSP class.