Where Is the Config File for Mods in Minecraft

A few weeks ago, YouTube recommended ME a Minecraft video from Dream's Channel in which atomic number 2 was trying to beat the game while his acquaintance George attempted to stop him. That video was really fun and got me to explore more of their content.

Right now, there's a bunch of people transcription and uploading Minecraft videos to YouTube, merely these two found a right smart to make their content different. Basically, they build their have plugins to change the rules of the game and then they record themselves attempting to beat the modified game. Every I keister articulate is that I love their content, and it's awesome to understand what you force out accomplish with the power of encrypt.

A a couple of days later, I had an idea to develop a Minecraft stylish and thought Wherefore not? It will be fun!

Selecting the tools

Just look-alike in Minecraft, we need some tools but in this display case, they will facilitate USA in the creation outgrowth of our first mod.

Bigeminal tools help you material body Minecraft mods, and I chose Fabric because one of the mods that I usually play with was built with information technology.

Minecraft uses Java and so does Fabric, which means we also need to have the Coffee Development Kit or JDK installed. To be more specific, we indigence the JDK 8 to be able to compile our mod. You can download it on this page.

Last but non least, we need to pick a computer code editor, in this case, I chose Seeable Studio Code because it's my favorite editor. Nevertheless, you buns use whatever editor you like for this guide, arsenic near of the stairs bequeath be performed in the CLI.

Setting up the project

For this conduct, we will be victimisation a fledgling to move quickly into actually building our first mod. Lashkar-e-Tayyiba's go through the pursual steps:

1. Clone / Download the secretary

If you use Git, sportsmanlike clone the repo:

                          $              git clone https://github.com/HorusGoul/fabric-mod-starter.stinker                      

Enter fullscreen mode Croak fullscreen mode

Otherwise, get through this link up to download it.

2. Open the project folder with your inscribe editor program

Victimization Modality Studio Code:

                          $              code fabric-mod-entran                      

Enter fullscreen mode Exit fullscreen mode

3. Open a terminal inside the project leaflet and run the client

                          $                            compact disk              fabric-mod-fledgling              $              ./gradlew runClient                      

Enter fullscreen mode Exit fullscreen mode

NOTE: In Windows, you'll necessitate to run .\gradlew.bat runClient instead.

4. Check that everything is working

A Minecraft instance should be running now on your computer, and the console should have printed these two lines alongside others:

            ...  [main/INFO]: [STDOUT]: Hello Fabric mankind!  ...  [main/Information]: [STDOUT]: This line is printed past an example mod mixin!  ...                      

Enter fullscreen modality Exit fullscreen mode

If that's not the eccentric for you, recheck everything and if nonentity seems to work, leave a annotate or send me a P.m. and I'll try to supporte you.


Acquiring to know the project

At the moment, we can already get our hands begrime aside starting to code, but LET's get familiarized with about of the files.

gradle.properties

In this file, we can configure some values that will be used when building our mod. For example, we tin can change the Minecraft version, the fabric loader rendering, the mod version and other properties that we may need to change if we want to use new features of Fabric Beaver State Minecraft.

                          # Done to increase the memory available to gradle.                            org.gradle.jvmargs              =              -Xmx1G              # Fabric Properties                            # check these happening https://fabricmc.lucre/use                            minecraft_version              =              1.15.1              yarn_mappings              =              1.15.1+build.1              loader_version              =              0.7.3+build.176              # Mod Properties                            mod_version              =              1.0.0              maven_group              =              starter              archives_base_name              =              starter              # Dependencies                            # presently not on the main fabric site, break on the maven: https://maven.fabricmc.net/ultimate/fabricmc/fabric-api/fabric-api                            fabric_version              =              0.4.25+work up.282-1.15                      

Enter fullscreen style Exit fullscreen way

src/main

Inside the src leaflet, we will be able to uncovering another folder called intense. That's where the code and resources of our mod are settled.

src/important/coffee

All the Java code is located deep down this folder. There we pot find a package called starter which contains two items: the StarterMod.java file and the mixin package.

We fanny find the file in StarterMixin.coffee wrong the mixin package.

TIP: If you're using Optic Studio Code, I recommend you to install the Java Extension Pack. IT will power your editor with a bunch of utilities to make Coffee developing easier.

