master
1
2<!DOCTYPE HTML>
3<html>
4<head>
5 <meta charset="utf-8">
6 <title>Move Minecraft Spawn with Python - BryFry</title>
7 <meta name="author" content="bryfry">
8
9 <meta name="description" content="The setup for this post is that in a vanilla Minecraft server there
10isn’t a way to set the protection size to 0 (yes, I know bukkit can do …">
11 <meta name="keywords" content="Python, Minecraft, NBT, Spawn">
12 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
13
14 <link href="/atom.xml" rel="alternate" title="BryFry" type="application/atom+xml">
15 <link rel="canonical" href="">
16 <link href="/favicon.ico" rel="shortcut icon">
17 <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
18
19<!-- Fonts -->
20 <link href='http://fonts.googleapis.com/css?family=Slackey' rel='stylesheet' type='text/css'>
21 <link href='http://fonts.googleapis.com/css?family=Fjalla+One' rel='stylesheet' type='text/css'>
22 <link href='http://fonts.googleapis.com/css?family=Amethysta' rel='stylesheet' type='text/css'>
23 <link href='http://fonts.googleapis.com/css?family=Exo' rel='stylesheet' type='text/css'>
24 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
25 <!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
26
27 <script type="text/javascript" src="/javascripts/jquery-tapir.js"></script>
28
29 <!-- remove or comment it to disable ajaxification -->
30 <script src="/javascripts/ajaxify.js"></script>
31
32
33</head>
34
35
36<body>
37 <div id="wrapper">
38 <header id="header" class="inner"><!-- for more effects see _animate.scss -->
39<h1>
40 <a href="">
41 <div id="headerbg">
42 BryFry
43 </div>
44 </a>
45</h1>
46
47<!-- use full url including 'index.html' for navigation bar if you are using ajax -->
48<ul id="nav">
49 <li id="ajax"><a href="/index.html">Home</a></li>
50 <li id="ajax"><a href="/blog/archives/index.html">Archives</a></li>
51 <li><a href="/atom.xml">RSS</a></li>
52
53</ul>
54
55
56
57
58</header>
59
60<div id="toload">
61<!-- begin toload -->
62 <div id="content" class="inner">
63 <article class="post">
64 <h2 class="title">Move Minecraft Spawn with Python</h2>
65 <div class="meta">
66 <div class="date">Published on:
67
68
69
70
71
72
73
74
75
76
77
78<time datetime="2012-04-29T21:54:00-04:00" pubdate data-updated="true">Apr 29<span>th</span>, 2012</time></div>
79 <div class="tags">Tags:
80
81
82 <a class='category' href='/blog/categories/minecraft/'>Minecraft</a>, <a class='category' href='/blog/categories/python/'>Python</a>
83
84
85</div>
86 </div>
87 <div class="entry-content"><p><img class="right" src="http://i.imgur.com/uubl0.png" width="150" height="150" title="Minecraft" ></p>
88
89<p>The setup for this post is that in a vanilla Minecraft server there
90isn’t a way to set the protection size to <code>0</code> (yes, I know bukkit can do
91this but, meh). This makes having the spawn in the middle of a nice
92area with shared chests, smelting, etc. a pain. So I wanted to move the
93spawn but I didn’t want to have to download the whole world, open it
94with a map editor, and then re-upload the whole thing again. Especially
95since I know the values are just stored inside the level.dat. So, below
96is how I used twoolie’s python NBT interface to move the spawn on our
97server.</p>
98
99<p>To install NBT, grab it from either <a
100href='https://github.com/twoolie/NBT'>github</a> or <a
101href='http://pypi.python.org/pypi/NBT'>pypi</a></p>
102
103<figure class='code'><figcaption><span>spawn-move.py</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
104<span class='line-number'>2</span>
105<span class='line-number'>3</span>
106<span class='line-number'>4</span>
107<span class='line-number'>5</span>
108<span class='line-number'>6</span>
109<span class='line-number'>7</span>
110<span class='line-number'>8</span>
111</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">from</span> <span class="nn">nbt</span> <span class="kn">import</span> <span class="o">*</span>
112</span><span class='line'><span class="n">level</span> <span class="o">=</span> <span class="n">nbt</span><span class="o">.</span><span class="n">NBTFile</span><span class="p">(</span><span class="s">'/<insert.path.here>/world/level.dat'</span><span class="p">,</span><span class="s">'rb'</span><span class="p">)</span>
113</span><span class='line'><span class="n">level</span><span class="p">[</span><span class="s">"Data"</span><span class="p">][</span><span class="s">"SpawnX"</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">newx</span>
114</span><span class='line'><span class="n">level</span><span class="p">[</span><span class="s">"Data"</span><span class="p">][</span><span class="s">"SpawnY"</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">newy</span>
115</span><span class='line'><span class="n">level</span><span class="p">[</span><span class="s">"Data"</span><span class="p">][</span><span class="s">"SpawnZ"</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">newz</span>
116</span><span class='line'><span class="k">print</span><span class="p">(</span><span class="n">level</span><span class="o">.</span><span class="n">pretty_tree</span><span class="p">())</span> <span class="c"># show changes</span>
117</span><span class='line'><span class="n">level</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="s">'/<insert.path.here>/world/level.dat'</span><span class="p">)</span>
118</span><span class='line'><span class="nb">exit</span><span class="p">()</span>
119</span></code></pre></td></tr></table></div></figure>
120
121</div>
122
123<div class="meta">
124
125</div>
126</article>
127
128 <div class="share">
129 <div class="addthis_toolbox addthis_default_style ">
130
131
132 <a class="addthis_button_tweet"></a>
133
134
135 <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
136
137 <a class="addthis_counter addthis_pill_style"></a>
138 </div>
139 <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid="></script>
140</div>
141
142
143
144<section id="comment">
145 <h2 class="title">Comments</h2>
146 <div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
147</div>
148</section>
149
150 </div>
151 <footer id="footer">
152 <div style="display:inline">
153 Copyright © 2013
154
155 bryfry
156. Powered by <a href="http://octopress.org">Octopress</a> |
157 Theme adapted from <a href="http://github.com/panks/fabric">fabric</a> by <a href="http://panks.me">Pankaj Kumar</a>
158</div>
159
160
161 </footer>
162 <script src="/javascripts/fabric.js"></script>
163<script src="/javascripts/jquery.fancybox.pack.js"></script>
164<script type="text/javascript">
165(function($){
166 $('.fancybox').fancybox();
167})(jQuery);
168</script> <!-- Delete or comment this line to disable Fancybox -->
169
170
171<script type="text/javascript">
172 var disqus_shortname = 'bryfry';
173
174
175 // var disqus_developer = 1;
176 var disqus_identifier = 'http://bryfry.github.com/blog/2012/04/29/move-minecraft-spawn-with-python/';
177 var disqus_url = 'http://bryfry.github.com/blog/2012/04/29/move-minecraft-spawn-with-python/';
178 var disqus_script = 'embed.js';
179
180 (function () {
181 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
182 dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
183 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
184 }());
185</script>
186
187
188
189 <script type="text/javascript">
190 var _gaq = _gaq || [];
191 _gaq.push(['_setAccount', 'UA-31317111-1']);
192 _gaq.push(['_trackPageview']);
193
194 (function() {
195 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
196 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
197 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
198 })();
199 </script>
200
201
202
203
204
205<!-- end toload -->
206</div>
207</div>
208<script src="/javascripts/jquery.ui.totop.js" type="text/javascript"></script>
209<script type="text/javascript">
210/*<![CDATA[*/
211;(function($){$().UItoTop({easingType:'easeOutCirc'});})(jQuery);
212/*]]>*/
213</script><!-- remove it to remove the scroll to top button -->
214</body>
215</html>