MCDOCS
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A question about making a mod

2 posters

Go down

A question about making a mod Empty A question about making a mod

Post  Cheeseyx Tue Nov 02, 2010 8:32 pm

I am just starting to make my first mod, and am trying to use Risugami's mod loader for it. I hope to eventually have it be a mod of the fishing rod that acts as a grappling hook, but the functionality can wait until I get it able to be crafted. So far I have been able to work out how to (using the maploader format) give it a specific crafting recipe, but I am at a loss as to the rest. I tried to find the fishing rod class file to reverse engineer the code, but I am at a loss as to which class it is in. It is listed as 'aP' in the items list, but sadly that means nothing to me as to what the class is. I checked the google spreadsheet for a clue as to where it would be, but alas I found nothing. My code so far is as follows. Help would be appreciated, more so if it were help as to how the syntax functions than just giving me a code fix. I am currently learning Java, so I understand a great deal of the code, but a good deal of the syntax I do not have full understanding of.

Code:
import java.util.Map;

public  class mod_GrapplingHook extends BaseMod
{
   public static dr grapple = new dr(131).a(205);
       
     public void AddRecipes(eh recipes)
     {   recipes.a(new fi(grapple, 1), new Object[] { "  #", " #X", "# Y",
/*    */      Character.valueOf('Y'), dr.m, Character.valueOf('X'), dr.I,
/*    */      Character.valueOf('#'), dr.B });
/*    */  }
/*    */
/*    */  public void RegisterBlocks(List<ne> registry)
/*    */  {
/*    */  }
/*    */
/*    */  public void AddRenderer(Map<Class, ao> renderers)
/*    */  {
/*    */  }
/*    */
/*    */  public void AddEntityID()
/*    */  {
/*    */  }
/*    */
/*    */  public int AddSmelting(int id)
/*    */  {
/* 18 */    return -1;
/*    */  }
/*    */
/*    */  public int AddFuel(int id) {
/* 22 */    return 0;
/*    */  }
/*    */ }

Cheeseyx

Posts : 5
Join date : 2010-11-02

Back to top Go down

A question about making a mod Empty Re: A question about making a mod

Post  DaninFuchs Tue Feb 15, 2011 10:02 pm

Not sure if you're still interested or not, since it's apparently been a while, but yesterday I decided to start working on Minecraft for a mod of my own...learn Java and OpenGL while I'm at it.. Rendering engine, world file management, things like that. Efficiency and requirements cleanup, mostly. Oh, and I'm gonna add some pretty, haha, so I have to learn how to work with GLSL in parallel.... Took me the entire night after work to get it going, but I got the source reversed and Minecraft now runs rather nicely from within Eclipse, so I can begin my real work... I came here looking for information on a few things, but I saw your question, decided I should help you figure it out. Before you read too much, check my last paragraph for what may be a dealbreaker, depending on how much work you want to do.

I'm not sure if you're working with decompiled or decompiled + deobfuscated code or not, and my information may not be 100% accurate depending on what version of the source you're using, what decompiler, etc....but, here goes. Though before I begin, I'm not sure it's this easy to simply 'add' a new block. Also I'm figuring some of this out as I go along, so bear with me.

In CraftingManager (Checked the spreadsheet, but its information is apparently not matching my decompiler, sorry! It'll be CraftingManager.java if it's properly deobfuscated) you'll find the class 'creation' function, starts; 'public void CraftingManager()' - sorry if my nomenclature is incorrect. This is my first venture into Java.

Within that function, you'll find a great many recipes. The rest are in Recipes* classes - RecipesWeapons, RecipesDyes etc. If you scroll down, you'll find the fishing rod recipe. (May not be all proper-named, I had to refactor a lot of the code to deobfuscate some things they hadn't figured out or hadn't gotten around to renaming.)

Code:
        addRecipe(new ItemStack(Item.fishingRod, 1), new Object[] {
            "  #", " #X", "# X", Character.valueOf('#'), Item.stick, Character.valueOf('X'), Item.silk
        });

That's proper recipe syntax - I've not used the ModLoader before (as a mod-maker at least) so I'm not sure that you can simply put the addRecipe function into your own class and have it work - you'll have to look elsewhere there, sorry. To find this with your obfuscated table you may have to search for (according to your syntax, if I'm wrong you are too - haha) a recipe listing new fi(dr.fA, 1).... Breaking it down (as I see it, again - not 100% guaranteed to be right) we have the following;

Add a new Recipe, creating a new Item Stack of type Item.fishingRod, quantity 1. (See Note1), with a new object array containing " #" " #X" "# X", replacing any # character with Item.stick, and X with Item.silk

Examining the declaration of Item.fishingrod, we have;

Code:
    public static Item fishingRod = (new ItemFishingRod(90)).itemIcon(5, 4).setMetadataString("fishingRod");

Creates a new item using the variable name fishingRod, assigned the value of a newly created ItemFishingRod class (which is an overload of the Item class, with extra functions/parameters) with Item ID 90, icon (5, 4) ...I assume row 5, column 4 or column 4, row 5...not sure...with the metadata declared by the string "fishingRod"

Note1; you can also use one of the overloaded functions here. ItemStack(block, [int quantity], [int itemMetadata]) or ItemStack(item, [int quantity], [int itemMetadata]) - there's also one more overload, using a struct NBTTagCompound - seems to be a complicated way to write/store itemID, quantity, and itemMetadata in one variable. itemMatadata is being referenced typically as itemDamage, but SHOULD be renamed to itemMetadata since Notch implimented dyes and other similar items using one ID, multiple possible values for 'itemDamage' aka itemMetadata for different results. (Dyes all use the same ID, different Data.)

Searching for the ItemFishingRod class, I find that it overloads the Item class. I'm not sure I'm allowed to post the entire contents of the source block, nor am I sure what the obfuscated class is, however the onItemRightClick function is the only one you need - it's passed three parameters, with classes ItemStack, World, and EntityPlayer...and it returns an ItemStack class.

The ItemStack parameter is a reference to the item that was right-clicked. In this case, fishing rod. In your case, Grappling hook. The World is a reference to the existing world instance, and the EntityPlayer reference is to the player itself - unless you (want to) set it to be used by mobs as a pseudo-'weapon' in their AI, which would require more work than it's worth right now.

In the original source, it checks if there's already a spawned fish entity. If there is, it takes the ItemStack class, damages it depending on the outcome (caught, not caught, returned without a 'nibble') of the pull, and then returns the same reference. If there is not a spawned fish, it spawns one near the player, calculates nibbles based on random values and time, and if you catch it during or shortly after a nibble, it spawns a raw fish (health item), "throws" it at you, etc.. You'd have to code your own "move the mob X amount" and figure out how to target it - it doesn't target a pre-existing fish by itself. The code wouldn't be terribly hard, but it would definitely take some work and learning, especially when working with obfuscated code. I feel the ModLoader should be adapted to de-obfuscate the code FOR the modder, thus referencing 'normal' class names, requiring (in most cases) that the modder not need to update each mod, only the ModLoader.

...if it isn't already that way, haha.

*Edit: This actually took three hours to post because I kept tangenting through code de-obfuscating things that were missed. Gah! If I've missed something, that's likely why - just ask any questions you may have and I'll try to answer them for you.

DaninFuchs

Posts : 1
Join date : 2011-02-15

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum