Skip to content

Commit

Permalink
Prepare for pypi release
Browse files Browse the repository at this point in the history
  • Loading branch information
maurosbicego committed Oct 21, 2021
1 parent 58ad282 commit 35a4eb6
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 40 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/python3
import sys
from pyanvil import World, BlockState, Material
from pyanvileditor import World, BlockState, Material

with World('A', save_location='/home/dallen/.minecraft/saves', debug=True) as wrld:
cv = wrld.get_canvas()
cv.select_rectangle((334, 67, -240), (347, 100, -222)).copy().paste(wrld, (411, 105, -302))
cv.select_rectangle((334, 67, -240), (347, 100, -222)).fill(BlockState(Material.diamond_block, {}))

print('Saved!')
print('Saved!')
7 changes: 0 additions & 7 deletions pyanvil/__init__.py

This file was deleted.

7 changes: 7 additions & 0 deletions pyanvileditor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyanvileditor.biomes import Biome
from pyanvileditor.materials import Material
from pyanvileditor.world import World, Chunk, Block, BlockState
from pyanvileditor.canvas import Canvas
from pyanvileditor.schematic import Schematic

import pyanvileditor.nbt
File renamed without changes.
6 changes: 3 additions & 3 deletions pyanvil/canvas.py → pyanvileditor/canvas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys, math
from pyanvil.schematic import Schematic
from pyanvileditor.schematic import Schematic

class WorldTask:
def __init__(self, location, new_state):
Expand All @@ -20,7 +20,7 @@ def fill(self, state):
self.work_queue.append(WorldTask(b, my_state))

self.selection.clear()

if self.auto_commit:
self.commit()

Expand Down Expand Up @@ -94,4 +94,4 @@ def _dist(loc1, loc2):
dy = abs(loc1[1] - loc2[1]) ** 2
dz = abs(loc1[2] - loc2[2]) ** 2

return math.sqrt(dx + dy + dz)
return math.sqrt(dx + dy + dz)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 14 additions & 14 deletions pyanvil/world.py → pyanvileditor/world.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys, math, gzip, zlib, time, os
from pathlib import Path
import pyanvil.nbt as nbt
import pyanvil.stream as stream
from pyanvil.biomes import Biome
from pyanvil.canvas import Canvas
import pyanvileditor.nbt as nbt
import pyanvileditor.stream as stream
from pyanvileditor.biomes import Biome
from pyanvileditor.canvas import Canvas

class BlockState:
def __init__(self, name, props):
Expand Down Expand Up @@ -67,7 +67,7 @@ def serialize(self):
new_palette = self._serialize_palette()
serial_section.add_child(new_palette)
serial_section.add_child(self._serialize_blockstates(mat_id_mapping))

if not serial_section.has('SkyLight'):
serial_section.add_child(nbt.ByteArrayTag(tag_name='SkyLight', children=[nbt.ByteTag(-1, tag_name='None') for i in range(2048)]))

Expand All @@ -88,7 +88,7 @@ def _serialize_palette(self):
serial_props.add_child(nbt.StringTag(str(val), tag_name=name))
palette_item.add_child(serial_props)
serial_palette.add_child(palette_item)

return serial_palette

def _serialize_blockstates(self, state_mapping):
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, xpos, zpos, sections, raw_nbt, orig_size):
self.raw_nbt = raw_nbt
self.biomes = [Biome.from_index(i) for i in self.raw_nbt.get('Level').get('Biomes').get()]
self.orig_size = orig_size

def get_block(self, block_pos):
return self.get_section(block_pos[1]).get_block([n % 16 for n in block_pos])

Expand All @@ -139,12 +139,12 @@ def find_like(self, string):
for z1 in range(16):
if string in section.get_block((x1, y1, z1))._state.name:
results.append((
(x1 + self.xpos * 16, y1 + sec * 16, z1 + self.zpos * 16),
(x1 + self.xpos * 16, y1 + sec * 16, z1 + self.zpos * 16),
section.get_block((x1, y1, z1))
))
return results

# Blockstates are packed based on the number of values in the pallet.
# Blockstates are packed based on the number of values in the pallet.
# This selects the pack size, then splits out the ids
def unpack(raw_nbt):
sections = {}
Expand All @@ -159,7 +159,7 @@ def unpack(raw_nbt):
# Sections which contain only air have no states.
states = []
if section.has('Palette'):
palette = [
palette = [
BlockState(
state.get('Name').get(),
state.get('Properties').to_dict() if state.has('Properties') else {}
Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(self, world_folder, save_location=None, debug=False, read=True, wri

def __enter__(self):
return self

def __exit__(self, typ, val, trace):
if typ is None:
self.close()
Expand All @@ -264,7 +264,7 @@ def close(self):
with open(self.world_folder / 'region' / region_name, mode='r+b') as region:
region.seek(0)
locations = [[
int.from_bytes(region.read(3), byteorder='big', signed=False) * 4096,
int.from_bytes(region.read(3), byteorder='big', signed=False) * 4096,
int.from_bytes(region.read(1), byteorder='big', signed=False) * 4096
] for i in range(1024) ]

Expand Down Expand Up @@ -345,7 +345,7 @@ def get_canvas(self):
def _load_chunk(self, chunk_pos):
with open(self.world_folder / 'region' / self._get_region_file(chunk_pos), mode='rb') as region:
locations = [[
int.from_bytes(region.read(3), byteorder='big', signed=False) * 4096,
int.from_bytes(region.read(3), byteorder='big', signed=False) * 4096,
int.from_bytes(region.read(1), byteorder='big', signed=False) * 4096
] for i in range(1024) ]

Expand Down Expand Up @@ -381,4 +381,4 @@ def _get_chunk(self, block_pos):
return (math.floor(block_pos[0] / 16), math.floor(block_pos[2] / 16))

def _get_region(self, chunk_pos):
return (math.floor(chunk_pos[0] / 32), math.floor(chunk_pos[1] / 32))
return (math.floor(chunk_pos[0] / 32), math.floor(chunk_pos[1] / 32))
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from distutils.core import setup
setup(
name = 'pyanvileditor',
packages = ['pyanvileditor'],
version = '0.1',
license='MIT',
description = 'Python3 library to load and edit minecraft savegames',
author = 'Donovan Allen, Mauro Sbicego',
author_email = '[email protected]',
url = 'https://github.com/maurosbicego/PyAnvilEditor',
download_url = 'https://github.com/maurosbicego/PyAnvilEditor/archive/v_01.tar.gz',
keywords = ['minecraft', 'anvil', 'editor'],
install_requires=[],
classifiers=[
'Development Status :: 4 - Beta'
],
)
24 changes: 12 additions & 12 deletions test/nbt_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyanvil.nbt import ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag
from pyanvil.nbt import ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag, LongArrayTag
from pyanvil.nbt import parse_nbt
from pyanvil.stream import OutputStream, InputStream
from pyanvileditor.nbt import ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag
from pyanvileditor.nbt import ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag, LongArrayTag
from pyanvileditor.nbt import parse_nbt
from pyanvileditor.stream import OutputStream, InputStream

def build_simple_nbt_tag_test(clz, test_val, test_bin):
class TestSimpleNBTTag:
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_deserializing(args):
assert parsed_tag == expected_tag, f'Tag {clz.clazz_name}'

return TestArrayNBTTag


TestByteTag = build_simple_nbt_tag_test(ByteTag, 75, [75])
TestShortTag = build_simple_nbt_tag_test(ShortTag, 3*10**4, [117, 48])
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_serializing_simple_data(args):
list(b'Test') + \
[5, 0, 0, 0, 2] +\
[63, 192, 0, 0, 65, 50, 102, 102]

assert binary_tag == expected_tag, 'Tag ListTag with FloatTag elements'

def test_deserializing_simple_data(args):
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_serializing_list_data(args):
[25, 31] +\
[5, 0, 0, 0, 1] +\
[63, 192, 0, 0]

assert binary_tag == expected_tag, 'Tag ListTag with ListTag elements'

def test_deserializing_list_data(args):
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_serializing_compund_data(args):
[1, 0, 3,] + list(b'dp2') + [31, 0] +\
[1, 0, 3,] + list(b'dp3') + [25] +\
[1, 0, 3,] + list(b'dp4') + [31, 0]

assert binary_tag == expected_tag, 'Tag ListTag with ListTag elements'

def test_deserializing_compund_data(args):
Expand All @@ -192,15 +192,15 @@ def test_deserializing_compund_data(args):
class TestCompoundNBTTag:
def test_serializing(args):
tag = CompoundTag(tag_name='Test', children=[
ByteTag(25, tag_name='dp1'),
ByteTag(25, tag_name='dp1'),
FloatTag(1.5, tag_name='dp2'),
ListTag(ByteTag.clazz_id, tag_name='dp3', children=[
ByteTag(35)
]),
CompoundTag(tag_name='dp4', children=[
ByteArrayTag(tag_name='sub_dp', children=[
ByteTag(10),
ByteTag(20)
ByteTag(20)
])
])
])
Expand Down Expand Up @@ -228,15 +228,15 @@ def test_deserializing(args):
[0]))
parsed_tag = parse_nbt(raw_tag)
tag = CompoundTag(tag_name='Test', children=[
ByteTag(25, tag_name='dp1'),
ByteTag(25, tag_name='dp1'),
FloatTag(1.5, tag_name='dp2'),
ListTag(ByteTag.clazz_id, tag_name='dp3', children=[
ByteTag(35)
]),
CompoundTag(tag_name='dp4', children=[
ByteArrayTag(tag_name='sub_dp', children=[
ByteTag(10),
ByteTag(20)
ByteTag(20)
])
])
])
Expand Down
4 changes: 2 additions & 2 deletions test/stream_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyanvil.stream import InputStream, OutputStream
from pyanvileditor.stream import InputStream, OutputStream

class TestInputStream:

Expand All @@ -23,4 +23,4 @@ def test_writing_data(args):
stream = OutputStream()
stream.write(b'Hello World')
stream_data = stream.get_data()
assert stream_data == b'Hello World'
assert stream_data == b'Hello World'

0 comments on commit 35a4eb6

Please sign in to comment.