diff --git a/mods/bworld/blocks/acacia_door.json b/mods/bworld/blocks/acacia_door.json new file mode 100644 index 0000000..99ff353 --- /dev/null +++ b/mods/bworld/blocks/acacia_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:acacia_door", + "name": "Acacia Door", + "textures": { + "item": "bworld:acacia_door", + "bottom": "bworld:acacia_door_bottom", + "top": "bworld:acacia_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:acacia_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/birch_door.json b/mods/bworld/blocks/birch_door.json new file mode 100644 index 0000000..499569d --- /dev/null +++ b/mods/bworld/blocks/birch_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:birch_door", + "name": "Birch Door", + "textures": { + "item": "bworld:birch_door", + "bottom": "bworld:birch_door_bottom", + "top": "bworld:birch_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:birch_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/cherry_door.json b/mods/bworld/blocks/cherry_door.json new file mode 100644 index 0000000..5dec4b2 --- /dev/null +++ b/mods/bworld/blocks/cherry_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:cherry_door", + "name": "Cherry Door", + "textures": { + "item": "bworld:cherry_door", + "bottom": "bworld:cherry_door_bottom", + "top": "bworld:cherry_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:cherry_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/dark_oak_door.json b/mods/bworld/blocks/dark_oak_door.json new file mode 100644 index 0000000..5a07247 --- /dev/null +++ b/mods/bworld/blocks/dark_oak_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:dark_oak_door", + "name": "Dark Oak Door", + "textures": { + "item": "bworld:dark_oak_door", + "bottom": "bworld:dark_oak_door_bottom", + "top": "bworld:dark_oak_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:dark_oak_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/jungle_door.json b/mods/bworld/blocks/jungle_door.json new file mode 100644 index 0000000..ad4a3ec --- /dev/null +++ b/mods/bworld/blocks/jungle_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:jungle_door", + "name": "Jungle Door", + "textures": { + "item": "bworld:jungle_door", + "bottom": "bworld:jungle_door_bottom", + "top": "bworld:jungle_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:jungle_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/oak_door.json b/mods/bworld/blocks/oak_door.json new file mode 100644 index 0000000..d540cb5 --- /dev/null +++ b/mods/bworld/blocks/oak_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:oak_door", + "name": "Oak Door", + "textures": { + "item": "bworld:oak_door", + "bottom": "bworld:oak_door_bottom", + "top": "bworld:oak_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:oak_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/blocks/spruce_door.json b/mods/bworld/blocks/spruce_door.json new file mode 100644 index 0000000..c7f8867 --- /dev/null +++ b/mods/bworld/blocks/spruce_door.json @@ -0,0 +1,98 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:spruce_door", + "name": "Spruce Door", + "textures": { + "item": "bworld:spruce_door", + "bottom": "bworld:spruce_door_bottom", + "top": "bworld:spruce_door_top" + }, + "model": "bworld:door_bottom", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + }, + { + "name": "half", + "bits": 1, + "default": 0 + }, + { + "name": "open", + "bits": 1, + "default": 0 + }, + { + "name": "hinge", + "bits": 1, + "default": 0 + } + ], + "variants": { + "half=0,hinge=0,open=1": { + "model": "bworld:door_bottom_rh" + }, + "half=0,hinge=1,open=0": { + "model": "bworld:door_bottom_rh" + }, + "half=1,hinge=0,open=1": { + "model": "bworld:door_top_rh" + }, + "half=1,hinge=1,open=0": { + "model": "bworld:door_top_rh" + }, + "half=1": { + "model": "bworld:door_top" + }, + "facing=0,open=0": { + "y": 270 + }, + "facing=0,open=1,hinge=0": { + "y": 0 + }, + "facing=0,open=1,hinge=1": { + "y": 180 + }, + "facing=1,open=0": { + "y": 0 + }, + "facing=1,open=1,hinge=0": { + "y": 90 + }, + "facing=1,open=1,hinge=1": { + "y": 270 + }, + "facing=2,open=0": { + "y": 90 + }, + "facing=2,open=1,hinge=0": { + "y": 180 + }, + "facing=2,open=1,hinge=1": { + "y": 0 + }, + "facing=3,open=0": { + "y": 180 + }, + "facing=3,open=1,hinge=0": { + "y": 270 + }, + "facing=3,open=1,hinge=1": { + "y": 90 + } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:spruce_door", + "interactive": true, + "components": { + "bworld:door": { "pairs_with": "bworld:wooden_doors" } + } + } +} diff --git a/mods/bworld/models/door_bottom.json b/mods/bworld/models/door_bottom.json new file mode 100644 index 0000000..9beed20 --- /dev/null +++ b/mods/bworld/models/door_bottom.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:door_bottom", + "elements": [ + { + "from": [0, 0, 0], + "to": [3, 16, 16], + "faces": { + "bottom": { + "texture": "#bottom", + "uv": [13, 0, 16, 16], + "cullface": "bottom" + }, + "north": { + "texture": "#bottom", + "uv": [3, 0, 0, 16], + "cullface": "north" + }, + "south": { + "texture": "#bottom", + "uv": [0, 0, 3, 16], + "cullface": "south" + }, + "west": { + "texture": "#bottom", + "uv": [0, 0, 16, 16], + "cullface": "west" + }, + "east": { + "texture": "#bottom", + "uv": [16, 0, 0, 16] + } + } + } + ] + } +} diff --git a/mods/bworld/models/door_bottom_rh.json b/mods/bworld/models/door_bottom_rh.json new file mode 100644 index 0000000..1a35ab2 --- /dev/null +++ b/mods/bworld/models/door_bottom_rh.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:door_bottom_rh", + "elements": [ + { + "from": [0, 0, 0], + "to": [3, 16, 16], + "faces": { + "bottom": { + "texture": "#bottom", + "uv": [13, 0, 16, 16], + "cullface": "bottom" + }, + "north": { + "texture": "#bottom", + "uv": [3, 0, 0, 16], + "cullface": "north" + }, + "south": { + "texture": "#bottom", + "uv": [0, 0, 3, 16], + "cullface": "south" + }, + "west": { + "texture": "#bottom", + "uv": [16, 0, 0, 16], + "cullface": "west" + }, + "east": { + "texture": "#bottom", + "uv": [0, 0, 16, 16] + } + } + } + ] + } +} diff --git a/mods/bworld/models/door_top.json b/mods/bworld/models/door_top.json new file mode 100644 index 0000000..1642f29 --- /dev/null +++ b/mods/bworld/models/door_top.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:door_top", + "elements": [ + { + "from": [0, 0, 0], + "to": [3, 16, 16], + "faces": { + "top": { + "texture": "#bottom", + "uv": [13, 0, 16, 16], + "cullface": "top" + }, + "north": { + "texture": "#top", + "uv": [3, 0, 0, 16], + "cullface": "north" + }, + "south": { + "texture": "#top", + "uv": [0, 0, 3, 16], + "cullface": "south" + }, + "west": { + "texture": "#top", + "uv": [0, 0, 16, 16], + "cullface": "west" + }, + "east": { + "texture": "#top", + "uv": [16, 0, 0, 16] + } + } + } + ] + } +} diff --git a/mods/bworld/models/door_top_rh.json b/mods/bworld/models/door_top_rh.json new file mode 100644 index 0000000..a11cfad --- /dev/null +++ b/mods/bworld/models/door_top_rh.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:door_top_rh", + "elements": [ + { + "from": [0, 0, 0], + "to": [3, 16, 16], + "faces": { + "top": { + "texture": "#bottom", + "uv": [13, 0, 16, 16], + "cullface": "top" + }, + "north": { + "texture": "#top", + "uv": [3, 0, 0, 16], + "cullface": "north" + }, + "south": { + "texture": "#top", + "uv": [0, 0, 3, 16], + "cullface": "south" + }, + "west": { + "texture": "#top", + "uv": [16, 0, 0, 16], + "cullface": "west" + }, + "east": { + "texture": "#top", + "uv": [0, 0, 16, 16] + } + } + } + ] + } +} diff --git a/mods/bworld/recipes/crafting_acacia_door.json b/mods/bworld/recipes/crafting_acacia_door.json new file mode 100644 index 0000000..ef442d1 --- /dev/null +++ b/mods/bworld/recipes/crafting_acacia_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:acacia_planks" + }, + "result": { + "id": "bworld:acacia_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_birch_door.json b/mods/bworld/recipes/crafting_birch_door.json new file mode 100644 index 0000000..d027814 --- /dev/null +++ b/mods/bworld/recipes/crafting_birch_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:birch_planks" + }, + "result": { + "id": "bworld:birch_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_cherry_door.json b/mods/bworld/recipes/crafting_cherry_door.json new file mode 100644 index 0000000..1f39787 --- /dev/null +++ b/mods/bworld/recipes/crafting_cherry_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:cherry_planks" + }, + "result": { + "id": "bworld:cherry_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_dark_oak_door.json b/mods/bworld/recipes/crafting_dark_oak_door.json new file mode 100644 index 0000000..95c9aff --- /dev/null +++ b/mods/bworld/recipes/crafting_dark_oak_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:dark_oak_planks" + }, + "result": { + "id": "bworld:dark_oak_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_jungle_door.json b/mods/bworld/recipes/crafting_jungle_door.json new file mode 100644 index 0000000..771e59c --- /dev/null +++ b/mods/bworld/recipes/crafting_jungle_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:jungle_planks" + }, + "result": { + "id": "bworld:jungle_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_oak_door.json b/mods/bworld/recipes/crafting_oak_door.json new file mode 100644 index 0000000..a3541bb --- /dev/null +++ b/mods/bworld/recipes/crafting_oak_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:oak_planks" + }, + "result": { + "id": "bworld:oak_door", + "count": 3 + } + } +} diff --git a/mods/bworld/recipes/crafting_spruce_door.json b/mods/bworld/recipes/crafting_spruce_door.json new file mode 100644 index 0000000..e32ffe1 --- /dev/null +++ b/mods/bworld/recipes/crafting_spruce_door.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "PP", + "PP", + "PP" + ], + "key": { + "P": "bworld:spruce_planks" + }, + "result": { + "id": "bworld:spruce_door", + "count": 3 + } + } +} diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 9fc449c..f99c83d 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -12,6 +12,7 @@ export function setup(ctx: ServerContext) { register_smithing_table(ctx); register_farming(ctx); register_fishing(ctx); + register_door(ctx); register_buckets(ctx); register_curios(ctx); register_effects(ctx); @@ -645,3 +646,42 @@ function register_growable_block(ctx: ServerContext) { }, }); } + +// doors are two blocks, a lower and an upper half, see register_door in shared.ts. one is only placed with air above +// it, where the upper half goes, and breaking either half takes the other away with it. only the half that was broken +// drops the door, the other is just taken away +const DOOR = "bworld:door"; + +function register_door(ctx: ServerContext) { + const is_door = (id: string) => DOOR in ctx.blocks.components(id); + ctx.events.before.block_place.subscribe((event) => { + const { id, x, y, z } = event.block; + if (is_door(id) && ctx.world.get_block(x, y + 1, z) !== "bworld:air") event.cancel = true; + }); + ctx.events.after.block_place.subscribe(({ block: { id, x, y, z } }) => { + if (!is_door(id)) return; + ctx.world.set_block(x, y + 1, z, id); + for (const state of ["facing", "open", "hinge"]) { + ctx.world.set_state(x, y + 1, z, state, ctx.world.get_state(x, y, z, state) ?? 0); + } + ctx.world.set_state(x, y + 1, z, "half", 1); + }); + + // the halves being taken away, so the other half's on_break doesn't take the first away again + const breaking = new Set(); + ctx.components.register_block(DOOR, { + on_break(block) { + const { x, y, z } = block; + if (breaking.has(`${x},${y},${z}`)) return; + const other = ctx.world.get_state(x, y, z, "half") ? y - 1 : y + 1; + if (ctx.world.get_block(x, other, z) !== block.id) return; + const halves = [`${x},${y},${z}`, `${x},${other},${z}`]; + for (const half of halves) breaking.add(half); + try { + ctx.world.set_block(x, other, z, "bworld:air"); + } finally { + for (const half of halves) breaking.delete(half); + } + }, + }); +} diff --git a/mods/bworld/scripts/shared.ts b/mods/bworld/scripts/shared.ts index 1862da7..9ca8b66 100644 --- a/mods/bworld/scripts/shared.ts +++ b/mods/bworld/scripts/shared.ts @@ -1,11 +1,12 @@ // the base game's block rules: how blocks are placed and how they change with the blocks beside them. they run on the // server and on every client, so players see a fence join or a trapdoor turn the moment they place it, and a trapdoor -// open the moment they click it +// or a door open the moment they click it import type { SharedBlock, SharedContext } from "bworld/shared"; export function setup(ctx: SharedContext) { register_fence(ctx); register_trapdoor(ctx); + register_door(ctx); } // the sides a fence connects on, and the face of the block there it connects to @@ -65,3 +66,68 @@ function register_trapdoor(ctx: SharedContext) { }, }); } + +// the way along the ground each facing goes, in FACINGS' order +const FACING_STEPS = [[0, -1], [1, 0], [0, 1], [-1, 0]]; + +// a door is two blocks, its lower half (half 0) and its upper half (half 1), with the same states. it faces the way +// the player placing it looks, and is hinged on the side away from a door of its kind beside it, so the two meet in +// the middle as a double door, like minecraft's DoorBlock.getHinge. without one, on the side of the block the player +// clicked toward. right clicking either half opens or closes both, and the other door of a double door with it. the +// server places the upper half and takes away the other half when one breaks, see register_door in server.ts. +// "pairs_with" is the tag of doors it makes double doors with +interface DoorParams { + pairs_with: string; +} + +function register_door(ctx: SharedContext) { + // a door's lower half there, of the kind this one pairs with + const door_at = (x: number, y: number, z: number, params: DoorParams) => { + const id = ctx.world.get_block(x, y, z); + return id !== undefined && ctx.tags.has("blocks", params.pairs_with, id) && + ctx.world.get_state(x, y, z, "half") === 0; + }; + // opens or closes both halves of the door whose lower half is there + const set_open = (x: number, y: number, z: number, open: number) => { + if (ctx.world.get_block(x, y + 1, z) === ctx.world.get_block(x, y, z)) { + ctx.world.set_state(x, y + 1, z, "open", open); + } + return ctx.world.set_state(x, y, z, "open", open); + }; + + ctx.components.register_block("bworld:door", { + on_interact(block, params) { + const { x, z } = block; + const y = ctx.world.get_state(x, block.y, z, "half") ? block.y - 1 : block.y; + const state = (name: string, at_x = x, at_z = z) => ctx.world.get_state(at_x, y, at_z, name); + const was_open = state("open"); + const open = was_open ? 0 : 1; + // the other door of a double door is beside its free edge, facing the same way, hinged the other way, and + // open or closed like it + const facing = state("facing")!; + const [step_x, step_z] = FACING_STEPS[(facing + (state("hinge") ? 3 : 1)) % 4]; + const [px, pz] = [x + step_x, z + step_z]; + if ( + door_at(px, y, pz, params) && state("facing", px, pz) === facing && + state("hinge", px, pz) !== state("hinge") && state("open", px, pz) === was_open + ) { + set_open(px, y, pz, open); + } + return set_open(x, y, z, open); + }, + state_for_placement(placement, params): Record { + const facing = FACINGS.indexOf(placement.facing); + const { x, y, z } = placement; + const [left_x, left_z] = FACING_STEPS[(facing + 3) % 4]; + const [right_x, right_z] = FACING_STEPS[(facing + 1) % 4]; + const door_left = door_at(x + left_x, y, z + left_z, params); + const door_right = door_at(x + right_x, y, z + right_z, params); + if (door_left !== door_right) return { facing, half: 0, hinge: door_left ? 1 : 0 }; + const [step_x, step_z] = FACING_STEPS[facing]; + const [hit_x, , hit_z] = placement.hit; + const right = (step_x < 0 && hit_z < 0.5) || (step_x > 0 && hit_z > 0.5) || + (step_z < 0 && hit_x > 0.5) || (step_z > 0 && hit_x < 0.5); + return { facing, half: 0, hinge: right ? 1 : 0 }; + }, + }); +} diff --git a/mods/bworld/tags/blocks/bworld/wooden_doors.json b/mods/bworld/tags/blocks/bworld/wooden_doors.json new file mode 100644 index 0000000..07b72f8 --- /dev/null +++ b/mods/bworld/tags/blocks/bworld/wooden_doors.json @@ -0,0 +1,14 @@ +{ + "format_version": 1, + "tag": { + "values": [ + "bworld:oak_door", + "bworld:spruce_door", + "bworld:birch_door", + "bworld:jungle_door", + "bworld:acacia_door", + "bworld:dark_oak_door", + "bworld:cherry_door" + ] + } +} diff --git a/mods/bworld/textures/acacia_door.png b/mods/bworld/textures/acacia_door.png new file mode 100644 index 0000000..4302468 Binary files /dev/null and b/mods/bworld/textures/acacia_door.png differ diff --git a/mods/bworld/textures/acacia_door_bottom.png b/mods/bworld/textures/acacia_door_bottom.png new file mode 100644 index 0000000..7ddaa19 Binary files /dev/null and b/mods/bworld/textures/acacia_door_bottom.png differ diff --git a/mods/bworld/textures/acacia_door_top.png b/mods/bworld/textures/acacia_door_top.png new file mode 100644 index 0000000..09b54ca Binary files /dev/null and b/mods/bworld/textures/acacia_door_top.png differ diff --git a/mods/bworld/textures/birch_door.png b/mods/bworld/textures/birch_door.png new file mode 100644 index 0000000..ca6c748 Binary files /dev/null and b/mods/bworld/textures/birch_door.png differ diff --git a/mods/bworld/textures/birch_door_bottom.png b/mods/bworld/textures/birch_door_bottom.png new file mode 100644 index 0000000..98cb69b Binary files /dev/null and b/mods/bworld/textures/birch_door_bottom.png differ diff --git a/mods/bworld/textures/birch_door_top.png b/mods/bworld/textures/birch_door_top.png new file mode 100644 index 0000000..2a8f711 Binary files /dev/null and b/mods/bworld/textures/birch_door_top.png differ diff --git a/mods/bworld/textures/cherry_door.png b/mods/bworld/textures/cherry_door.png new file mode 100644 index 0000000..bcb01d9 Binary files /dev/null and b/mods/bworld/textures/cherry_door.png differ diff --git a/mods/bworld/textures/cherry_door_bottom.png b/mods/bworld/textures/cherry_door_bottom.png new file mode 100644 index 0000000..e25c957 Binary files /dev/null and b/mods/bworld/textures/cherry_door_bottom.png differ diff --git a/mods/bworld/textures/cherry_door_top.png b/mods/bworld/textures/cherry_door_top.png new file mode 100644 index 0000000..8d1d874 Binary files /dev/null and b/mods/bworld/textures/cherry_door_top.png differ diff --git a/mods/bworld/textures/dark_oak_door.png b/mods/bworld/textures/dark_oak_door.png new file mode 100644 index 0000000..10c9a52 Binary files /dev/null and b/mods/bworld/textures/dark_oak_door.png differ diff --git a/mods/bworld/textures/dark_oak_door_bottom.png b/mods/bworld/textures/dark_oak_door_bottom.png new file mode 100644 index 0000000..40155df Binary files /dev/null and b/mods/bworld/textures/dark_oak_door_bottom.png differ diff --git a/mods/bworld/textures/dark_oak_door_top.png b/mods/bworld/textures/dark_oak_door_top.png new file mode 100644 index 0000000..06e27e0 Binary files /dev/null and b/mods/bworld/textures/dark_oak_door_top.png differ diff --git a/mods/bworld/textures/jungle_door.png b/mods/bworld/textures/jungle_door.png new file mode 100644 index 0000000..e586025 Binary files /dev/null and b/mods/bworld/textures/jungle_door.png differ diff --git a/mods/bworld/textures/jungle_door_bottom.png b/mods/bworld/textures/jungle_door_bottom.png new file mode 100644 index 0000000..837499b Binary files /dev/null and b/mods/bworld/textures/jungle_door_bottom.png differ diff --git a/mods/bworld/textures/jungle_door_top.png b/mods/bworld/textures/jungle_door_top.png new file mode 100644 index 0000000..c5493bd Binary files /dev/null and b/mods/bworld/textures/jungle_door_top.png differ diff --git a/mods/bworld/textures/oak_door.png b/mods/bworld/textures/oak_door.png new file mode 100644 index 0000000..01eb59c Binary files /dev/null and b/mods/bworld/textures/oak_door.png differ diff --git a/mods/bworld/textures/oak_door_bottom.png b/mods/bworld/textures/oak_door_bottom.png new file mode 100644 index 0000000..1720a1a Binary files /dev/null and b/mods/bworld/textures/oak_door_bottom.png differ diff --git a/mods/bworld/textures/oak_door_top.png b/mods/bworld/textures/oak_door_top.png new file mode 100644 index 0000000..c1b6d5b Binary files /dev/null and b/mods/bworld/textures/oak_door_top.png differ diff --git a/mods/bworld/textures/spruce_door.png b/mods/bworld/textures/spruce_door.png new file mode 100644 index 0000000..2f8d075 Binary files /dev/null and b/mods/bworld/textures/spruce_door.png differ diff --git a/mods/bworld/textures/spruce_door_bottom.png b/mods/bworld/textures/spruce_door_bottom.png new file mode 100644 index 0000000..add317c Binary files /dev/null and b/mods/bworld/textures/spruce_door_bottom.png differ diff --git a/mods/bworld/textures/spruce_door_top.png b/mods/bworld/textures/spruce_door_top.png new file mode 100644 index 0000000..692b70f Binary files /dev/null and b/mods/bworld/textures/spruce_door_top.png differ diff --git a/tests/door_test.ts b/tests/door_test.ts new file mode 100644 index 0000000..6b28bcd --- /dev/null +++ b/tests/door_test.ts @@ -0,0 +1,148 @@ +// doors: two blocks tall, facing the way the player looks, opened from either half, broken as one +import { assertEquals } from "@std/assert"; +import { Container, ItemStack } from "$/common/inventory.ts"; +import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts"; +import { shape_at } from "$/common/block_shapes.ts"; +import { bake_block, type ModelJson } from "$/common/block_models.ts"; +import { type BlockRegistry, EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts"; +import { get_state_value } from "$/common/utils.ts"; +import { update_crafting_result } from "$/server/game/crafting.ts"; +import { test_game } from "./helpers.ts"; + +// alice on a stone floor at y 100, south of 0 100 0 and looking north, with oak doors in hand +async function setup() { + const t = await test_game("mods"); + t.join(1, "alice"); + for (let x = -3; x <= 3; x++) { + for (let z = -3; z <= 3; z++) { + t.game.set_block(x, 99, z, "bworld:stone"); + for (let y = 100; y < 103; y++) t.game.set_block(x, y, z, "bworld:air"); + } + } + t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: 0, pitch: 0 }); + t.send(1, { type: "chat", text: "/give bworld:oak_door 64" }); + t.send(1, { type: "select_slot", slot: 0 }); + const states = (x: number, y: number, z: number) => { + const info = t.game.world.get_block_info(x, y, z)!; + const value = t.game.world.get_block_value(x, y, z); + return Object.fromEntries( + ["facing", "half", "open", "hinge"].map((name) => [name, get_state_value(value, info, name)]), + ); + }; + const held = () => t.game.players()[0].held_item?.amount; + const dropped = () => t.game.item_entities().map((e) => `${e.item.type_id} ${e.item.amount}`); + return { t, states, held, dropped }; +} + +Deno.test("a door is placed with its upper half above it, facing the way the player looks", async () => { + const { t, states, held } = await setup(); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:oak_door"); + assertEquals(t.game.world.get_block_id(0, 101, 0), "bworld:oak_door"); + // alice looks north, and clicked the west half, which is on her left + assertEquals(states(0, 100, 0), { facing: 0, half: 0, open: 0, hinge: 0 }); + assertEquals(states(0, 101, 0), { facing: 0, half: 1, open: 0, hinge: 0 }); + assertEquals(held(), 63); + + // clicking the east half hinges it on the right + t.send(1, { type: "use_block", x: 2, y: 99, z: 0, face: "top", hit: [0.8, 1, 0.5] }); + assertEquals(states(2, 100, 0).hinge, 1); + assertEquals(states(2, 101, 0).hinge, 1); +}); + +Deno.test("a door isn't placed without room for its upper half", async () => { + const { t, held } = await setup(); + t.game.set_block(0, 101, 0, "bworld:stone"); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:air"); + assertEquals(held(), 64); +}); + +Deno.test("right clicking either half opens and closes both, and the door turns on its hinge", async () => { + const { t, states } = await setup(); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + const info = t.game.world.get_block_info(0, 100, 0)!; + const shape = () => shape_at(info, t.game.world.get_block_value(0, 100, 0)); + // closed, across the south side, where alice is + assertEquals(shape(), [[0, 0, 13 / 16, 1, 1, 1]]); + + t.send(1, { type: "use_block", x: 0, y: 101, z: 0, face: "south", hit: [0.5, 0.5, 1] }); + assertEquals([states(0, 100, 0).open, states(0, 101, 0).open], [1, 1]); + // swung against the west side, its hinge on alice's left + assertEquals(shape(), [[0, 0, 0, 3 / 16, 1, 1]]); + // nothing placed in the doorway + assertEquals(t.game.world.get_block_id(0, 102, 0), "bworld:air"); + + t.send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "west", hit: [0, 0.5, 0.5] }); + assertEquals([states(0, 100, 0).open, states(0, 101, 0).open], [0, 0]); +}); + +Deno.test("breaking either half breaks the whole door, which drops one door", async () => { + const { t, dropped } = await setup(); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + t.send(1, { type: "break_block", x: 0, y: 101, z: 0 }); + assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:air"); + assertEquals(t.game.world.get_block_id(0, 101, 0), "bworld:air"); + assertEquals(dropped(), ["bworld:oak_door 1"]); + + t.send(1, { type: "use_block", x: 1, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + t.send(1, { type: "break_block", x: 1, y: 100, z: 0 }); + assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air"); + assertEquals(dropped(), ["bworld:oak_door 1", "bworld:oak_door 1"]); +}); + +Deno.test("a door beside another is hinged away from it, whichever half was clicked, making a double door", async () => { + const { t, states } = await setup(); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + assertEquals(states(0, 100, 0).hinge, 0); + // alice looks north, so the first door is on its left, and it's hinged on the right + t.send(1, { type: "use_block", x: 1, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + assertEquals(states(1, 100, 0).hinge, 1); + assertEquals(states(1, 101, 0).hinge, 1); + // and one with a door on its right is hinged on the left, a different wood too + t.send(1, { type: "chat", text: "/give bworld:birch_door 1" }); + t.send(1, { type: "select_slot", slot: 1 }); + t.send(1, { type: "use_block", x: -1, y: 99, z: 0, face: "top", hit: [0.8, 1, 0.5] }); + assertEquals(t.game.world.get_block_id(-1, 100, 0), "bworld:birch_door"); + assertEquals(states(-1, 100, 0).hinge, 0); +}); + +Deno.test("a double door opens and closes together, from either door and either half", async () => { + const { t, states } = await setup(); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + t.send(1, { type: "use_block", x: 1, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + const open = () => [states(0, 100, 0).open, states(0, 101, 0).open, states(1, 100, 0).open, states(1, 101, 0).open]; + t.send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "south", hit: [0.5, 0.5, 1] }); + assertEquals(open(), [1, 1, 1, 1]); + t.send(1, { type: "use_block", x: 1, y: 101, z: 0, face: "west", hit: [0, 0.5, 0.5] }); + assertEquals(open(), [0, 0, 0, 0]); + + // a door beside one but hinged the same way isn't its other half: a third door on the right is hinged on the right + // too, away from the second, and opens on its own + t.send(1, { type: "use_block", x: 2, y: 99, z: 0, face: "top", hit: [0.2, 1, 0.5] }); + assertEquals(states(2, 100, 0).hinge, 1); + t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "south", hit: [0.5, 0.5, 1] }); + assertEquals([...open(), states(2, 100, 0).open], [0, 0, 0, 0, 1]); +}); + +Deno.test("doors are drawn with their wood's bottom and top textures, and their item is flat", async () => { + const { t } = await setup(); + const door = EverythingRegistry.get("blocks", "bworld:spruce_door")!; + const models = Object.fromEntries(EverythingRegistry.entries("models")); + t.game.set_block(0, 100, 0, "bworld:spruce_door"); + const value = (half: number) => (t.game.world.get_block_value(0, 100, 0) & 0xffff) | (half << 2 << 16); + const textures = (half: number) => [...new Set(bake_block(door, value(half), models).map((q) => q.texture))].sort(); + assertEquals(textures(0), ["bworld:spruce_door_bottom"]); + // the top of the upper half is the bottom texture's edge, like minecraft's + assertEquals(textures(1), ["bworld:spruce_door_bottom", "bworld:spruce_door_top"]); + assertEquals(EverythingRegistry.get("items", "bworld:spruce_door")?.texture_id, "bworld:spruce_door"); +}); + +Deno.test("six planks make three doors of that wood", async () => { + const { game } = await test_game("mods"); + const grid = new Container(10); + for (const slot of [0, 1, 3, 4, 6, 7]) grid.set_item(slot, new ItemStack("bworld:cherry_planks", 1)); + update_crafting_result(grid, game.recipes.shaped); + const result = grid.get_item(CRAFTING_RESULT_SLOT); + assertEquals([result?.type_id, result?.amount], ["bworld:cherry_door", 3]); +});