Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TileEntity.copyWithOffset now adjusts the coordinates of teleport com…

…mand blocks.
  • Loading branch information...
commit d6196eb136127ae57238d694338cd2107b3aac55 1 parent b824cfb
@codewarrior0 codewarrior0 authored
View
32 entity.py
@@ -96,6 +96,38 @@ def copyWithOffset(cls, tileEntity, copyOffset):
eTag['x'] = nbt.TAG_Int(tileEntity['x'].value + copyOffset[0])
eTag['y'] = nbt.TAG_Int(tileEntity['y'].value + copyOffset[1])
eTag['z'] = nbt.TAG_Int(tileEntity['z'].value + copyOffset[2])
+ if eTag['id'].value == "Control":
+ command = eTag['Command'].value
+
+ # Adjust teleport command coordinates.
+ # /tp <playername> <x> <y> <z>
+ if command.startswith('/tp'):
+ words = command.split(' ')
+ if len(words) > 4:
+ x, y, z = words[2:5]
+
+ # Only adjust non-relative teleport coordinates.
+ # These coordinates can be either ints or floats. If ints, Minecraft adds
+ # 0.5 to the coordinate to center the player in the block.
+ # We need to preserve the int/float status or else the coordinates will shift.
+ # Note that copyOffset is always ints.
+
+ def num(x):
+ try:
+ return int(x)
+ except ValueError:
+ return float(x)
+
+ if x[0] != "~":
+ x = str(num(x) + copyOffset[0])
+ if y[0] != "~":
+ y = str(num(y) + copyOffset[1])
+ if z[0] != "~":
+ z = str(num(z) + copyOffset[2])
+
+ words[2:5] = x, y, z
+ eTag['Command'].value = ' '.join(words)
+
return eTag
View
20 test/entity_test.py
@@ -0,0 +1,20 @@
+from pymclevel import fromFile
+from templevel import TempLevel
+
+__author__ = 'Rio'
+
+def test_command_block():
+ level = TempLevel("AnvilWorld").level
+
+ cmdblock = fromFile("testfiles/Commandblock.schematic")
+
+ point = level.bounds.origin + [p/2 for p in level.bounds.size]
+ level.copyBlocksFrom(cmdblock, cmdblock.bounds, point)
+
+ te = level.tileEntityAt(*point)
+ command = te['Command'].value
+ words = command.split(' ')
+ x, y, z = words[2:5]
+ assert x == str(point[0])
+ assert y == str(point[1] + 10)
+ assert z == str(point[2])
View
BIN  testfiles/Commandblock.schematic
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.