StarterMod.java

This is the main entry point of our mod, as we can see, it belongs to the freshman package and implements the onInitialize() method, which merely prints Hello Fabric world! to the console.

                          package              starter              ;              import              net.fabricmc.api.ModInitializer              ;              public              class              StarterMod              implements              ModInitializer              {              @Override              public              void              onInitialize              ()              {              // This code runs as soon as Minecraft is in a mod-load-ready state.              // However, some things (comparable resources) may still be uninitialized.              // Proceed with mild care.              System              .              out              .              println              (              "Hello Fabric humanity!"              );              }              }                      

Figure fullscreen mode Exit fullscreen manner

StarterMixin.Java

This class belongs to the starter.mixin package. Our mod will be really smallish so we shouldn't worry very much almost the file structure of our project. Let's good assume that all mixins volition be located inside the starter.mixin package.

And what are mixins?

Mixins are in agitate of injecting code into existing classes of the courageous. For case, in StarterMixin.java, we are injecting a method at the beginning (HEAD) of the init() method acting that is implemented in the TitleScreen category from Minecraft.

Now, if we lade this mixin, erst Minecraft calls the init() method of TitleScreen, our method that includes the Scheme.out.println("This line is printed past an example mod mixin!"); will also comprise called!

That's part of the magic of mixins, and this is just the tip of the iceberg, for now, this is all we need to build our mod. If you want more in-astuteness noesis you should go check the Mixin docs.

                          package              appetiser.mixin              ;              importee              net.minecraft.client.GUI.screen door.TitleScreen              ;              import              org.spongepowered.asm.mixin.Mixin              ;              import              org.spongepowered.asm.mixin.shot.At              ;              import              org.spongepowered.asm.mixin.injection.Inject              ;              import              org.spongepowered.asm.mixin.injectant.recall.CallbackInfo              ;              @Mixin              (              TitleScreen              .              class              )              public              assort              StarterMixin              {              @Inject              (              at              =              @At              (              "HEAD"              ),              method              =              "init()V"              )              private              void              init              (              CallbackInfo              info              )              {              Organisation              .              out              .              println              (              "This line is printed by an representative mod mixin!"              );              }              }                      

Put down fullscreen mode Way out fullscreen mode

src/of import/resources

Inside the resources folder, we rump find the assets folder, which right forthwith only contains the ikon for our mod. Besides that folder, there are two JSON files:

fabric.modernistic.json

For this file, I recommend you to depart into the Textile docs active fabric.mod.json and show just about every field defined inside the file of our imag.

If you favor to read the docs later, just take a look into at the entrypoints and mixins properties.

I bet you can already see a joining here. In the entrypoints is where we are tattle Textile which one of our Java classes should act as as the main entry point of our mod.

And then, there's the mixins prop, where we simply tell Framework the location of some Mixin configuration file we want to include in our mod. Therein case, we only have one, freshman.mixins.json.

                          {                                          "schemaVersion"              :                                          1              ,                                          "id"              :                                          "starter"              ,                                          "version"              :                                          "${version}"              ,                                          "list"              :                                          "Newbie Mod"              ,                                          "description"              :                                          "Describe your mod!"              ,                                          "authors"              :                                          [              "Your Name"              ],                                          "meet"              :                                          {                                          "homepage"              :                                          "https://horuslugo.com"              ,                                          "sources"              :                                          "https://github.com/HorusGoul/fabric-modernistic-starter motor"                                          },                                          "license"              :                                          "MIT"              ,                                          "icon"              :                                          "assets/appetizer/icon.png"              ,                                          "environment"              :                                          "*"              ,                                          "entrypoints"              :                                          {                                          "main"              :                                          [              "starter.StarterMod"              ]                                          },                                          "mixins"              :                                          [              "starter.mixins.json"              ],                                          "depends"              :                                          {                                          "fabricloader"              :                                          ">=0.7.3"              ,                                          "minecraft"              :                                          "1.15.x"                                          },                                          "suggests"              :                                          {                                          "flamingo"              :                                          "*"                                          }                                          }                                                  

Enter fullscreen mode Exit fullscreen mode

starter.mixins.json

Remember our StarterMixin class? This is how we can tell the toolchain the mixins that we lack to include in our mod. The package prop is where we delineate the Java package where the mixins are located, and inside the mixins array is where we hind end set down wholly the mixin classes that we want to include to the game.

Alongside mixins there are two early properties that allow us to specify the environment where we desire to load up some mixins. Those properties are server and client, just in this case, we're not using them.

This file follows the specification defined in the Mixin configuration files section of the Mixin Docs. Just the synoptical atomic number 3 earlier, I recommend you to attend the docs and learn more about this register 😄

                          {                                          "required"              :                                          true              ,                                          "package"              :                                          "newcomer.mixin"              ,                                          "compatibilityLevel"              :                                          "JAVA_8"              ,                                          "mixins"              :                                          [              "StarterMixin"              ],                                          "injectors"              :                                          {                                          "defaultRequire"              :                                          1                                          }                                          }                                                  

Enter fullscreen mode Exit fullscreen musical mode


Let's build our mod!

Today that we are familiar with the protrude, let's gets our hands dirty and create our mod!

In this case, the stylish testament simply alter one mechanic of the brave: receiving damage. We'll make it sol whenever a player receives damage, it testament switch its set back and inventory with another player in the server.

For this, we'ray going to need a mixin that injects code in the PlayerEntity class, to be more specified, scarcely before the end of the damage() method acting.

Detecting when players get hurt

Permit's make over this new mixin in the entran.mixin package with the name SwitchPlayerEntityMixin.java:

                          bundle              fledgling.mixin              ;              moment              org.spongepowered.asm.mixin.Mixin              ;              import              org.spongepowered.asm.mixin.injection.At              ;              implication              org.spongepowered.asm.mixin.injectant.Shoot              ;              importation              org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable              ;              spell              net.minecraft.entity.damage.DamageSource              ;              import              net.minecraft.entity.player.PlayerEntity              ;              @Mixin              (              PlayerEntity              .              social class              )              public              class              SwitchPlayerEntityMixin              {              @Inject              (              at              =              @At              (              "RETURN"              ),              method              =              "damage"              )              cloistered              evacuate              onDamage              (              DamageSource              source              ,              float              amount              ,              CallbackInfoReturnable              info              )              {              Arrangement              .              out              .              println              (              "The player received damage!"              );              }              }                      

Enter fullscreen modal value Exit fullscreen mode

Don't forget to add information technology to the starter.mixins.json file:

                          {                                          "required"              :                                          true              ,                                          "package"              :                                          "starter.mixin"              ,                                          "compatibilityLevel"              :                                          "JAVA_8"              ,                                          "mixins"              :                                          [              "StarterMixin"              ,                                          "SwitchPlayerEntityMixin"              ],                                          "injectors"              :                                          {                                          "defaultRequire"              :                                          1                                          }                                          }                                                  

Enter fullscreen mode Exit fullscreen mode

Nowadays perform the command ./gradlew runClient in the console, set up a Minecraft Earth in original way, snap some inst damage potions and try to make hurt.

Receiving Damage

Just like in the GIF, you should be able to construe with a new line pop in the console every time the player gets distress, and that means we can uphold to the explanation of what is going on.

Postulate a look to the mixin code, our intention was to get the method onDamage executed at the final stage of the method harm, that's why we are using the string Render instead of HEAD. Likewise, we are going to need the equipment casualty source and the quantity of damage inflicted. The in conclusion parametric quantity, info is required by the Mixin framing.

Both the generator and amount are parameters that the innovative price method acting receives, and that's the reason we can sportsmanlike expend them in our method.


Accessing the prevalent player

Right now, the modernistic is just printing process a furrow every time a player gets hurt, our next objective is accessing the player representativ.

We moldiness first remember that the onDamage method acting is inside of a PlayerEntity exemplify. We can claim reward of that and simply use this to access the instance properties and methods. The problem comes when the compiler yells at the States because information technology thinks that we're an instance of SwitchPlayerEntityMixin.

We don't have a way of life to tell the encyclopedist that this method is being executed in spite of appearanc of another type of class, and then we can use this trick:

                          PlayerEntity              self              =              (              PlayerEntity              )              (              Object              )              this              ;                      

Enter fullscreen mode Exit fullscreen mode

With this, we are telling the compiler that this is an Object and then, we cast the object as a PlayerEntity. And voilá! We have access to the player that is receiving damage, we buns now update our printed line to display the role player's name.

                          ...              @Mixin              (              PlayerEntity              .              class              )              populace              class              SwitchPlayerEntityMixin              {              @Throw i              (              at              =              @At              (              "RETURN"              ),              method              =              "damage"              )              one-on-one              void              onDamage              (              DamageSource              source              ,              float              quantity              ,              CallbackInfoReturnable              info              )              {              PlayerEntity              self              =              (              PlayerEntity              )              (              Object              )              this              ;              System              .              out              .              println              (              "The actor "              +              self              .              getGameProfile              ().              getName              ()              +              " received damage"              );              }              }                      

Enter fullscreen mode Exit fullscreen way

Showing the player's name in the console

Switching positions with another player

Now that we can access the player's properties and methods, we can use one of those to access the whole universe.

The world property references the current Minecraft World that is being played, and one of the things we can behave with it is getting the lean of the online players.

Therewith heel, we can pick one of those players and later, swop their positions as you fanny see in the following code:

                          package              starter.mixin              ;              import              coffee.util.List              ;              import              org.spongepowered.asm.mixin.Mixin              ;              spell              org.spongepowered.asm.mixin.injection.At              ;              moment              org.spongepowered.asm.mixin.injection.Inject              ;              import              org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable              ;              import              net.minecraft.entity.damage.DamageSource              ;              import              profits.minecraft.entity.player.PlayerEntity              ;              import              net.minecraft.util.math.BlockPos              ;              @Mixin              (              PlayerEntity              .              class              )              public              class              SwitchPlayerEntityMixin              {              @Interpose              (              at              =              @At              (              "RETURN"              ),              method acting              =              "damage"              )              private              void              onDamage              (              DamageSource              source              ,              float              amount              ,              CallbackInfoReturnable              info              )              {              PlayerEntity              self              =              (              PlayerEntity              )              (              Object              )              this              ;              // Pose all the players in the current minecraft world              List              <              PlayerEntity              >              players              =              (              List              <              PlayerEntity              >)              self              .              world              .              getPlayers              ();              // The player we'll change positions with.              PlayerEntity              otherPlayer              ;              // Stop the performance if the player is playing alone.              if              (              players              .              size              ()              <=              1              )              {              retrovert              ;              }              // Get a ergodic player from the players list.              // Repeat this process until we have a participant that is              // not the instrumentalist World Health Organization got hurt.              do              {              int              index              =              (              int              )              Maths              .              shock              (              Math              .              random              ()              *              players              .              sized              ());              otherPlayer              =              players              .              get              (              index              );              }              while              (              otherPlayer              ==              self              );              // Get the block position of both players              BlockPos              selfPos              =              self              .              getBlockPos              ();              BlockPos              otherPlayerPos              =              otherPlayer              .              getBlockPos              ();              // Teleport damaged player to the other player's coordinates              // We set the Y to 300 in order to avoid a collision with the other player.              //              // We add 0.5 to both X and Z because that's the heart and soul point of a halt              // and the players could suffocate low-level certain luck if we didn't              self              .              teleport              (              otherPlayerPos              .              getX              ()              +              0.5              ,              300              ,              otherPlayerPos              .              getZ              ()              +              0.5              );              // Teleport the other instrumentalist to the position of the broken player.              otherPlayer              .              teleport              (              selfPos              .              getX              ()              +              0.5              ,              selfPos              .              getY              (),              selfPos              .              getZ              ()              +              0.5              );              // Finally change the Y to the real esteem and complete the teleport of both              // players.              self              .              teleport              (              otherPlayerPos              .              getX              ()              +              0.5              ,              otherPlayerPos              .              getY              (),              otherPlayerPos              .              getZ              ()              +              0.5              );              }              }                      

Enter fullscreen mode Exit fullscreen mode

Later implementing this, you'll need two Minecraft clients to be able to test it. You can do it past opening one with ./gradlew runClient and then using the official Minecraft client with your Mojang account. And so, active the test world in Local area network and join it with the other client.

Switching player positions

Swapping their inventories

And now we'll add the finale feature of the mod: swapping the inventory of the players.

To swap the inventories of two players, we have to dead ringer each inventory and after that, we hindquarters just replace and swap them. The inventory of a participant canful be accessed victimisation the inventory property.

The class PlayerInventory has 2 methods that we'll use, serialize and deserialize. The first base one allows us to clone the content of the stock-take aside putting it inside of a ListTag so, we can use the second extraordinary to substitute the content of an inventory with the content that is at bottom of a ListTag.

Hera's the code:

                          // ... teleports ...              // Only swap inventories if the players are alive              if              (              self              .              getHealth              ()              >              0.0f              &&adenosine monophosphate;              otherPlayer              .              getHealth              ()              >              0.0f              )              {              // Set out the inventories of both players              ListTag              selfInventory              =              person              .              inventory              .              serialize              (              new              ListTag              ());              ListTag              otherPlayerInventory              =              otherPlayer              .              inventory              .              serialise              (              new              ListTag              ());              // Swap them              self              .              stock list              .              deserialize              (              otherPlayerInventory              );              otherPlayer              .              inventory              .              deserialize              (              selfInventory              );              }                      

Move in fullscreen mode Exit fullscreen mode

As you may have noticed, we're simply swapping the inventories if both players are alive because if we get into't admit this check, uncomparable of the inventories would bring fort lost whenever a role player died.

Swapping their inventories

The inalterable code

If you reached up until this dot, congrats! You've built your 1st Minecraft mod, we should now remove the files that aren't needed, for instance, StarterMixin.coffee and StarterMod.coffee. Wear't leave to get rid of the references to these files deep down cloth.mod.json and starters.mixins.json.

I also recommend you to rename the software from starter to whatever you want, just recall to change every occurrence in the envision.

You can find the latest version of the code in the branch final-code of the fledgling repo. Click Hera see the final version of the mod.

Packaging the mod

If you're familiar with Minecraft Mods, you may already know that mods usually seminal fluid packaged inside .zip or .jar files which later you drop inside the mods leaflet in the server or client of Minecraft.

To create a bundle of your mod, you only need to run the following command:

            $ ./gradlew build                      

Enter fullscreen mode Outlet fullscreen mode

If everything compiles aright, you'll be able to find the .jar inside the ./build/libs folder of your project. In all but cases, you'll wishing to pick the production version without sources, but there Crataegus laevigata be cases where also shipping a ontogenesis version along with the sources is punter.

starter-1.0.0.jar inside of the ./build/libs folder

That's it, you can today free fall that .jar inside your mods brochure, just don't block to install the Fabric API first, and for that, you hind end read the Installing Fabric section in their wiki if you want to learn how to do it.


Learning resources

Here are some resources that may place handy if you wishing to learn more about Minecraft Modding:

  • The Fabric Wiki. This one has already been mentioned in the article, but badly, go check information technology out because at that place's a good deal of content that I haven't covered!

  • The Forge API. The Forge API is the most famous Minecraft API, you may want to stop it out because some of the outflank mods out there have been made-up with information technology!

  • ScriptCraft. In that location seems to be a way to soma mods using JavaScript, so if you have a background in network dev, you whitethorn want to try this one.

  • MCreator. As their site says, MCreator is a software wont to nominate Minecraft mods and data packs using an visceral easy-to-learn interface or with an integrated code editor. If you know about someone that wants to get rolling with programming, this may be a good direction to introduce them!

Conclusion

Building my first Minecraft Mod was interesting because I got to know a little more about how my favorite game works, and I even managed to guile something really fun to play.

Also, I took this as an opportunity to create this article because I think modding is a great elbow room to get introduced to programming, and in that respect are a good deal of Minecraft players that may get interested and end up learnedness a lot about software development.

I hope you had a great time meter reading this clause. If you decide to continue learning I invite you to share your progress with U.S.A, who knows, maybe a Minecraft Modding community can follow born inside of dev.to 🔥

Where Is the Config File for Mods in Minecraft

Source: https://dev.to/horusgoul/creating-a-minecraft-mod-using-java-and-fabric-3bmo

0 Response to "Where Is the Config File for Mods in Minecraft"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel