def _get_structure_schema(entity_schema):
    return {
        "format_version":
        Int,
        "size":
        List[Int],
        "structure_world_origin":
        List[Int],
        "structure":
        schema(
            "structure", {
                "block_indices":
                List[List[Int]],
                "palette":
                schema(
                    "palette", {
                        "default":
                        schema(
                            "default", {
                                "block_palette": List[Int],
                                "block_position_data": Compound
                            })
                    }),
                "entities":
                List[entity_schema]
            })
    }
Exemple #2
0
def StrictSchema():
    return schema(
        "Thing",
        {
            "foo": String,
            "bar": List[schema("Bar", {"value": Int}, strict=True)]
        },
        strict=True,
    )
class StructureFile(File, schema('StructureFileSchema', {'': Structure})):
    def __init__(self, structure_data=None):
        super().__init__({'': structure_data or {}})
        self.gzipped = True

    @classmethod
    def load(cls, filename, gzipped=True):
        return super().load(filename, gzipped)
Exemple #4
0

StructureSchema = schema('StructureSchema', {
    'DataVersion':
    tag.Int,
    'author':
    tag.String,
    'size':
    tag.List[tag.Int],
    'palette':
    tag.List[schema('State', {
        'Name': tag.String,
        'Properties': tag.Compound,
    })],
    'blocks':
    tag.List[schema('Block', {
        'state': tag.Int,
        'pos': tag.List[tag.Int],
        'nbt': tag.Compound,
    })],
    'entities':
    tag.List[schema(
        'Entity', {
            'pos': tag.List[tag.Double],
            'blockPos': tag.List[tag.Int],
            'nbt': tag.Compound,
        })],
},
                         strict=True)

Exemple #5
0
BedrockLevelData = schema(
    "BedrockLevelData", {
        "CenterMapsToOrigin":
        Byte,
        "Difficulty":
        Int,
        "FlatWorldLayers":
        String,
        "ForceGameType":
        Byte,
        "GameType":
        Int,
        "Generator":
        Int,
        "InventoryVersion":
        String,
        "LANBroadcast":
        Byte,
        "LastPlayed":
        Long,
        "LevelName":
        String,
        "LimitedWorldOriginX":
        Int,
        "LimitedWorldOriginY":
        Int,
        "LimitedWorldOriginZ":
        Int,
        "MultiplayerGame":
        Byte,
        "NetherScale":
        Int,
        "NetworkVersion":
        Int,
        "Platform":
        Int,
        "PlatformBroadcast":
        Byte,
        "PlatformBroadcastMode":
        Int,
        "RandomSeed":
        Long,
        "SpawnX":
        Int,
        "SpawnY":
        Int,
        "SpawnZ":
        Int,
        "StorageVersion":
        Int,
        "Time":
        Long,
        "XBLBroadcast":
        Byte,
        "XBLBroadcastIntent":
        Byte,
        "XBLBroadcastMode":
        Int,
        "abilities":
        schema(
            "Abilities", {
                "attackmobs": Byte,
                "attackplayers": Byte,
                "buildandmine": Byte,
                "doorsandswitches": Byte,
                "flySpeed": Float,
                "flying": Byte,
                "instabuild": Byte,
                "invulnerable": Byte,
                "lightning": Byte,
                "mayfly": Byte,
                "op": Byte,
                "opencontainers": Byte,
                "permissionsLevel": Int,
                "playerPermissionsLevel": Int,
                "teleport": Byte,
                "walkSpeed": Float,
            }),
        "bonusChestEnabled":
        Byte,
        "bonusChestSpawned":
        Byte,
        "commandblockoutput":
        Byte,
        "commandsEnabled":
        Byte,
        "currentTick":
        Long,
        "dodaylightcycle":
        Byte,
        "doentitydrops":
        Byte,
        "dofiretick":
        Byte,
        "domobloot":
        Byte,
        "domobspawning":
        Byte,
        "dotiledrops":
        Byte,
        "doweathercycle":
        Byte,
        "drowningdamage":
        Byte,
        "eduLevel":
        Byte,
        "educationFeaturesEnabled":
        Byte,
        "experimentalgameplay":
        Byte,
        "falldamage":
        Byte,
        "firedamage":
        Byte,
        "hasBeenLoadedInCreative":
        Byte,
        "hasLockedBehaviorPack":
        Byte,
        "hasLockedResourcePack":
        Byte,
        "immutableWorld":
        Byte,
        "isFromLockedTemplate":
        Byte,
        "keepinventory":
        Byte,
        "lastOpenedWithVersion":
        List[Int],
        "lightningLevel":
        Float,
        "lightningTime":
        Int,
        "maxcommandchainlength":
        Int,
        "mobgriefing":
        Byte,
        "naturalregeneration":
        Byte,
        "prid":
        String,
        "pvp":
        Byte,
        "rainLevel":
        Float,
        "rainTime":
        Int,
        "sendcommandfeedback":
        Byte,
        "serverChunkTickRange":
        Int,
        "showcoordinates":
        Byte,
        "spawnMobs":
        Byte,
        "startWithMapEnabled":
        Byte,
        "texturePacksRequired":
        Byte,
        "tntexplodes":
        Byte,
        "worldStartCount":
        Long,
    })
