Switch to simpler ore gen config
- Ditch use of LargeOreDepsoits in favor of using Minecraft's native placed features, but with auto-generated files which give more subtly and expression in an automated way
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.format.datapack.moddata import ModData
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class DataPack:
|
||||
"""
|
||||
A collection of data used to configure a Minecraft instance.
|
||||
|
||||
see: https://minecraft.wiki/w/Data_pack
|
||||
"""
|
||||
|
||||
def __init__(self, name:str, mods:Iterable[ModData]|None=None):
|
||||
self.name = name
|
||||
self._mods:dict[str,ModData] = {}
|
||||
self._defaultMod:ModData|None = None
|
||||
|
||||
for mod in (mods or []):
|
||||
self.add(mod)
|
||||
|
||||
def add(self, mod:ModData) -> "DataPack":
|
||||
if not self._defaultMod:
|
||||
self._defaultMod = mod
|
||||
|
||||
self._mods[mod.name] = mod
|
||||
return self
|
||||
|
||||
def get(self, name:str) -> ModData:
|
||||
result = self._mods.get(name, None)
|
||||
if not result:
|
||||
result = self._mods[name] = ModData(name)
|
||||
|
||||
return result
|
||||
|
||||
@property
|
||||
def defaultMod(self) -> ModData|None:
|
||||
return self._defaultMod
|
||||
|
||||
@defaultMod.setter
|
||||
def defaultMod(self, mod:ModData):
|
||||
if mod:
|
||||
existingModData = self.get(mod.name)
|
||||
if not existingModData:
|
||||
self.add(mod)
|
||||
elif existingModData != mod:
|
||||
raise Exception(f"Datapack already has a mod named {mod.name}")
|
||||
|
||||
self._defaultMod = mod
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import mcpacker.format.datapack
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Classes ##########################################################################################
|
||||
|
||||
class BiomeModifier:
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": "neoforge:none",
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.format.datapack.biomemodifier import BiomeModifier
|
||||
from mcpacker.format.datapack.generationstep import GenerationStep
|
||||
from mcpacker.json import JsonBlob
|
||||
from mcpacker.format.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class AddFeatureBiomeModifier(BiomeModifier):
|
||||
class AddFeatureBiomeModifier:
|
||||
|
||||
def __init__(self, biomes:Iterable[str]|str, features:Iterable[str]|str, step:GenerationStep):
|
||||
if isinstance(biomes, str):
|
||||
@@ -21,7 +20,7 @@ class AddFeatureBiomeModifier(BiomeModifier):
|
||||
|
||||
def asJsobBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": "neoforge:add_features",
|
||||
"type": "forge:add_features",
|
||||
"biomes": list(self.biomes),
|
||||
"features": list(self.features),
|
||||
"step": str(self.step),
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.biomemodifier.addfeature
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
+3
-6
@@ -1,14 +1,11 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
from mcpacker.format.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Placement:
|
||||
|
||||
def __init__(self, gameId:str):
|
||||
self.gameId = gameId
|
||||
class NoopBiomeModifier:
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"type": "forge:none",
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.format.datapack.biomemodifier import BiomeModifier
|
||||
from mcpacker.format.datapack.generationstep import GenerationStep
|
||||
from mcpacker.json import JsonBlob
|
||||
from mcpacker.format.json import JsonBlob
|
||||
|
||||
|
||||
# Classes ##########################################################################################
|
||||
# Class ############################################################################################
|
||||
|
||||
class RemoveFeatureBiomeModifier(BiomeModifier):
|
||||
class RemoveFeatureBiomeModifier:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -26,7 +25,7 @@ class RemoveFeatureBiomeModifier(BiomeModifier):
|
||||
|
||||
def asJsobBlob(self) -> JsonBlob:
|
||||
result:dict[str,JsonBlob] = {
|
||||
"type": "neoforge:remove_features",
|
||||
"type": "forge:remove_features",
|
||||
"biomes": list(self.biomes),
|
||||
"features": list(self.features),
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.biomemodifier.removefeature
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -1,12 +1,11 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.format.datapack.biomemodifier import BiomeModifier
|
||||
from mcpacker.format.json import JsonBlob
|
||||
from mcpacker.model.resourceid import ResourceId
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Classes ##########################################################################################
|
||||
# Class ############################################################################################
|
||||
|
||||
class RemoveSpawnBiomeModifier(BiomeModifier):
|
||||
class RemoveSpawnBiomeModifier:
|
||||
|
||||
def __init__(self, biomes:Iterable[str]|str, entityTypes:Iterable[ResourceId]):
|
||||
if isinstance(biomes, str):
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.biomemodifier.removespawn
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -1,20 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
from typing import cast
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class BlockState:
|
||||
|
||||
def __init__(self, blockId:str, properties:JsonBlob|None=None):
|
||||
self.blockId = blockId
|
||||
self.properties = properties
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
result = cast(dict[str,JsonBlob], { "Name": self.blockId })
|
||||
|
||||
if self.properties:
|
||||
result["Properties"] = self.properties
|
||||
|
||||
return result
|
||||
@@ -1,20 +0,0 @@
|
||||
from mcpacker.format.datapack.blockstate import BlockState
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="state")
|
||||
def createBlockState():
|
||||
yield BlockState("minecraft:button", {"waterlogged": "true"})
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(state:BlockState):
|
||||
assert state.asJsonBlob() == {
|
||||
"Name": "minecraft:button",
|
||||
"Properties": {
|
||||
"waterlogged": "true"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class BlockStateProvider:
|
||||
|
||||
def __init__(self, gameId:str):
|
||||
self.gameId = gameId
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
raise NotImplementedError()
|
||||
@@ -1,19 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
from mcpacker.format.datapack.blockstate import BlockState
|
||||
from mcpacker.format.datapack.blockstateprovider import BlockStateProvider
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class SimpleStateProvider(BlockStateProvider):
|
||||
|
||||
def __init__(self, state:BlockState):
|
||||
super().__init__("minecraft:simple_state_provider")
|
||||
self.state = state
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"state": self.state.asJsonBlob(),
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
from mcpacker.format.datapack.blockstate import BlockState
|
||||
from mcpacker.format.datapack.blockstateprovider.simplestateprovider import SimpleStateProvider
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="state")
|
||||
def createBlockState():
|
||||
yield BlockState("minecraft:button", {"waterlogged": "true"})
|
||||
|
||||
@fixture(name="provider")
|
||||
def createProvider(state:BlockState):
|
||||
return SimpleStateProvider(state)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(provider:SimpleStateProvider):
|
||||
assert provider.asJsonBlob() == {
|
||||
"type": "minecraft:simple_state_provider",
|
||||
"state": {
|
||||
"Name": "minecraft:button",
|
||||
"Properties": {
|
||||
"waterlogged": "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class ConfiguredFeature:
|
||||
|
||||
def __init__(self, gameId:str):
|
||||
self.gameId = gameId
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"config": {},
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
from mcpacker.format.datapack.configuredfeature import ConfiguredFeature
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from mcpacker.format.datapack.placedfeature import PlacedFeature
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class RandomPatch(ConfiguredFeature):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
gameId:str,
|
||||
feature:"PlacedFeature",
|
||||
tries:int=128,
|
||||
xzSpread:int=7,
|
||||
ySpread:int=3,
|
||||
):
|
||||
super().__init__("minecraft:random_patch")
|
||||
|
||||
self.feature = feature
|
||||
self.tries = tries
|
||||
self.xzSpread = xzSpread
|
||||
self.ySpread = ySpread
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"feature": self.feature.gameId,
|
||||
"tries": self.tries,
|
||||
"xz_spread": self.xzSpread,
|
||||
"y_spread": self.ySpread
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
from mcpacker.format.datapack.blockstate import BlockState
|
||||
from mcpacker.format.datapack.placedfeature import PlacedFeature
|
||||
from mcpacker.format.datapack.blockstateprovider.simplestateprovider import SimpleStateProvider
|
||||
from mcpacker.format.datapack.configuredfeature.randompatch import RandomPatch
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="state")
|
||||
def createBlockState():
|
||||
yield BlockState("minecraft:button", {"waterlogged": "true"})
|
||||
|
||||
@fixture(name="provider")
|
||||
def createProvider(state:BlockState):
|
||||
return SimpleStateProvider(state)
|
||||
|
||||
@fixture(name="placedFeature")
|
||||
def createPlacedFeature():
|
||||
return PlacedFeature("noop", [])
|
||||
|
||||
@fixture(name="feature")
|
||||
def createFeature(placedFeature:PlacedFeature):
|
||||
return RandomPatch("test", placedFeature)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asJsonBlob(feature:RandomPatch):
|
||||
assert feature.asJsonBlob() == {
|
||||
"type": "minecraft:random_patch",
|
||||
"feature": "noop",
|
||||
"tries": 128,
|
||||
"xz_spread": 7,
|
||||
"y_spread": 3,
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
from mcpacker.format.datapack.blockstateprovider import BlockStateProvider
|
||||
from mcpacker.format.datapack.configuredfeature import ConfiguredFeature
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class SimpleBlock(ConfiguredFeature):
|
||||
|
||||
def __init__(self, toPlace:BlockStateProvider):
|
||||
super().__init__("minecraft:simple_block")
|
||||
self.toPlace = toPlace
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"config": {
|
||||
"to_place": self.toPlace.asJsonBlob()
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
from mcpacker.format.datapack.blockstate import BlockState
|
||||
from mcpacker.format.datapack.blockstateprovider.simplestateprovider import SimpleStateProvider
|
||||
from mcpacker.format.datapack.configuredfeature.simpleblock import SimpleBlock
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="state")
|
||||
def createBlockState():
|
||||
yield BlockState("minecraft:button", {"waterlogged": "true"})
|
||||
|
||||
@fixture(name="provider")
|
||||
def createProvider(state:BlockState):
|
||||
return SimpleStateProvider(state)
|
||||
|
||||
@fixture(name="feature")
|
||||
def createSimpleBlockFeature(provider:SimpleStateProvider):
|
||||
return SimpleBlock(provider)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(feature:SimpleBlock):
|
||||
assert feature.asJsonBlob() == {
|
||||
"type": "minecraft:simple_block",
|
||||
"config": {
|
||||
"to_place": {
|
||||
"type": "minecraft:simple_state_provider",
|
||||
"state": {
|
||||
"Name": "minecraft:button",
|
||||
"Properties": {
|
||||
"waterlogged": "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.generationstep
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -1,30 +0,0 @@
|
||||
# Class ############################################################################################
|
||||
|
||||
class HeightMapType:
|
||||
"""
|
||||
A cached record of the top block at all points in the world.
|
||||
|
||||
see: https://minecraft.wiki/w/Heightmap
|
||||
"""
|
||||
|
||||
def __init__(self, name:str):
|
||||
self.name = name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"HeightMapType(name={self.name})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def asData(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
# Constants ########################################################################################
|
||||
|
||||
MOTION_BLOCKING = HeightMapType("MOTION_BLOCKING")
|
||||
MOTION_BLOCKING_NO_LEAVES = HeightMapType("MOTION_BLOCKING_NO_LEAVES")
|
||||
OCEAN_FLOOR = HeightMapType("OCEAN_FLOOR")
|
||||
OCEAN_FLOOR_WG = HeightMapType("OCEAN_FLOOR_WG")
|
||||
WORLD_SURFACE = HeightMapType("WORLD_SURFACE")
|
||||
WORLD_SURFACE_WG = HeightMapType("WORLD_SURFACE_WG")
|
||||
@@ -1,7 +0,0 @@
|
||||
from mcpacker.format.datapack.heightmaptype import HeightMapType
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -1,23 +0,0 @@
|
||||
from mcpacker.format.datapack.configuredfeature import ConfiguredFeature
|
||||
from mcpacker.format.datapack.placedfeature import PlacedFeature
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class ModData:
|
||||
|
||||
def __init__(self, name:str):
|
||||
self.name = name
|
||||
self.biomeModifiers:list[Any] = []
|
||||
self.configuredFeatures:list[ConfiguredFeature] = []
|
||||
self.functions:list[Any] = []
|
||||
self.functionTags:list[Any] = []
|
||||
self.lootModifiers:list[Any] = []
|
||||
self.lootTables:list[Any] = []
|
||||
self.placedFeatures:list[PlacedFeature] = []
|
||||
self.recipes:list[Any] = []
|
||||
self.structures:list[Any] = []
|
||||
self.structureSets:list[Any] = []
|
||||
self.tags:list[Any] = []
|
||||
self.templatePools:list[Any] = []
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.moddata
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -0,0 +1,21 @@
|
||||
from mcpacker.format.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class NoopConfiguredFeature:
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": "minecraft:noop",
|
||||
"config": {},
|
||||
}
|
||||
|
||||
class NoopPlacedFeature:
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"feature": NoopConfiguredFeature().asJsonBlob(),
|
||||
"placement": []
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class PlacedFeature:
|
||||
|
||||
def __init__(self, gameId:str, placements:Iterable[Placement]):
|
||||
self.gameId = gameId
|
||||
self.placements = placements
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"feature": self.gameId,
|
||||
"placements": [p.asJsonBlob() for p in self.placements],
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
from mcpacker.format.datapack.placedfeature import PlacedFeature
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
@@ -1,9 +0,0 @@
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from typing import Any
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Biome(Placement):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("minecraft:biome")
|
||||
@@ -1,18 +0,0 @@
|
||||
from mcpacker.format.datapack.placement.biome import Biome
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="placement")
|
||||
def createPlacement():
|
||||
yield Biome()
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:biome",
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from mcpacker.format.datapack.heightmaptype import HeightMapType
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class HeightMap(Placement):
|
||||
|
||||
def __init__(self, heightMap:HeightMapType):
|
||||
super().__init__("minecraft:heightmap")
|
||||
self.heightMap = heightMap
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"heightmap": self.heightMap.asData()
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
from mcpacker.format.datapack.heightmaptype import WORLD_SURFACE
|
||||
from mcpacker.format.datapack.placement.heightmap import HeightMap
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="placement")
|
||||
def createPlacement():
|
||||
yield HeightMap(WORLD_SURFACE)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:heightmap",
|
||||
"heightmap": "WORLD_SURFACE"
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class InSquare(Placement):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("minecraft:in_square")
|
||||
@@ -1,18 +0,0 @@
|
||||
from mcpacker.format.datapack.placement.insquare import InSquare
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="placement")
|
||||
def createPlacement():
|
||||
yield InSquare()
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:in_square",
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class RarityFilter(Placement):
|
||||
|
||||
def __init__(self, chance:int):
|
||||
super().__init__("minecraft:rarity_filter")
|
||||
self.chance = chance
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"chance": self.chance,
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from mcpacker.format.datapack.placement.rarityfilter import RarityFilter
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="placement")
|
||||
def createPlacement():
|
||||
yield RarityFilter(4)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:rarity_filter",
|
||||
"chance": 4
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Mapping
|
||||
from mcpacker.model.resourceid import ResourceId
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Recipe:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
gameId:str|ResourceId,
|
||||
resultId:str|ResourceId,
|
||||
resultCount:int=1,
|
||||
resultComponents:Mapping[str,str]|None=None,
|
||||
):
|
||||
self.gameId = ResourceId.parse(gameId)
|
||||
self.resultComponents = resultComponents
|
||||
self.resultCount = resultCount
|
||||
self.resultId = ResourceId.parse(resultId)
|
||||
@@ -1,56 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Mapping
|
||||
from mcpacker.format.datapack.recipe import Recipe
|
||||
from mcpacker.model.resourceid import ResourceId
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class ShapedRecipe(Recipe):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
gameId:str|ResourceId,
|
||||
key:Mapping[str,(str|ResourceId|Iterable[ResourceId|str])],
|
||||
pattern:Iterable[str],
|
||||
resultId:str|ResourceId,
|
||||
resultCount:int=1,
|
||||
resultComponents:Mapping[str,str]|None=None,
|
||||
):
|
||||
super().__init__(gameId, resultId, resultCount, resultComponents)
|
||||
self.key = self._parseKey(key)
|
||||
self.pattern = self._parsePattern(pattern)
|
||||
|
||||
# Private Methods ##########################################################
|
||||
|
||||
def _parseKey(
|
||||
self,
|
||||
key:Mapping[str,(str|ResourceId|Iterable[ResourceId|str])]
|
||||
) -> dict[str, list[ResourceId]]:
|
||||
result:dict[str, list[ResourceId]] = {}
|
||||
|
||||
for name, value in key.items():
|
||||
finalValue:list[ResourceId] = []
|
||||
|
||||
if isinstance(value, str) or isinstance(value, ResourceId):
|
||||
finalValue = [ ResourceId.parse(value) ]
|
||||
elif isinstance(value, Iterable):
|
||||
finalValue = [ ResourceId.parse(e) for e in value ]
|
||||
|
||||
if len(name) != 1:
|
||||
raise ValueError(f"key names must be a single letter (\"{name}\" is not valid)")
|
||||
|
||||
result[name] = finalValue
|
||||
|
||||
return result
|
||||
|
||||
def _parsePattern(self, pattern:Iterable[str]) -> list[str]:
|
||||
result:list[str] = []
|
||||
|
||||
for row in pattern:
|
||||
if len(row) not in [2, 3]:
|
||||
raise ValueError(f"pattern rows must be 2 or 3 letters: (\"{row}\" is not valid)")
|
||||
|
||||
result.append(row)
|
||||
|
||||
return result
|
||||
@@ -1,27 +0,0 @@
|
||||
from pytest import fixture
|
||||
from mcpacker.format.datapack.recipe.shapedrecipe import ShapedRecipe
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="recipe")
|
||||
def createRecipe():
|
||||
yield ShapedRecipe(
|
||||
"iron_pickaxe",
|
||||
{"s": "stick", "i": "iron_ingot"},
|
||||
["iii", " s ", " s "],
|
||||
"iron_pickaxe"
|
||||
)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_recipe(recipe:ShapedRecipe):
|
||||
keyText = ", ".join(f"{k}:{str(v[0])}" for k,v in recipe.key.items())
|
||||
recipeText = "|".join(str(i) for i in recipe.pattern)
|
||||
|
||||
assert keyText == "s:minecraft:stick, i:minecraft:iron_ingot"
|
||||
assert recipeText == "iii| s | s "
|
||||
assert str(recipe.resultId) == "minecraft:iron_pickaxe"
|
||||
assert recipe.resultCount == 1
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Mapping
|
||||
from mcpacker.model.resourceid import ResourceId
|
||||
from mcpacker.format.datapack.recipe import Recipe
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class ShapelessRecipe(Recipe):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
gameId:str|ResourceId,
|
||||
ingredients:Iterable[str|ResourceId],
|
||||
resultId:str|ResourceId,
|
||||
resultCount:int=1,
|
||||
resultComponents:Mapping[str,str]|None=None,
|
||||
):
|
||||
super().__init__(gameId, resultId, resultCount, resultComponents)
|
||||
self.ingredients = self._parseIngredients(ingredients)
|
||||
|
||||
def _parseIngredients(self, ingredients:Iterable[str|ResourceId]) -> list[ResourceId]:
|
||||
result = [ ResourceId.parse(e) for e in ingredients ]
|
||||
|
||||
if len(result) > 9:
|
||||
raise ValueError("cannot have more than 9 ingredients (\"{len(result}\" is not valid")
|
||||
|
||||
return result
|
||||
@@ -1,17 +0,0 @@
|
||||
from pytest import fixture
|
||||
from mcpacker.format.datapack.recipe.shapelessrecipe import ShapelessRecipe
|
||||
|
||||
|
||||
# Fixtures #########################################################################################
|
||||
|
||||
@fixture(name="recipe")
|
||||
def createRecipe():
|
||||
yield ShapelessRecipe("flint_and_steel", ["iron_ingot", "flint"], "flint_and_steel")
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_recipe(recipe:ShapelessRecipe):
|
||||
assert ", ".join(str(i) for i in recipe.ingredients) == "minecraft:iron_ingot, minecraft:flint"
|
||||
assert str(recipe.resultId) == "minecraft:flint_and_steel"
|
||||
assert recipe.resultCount == 1
|
||||
@@ -1,33 +0,0 @@
|
||||
from collections.abc import Iterable
|
||||
from mcpacker.model.resourceid import ResourceId
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
import mcpacker.format.datapack.heightmaptype as HM
|
||||
import mcpacker.format.datapack.generationstep as GS
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Structure:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
gameId:ResourceId,
|
||||
biomes:Iterable[ResourceId],
|
||||
):
|
||||
self.gameId = gameId
|
||||
self.biomes = list(biomes)
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"biomes": [str(b) for b in self.biomes],
|
||||
"max_distance_from_center": 10,
|
||||
"project_start_to_heightmap": str(HM.OCEAN_FLOOR),
|
||||
"size": 1,
|
||||
"spawn_overrides": {},
|
||||
"start_height": { "absolute": 0 },
|
||||
"start_pool": f"{self.gameId.mod}:deposit/{self.gameId.name}_marker",
|
||||
"step": str(GS.SURFACE_STRUCTURES),
|
||||
"type": "minecraft:jigsaw",
|
||||
"use_expansion_hack": False,
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import mcpacker.format.datapack.structure
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_syntax():
|
||||
pass
|
||||
Reference in New Issue
Block a user