Jump to content

Reading minecraft source code


Skrallbadoor

Recommended Posts

Hello there,

 

I'm modding a bit for a while now and I saw in a few tutorials that some people can read the code of the files in "Referenced Libaries" in Eclipse, what'd make modding way easier for me.

Sadly, it isn't the case for me, the only informations I get when I'm trying to open the files are:

"Class File Editor"

"Source not found"

"The JAR file C:\Users\Skrallbadoor\.gradle\cache\forge_gradle_minecraft:user_repo\net\minecraft......................\1.14.2.jar has no source attachment"

"You can attach the source by clicking Attach Source below:"

[Attach Source...]

and then code like:

/ Compiled from ItemEntity.java (version 1.8 : 52.0, super bit)
public class net.minecraft.entity.item.ItemEntity extends net.minecraft.entity.Entity {
  
  // Field descriptor #12 Lnet/minecraft/network/datasync/DataParameter;
  // Signature: Lnet/minecraft/network/datasync/DataParameter<Lnet/minecraft/item/ItemStack;>;
  private static final net.minecraft.network.datasync.DataParameter ITEM;
  
  // Field descriptor #15 I
  private int age;
  
  // Field descriptor #15 I
  private int pickupDelay;
  
  // Field descriptor #15 I
  private int health;
  
  // Field descriptor #19 Ljava/util/UUID;
  private java.util.UUID thrower;
  
  // Field descriptor #19 Ljava/util/UUID;
  private java.util.UUID owner;
  
  // Field descriptor #15 I
  public int lifespan;
  
  // Field descriptor #23 F
  public final float hoverStart;
  
  // Method descriptor #25 (Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V
  // Signature: (Lnet/minecraft/entity/EntityType<+Lnet/minecraft/entity/item/ItemEntity;>;Lnet/minecraft/world/World;)V
  // Stack: 5, Locals: 3
  public ItemEntity(net.minecraft.entity.EntityType p_i50217_1_, net.minecraft.world.World p_i50217_2_);
     0  aload_0 [this]
     1  aload_1 [p_i50217_1_]
     2  aload_2 [p_i50217_2_]
     3  invokespecial net.minecraft.entity.Entity(net.minecraft.entity.EntityType, net.minecraft.world.World) [28]
     6  aload_0 [this]
     7  iconst_5
     8  putfield net.minecraft.entity.item.ItemEntity.health : int [30]
    11  aload_0 [this]
    12  sipush 6000
    15  putfield net.minecraft.entity.item.ItemEntity.lifespan : int [32]
    18  aload_0 [this]
    19  invokestatic java.lang.Math.random() : double [38]
    22  ldc2_w <Double 3.141592653589793> [39]
    25  dmul
    26  ldc2_w <Double 2.0> [41]
    29  dmul
    30  d2f
    31  putfield net.minecraft.entity.item.ItemEntity.hoverStart : float [44]
    34  return
      Line numbers:
        [pc: 0, line: 48]
        [pc: 6, line: 38]
        [pc: 11, line: 44]
        [pc: 18, line: 45]
        [pc: 34, line: 49]
      Local variable table:
        [pc: 0, pc: 35] local: this index: 0 type: net.minecraft.entity.item.ItemEntity
        [pc: 0, pc: 35] local: p_i50217_1_ index: 1 type: net.minecraft.entity.EntityType
        [pc: 0, pc: 35] local: p_i50217_2_ index: 2 type: net.minecraft.world.World
      Local variable type table:
        [pc: 0, pc: 35] local: p_i50217_1_ index: 1 type: net.minecraft.entity.EntityType<? extends net.minecraft.entity.item.ItemEntity>
  
  // Method descriptor #52 (Lnet/minecraft/world/World;DDD)V
  // Stack: 9, Locals: 8
  public ItemEntity(net.minecraft.world.World p_i1709_1_, double p_i1709_2_, double p_i1709_4_, double p_i1709_6_);
     0  aload_0 [this]
     1  getstatic net.minecraft.entity.EntityType.ITEM : net.minecraft.entity.EntityType [56]
     4  aload_1 [p_i1709_1_]
     5  invokespecial net.minecraft.entity.item.ItemEntity(net.minecraft.entity.EntityType, net.minecraft.world.World) [57]
     8  aload_0 [this]
     9  dload_2 [p_i1709_2_]
    10  dload 4 [p_i1709_4_]
    12  dload 6 [p_i1709_6_]
    14  invokevirtual net.minecraft.entity.item.ItemEntity.setPosition(double, double, double) : void [61]
    17  aload_0 [this]
    18  aload_0 [this]
    19  getfield net.minecraft.entity.item.ItemEntity.rand : java.util.Random [65]
    22  invokevirtual java.util.Random.nextFloat() : float [71]
    25  ldc <Float 360.0> [72]
    27  fmul
    28  putfield net.minecraft.entity.item.ItemEntity.rotationYaw : float [75]
    31  aload_0 [this]
    32  aload_0 [this]
    33  getfield net.minecraft.entity.item.ItemEntity.rand : java.util.Random [65]
    36  invokevirtual java.util.Random.nextDouble() : double [78]
    39  ldc2_w <Double 0.2> [79]
    42  dmul
    43  ldc2_w <Double 0.1> [81]
    46  dsub
    47  ldc2_w <Double 0.2> [79]
    50  aload_0 [this]
    51  getfield net.minecraft.entity.item.ItemEntity.rand : java.util.Random [65]
    54  invokevirtual java.util.Random.nextDouble() : double [78]
    57  ldc2_w <Double 0.2> [79]
    60  dmul
    61  ldc2_w <Double 0.1> [81]
    64  dsub
    65  invokevirtual net.minecraft.entity.item.ItemEntity.setMotion(double, double, double) : void [85]
    68  return
      Line numbers:
        [pc: 0, line: 52]
        [pc: 8, line: 53]
        [pc: 17, line: 54]
        [pc: 31, line: 55]
        [pc: 68, line: 56]
      Local variable table:
        [pc: 0, pc: 69] local: this index: 0 type: net.minecraft.entity.item.ItemEntity
        [pc: 0, pc: 69] local: p_i1709_1_ index: 1 type: net.minecraft.world.World
        [pc: 0, pc: 69] local: p_i1709_2_ index: 2 type: double
        [pc: 0, pc: 69] local: p_i1709_4_ index: 4 type: double
        [pc: 0, pc: 69] local: p_i1709_6_ index: 6 type: double
  
  // Method descriptor #91 (Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V
  // Stack: 8, Locals: 9
  public ItemEntity(net.minecraft.world.World p_i1710_1_, double p_i1710_2_, double p_i1710_4_, double p_i1710_6_, net.minecraft.item.ItemStack p_i1710_8_);
     0  aload_0 [this]
     1  aload_1 [p_i1710_1_]
     2  dload_2 [p_i1710_2_]
     3  dload 4 [p_i1710_4_]
     5  dload 6 [p_i1710_6_]
     7  invokespecial net.minecraft.entity.item.ItemEntity(net.minecraft.world.World, double, double, double) [93]
    10  aload_0 [this]
    11  aload 8 [p_i1710_8_]
    13  invokevirtual net.minecraft.entity.item.ItemEntity.setItem(net.minecraft.item.ItemStack) : void [97]
    16  aload_0 [this]
    17  aload 8 [p_i1710_8_]
    19  invokevirtual net.minecraft.item.ItemStack.getItem() : net.minecraft.item.Item [103]
    22  ifnonnull 31
    25  sipush 6000
    28  goto 37
    31  aload 8 [p_i1710_8_]
    33  aload_1 [p_i1710_1_]
    34  invokevirtual net.minecraft.item.ItemStack.getEntityLifespan(net.minecraft.world.World) : int [109]
    37  putfield net.minecraft.entity.item.ItemEntity.lifespan : int [32]
    40  return
      Line numbers:
        [pc: 0, line: 59]
        [pc: 10, line: 60]
        [pc: 16, line: 61]
        [pc: 40, line: 62]
      Local variable table:
        [pc: 0, pc: 41] local: this index: 0 type: net.minecraft.entity.item.ItemEntity
        [pc: 0, pc: 41] local: p_i1710_1_ index: 1 type: net.minecraft.world.World
        [pc: 0, pc: 41] local: p_i1710_2_ index: 2 type: double
        [pc: 0, pc: 41] local: p_i1710_4_ index: 4 type: double
        [pc: 0, pc: 41] local: p_i1710_6_ index: 6 type: double
        [pc: 0, pc: 41] local: p_i1710_8_ index: 8 type: net.minecraft.item.ItemStack
      Stack map table: number of frames 2
        [pc: 31, full, stack: {net.minecraft.entity.item.ItemEntity}, locals: {net.minecraft.entity.item.ItemEntity, net.minecraft.world.World, double, double, double, net.minecraft.item.ItemStack}]
        [pc: 37, full, stack: {net.minecraft.entity.item.ItemEntity, int}, locals: {net.minecraft.entity.item.ItemEntity, net.minecraft.world.World, double, double, double, net.minecraft.item.ItemStack}]
  
  // Method descriptor #117 ()Z
  // Stack: 1, Locals: 1
  protected boolean canTriggerWalking();
    0  iconst_0
    1  ireturn
      Line numbers:
        [pc: 0, line: 65]
      Local variable table:
        [pc: 0, pc: 2] local: this index: 0 type: net.minecraft.entity.item.ItemEntity
  
  // Method descriptor #119 ()V
  // Stack: 3, Locals: 1
  protected void registerData();
     0  aload_0 [this]
     1  invokevirtual net.minecraft.entity.item.ItemEntity.getDataManager() : net.minecraft.network.datasync.EntityDataManager [123]
     4  getstatic net.minecraft.entity.item.ItemEntity.ITEM : net.minecraft.network.datasync.DataParameter [125]
     7  getstatic net.minecraft.item.ItemStack.EMPTY : net.minecraft.item.ItemStack [128]
    10  invokevirtual net.minecraft.network.datasync.EntityDataManager.register(net.minecraft.network.datasync.DataParameter, java.lang.Object) : void [134]
    13  return
      Line numbers:
        [pc: 0, line: 69]
        [pc: 13, line: 70]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: net.minecraft.entity.item.ItemEntity
  
  // Method descriptor #119 ()V
  // Stack: 8, Locals: 6
  public void tick();
      0  aload_0 [this]
      1  invokevirtual net.minecraft.entity.item.ItemEntity.getItem() : net.minecraft.item.ItemStack [138]
      4  aload_0 [this]
      5  invokevirtual net.minecraft.item.ItemStack.onEntityItemUpdate(net.minecraft.entity.item.ItemEntity) : boolean [142]
      8  ifeq 12
     11  return
     12  aload_0 [this]
     13  invokevirtual net.minecraft.entity.item.ItemEntity.getItem() : net.minecraft.item.ItemStack [138]
     16  invokevirtual net.minecraft.item.ItemStack.isEmpty() : boolean [145]
     19  ifeq 29
     22  aload_0 [this]

 

On the right side, I have an Outline Window where I can see method and variable names, but thoses aren't what I'm searching for.

 

Well, now to my question, is there a way to open the jsons in Referenced Libs. and is there a way to get the decompiled code of the class files?

I tried to copy and paste the files, what didint work, that way I can't put the class files into a decompiler. I opened the path where the files are then, and put the class files into a decompiler, but I only got "field_number_letter"s and "function_number_letters"s as code.

 

I've heard something about a MCP(Minecraft Coder Pack). I'm not sure if I need this to solve my problems and if yes, how to use/install MCP.

Link to comment
Share on other sites

For many of the non-Minecraft libraries, there is no source code.

Minecraft source code in all in the Minecraft Forge library(ies) which usually are at the top of the list of referenced libraries in Eclipse.

 

MCP maps the deobfuscation of the Minecraft source code and is applied through Gradle directives.  There are stable and daily exports depending on which version of MC you are working with.  To update MCP mappings, edit the 'build.gradle' file and re-run gradlew.

 

Hope this helps.

/P

Link to comment
Share on other sites

You should NEVER use MCP directly.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.