Exemple #6
0
def LooseSchema():
    return schema('Thing', {
        'foo': String,
        'bar': List[schema('Bar', {'value': Int})]
    })
Exemple #7
0
def StrictSchema():
    return schema('Thing', {
        'foo': String,
        'bar': List[schema('Bar', {'value': Int}, strict=True)]
    },
                  strict=True)
BedrockLevelData = schema(
    'BedrockLevelData', {
        'CenterMapsToOrigin':
        Byte,
        'Difficulty':
        Int,
        'FlatWorldLayers':
        String,
        'ForceGameType':
        Byte,
        'GameType':
        Int,
        'Generator':
        Int,
        'InventoryVersion':
        String,
        'LANBroadcast':
        Byte,
        'LastPlayed':
        Long,
        'LevelName':
        String,
        'LimitedWorldOriginX':
        Int,
        'LimitedWorldOriginY':
        Int,
        'LimitedWorldOriginZ':
        Int,
        'MultiplayerGame':
        Byte,
        'NetherScale':
        Int,
        'NetworkVersion':
        Int,
        'Platform':
        Int,
        'PlatformBroadcast':
        Byte,
        'PlatformBroadcastMode':
        Int,
        'RandomSeed':
        Long,
        'SpawnX':
        Int,
        'SpawnY':
        Int,
        'SpawnZ':
        Int,
        'StorageVersion':
        Int,
        'Time':
        Long,
        'XBLBroadcast':
        Byte,
        'XBLBroadcastIntent':
        Byte,
        'XBLBroadcastMode':
        Int,
        'abilities':
        schema(
            'Abilities', {
                'attackmobs': Byte,
                'attackplayers': Byte,
                'buildandmine': Byte,
                'doorsandswitches': Byte,
                'flySpeed': Float,
                'flying': Byte,
                'instabuild': Byte,
                'invulnerable': Byte,
                'lightning': Byte,
                'mayfly': Byte,
                'op': Byte,
                'opencontainers': Byte,
                'permissionsLevel': Int,
                'playerPermissionsLevel': Int,
                'teleport': Byte,
                'walkSpeed': Float
            }),
        'bonusChestEnabled':
        Byte,
        'bonusChestSpawned':
        Byte,
        'commandblockoutput':
        Byte,
        'commandsEnabled':
        Byte,
        'currentTick':
        Long,
        'dodaylightcycle':
        Byte,
        'doentitydrops':
        Byte,
        'dofiretick':
        Byte,
        'domobloot':
        Byte,
        'domobspawning':
        Byte,
        'dotiledrops':
        Byte,
        'doweathercycle':
        Byte,
        'drowningdamage':
        Byte,
        'eduLevel':
        Byte,
        'educationFeaturesEnabled':
        Byte,
        'experimentalgameplay':
        Byte,
        'falldamage':
        Byte,
        'firedamage':
        Byte,
        'hasBeenLoadedInCreative':
        Byte,
        'hasLockedBehaviorPack':
        Byte,
        'hasLockedResourcePack':
        Byte,
        'immutableWorld':
        Byte,
        'isFromLockedTemplate':
        Byte,
        'keepinventory':
        Byte,
        'lastOpenedWithVersion':
        List[Int],
        'lightningLevel':
        Float,
        'lightningTime':
        Int,
        'maxcommandchainlength':
        Int,
        'mobgriefing':
        Byte,
        'naturalregeneration':
        Byte,
        'prid':
        String,
        'pvp':
        Byte,
        'rainLevel':
        Float,
        'rainTime':
        Int,
        'sendcommandfeedback':
        Byte,
        'serverChunkTickRange':
        Int,
        'showcoordinates':
        Byte,
        'spawnMobs':
        Byte,
        'startWithMapEnabled':
        Byte,
        'texturePacksRequired':
        Byte,
        'tntexplodes':
        Byte,
        'worldStartCount':
        Long
    })
