Minecraft Server: Difference between revisions

DoggoBit (talk | contribs)
Removed flags from example, they were old and broken (causing minecraft-server to fail upon using them); instead recommended user to find their own flags. Also added a tip on changing server version/package
Line 6: Line 6:
== Setup ==
== Setup ==


The minimum example to have a Minecraft server running on localhost at the default port of <code>25565</code>. By setting the <code>eula</code> option to <code>true</code>, you are agreeing to the [https://www.minecraft.net/en-us/eula Minecraft EULA]
The minimum example to have a Minecraft server running on localhost at the default port of <code>25565</code>. By setting the <code>eula</code> option to <code>true</code>, you are agreeing to the [https://www.minecraft.net/en-us/eula Minecraft EULA].


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 37: Line 37:
     allow-cheats = true;
     allow-cheats = true;
   };
   };
   jvmOpts = "-Xms4092M -Xmx4092M -XX:+UseG1GC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10";
   jvmOpts = "-Xms2048M -Xmx4096M";
};
};
</nowiki>}}
</nowiki>}}
You might want to look at using using [https://docs.papermc.io/paper/aikars-flags/ Aikar's flags] or the [https://github.com/brucethemoose/Minecraft-Performance-Flags-Benchmarks Minecraft performance flags benchmark].


== Tips and tricks ==
== Tips and tricks ==
Line 45: Line 46:
=== Prefer IPv4 ===
=== Prefer IPv4 ===


To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code> (the first two options are just the defaults)
To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code>.


<syntaxhighlight lang="nix">
=== Use a different server version/package ===
jvmOpts = "-Xmx2048M -Xms2048M -Djava.net.preferIPv4Stack=true";
 
</syntaxhighlight>
To use a specific server version, or another Minecraft server—such as [https://papermc.io/ PaperMC]—change <code>services.minecraft-server.package</code> to a nix package that represents your desired server.
 
For example:
 
<code>services.minecraft-server.package = pkgs.minecraftServers.vanilla-1-12;</code>
 
or
 
<code>services.minecraft-server.package = pkgs.papermc;</code>


[[Category: Applications]]
[[Category: Applications]]
[[Category: Gaming]]
[[Category: Gaming]]