Add the ability to disable existing placed features
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
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,4 +1,5 @@
|
||||
from mcpacker.format.datapack.configuredfeature import ConfiguredFeature
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@@ -13,7 +14,7 @@ class RandomPatch(ConfiguredFeature):
|
||||
def __init__(
|
||||
self,
|
||||
gameId:str,
|
||||
feature:PlacedFeature,
|
||||
feature:"PlacedFeature",
|
||||
tries:int=128,
|
||||
xzSpread:int=7,
|
||||
ySpread:int=3,
|
||||
@@ -25,7 +26,7 @@ class RandomPatch(ConfiguredFeature):
|
||||
self.xzSpread = xzSpread
|
||||
self.ySpread = ySpread
|
||||
|
||||
def asData(self) -> dict[str,Any]:
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"feature": self.feature.gameId,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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.simpleblock import SimpleBlock
|
||||
from mcpacker.format.datapack.configuredfeature.randompatch import RandomPatch
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
@@ -14,25 +15,22 @@ def createBlockState():
|
||||
def createProvider(state:BlockState):
|
||||
return SimpleStateProvider(state)
|
||||
|
||||
@fixture(name="placedFeature")
|
||||
def createPlacedFeature():
|
||||
return PlacedFeature("noop", [])
|
||||
|
||||
@fixture(name="feature")
|
||||
def createSimpleBlockFeature(provider:SimpleStateProvider):
|
||||
return SimpleBlock(provider)
|
||||
def createFeature(placedFeature:PlacedFeature):
|
||||
return RandomPatch("test", placedFeature)
|
||||
|
||||
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(feature:SimpleBlock):
|
||||
def test_asJsonBlob(feature:RandomPatch):
|
||||
assert feature.asJsonBlob() == {
|
||||
"type": "minecraft:simple_block",
|
||||
"config": {
|
||||
"to_place": {
|
||||
"type": "minecraft:simple_state_provider",
|
||||
"state": {
|
||||
"Name": "minecraft:button",
|
||||
"Properties": {
|
||||
"waterlogged": "true"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"type": "minecraft:random_patch",
|
||||
"feature": "noop",
|
||||
"tries": 128,
|
||||
"xz_spread": 7,
|
||||
"y_spread": 3,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
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:list[Placement]):
|
||||
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,6 +1,14 @@
|
||||
from mcpacker.json import JsonBlob
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class Placement:
|
||||
|
||||
def __init__(self, gameId:str):
|
||||
self.gameId = gameId
|
||||
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,3 @@ class Biome(Placement):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("minecraft:biome")
|
||||
|
||||
def asData(self) -> dict[str,Any]:
|
||||
return { "type": self.gameId }
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def createPlacement():
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asData() == {
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:biome",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
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):
|
||||
@@ -10,7 +12,7 @@ class HeightMap(Placement):
|
||||
super().__init__("minecraft:heightmap")
|
||||
self.heightMap = heightMap
|
||||
|
||||
def asData(self) -> dict[str,Any]:
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"heightmap": self.heightMap.asData()
|
||||
|
||||
@@ -13,7 +13,7 @@ def createPlacement():
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asData() == {
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:heightmap",
|
||||
"heightmap": "WORLD_SURFACE"
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class InSquare(Placement):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("minecraft:in_square")
|
||||
|
||||
def asData(self) -> dict[str,Any]:
|
||||
return { "type": self.gameId }
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def createPlacement():
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asData() == {
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:in_square",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from mcpacker.format.datapack.placement import Placement
|
||||
from mcpacker.json import JsonBlob
|
||||
from typing import Any
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class RarityFilter(Placement):
|
||||
@@ -9,9 +11,9 @@ class RarityFilter(Placement):
|
||||
super().__init__("minecraft:rarity_filter")
|
||||
self.chance = chance
|
||||
|
||||
def asData(self) -> dict[str,Any]:
|
||||
def asJsonBlob(self) -> JsonBlob:
|
||||
return {
|
||||
"type": self.gameId,
|
||||
"chance": self.chance
|
||||
"chance": self.chance,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def createPlacement():
|
||||
# Tests ############################################################################################
|
||||
|
||||
def test_asData(placement):
|
||||
assert placement.asData() == {
|
||||
assert placement.asJsonBlob() == {
|
||||
"type": "minecraft:rarity_filter",
|
||||
"chance": 4
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user