schemX = 32
schemY = 32
schemZ = 32
Structure = schema(
    'Structure', {
        'DataVersion':
        Int,
        'author':
        String,
        'size':
        List[Int],
        'palette':
        List[schema('State', {
            'Name': String,
            'Properties': Compound,
        })],
        'blocks':
        List[schema('Block', {
            'state': Int,
            'pos': List[Int],
            'nbt': Compound,
        })],
        'entities':
        List[schema('Entity', {
            'pos': List[Double],
            'blockPos': List[Int],
            'nbt': Compound,
        })],
    })


class StructureFile(File, schema('StructureFileSchema', {'': Structure})):
Exemple #10
0
from collections import namedtuple
from io import BytesIO
import time
import json
import zipfile

from nbtlib import File, CompoundSchema, schema
from nbtlib.tag import (Int, Long, String, write_numeric, INT)

Block = namedtuple("Block", ["id", "data"])

BedrockLevelData = schema(
    "BedrockLevelData", {
        "FlatWorldLayers": String,
        "Generator": Int,
        "LastPlayed": Long,
        "LevelName": String,
        "StorageVersion": Int
    })


class BedrockLevelFile(File, CompoundSchema):
    schema = {"": BedrockLevelData}

    def __init__(self, level_data, version=8):
        super().__init__({"": level_data}, gzipped=False, byteorder="little")
        self.version = version

    def write(self, buff, byteorder="little"):
        tmp = BytesIO()
        super().write(tmp, byteorder)
Exemple #11
0
def LooseSchema():
    return schema("Thing", {
        "foo": String,
        "bar": List[schema("Bar", {"value": Int})]
    })
Exemple #12
0
    Pos: list[float]
    identifier: str
    Item: Optional[Item] = None

    def to_dict(self):
        dict = self.__dict__
        if dict["Item"] is None:
            del dict["Item"]
        else:
            dict["Item"] = self.Item.to_dict()

        return dict


EntitySchema = schema("EntitySchema", {
    "Pos": List[Float],
    "identifier": String,
})

ItemEntitySchema = schema(
    "ItemEntitySchema", {
        **EntitySchema.schema, "Item":
        schema(
            "Item", {
                "Name":
                String,
                "Damage":
                Short,
                "Count":
                Byte,
                "tag":
                schema(
Exemple #13
0
import nbtlib as nbt
from nbtlib import String, Int, List, Byte, Compound, Double, Long

# region:item_schemas

# region:--main_item_schemas

ItemDisplaySchema = nbt.schema("ItemDisplaySchema",
                               dict(color=Int, Name=String, Lore=List[String]))
"""Represents the 'display' key of :class:`ItemTagSchema`."""
ItemDisplaySchema.__doc__ = """Represents the 'display' key of :class:`ItemTagSchema`."""

ItemEnchantmentSchema = nbt.schema("ItemEnchantmentSchema",
                                   dict(id=String, lvl=Int))
"""Represents an enchantment, within the 'Enchantments' key of :class:`ItemTagSchema`."""
ItemEnchantmentSchema.__doc__ = """Represents an enchantment, within the 'Enchantments' key of \
:class:`ItemTagSchema`."""

ItemAttributeModifierSchema = nbt.schema(
    "ItemAttributeModifierSchema",
    dict(AttributeName=String,
         Name=String,
         Slot=String,
         Operation=Int,
         Amount=Double,
         UUIDMost=Long,
         UUIDLeast=Long))
"""Represents an attribute modifier, within the 'AttributeModifiers' key of :class:`ItemTagSchema`."""
ItemAttributeModifierSchema.__doc__ = """Represents an attribute modifier, within the 'AttributeModifiers' key of \
:class:`ItemTagSchema`."""
from __future__ import annotations

import json

from nbtlib import tag, schema, nbt, parse_nbt

from fast_world_creator.utils.level_dat_utils import get_template_dict

xyz_dict = {'X': tag.Byte, 'Y': tag.Byte, 'Z': tag.Byte}
dragon_fight_dict = {
    'ExitPortalLocation': schema('ExitPortalLocation', xyz_dict),
    'Gateways': tag.List[tag.Int],
    'DragonKilled': tag.Byte,
    'DragonUUIDLeast': tag.Long,
    'DragonUUIDMost': tag.Long,
    'PreviouslyKilled': tag.Byte
}
end_data_dict = {'DragonFight': schema('DragonFight', dragon_fight_dict)}
dimension_data_dict = {'1': schema('EndData', end_data_dict)}
game_rule_dict = {
    'announceAdvancements': tag.String,
    'commandBlockOutput': tag.String,
    'disableElytraMovementCheck': tag.String,
    'disableRaids': tag.String,
    'doDaylightCycle': tag.String,
    'doEntityDrops': tag.String,
    'doFireTick': tag.String,
    'doInsomnia': tag.String,
    'doImmediateRespawn': tag.String,
    'doLimitedCrafting': tag.String,
    'doMobLoot': tag.String,