That's definitely due to decompiling an incompatible version of minecraft.jar. Block.java shouldn't look anything like that, and it certainly doesn't extend MinecraftError (it doesn't extend anything, actually).
That's definitely due to decompiling an incompatible version of minecraft.jar. Block.java shouldn't look anything like that, and it certainly doesn't extend MinecraftError (it doesn't extend anything, actually).
Thats what i thought. I tried decompiling the latest version (I knew that MCP said it wouldnt work but i decided to try anyway)
So since there is no MCP for the newest version, I would have to figure out whats what and go from there?
Essentially, yes. However, it does help if you have a previous version to look through. Of course, if you don't, you can also look through some fellow modder's decompiled code for some hints to what a few of the classes are.
Also, since the real block and item class contain a bunch of variables with the names of the blocks and items (as well as the classes for all of these, if they have unique classes), so it's certainly a relatively easy file to find (btw, I think the block class is currently pj, so look around there if you want to find that one).
hey should this change the spawn point to the players position?
public void onBlockClicked(World world, int x ,int y , int z, EntityPlayer entityplayer)
{
world.spawnX=MathHelper.floor_double(entityplayer.posX);
world.spawnY=MathHelper.floor_double(entityplayer.posY);
world.spawnZ=MathHelper.floor_double(entityplayer.posZ);
}
Essentially, yes. However, it does help if you have a previous version to look through. Of course, if you don't, you can also look through some fellow modder's decompiled code for some hints to what a few of the classes are.
Also, since the real block and item class contain a bunch of variables with the names of the blocks and items (as well as the classes for all of these, if they have unique classes), so it's certainly a relatively easy file to find (btw, I think the block class is currently pj, so look around there if you want to find that one).
Thanks for your help so far.
Where could i find previous versions of minecraft?
Essentially, yes. However, it does help if you have a previous version to look through. Of course, if you don't, you can also look through some fellow modder's decompiled code for some hints to what a few of the classes are.
Also, since the real block and item class contain a bunch of variables with the names of the blocks and items (as well as the classes for all of these, if they have unique classes), so it's certainly a relatively easy file to find (btw, I think the block class is currently pj, so look around there if you want to find that one).
Thanks for your help so far.
Where could i find previous versions of minecraft?
Unless you have a backup of the previous versions the only thing u can do is use this program that reverts it i forget its name tho. Its the only legal way to do it because downloading a torrent of it is illegal.
Someone should no the name.
The Meaning of Life, the Universe, and Everything.
Location:
worthington
Join Date:
11/3/2010
Posts:
51
Member Details
Would this code work? (also, a couple questions about Java commands, I'm new to Java, though I do have programming experience.)
Basically, I want (on a certain key press) the code to look through the inventory for armor, and equip the best armor in your inventory. (essentially checking each inventory slot, checking if it's armor, then if so checking what type of armor it is. After going through each slot, equip armor H C L F (Head, Chest, Legs, Feet. Respectively.))
(this is the code specifically for the head slot. The code will be repeated for each slot.)
h = 0
for (i = 0, i <= 35, i += 1) {
getBlocktype.i;
if (blockType = 1){
getArmortype;
for (a = 1, a <=5, a+=1){
if (armortype = a && a > h){
h = i
}
}
}
}
(Equipping code here.)
My question is, would that code (repeated) do what I said above? Also, how would I equip the armor to the slot (I was thinking something like H storing the inventory slot carrying the highest armor, then telling the code to equip whatever is in slot H)
I have been playing around with Jd-gui for a bit looking through the class files. Yesterday i decided to play around with making changes and recompiling Minecraft.java. I used both netbeans with the lwjgl and the minecraft.jar as libraries. Had some issues most were understandable as decompile on any platform is never perfect. But how do you get around java not wanting to reference class files in the default package? (deprecated after jkd 1.4)
Returning to java after a very long hiatus. Thought i might try to make a parachute mod.
Essentially, yes. However, it does help if you have a previous version to look through. Of course, if you don't, you can also look through some fellow modder's decompiled code for some hints to what a few of the classes are.
Also, since the real block and item class contain a bunch of variables with the names of the blocks and items (as well as the classes for all of these, if they have unique classes), so it's certainly a relatively easy file to find (btw, I think the block class is currently pj, so look around there if you want to find that one).
Thanks for your help so far.
Where could i find previous versions of minecraft?
Unless you have a backup of the previous versions the only thing u can do is use this program that reverts it i forget its name tho. Its the only legal way to do it because downloading a torrent of it is illegal.
Someone should no the name.
I found an older version of the actual .jar file on my computer. I just replaced the .jar file in the /bin file. Would that work?
Where could i find previous versions of minecraft?
Unless you have a backup of the previous versions the only thing u can do is use this program that reverts it i forget its name tho. Its the only legal way to do it because downloading a torrent of it is illegal.
Someone should no the name.
I found an older version of the actual .jar file on my computer. I just replaced the .jar file in the /bin file. Would that work?
Hey Simo, is there anyway to spawn something on the underside of a block? Cuz I may be making a bat entity that hopefully will rest upside down, clinging onto the ceiling. WIth some coding I could probably get it to find a "ceiling" block that then finds the space underneath (it will check if a block is there) then the bat is added in that location (meaning more code for the bat so it is not affected by gravity). You have any tips on what I should do?
Rollback Post to RevisionRollBack
Check out my Youtube Channel! http://www.youtube.com/user/EiDeHua Right now I'm doing a let's play of Sleeping Dogs! Working on updating my Luck's Edge mod, a LOT of new content! Also I've got another mod idea in mind! -Updated 8/16/12
I figured I'd try contributing a tutorial. Hope you guys like it:
Advanced NPC Tutorial: Controlling NPC movement. Last Updated February 16, 2011
This tutorial will explore multiple methods for modders to control NPC movement. This tutorial is currently meant for Beta 1.2_02 and the java code shown in this tutorial uses MCP 2.7's de-obfuscated names. For now, this tutorial only details 2 methods of controlling NPC movement, but I will add more methods in the future.
Method 1: Overriding EntityCreature's getBlockPathWeight() function
When an NPC is idle, it will randomly move around. The NPC does this by occasionally randomly selecting 10 nearby blocks, and checking their Block Path Weights (BPW). The block with the highest BPW will be selected as the destination for the NPC to move to.
The getBlockPathWeight() function is called for each of the 10 blocks and returns a block's BPW. This function influences how certain NPCs wander around while idle (as in not attacking anything).
default
protected float getBlockPathWeight(int i, int j, int k)
{
return 0.0F;
}
The default function of EntityCreature gives the NPC no preference for any specific location.
Animals
protected float getBlockPathWeight(int i, int j, int k)
{
if(worldObj.getBlockId(i, j - 1, k) == Block.grass.blockID)
{
return 10F;
} else
{
return worldObj.getLightBrightness(i, j, k) - 0.5F;
}
}
Animals will favor moving toward blocks above grass. Otherwise, Animals will move toward lighted locations.
Monsters
protected float getBlockPathWeight(int i, int j, int k)
{
return 0.5F - worldObj.getLightBrightness(i, j, k);
}
Monsters prefer moving toward dark locations.
By modifying or overriding the getBlockPathWeight function, you can change what locations a type of NPC will prefer to wander to.
For example, suppose I am creating a Mountain Goat NPC. I want Mountain Goats to prefer high locations, thus I would use this getBlockPathWeight function:
protected float getBlockPathWeight(int i, int j, int k)
{
return (float) j;
}
This simple getBlockPathWeight function makes the highest randomly selected block the Mountain Goat's destination. Thus, Mountain Goats would have slightly better odds of traveling up hills, mountains, etc.
Now if I wanted to make Mountain Goats wander differently depending on the circumstances, I could try a getBlockPathWeight function like this:
protected float getBlockPathWeight(int i, int j, int k)
{
if(health < 5)
return MathHelper.floor_double(getDistance(i, j, k));
else if(!worldObj.isDaytime())
return -(MathHelper.floor_double(getDistance(i, j, k)));
else
return (float) j;
}
This function expands Goats to move differently depending on the circumstances.
When they are low on hp, they will move much farther distances at a time.
During night time, they will move very short distances at a time.
During the day time, while they have high hp, they will prefer higher altitudes.
As a final example, let's say that I also wanted to make the Mountain Goat have no preference while swimming. Then I would change my function to this:
This getBlockPathWeight function would make my Mountain Goat wander with no preferences while in water.
Thus, overriding or changing this function presents a fairly easy way for you to influence what places NPCs prefer moving toward. You could make specific NPCs prefer moving toward other specific NPCs or even the player. You could also have NPCs prefer moving toward specific coordinates. Why not make NPCs that wander differently depending on the block they are standing on? The possibilities are endless!
PS: It is advised that you make sure the getBPW function does not return a negative number before your NPC spawns. EntityLiving's canSpawnHere() function calls the getBPW function and will prevent your NPC from spawning if the BPW is less than 0.
Each NPC extended from the EntityCreature class has a single playerToAttack variable which holds an entity.
When this variable is set to any entity, the NPC will set its next destination to the position of this playerToAttack entity.
By changing this playerToAttack variable, you can make an NPC move toward almost any entity.
However, there are some additional rules that must be considered when trying to do this:
1. While the playerToAttack variable is null, the NPC will regularly call the findPlayerToAttack()* function until the playerToAttack is no longer null.
2. Once an NPC sets its playerToAttack variable, by default, this variable will only change when the playerToAttack entity is dead.
3. The NPC will only move toward the playerToAttack entity if the playerToAttack is within a distance of 16.
4. The NPC will only move toward the playerToAttack entity if there are no obstacles blocking all possible paths to the playerToAttack.
5. While either rule 3 or 4 is violated, the NPC will be idle and wander around until both conditions are met.
6. NPCs extended from the EntityMobs class have additional coding that makes them damage their target when close, and change their target under additional circumstances.
*EntityCreature's default findPlayerToAttack() function always returns null.
So, how should you change this variable? Well, you have almost unlimited options. You can simply set or nullify this variable like any other variable. You can change this variable at any time by using overwritten functions. The most obvious function to overwrite would be the findPlayerToAttack() function.
Let's look back at my Mountain Goat example from Movement Control Method 1. Here's what overwritten findPlayerToAttack() function I would use if I wanted Goats to follow the nearest sheep:
protected Entity findPlayerToAttack()
{
double d1 = -1D;
EntitySheep sheep = null;
//check each entity that is in the world
for(int i = 0; i < worldObj.loadedEntityList.size(); i++)
{
Entity entity1 = (Entity)worldObj.loadedEntityList.get(i);
//if entity is not a sheep, check next entity on entityList
if(!(entity1 instanceof EntitySheep))
{
continue;
}
//if sheep, check how far it is from goat.
//The closest "seen" sheep within a distance of 16 will be identified by the sheep variable.
double d2 = entity1.getDistance(posX, posY, posZ);
if((d2 < 16) && (d1 == -1D || d2 < d1) && ((EntitySheep)entity1).canEntityBeSeen(this))
{
d1 = d2;
sheep = (EntitySheep)entity1;
}
}
return sheep; //returns the closest sheep to the goat
}
This function will make Mountain Goats regularly check for nearby sheep when they have no playerToAttack set. If they find a nearby sheep, they will set that sheep as their permanent target and follow it for as long as it lives.
Not satisfied with just moving your own NPC? Well, there's more!
Since all NPCs have a public playerToAttack variable, you can change the playerToAttack of any creature at any time.
For example, instead of having my Mountain Goats follow sheep, lets have the sheep follow my goats.
To do this, I will no longer need a modified findPlayerToAttack() function. Instead I will use this overwritten onUpdate() function:
public void onUpdate()
{
super.onUpdate();
//check each entity that is in the world
for(int i = 0; i < worldObj.loadedEntityList.size(); i++)
{
Entity entity1 = (Entity)worldObj.loadedEntityList.get(i);
//if entity is not a sheep, check next entity on entityList
if(!(entity1 instanceof EntitySheep))
{
continue;
}
//if nearby "seen" sheep's playerToAttack is null, set it to this goat
double d2 = entity1.getDistance(posX, posY, posZ);
EntitySheep sheep = (EntitySheep)entity1;
if((d2 < 16) && sheep.canEntityBeSeen(this) && sheep.playerToAttack == null)
{
sheep.playerToAttack = this;
}
}
}
This function will make goats regularly check for nearby idle sheep. Any idle sheep near a goat will follow that goat.
Finally, there is one more trick for using the playerToAttack variable. Instead of setting the playerToAttack variable to existing creatures, you can also set the playerToAttack variable to a newly created entity altogether. If you never call worldObj's entityJoinedWorld() function for this entity, it will be completely invisible and "frozen". Since the entity never joins the world, its OnUpdate function will never be called, thus preventing it from moving and being interacted with. If you are creative, you can use this for a variety of "Orders" that your NPC will follow.
For example, suppose I want my Mountain Goats to continuously patrol between location A and location B. Assuming I have already set the coordinates for these locations, I could overwrite my Goat's onUpdate function as follows:
public void onUpdate()
{
super.onUpdate();
//if Goat is near location A, order it to move to location B
if(this.getDistance(locAX, locAY, locAZ) < 4){
//create new Entity at location B for Goat to move toward
playerToAttack = (Entity) new EntityItem(worldObj);
playerToAttack.setPosition(locBX, locBY, locBZ);
}
//if Goat is near location B or has no playerToAttack set, order it to move to location A
else if(this.getDistance(locBX, locBY, locBZ) < 4 || playerToAttack == null){
//create new Entity at location A for Goat to move toward
playerToAttack = (Entity) new EntityItem(worldObj);
playerToAttack.setPosition(locAX, locAY, locAZ);
}
}
This onUpdate() function would cause the Goat to continiously walk back and forth between locations A and B. Since I have to consider the rules of the playerToAttack variable, the distance between locations A and B must be less than 16, and there has to be no major obstacles between them. If I added more locations, I could have my Goats patrol farther distances.
In conclusion, the playerToAttack variable is very versatile, provided you keep in mind the rules of its use. I encourage you to experiment with it. Enjoy!
-----
I will update this post with an additional NPC movement control method eventually, involving setting the creature's private pathEntity using ModLoader's setPrivateField method.
Note: I am unsure of whether it is animals or monsters that prefer bright places. The code for that GetLightBrightness function is really complicated. Can anyone verify which one prefers bright places?
That's some very helpful code there OgreSean. I'll be sure to use these in my crab, thank you.
Glad I could help!
This was the simplest movement control method I spotted while looking through EntityCreature's java code. Two other methods I know of would be using a PathEntity or setting a creature's playerToAttack to another entity(like an item, invisible creature, etc.). These are quite a bit more complex, though. I will add tutorials on these when I get the time.
Thats what i thought. I tried decompiling the latest version (I knew that MCP said it wouldnt work but i decided to try anyway)
So since there is no MCP for the newest version, I would have to figure out whats what and go from there?
Also, since the real block and item class contain a bunch of variables with the names of the blocks and items (as well as the classes for all of these, if they have unique classes), so it's certainly a relatively easy file to find (btw, I think the block class is currently pj, so look around there if you want to find that one).
Thanks for your help so far.
Where could i find previous versions of minecraft?
Unless you have a backup of the previous versions the only thing u can do is use this program that reverts it i forget its name tho. Its the only legal way to do it because downloading a torrent of it is illegal.
Someone should no the name.
Basically, I want (on a certain key press) the code to look through the inventory for armor, and equip the best armor in your inventory. (essentially checking each inventory slot, checking if it's armor, then if so checking what type of armor it is. After going through each slot, equip armor H C L F (Head, Chest, Legs, Feet. Respectively.))
(this is the code specifically for the head slot. The code will be repeated for each slot.)
My question is, would that code (repeated) do what I said above? Also, how would I equip the armor to the slot (I was thinking something like H storing the inventory slot carrying the highest armor, then telling the code to equip whatever is in slot H)
Returning to java after a very long hiatus. Thought i might try to make a parachute mod.
MC 1.8.9
Forge 11.15.0.1688
Optifine 1.8.9 HD U H1
Villager Info 1.8-2.1
Xaero Minimap 1.7.9
Zyin HUD 1.4.8
I found an older version of the actual .jar file on my computer. I just replaced the .jar file in the /bin file. Would that work?
Ughh
Can u tell me what the new class files for
Items
Blocks
RenderManager
CraftingManager
RecipesWeapons
TileFurnace
MobSpawnerBase
and i think thats about it
Im having so much trouble doing it i dont even think i can update my mod
If you do answer Thank You So Much !
Check here.
https://spreadsheets.google.com/ccc?key ... 4skP#gid=2
Yer that should work
o cause so far i've made a block that when clicked changes the spawn point to there.
i guess i wont bother finishing mine then since urs is better lol
Advanced NPC Tutorial: Controlling NPC movement.
Last Updated February 16, 2011
This tutorial will explore multiple methods for modders to control NPC movement. This tutorial is currently meant for Beta 1.2_02 and the java code shown in this tutorial uses MCP 2.7's de-obfuscated names. For now, this tutorial only details 2 methods of controlling NPC movement, but I will add more methods in the future.
Method 1: Overriding EntityCreature's getBlockPathWeight() function
When an NPC is idle, it will randomly move around. The NPC does this by occasionally randomly selecting 10 nearby blocks, and checking their Block Path Weights (BPW). The block with the highest BPW will be selected as the destination for the NPC to move to.
The getBlockPathWeight() function is called for each of the 10 blocks and returns a block's BPW. This function influences how certain NPCs wander around while idle (as in not attacking anything).
default
The default function of EntityCreature gives the NPC no preference for any specific location.
Animals
Animals will favor moving toward blocks above grass. Otherwise, Animals will move toward lighted locations.
Monsters
Monsters prefer moving toward dark locations.
By modifying or overriding the getBlockPathWeight function, you can change what locations a type of NPC will prefer to wander to.
For example, suppose I am creating a Mountain Goat NPC. I want Mountain Goats to prefer high locations, thus I would use this getBlockPathWeight function:
This simple getBlockPathWeight function makes the highest randomly selected block the Mountain Goat's destination. Thus, Mountain Goats would have slightly better odds of traveling up hills, mountains, etc.
Now if I wanted to make Mountain Goats wander differently depending on the circumstances, I could try a getBlockPathWeight function like this:
This function expands Goats to move differently depending on the circumstances.
When they are low on hp, they will move much farther distances at a time.
During night time, they will move very short distances at a time.
During the day time, while they have high hp, they will prefer higher altitudes.
As a final example, let's say that I also wanted to make the Mountain Goat have no preference while swimming. Then I would change my function to this:
This getBlockPathWeight function would make my Mountain Goat wander with no preferences while in water.
Thus, overriding or changing this function presents a fairly easy way for you to influence what places NPCs prefer moving toward. You could make specific NPCs prefer moving toward other specific NPCs or even the player. You could also have NPCs prefer moving toward specific coordinates. Why not make NPCs that wander differently depending on the block they are standing on? The possibilities are endless!
PS: It is advised that you make sure the getBPW function does not return a negative number before your NPC spawns. EntityLiving's canSpawnHere() function calls the getBPW function and will prevent your NPC from spawning if the BPW is less than 0.
-----
Method 2: Setting EntityCreature's playerToAttack variable
Each NPC extended from the EntityCreature class has a single playerToAttack variable which holds an entity.
When this variable is set to any entity, the NPC will set its next destination to the position of this playerToAttack entity.
By changing this playerToAttack variable, you can make an NPC move toward almost any entity.
However, there are some additional rules that must be considered when trying to do this:
1. While the playerToAttack variable is null, the NPC will regularly call the findPlayerToAttack()* function until the playerToAttack is no longer null.
2. Once an NPC sets its playerToAttack variable, by default, this variable will only change when the playerToAttack entity is dead.
3. The NPC will only move toward the playerToAttack entity if the playerToAttack is within a distance of 16.
4. The NPC will only move toward the playerToAttack entity if there are no obstacles blocking all possible paths to the playerToAttack.
5. While either rule 3 or 4 is violated, the NPC will be idle and wander around until both conditions are met.
6. NPCs extended from the EntityMobs class have additional coding that makes them damage their target when close, and change their target under additional circumstances.
*EntityCreature's default findPlayerToAttack() function always returns null.
So, how should you change this variable? Well, you have almost unlimited options. You can simply set or nullify this variable like any other variable. You can change this variable at any time by using overwritten functions. The most obvious function to overwrite would be the findPlayerToAttack() function.
Let's look back at my Mountain Goat example from Movement Control Method 1. Here's what overwritten findPlayerToAttack() function I would use if I wanted Goats to follow the nearest sheep:
This function will make Mountain Goats regularly check for nearby sheep when they have no playerToAttack set. If they find a nearby sheep, they will set that sheep as their permanent target and follow it for as long as it lives.
Not satisfied with just moving your own NPC? Well, there's more!
Since all NPCs have a public playerToAttack variable, you can change the playerToAttack of any creature at any time.
For example, instead of having my Mountain Goats follow sheep, lets have the sheep follow my goats.
To do this, I will no longer need a modified findPlayerToAttack() function. Instead I will use this overwritten onUpdate() function:
This function will make goats regularly check for nearby idle sheep. Any idle sheep near a goat will follow that goat.
Finally, there is one more trick for using the playerToAttack variable. Instead of setting the playerToAttack variable to existing creatures, you can also set the playerToAttack variable to a newly created entity altogether. If you never call worldObj's entityJoinedWorld() function for this entity, it will be completely invisible and "frozen". Since the entity never joins the world, its OnUpdate function will never be called, thus preventing it from moving and being interacted with. If you are creative, you can use this for a variety of "Orders" that your NPC will follow.
For example, suppose I want my Mountain Goats to continuously patrol between location A and location B. Assuming I have already set the coordinates for these locations, I could overwrite my Goat's onUpdate function as follows:
This onUpdate() function would cause the Goat to continiously walk back and forth between locations A and B. Since I have to consider the rules of the playerToAttack variable, the distance between locations A and B must be less than 16, and there has to be no major obstacles between them. If I added more locations, I could have my Goats patrol farther distances.
In conclusion, the playerToAttack variable is very versatile, provided you keep in mind the rules of its use. I encourage you to experiment with it. Enjoy!
-----
I will update this post with an additional NPC movement control method eventually, involving setting the creature's private pathEntity using ModLoader's setPrivateField method.
Note: I am unsure of whether it is animals or monsters that prefer bright places. The code for that GetLightBrightness function is really complicated. Can anyone verify which one prefers bright places?
Builder Mobs 0.53
My Other Mods Here
Glad I could help!
This was the simplest movement control method I spotted while looking through EntityCreature's java code. Two other methods I know of would be using a PathEntity or setting a creature's playerToAttack to another entity(like an item, invisible creature, etc.). These are quite a bit more complex, though. I will add tutorials on these when I get the time.
Builder Mobs 0.53
My Other Mods Here