How to Write a Basic Moon Addon (1.7)

Should I release the tutorial files compiled as an addon?


  • Total voters
    57

jasonB221

Member
Jul 27, 2013
124
9
18
Lost in Space
Hi yall, its me again. Back with another tutorial on making an addon for Galacticraft 1.7. A lot has changed since my last one, and this is going to be my attempt to explain it. Luckily for any prospective addon makers, Mic and Radfast have done an excellent job in making the 1.7 API extremely easy to use. However, the 1.7 API is still changing on a constant basis. I will do my best to keep this tutorial up-to-date until a stable API is released. Disclaimer aside, lets get to some modding!

Basic assumptions:
  1. You know Java. I wont answer questions when the answer is "Go learn Java"
  2. You have an IDE installed, such as Eclipse (recommended) or Netbeans
  3. You have a little bit of experience with Forge modding, or you are at least comfortable googling what you do not know.

Like any forge mod, the first step is to set up your development environment. But with Forge's switch to Gradle, it has gotten a little tricky. The first thing you need to do is download forge source from here. Last I checked, GC was running forge 10.13.0.1180. It would be best if you also used that version when making your addon. You then want to follow the install directions, accessible here. Once you have that done, you need to grab some files. You will want to grab the UNOFFICIAL jar files from my jenkins, located here. Those files are distributed under the same license that the main mod files are, the LGPL. To be clear, I do NOT own these files, I just did this as a convenience for myself and am sharing it with you. Anyways, with the legal stuff out of the way, you then want to drop those three jars into a new folder in your forge directory titled libs. Boot up your IDE and add those three jars to the java build path. The next two files you need to grab are access transformers, they will tell forge to make certain minecraft methods visible. They can be gotten here and here. Put both of those files in /src/main/resources, then you need to run gradle again. This time the command is gradlew clean setupDecompWorkspace --refreshDependencies. After that command is run, you should be able to launch Galacticraft from your IDE. (Thanks to Radfast for telling me how to do this)

With setup out of the way, lets move on to the hard part: the code. Like any mod, you want to create your @Mod file first. What I am going to do is show you all the code then explain bits and pieces of it. You can call this class TutorialMoon:

http://pastebin.com/bLAE51Vg

Now if you have any experience with Forge modding, most of this should look familiar. I am going to highlight two sections. The first is defining the moon object, seen here:
Code:
moonTutorial = (Moon) new Moon("Tutorial").setParentPlanet(GalacticraftCore.overworld).setRelativeSize(0.0017F).setRelativeDistanceFromCenter(new CelestialBody.ScalableDistance(8F, 8F));
        moonTutorial.setRelativeOrbitTime(100F).setTierRequired(1).setBodyIcon(new ResourceLocation(this.ASSETPREFIX, "textures/gui/celestial/moonTutorial.png"));
        moonTutorial.setDimensionInfo(3, TutorialWorldProvider.class);
Breaking it down, the first part is simply declaring a new object. The string passed to the constructor is the unlocalized name of your moon, you need it for your lang files. We are setting it's parent to be the overworld: in essence this is a second moon for the overworld. The next three set methods called are used to draw the object on the Celestial Screen, play around with them until they look right. The setTier is used to define what tier rocket you need to access the planet. setBodyIcon is the icon used to draw the moon on the Celestial Screen, it is a 48 pixel by 48 pixel png located in forge/src/main/resources/assets/tutorialMoon/textures/gui/celestial. You can copy any of the planet textures from Galacticraft, or make your own. Just make sure you have a texture saved in that folder as moonTutorial.png or your code will error. The final line registers the dimension id number and world provider for the dimension so Galacticraft can register it.

The next part of the code registers the moon with Galacticraft so it knows it exists.
Code:
GalaxyRegistry.registerMoon(moonTutorial);
        GalacticraftRegistry.registerTeleportType(TutorialWorldProvider.class, new TutorialWorldProvider());
The first part just lets Galacticraft know about the moon, while the second part tells Galacticraft how to send a player to your moon. Now you should have some errors, lets fix those.
  1. Create your common and client proxies as you would for any forge mod. No methods are needed in them.
  2. In the package tutorial.dimension, create a TutorialWorldProvider class that extends WorldProviderSpace and implements IExitHeight, ISolarLevel, and ITeleportType
As a little note about Forge dimensions, a world provider is where the most amount of customization occurs. You will want to look over the source code for WorldProviderSpace on the github so you see exactly what you can do. This is a very minimalist worldgen. Feel free to customize it how you want.

http://pastebin.com/1FfmAKhr

Having fun yet? Still some more classes to go, but not much. If you haven't already, you should look over the github. You can learn a lot from it, they have some really good code.

Now that you are back and have some appreciation for how much work has gone into Galacticraft, lets get back to making it even better.

It is time to fix some errors in your WorldProvider. Make two classes in the same package, called TutorialChunkProvider and WorldChunkProviderTutorial.

TutorialChunkProvider:

http://pastebin.com/tkvtPPjC

Most of these methods are self explanatory. There are a few you need to watch out for though. You do not want to return null for any value here. Even if you do not need something, it is better to return an empty array or list than to return null. If you need to generate anything like caves or ravines, put your generator class inside the list returned by getWorldGenerators() and Galacticraft will take care of executing them for you. If you modify the mountain, valley, and hill heights, you can use the same terrain generation engine that Galacticraft uses and gets those crevices and such on Mars. This is another one of those 'Play with it how you want' classes, thanks to the hard work the Galacticraft devs put in already.

There will be an error on the biome decorator, that can be solved quickly. Create a new class BiomeDecoratorTutorial in the same package, have it extend BiomeDecoratorSpace, and implement the unimplemented method, but you can leave it blank. That method is where you would put any ore generation, flowers, or biome-specific mobs. Again, the details of it are outside the scope of this tutorial, but leaving it blank works fine to get a basic world.

The last class you need to make is the WorldChunkManagerTutorial, again in the same package.

http://pastebin.com/6FQt2QYy

In it's simplest form, all you need to do is return one biome because most planets will only have one biome. You will need to do a lot more work if you want multiple biomes, but if you only need one across the entire world, then this is it.

Alrighty! Thats it. You are done! Save, check all your imports, and you should be able to start up the mod. New world, /dimensiontp, zoom to the overworld, and you should see your moon listed. You will need to add a lang file for localization, the key being 'moon.Tutorial.name'. If you don't know what that means, Google is your friend (or Bing, or DuckDuckGo. Your choice).

TL;DR: Thats never going to help you in life. Go back up and read from the top. Then do it again because you were lazy. Modding is not simple.

For those of you who did read and just want easily copyable code, a zip with the source code can be found here.

~Jason

Note For Staff: As in my previous post, I do not mean to violate any licenses. This time is different because I am posting the mod downloads at a different site, which I believe is my right but I will not stop you if you wish to remove it.

Second Staff Note: I would love to post all the code in this one thread so I don't need to redirect people, but its over 10000 characters. Is there any way I could get permission to do so, or one of the mods moves the code off of pastebin and into this thread?
 

Urkaz

Member
Sep 4, 2014
4
0
1
26
Thanks for this guide, it will be useful to me when I can start coding (xD), but your unofficial jar files are down, can you upload it again, please? :p

Thanks!
 

Brickfix

Member
Nov 20, 2013
1
0
1
24
Hi,

I tried to follow your guide, but I have a problem with the access transformers that I can't figure out. I even pointed out the files in the gradle.build file, but it is still giving me the same crash-report urkaz encounterd here: http://forum.micdoodle8.com/index.php?threads/error-with-dev-versions-1-7.4523/

Could you maybe show a screenshot or something simiular?
That would be great :)

Greetings, and thanks again for posting the tutorial

EDIT:
I figured it out myself, works like a charm :)
Thanks again, really good tutorial
 
Last edited:

knuckles001

Member
Oct 31, 2014
1
0
1
28
Hi, I'm having a problem making the workspace. When I run the command "gradlew clean setupDecompWorkspace --refresh-dependencies" it gives me an error "Execution failed on task: deobfuscateJar. Invalid acces visibility <!DOCTYPE". I have search a little bit on google and maybe can be that I'm not doing somethig well with the access transformers :S
Help I'm really lost xD
 

radfast

Administrator
Staff member
Apr 27, 2014
1,142
353
83
@knuckles001 Take a look at this tutorial, see if anything here helps you. wiki.micdoodle8.com/wiki/GC3_API

@BlesseNtumble

Stars in the sky are drawn by a SkyProvider in the client, see for example: https://github.com/micdoodle8/Galac...galacticraft/core/client/SkyProviderMoon.java

That is referenced from: world.provider.getSkyRenderer()

For Galacticraft's own worlds, instead of setting the world.provider.getSkyRenderer() method with a constant return value, we call setSkyRenderer() once from the TickHandlerClient. I'm not sure exactly why - probably it does not have to be done that way and it is only to make sure that there is just once instance of the SkyProvider in use.
 
Last edited:
Dec 7, 2015
12
2
3
25
Can you make a tutorial on how to make a multi-biome planet with a breathable atmosphere?
And a custom model for a new tier of rocket? I want to make an addon with these two things.
I want a rocket that looks like a space shuttle and an Earthlike planet with higher gravity than normal.
 

genius64

Member
Content developer
Cosmic Horizons
Giant Galaxy
Jan 18, 2017
139
25
28
16
how to do galacticraft saw a PLANET and not a moon?
 
Feb 6, 2018
1
0
1
15
I am really trying to get this working in 1.12.2 with Galacticraft 4. So I downloaded the API Files for Galacticraft 4 and imported them and started coding, I didn't get much errors that I couldn't figure out how to solve, one error was in the ChunkProvider with the biome, the other error was in the WorldChunkManager. I just deleted all parts that gave me errors and with 0 errors I started the game.
When I look at the "star map" I see my moon, but when I get into a rocket and launch I get a crash as soon as the selection screen should be coming.
What did I do wrong / is this tutorial possible with Galacticraft 4?
 

hohserg

Member
Mar 1, 2020
1
0
1
23
Last edited:

genius64

Member
Content developer
Cosmic Horizons
Giant Galaxy
Jan 18, 2017
139
25
28
16
This guide is outdated and not updated. None of this will work on new versions 1.7.10, and even more so on 1.8.9, 1.10.2 and 1.11.2