DEADSOFTWARE

Add spruce and snow to winter biome
authorfredboy <fredboy@protonmail.com>
Tue, 7 May 2024 14:16:11 +0000 (21:16 +0700)
committerfredboy <fredboy@protonmail.com>
Tue, 7 May 2024 14:16:11 +0000 (21:16 +0700)
android/assets/json/crafting.json
android/assets/json/game_items.json
android/assets/textures/blocks/leaves_spruce.png [new file with mode: 0644]
android/assets/textures/blocks/snow.png [new file with mode: 0644]
android/assets/textures/items/snowball.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSnowedGrassAction.kt
core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt
core/src/ru/deadsoftware/cavedroid/game/world/GameWorldGenerator.kt

index 6f651bb297f24b0acc6e0ad41637051d6a170a19..94cbe4705b786d40dc0d3daf2c1ca1497cf5ee6c 100644 (file)
@@ -38,5 +38,9 @@
   "stone_shovel": {
     "input": ["none", "cobblestone", "none", "none", "stick", "none", "none", "stick", "none"],
     "count": 131
+  },
+  "snow_block": {
+    "input": ["snowball", "snowball", "none", "snowball", "snowball", "none", "none", "none", "none"],
+    "count": 1
   }
 }
\ No newline at end of file
index d6c3b441a3fc0cff5672e08a10985e8705bfbcd0..f6bfb63201f9b2f517313855cc4ea063a0e6729e 100644 (file)
       "tool_level": 0,
       "tool_type": "axe"
     },
+    "planks_spruce": {
+      "hp": 180,
+      "drop": "planks_spruce",
+      "texture": "planks_spruce",
+      "tool_level": 0,
+      "tool_type": "axe"
+    },
     "sapling_oak": {
       "collision": false,
       "transparent": true,
       "texture": "sapling_oak",
       "hp": 0
     },
+    "sapling_spruce": {
+      "collision": false,
+      "transparent": true,
+      "block_required": true,
+      "drop": "sapling_spruce",
+      "texture": "sapling_spruce",
+      "hp": 0
+    },
     "bedrock": {
       "drop": "bedrock",
       "texture": "bedrock"
       "tool_type": "shears",
       "tint": "#5AC557"
     },
+    "log_spruce": {
+      "hp": 180,
+      "drop": "log_spruce",
+      "texture": "log_spruce",
+      "tool_level": 0,
+      "tool_type": "axe"
+    },
+    "leaves_spruce": {
+      "hp": 21,
+      "drop": "leaves_spruce",
+      "texture": "leaves_spruce",
+      "tool_level": 1,
+      "tool_type": "shears",
+      "tint": "#486D4E"
+    },
     "sponge": {
       "hp": 54,
       "drop": "sponge",
       "tool_level": 0,
       "tool_type": "axe"
     },
+    "spruce_slab_bottom": {
+      "top": 8,
+      "sprite_top": 8,
+      "hp": 180,
+      "transparent": true,
+      "drop": "spruce_slab",
+      "meta": "slab",
+      "texture": "planks_spruce",
+      "full_block": "planks_spruce",
+      "other_part": "spruce_slab_top",
+      "tool_level": 0,
+      "tool_type": "axe"
+    },
+    "spruce_slab_top": {
+      "bottom": 8,
+      "sprite_bottom": 8,
+      "hp": 180,
+      "transparent": true,
+      "drop": "spruce_slab",
+      "meta": "slab",
+      "texture": "planks_spruce",
+      "full_block": "planks_spruce",
+      "other_part": "spruce_slab_bottom",
+      "tool_level": 0,
+      "tool_type": "axe"
+    },
     "cobblestone_slab_bottom": {
       "top": 8,
       "sprite_top": 8,
       "texture": "obsidian",
       "tool_level": 4,
       "tool_type": "pickaxe"
+    },
+    "snow": {
+      "top": 14,
+      "sprite_top": 14,
+      "collision": false,
+      "transparent": true,
+      "drop": "snowball",
+      "texture": "snow",
+      "hp": 6,
+      "tool_level": 1,
+      "tool_type": "shovel",
+      "block_required": true
+    },
+    "snow_block": {
+      "collision": true,
+      "transparent": true,
+      "drop": "snowball",
+      "drop_count": 4,
+      "texture": "snow",
+      "hp": 60,
+      "tool_level": 1,
+      "tool_type": "shovel"
     }
   },
   "items": {
       "type": "block",
       "texture": "sapling_oak"
     },
-    "bedrock": {
-      "name": "Bedrock",
+    "planks_spruce": {
+      "name": "Spruce Planks",
       "type": "block",
-      "texture": "bedrock"
+      "texture": "planks_spruce"
     },
-    "water": {
-      "name": "Water",
+    "sapling_spruce": {
+      "name": "Spruce Sapling",
       "type": "block",
-      "texture": "water"
+      "texture": "sapling_spruce"
     },
-    "lava": {
-      "name": "Lava",
+    "bedrock": {
+      "name": "Bedrock",
       "type": "block",
-      "texture": "lava"
+      "texture": "bedrock"
     },
     "sand": {
       "name": "Sand",
       "type": "block",
       "texture": "leaves_oak"
     },
+    "log_spruce": {
+      "name": "Spruce",
+      "type": "block",
+      "texture": "log_spruce"
+    },
+    "leaves_spruce": {
+      "name": "Spruce Leaves",
+      "type": "block",
+      "texture": "leaves_spruce"
+    },
     "glass": {
       "name": "Glass",
       "type": "block",
       "top_slab_block": "oak_slab_top",
       "bottom_slab_block": "oak_slab_bottom"
     },
+    "spruce_slab": {
+      "name": "Spruce Slab",
+      "type": "slab",
+      "texture": "spruce_slab",
+      "top_slab_block": "spruce_slab_top",
+      "bottom_slab_block": "spruce_slab_bottom"
+    },
     "cobblestone_slab": {
       "name": "Cobblestone Slab",
       "type": "slab",
       "type": "block",
       "texture": "obsidian"
     },
+    "snow_block": {
+      "name": "Snow Block",
+      "type": "block",
+      "texture": "snow"
+    },
     "stick": {
       "name": "Stick",
       "texture": "stick"
       "origin_x": 0.25,
       "action_key": "use_lava_bucket",
       "max_stack": 1
+    },
+    "snowball": {
+      "name": "Snowball",
+      "texture": "snowball",
+      "max_stack": 16
     }
   }
 }
diff --git a/android/assets/textures/blocks/leaves_spruce.png b/android/assets/textures/blocks/leaves_spruce.png
new file mode 100644 (file)
index 0000000..0be1897
Binary files /dev/null and b/android/assets/textures/blocks/leaves_spruce.png differ
diff --git a/android/assets/textures/blocks/snow.png b/android/assets/textures/blocks/snow.png
new file mode 100644 (file)
index 0000000..20a836e
Binary files /dev/null and b/android/assets/textures/blocks/snow.png differ
diff --git a/android/assets/textures/items/snowball.png b/android/assets/textures/items/snowball.png
new file mode 100644 (file)
index 0000000..56a11e9
Binary files /dev/null and b/android/assets/textures/items/snowball.png differ
index 27005b8da53f4eb008c31ab26ba92b2568f11953..d5ca3b161c242b97e1e6931ad0ee64f66ccc5d3c 100644 (file)
@@ -13,8 +13,12 @@ class UpdateGrassAction @Inject constructor(
 
     override fun update(x: Int, y: Int) {
         val blockOnTop = gameWorld.getForeMap(x, y - 1)
-        if (blockOnTop.collision || blockOnTop.isFluid()) {
-            gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("dirt"))
+
+        val makesDirt = blockOnTop.params.hasCollision || blockOnTop.isFluid()
+
+        when {
+            makesDirt -> gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("dirt"))
+            blockOnTop.params.key == "snow" -> gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("grass_snowed"))
         }
     }
 
index 8b7f0e34ecc9be0e650590edb9a152115d45e670..0aa5c90f9ae94e66617bee224415ff71cac841b2 100644 (file)
@@ -13,8 +13,11 @@ class UpdateSnowedGrassAction @Inject constructor(
 
     override fun update(x: Int, y: Int) {
         val blockOnTop = gameWorld.getForeMap(x, y - 1)
-        if (blockOnTop.collision || blockOnTop.isFluid()) {
-            gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("dirt"))
+        val makesDirt = blockOnTop.params.hasCollision || blockOnTop.isFluid()
+
+        when {
+            makesDirt -> gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("dirt"))
+            blockOnTop.params.key != "snow" -> gameWorld.setForeMap(x, y, mGameItemsHolder.getBlock("grass"))
         }
     }
 
index 31f4c7801a4b35c4756879ca5a60d762975ca89a..4469038ba6f7a1632c54297202650085b02e00e0 100644 (file)
@@ -80,6 +80,6 @@ class Inventory(
             endIndex = size - 1
         )
 
-        _items[0] = item.toInventoryItem()
+        _items[0] = item.toInventoryItem(item.params.maxStack)
     }
 }
\ No newline at end of file
index e00a0ea4dd2cd3397b632650b69b635cdc1ec24f..004a56b01a945ec581dd084a5e26c390da3de190 100644 (file)
@@ -72,12 +72,17 @@ class GameWorldGenerator(
         val bedrock = gameItemsHolder.getBlock("bedrock")
         val dirt = gameItemsHolder.getBlock("dirt")
         val stone = gameItemsHolder.getBlock("stone")
+        val snow = gameItemsHolder.getBlock("snow")
 
         foreMap[x][surfaceHeight] = grass
         foreMap[x][config.height - 1] = bedrock
         backMap[x][surfaceHeight] = grass
         backMap[x][config.height - 1] = bedrock
 
+        if (surfaceHeight - 1 < config.seaLevel) {
+            foreMap[x][surfaceHeight - 1] = snow
+        }
+
         for (y in min(surfaceHeight + 1, config.seaLevel) ..< config.height - 1) {
             if (y <= surfaceHeight) {
                 backMap[x][y] = dirt
@@ -90,6 +95,13 @@ class GameWorldGenerator(
             }
             backMap[x][y] = foreMap[x][y]
         }
+
+        val plant = random.nextInt(100)
+        if (surfaceHeight < config.seaLevel) {
+            if (plant < 10) {
+                generateSpruce(x)
+            }
+        }
     }
 
     private fun plainsBiome(x: Int) {
@@ -222,6 +234,37 @@ class GameWorldGenerator(
         }
     }
 
+    private fun generateSpruce(x: Int) {
+        val log = gameItemsHolder.getBlock("log_spruce")
+        val leaves = gameItemsHolder.getBlock("leaves_spruce")
+        val h = heights[x] - 1
+        val treeH = random.nextInt(7, 9)
+        val height = max(0, h - treeH)
+
+        val top = height - 1
+        if (top >= 0) {
+            foreMap[x][top] = leaves
+            backMap[x][top] = leaves
+        }
+
+        for (x1 in max(0, x - 1) .. min(config.width - 1, x + 1)) {
+            val y = height
+            foreMap[x1][y] = leaves
+            backMap[x1][y] = leaves
+        }
+
+        for (y in 1..2) {
+            for (x1 in max(0, x - y) .. min(config.width - 1, x + y)) {
+                foreMap[x1][height + 1 + y] = leaves
+                backMap[x1][height + 1 + y] = leaves
+            }
+        }
+
+        for (y in h downTo height) {
+            backMap[x][y] = log
+        }
+    }
+
     private fun generateTallGrass(x: Int) {
         val tallGrass = gameItemsHolder.getBlock(plainsPlants.random(random))
         val h = heights[x] - 1