DEADSOFTWARE

Add items count and tools duration
authorfredboy <fredboy@protonmail.com>
Mon, 22 Apr 2024 11:22:29 +0000 (18:22 +0700)
committerfredboy <fredboy@protonmail.com>
Mon, 22 Apr 2024 11:22:29 +0000 (18:22 +0700)
17 files changed:
android/assets/json/game_items.json
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToBackgroundAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt
core/src/ru/deadsoftware/cavedroid/game/model/item/CommonItemParams.kt
core/src/ru/deadsoftware/cavedroid/game/model/item/InventoryItem.kt
core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt
core/src/ru/deadsoftware/cavedroid/game/render/DebugRenderer.kt
core/src/ru/deadsoftware/cavedroid/game/render/HudRenderer.kt
core/src/ru/deadsoftware/cavedroid/game/render/windows/CreativeWindowRenderer.kt
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt

index 47636290ece1d3ead25ea3fbecd12054c739134e..0e407860a4cee30667b02f1caadcccc9f8bb5545 100644 (file)
       "type": "sword",
       "texture": "wood_sword",
       "origin_x": 0.125,
-      "tool_level": 1
+      "tool_level": 1,
+      "max_stack": 60
     },
     "stone_sword": {
       "name": "Stone Sword",
       "type": "sword",
       "texture": "stone_sword",
       "origin_x": 0.125,
-      "tool_level": 2
+      "tool_level": 2,
+      "max_stack": 132
     },
     "iron_sword": {
       "name": "Iron Sword",
       "type": "sword",
       "texture": "iron_sword",
       "origin_x": 0.125,
-      "tool_level": 3
+      "tool_level": 3,
+      "max_stack": 251
     },
     "diamond_sword": {
       "name": "Diamond Sword",
       "type": "sword",
       "texture": "diamond_sword",
       "origin_x": 0.125,
-      "tool_level": 4
+      "tool_level": 4,
+      "max_stack": 1562
     },
     "gold_sword": {
       "name": "Golden Sword",
       "type": "sword",
       "texture": "gold_sword",
       "origin_x": 0.125,
-      "tool_level": 1
+      "tool_level": 1,
+      "max_stack": 33
     },
     "wood_shovel": {
       "name": "Wooden Shovel",
       "type": "shovel",
       "texture": "wood_shovel",
       "origin_x": 0.125,
-      "tool_level" : 1
+      "tool_level" : 1,
+      "max_stack": 59
     },
     "stone_shovel": {
       "name": "Stone Shovel",
       "type": "shovel",
       "texture": "stone_shovel",
       "origin_x": 0.125,
-      "tool_level" : 2
+      "tool_level" : 2,
+      "max_stack": 131
     },
     "iron_shovel": {
       "name": "Iron Shovel",
       "type": "shovel",
       "texture": "iron_shovel",
       "origin_x": 0.125,
-      "tool_level" : 3
+      "tool_level" : 3,
+      "max_stack": 250
     },
     "diamond_shovel": {
       "name": "Diamond Shovel",
       "type": "shovel",
       "texture": "diamond_shovel",
       "origin_x": 0.125,
-      "tool_level" : 4
+      "tool_level" : 4,
+      "max_stack": 1561
     },
     "gold_shovel": {
       "name": "Golden Shovel",
       "texture": "gold_shovel",
       "origin_x": 0.125,
       "tool_level" : 1,
-      "block_damage_multiplier": 6
+      "block_damage_multiplier": 6,
+      "max_stack": 32
     },
     "wood_pickaxe": {
       "name": "Wooden Pickaxe",
       "type": "pickaxe",
       "texture": "wood_pickaxe",
       "origin_x": 0.125,
-      "tool_level" : 1
+      "tool_level" : 1,
+      "max_stack": 59
     },
     "stone_pickaxe": {
       "name": "Stone Pickaxe",
       "type": "pickaxe",
       "texture": "stone_pickaxe",
       "origin_x": 0.125,
-      "tool_level" : 2
+      "tool_level" : 2,
+      "max_stack": 131
     },
     "iron_pickaxe": {
       "name": "Iron Pickaxe",
       "type": "pickaxe",
       "texture": "iron_pickaxe",
       "origin_x": 0.125,
-      "tool_level" : 3
+      "tool_level" : 3,
+      "max_stack": 251
     },
     "diamond_pickaxe": {
       "name": "Diamond Pickaxe",
       "type": "pickaxe",
       "texture": "diamond_pickaxe",
       "origin_x": 0.125,
-      "tool_level" : 4
+      "tool_level" : 4,
+      "max_stack": 1562
     },
     "gold_pickaxe": {
       "name": "Golden Pickaxe",
       "texture": "gold_pickaxe",
       "origin_x": 0.125,
       "tool_level" : 1,
-      "block_damage_multiplier": 6
+      "block_damage_multiplier": 6,
+      "max_stack": 33
     },
     "wood_axe": {
       "name": "Wooden Axe",
       "type": "axe",
       "texture": "wood_axe",
       "origin_x": 0.125,
-      "tool_level" : 1
+      "tool_level" : 1,
+      "max_stack": 60
     },
     "stone_axe": {
       "name": "Stone Axe",
       "type": "axe",
       "texture": "stone_axe",
       "origin_x": 0.125,
-      "tool_level" : 2
+      "tool_level" : 2,
+      "max_stack": 131
     },
     "iron_axe": {
       "name": "Iron Axe",
       "type": "axe",
       "texture": "iron_axe",
       "origin_x": 0.125,
-      "tool_level" : 3
+      "tool_level" : 3,
+      "max_stack": 250
     },
     "diamond_axe": {
       "name": "Diamond Axe",
       "type": "axe",
       "texture": "diamond_axe",
       "origin_x": 0.125,
-      "tool_level" : 4
+      "tool_level" : 4,
+      "max_stack": 1561
     },
     "gold_axe": {
       "name": "Golden Axe",
       "texture": "gold_axe",
       "origin_x": 0.125,
       "tool_level" : 1,
-      "block_damage_multiplier": 6
+      "block_damage_multiplier": 6,
+      "max_stack": 32
     },
     "shears": {
       "name": "Shears",
       "type": "shears",
       "texture": "shears",
       "tool_level" : 1,
-      "origin_x": 0.125
+      "origin_x": 0.125,
+      "max_stack": 238
     },
     "bucket_empty": {
       "name": "Empty Bucket",
index e1257d518fce877884bde4e669a5b089918e2037..a45e7045446eb51feef1afb024dc211a54b3da5a 100644 (file)
@@ -407,7 +407,8 @@ public class GameInput {
                 }
 
                 System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8);
-                mPlayer.inventory[0] = mGameItemsHolder.getItemFromCreativeInventory(itemPos).toInventoryItem();
+                final Item newItem = mGameItemsHolder.getItemFromCreativeInventory(itemPos);
+                mPlayer.inventory[0] = newItem.toInventoryItem(newItem.getParams().getMaxStack());
             } else if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY)) {
                 mMainConfig.setGameUiWindow(GameUiWindow.NONE);
             } else if (screenY < hotbar.getRegionHeight() &&
index bdebfcbfed133a3ac880bd0086b86ec4049df2cc..fdfb61a53008914d6ed9650c5931e204d58d677b 100644 (file)
@@ -1,6 +1,8 @@
 package ru.deadsoftware.cavedroid.game.actions.placeblock
 
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
 import ru.deadsoftware.cavedroid.game.model.item.Item
 import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
@@ -8,10 +10,14 @@ import javax.inject.Inject
 @GameScope
 class PlaceBlockItemToBackgroundAction @Inject constructor(
     private val gameWorld: GameWorld,
+    private val gameItemsHolder: GameItemsHolder,
+    private val mobsController: MobsController,
 ) : IPlaceBlockAction {
 
     override fun place(placeable: Item.Placeable, x: Int, y: Int) {
-        gameWorld.placeToBackground(x, y, placeable.block)
+        if (gameWorld.placeToBackground(x, y, placeable.block)) {
+            mobsController.player.decreaseCurrentItemCount(gameItemsHolder)
+        }
     }
 
     companion object {
index d409a803d38efffd2b815cf0536ca41c2caffeb6..22aafdd98e5c75a75aeb1a5fbc39c2317e5d5111 100644 (file)
@@ -1,6 +1,8 @@
 package ru.deadsoftware.cavedroid.game.actions.placeblock
 
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
 import ru.deadsoftware.cavedroid.game.model.item.Item
 import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
@@ -9,13 +11,17 @@ import javax.inject.Inject
 class PlaceBlockItemToForegroundAction @Inject constructor(
     private val gameWorld: GameWorld,
     private val placeSlabAction: PlaceSlabAction,
+    private val gameItemsHolder: GameItemsHolder,
+    private val mobsController: MobsController,
 ) : IPlaceBlockAction {
 
     override fun place(placeable: Item.Placeable, x: Int, y: Int) {
         if (placeable.isSlab()) {
             placeSlabAction.place(placeable, x, y)
         } else {
-            gameWorld.placeToForeground(x, y, placeable.block)
+            if (gameWorld.placeToForeground(x, y, placeable.block)) {
+                mobsController.player.decreaseCurrentItemCount(gameItemsHolder)
+            }
         }
     }
 
index 079d2258336b72a30524b0c590f03630fa111a35..6ac94c98edfafd03a86b188a79ab004cc01180ed 100644 (file)
@@ -7,7 +7,6 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController
 import ru.deadsoftware.cavedroid.game.model.item.Item
 import ru.deadsoftware.cavedroid.game.world.GameWorld
 import javax.inject.Inject
-import kotlin.random.Random
 
 @GameScope
 class PlaceSlabAction @Inject constructor(
@@ -22,8 +21,18 @@ class PlaceSlabAction @Inject constructor(
             return
         }
 
-        val slabPart = if (Random.nextBoolean()) placeable.topPartBlock else placeable.bottomPartBlock
-        gameWorld.placeToForeground(x, y, slabPart)
+        val slabPart = if ((gameWorld.hasForeAt(x, y - 1)
+                    || gameWorld.getForeMap(x - 1, y) == placeable.topPartBlock
+                    || gameWorld.getForeMap(x + 1, y) == placeable.topPartBlock)
+            && !gameWorld.hasForeAt(x, y + 1)) {
+            placeable.topPartBlock
+        } else {
+            placeable.bottomPartBlock
+        }
+
+        if (gameWorld.placeToForeground(x, y, slabPart)) {
+            mobsController.player.decreaseCurrentItemCount(gameItemsHolder)
+        }
     }
 
     companion object {
index 4743fcfc54289382a255855e97210dc113c1bc34..641ffe554ec84255bbe0b1099b3f67a9aded0464 100644 (file)
@@ -42,7 +42,7 @@ public class FallingGravel extends Mob {
     @Override
     public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
         if (mVelocity.isZero()) {
-            gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("gravel"));
+            gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("gravel"));
             kill();
         }
     }
index bce918e34fb811024815022970dd00ffa834e316..f41da96872c12aa7fc32ce6dffc885822d13935d 100644 (file)
@@ -43,7 +43,7 @@ public class FallingSand extends Mob {
     @Override
     public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, float delta) {
         if (mVelocity.isZero()) {
-            gameWorld.setForeMap(getMapX(), getMiddleMapY(), gameItemsHolder.getBlock("sand"));
+            gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("sand"));
             kill();
         }
     }
index 46cb8cd1fc250d8fab4582ba23cad5e67e19b114..6e0dfe394700d5f1e63eeb9b5e33c0f5b2c2a930 100644 (file)
@@ -65,9 +65,33 @@ public class Player extends Mob {
         heal(MAX_HEALTH);
     }
 
+    public void decreaseCurrentItemCount(GameItemsHolder gameItemsHolder) {
+        if (gameMode == 1) {
+            return;
+        }
+        getCurrentItem().setAmount(getCurrentItem().getAmount() - 1);
+        if (getCurrentItem().getAmount() <= 0) {
+            setCurrentInventorySlotItem(gameItemsHolder.getFallbackItem());
+        }
+    }
+
+    public InventoryItem getCurrentItem() {
+        return inventory[slot];
+    }
+
     public void pickUpDrop(Drop drop) {
+        for (InventoryItem invItem : inventory) {
+            if (!invItem.getItem().isTool()
+                    && invItem.getItem() == drop.getItem()
+                    && invItem.getAmount() < invItem.getItem().getParams().getMaxStack()) {
+                invItem.setAmount(invItem.getAmount() + 1);
+                drop.setPickedUp(true);
+                return;
+            }
+        }
+
         for (int i = 0; i < inventory.length; i++) {
-            if (inventory(i) == null || inventory(i).getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY) || inventory(i) == drop.getItem()) {
+            if (inventory(i) == null || inventory(i).getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY)) {
                 inventory[i] = drop.getItem().toInventoryItem();
                 drop.setPickedUp(true);
                 break;
index 0fa2075e5215416efa11bcfbb8405dd4e3c638a6..3573fa986d70718f44cbe385f5b782147060ff8d 100644 (file)
@@ -17,4 +17,5 @@ data class ItemDto(
     @SerialName("top_slab_block") val topSlabBlock: String? = null,
     @SerialName("bottom_slab_block") val bottomSlabBlock: String? = null,
     @SerialName("tool_level") val toolLevel: Int? = null,
+    @SerialName("max_stack") val maxStack: Int = 64,
 )
index 06da72fd69bd88ade678e4c49c934b5b2a9decea..291cfb896aab462b4dda9b7eb1a8d473712dffc9 100644 (file)
@@ -7,4 +7,5 @@ data class CommonItemParams(
     val key: String,
     val name: String,
     val inHandSpriteOrigin: SpriteOrigin,
+    val maxStack: Int,
 )
\ No newline at end of file
index 1e1f43eeb85ad707d4851b045aa25c6ec4de46bc..49cc59d6a5366f484df8a51a6ecd400d538a2a14 100644 (file)
@@ -1,11 +1,17 @@
 package ru.deadsoftware.cavedroid.game.model.item
 
+import com.badlogic.gdx.graphics.Color
+import com.badlogic.gdx.graphics.g2d.SpriteBatch
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.misc.Assets
+import ru.deadsoftware.cavedroid.misc.utils.drawString
+import ru.deadsoftware.cavedroid.misc.utils.px
 import java.io.Serializable
 
 class InventoryItem @JvmOverloads constructor(
     val itemKey: String,
-    val amount: Int = 1,
+    var amount: Int = 1,
 ) : Serializable {
 
     @Transient
@@ -24,4 +30,44 @@ class InventoryItem @JvmOverloads constructor(
         item = gameItemsHolder.getItem(itemKey)
     }
 
+    private fun drawAmountText(spriteBatch: SpriteBatch, text: String,  x: Float, y: Float) {
+        spriteBatch.drawString(text, x + 1, y + 1, Color.BLACK)
+        spriteBatch.drawString(text, x, y, Color.WHITE)
+    }
+
+    fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, x: Float, y: Float) {
+        if (item.isNone()) {
+            return
+        }
+
+        val sprite = item.sprite
+        spriteBatch.draw(sprite, x, y)
+
+        if (amount < 2) {
+            return
+        }
+
+        if (item.isTool()) {
+            spriteBatch.end()
+            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
+            shapeRenderer.color = Color.GREEN
+            shapeRenderer.rect(
+                /* x = */ x,
+                /* y = */ y + 1.px - 2,
+                /* width = */ 1.px * (amount.toFloat() / item.params.maxStack.toFloat()),
+                /* height = */ 2f
+            )
+            shapeRenderer.end()
+            spriteBatch.begin()
+        } else {
+            val amountString = amount.toString()
+            drawAmountText(
+                spriteBatch = spriteBatch,
+                text = amountString,
+                x = x + 1.px - Assets.getStringWidth(amountString),
+                y = y + 1.px - Assets.getStringHeight(amountString)
+            )
+        }
+    }
+
 }
index 1e6b528b5cce8c99e3b59c3f9436f557ef7e3597..4d6d5512276af372e5be34f0acacfd98e92dd708 100644 (file)
@@ -43,7 +43,8 @@ class ItemMapper @Inject constructor(
             inHandSpriteOrigin = SpriteOrigin(
                 x = dto.originX,
                 y = dto.origin_y,
-            )
+            ),
+            maxStack = dto.maxStack,
         )
     }
 
index c8be75594fa19c298404d9dfc6c333b60f787cf8..03f62534522264f008936a451faaa9d2139ea989 100644 (file)
@@ -12,6 +12,7 @@ import ru.deadsoftware.cavedroid.game.model.block.Block
 import ru.deadsoftware.cavedroid.game.world.GameWorld
 import ru.deadsoftware.cavedroid.misc.Assets
 import ru.deadsoftware.cavedroid.misc.utils.bl
+import ru.deadsoftware.cavedroid.misc.utils.drawString
 import ru.deadsoftware.cavedroid.misc.utils.forEachBlockInArea
 import ru.deadsoftware.cavedroid.misc.utils.px
 import javax.inject.Inject
@@ -26,10 +27,6 @@ class DebugRenderer @Inject constructor(
 
     override val renderLayer get() = RENDER_LAYER
 
-    private fun SpriteBatch.drawString(str: String, x: Float, y: Float) {
-        Assets.minecraftFont.draw(this, str, x, y)
-    }
-
     private fun getMinimapColor(x: Int, y: Int): Color? {
         val foregroundBlock = gameWorld.getForeMap(x, y)
 
index cea623a40d0194f6e87d13570ab9cfc75229278f..7bbb87689d7b6adb77742385a8ae2f2c454355ab 100644 (file)
@@ -59,19 +59,19 @@ class HudRenderer @Inject constructor(
         }
     }
 
-    private fun drawHotbarItems(spriteBatch: SpriteBatch, hotbarX: Float) {
-        mobsController.player.inventory.asSequence()
-            .map(InventoryItem::item)
+    private fun drawHotbarItems(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer,  hotbarX: Float) {
+        mobsController.player.inventory
             .forEachIndexed { index, item ->
-                if (item.isNone()) {
+                if (item.item.isNone()) {
                     return@forEachIndexed
                 }
 
-                spriteBatch.draw(
-                    /* region = */ item.sprite,
-                    /* x = */ hotbarX + HotbarConfig.horizontalMargin
-                            + index * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace),
-                    /* y = */ HotbarConfig.verticalMargin,
+                item.draw(
+                    spriteBatch = spriteBatch,
+                    shapeRenderer = shapeRenderer,
+                    x = hotbarX + HotbarConfig.horizontalMargin +
+                            index * (HotbarConfig.itemSeparatorWidth + HotbarConfig.itemSlotSpace),
+                    y = HotbarConfig.verticalMargin,
                 )
             }
     }
@@ -85,19 +85,19 @@ class HudRenderer @Inject constructor(
         )
     }
 
-    private fun drawHotbar(spriteBatch: SpriteBatch, viewport: Rectangle) {
+    private fun drawHotbar(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle) {
         val hotbar = hotbarTexture
         val hotbarX = viewport.width / 2 - hotbar.regionWidth / 2
 
         spriteBatch.draw(hotbar, hotbarX, 0f)
         drawHealth(spriteBatch, hotbarX, hotbarTexture.regionHeight.toFloat())
-        drawHotbarItems(spriteBatch, hotbarX)
         drawHotbarSelector(spriteBatch, hotbarX)
+        drawHotbarItems(spriteBatch, shapeRenderer, hotbarX)
     }
 
     override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
         drawCursor(spriteBatch, viewport)
-        drawHotbar(spriteBatch, viewport)
+        drawHotbar(spriteBatch, shapeRenderer, viewport)
     }
 
     companion object {
index 3480e2783f9fb12c5d26ede452ede14a11da8fc1..d9423ff2ce8c5381c379e5bc8e4813ed6e13a5be 100644 (file)
@@ -32,7 +32,7 @@ class CreativeWindowRenderer @Inject constructor(
         val startIndex = gameInput.creativeScroll * CreativeWindowConfig.itemsInRow
         val endIndex = startIndex + CreativeWindowConfig.itemsOnPage
 
-        for (i in startIndex ..< endIndex) {
+        for (i in startIndex..<endIndex) {
             if (i !in allItems.indices) {
                 break
             }
@@ -51,21 +51,25 @@ class CreativeWindowRenderer @Inject constructor(
         }
     }
 
-    private fun drawPlayerInventory(spriteBatch: SpriteBatch, inventoryX: Float, inventoryY: Float) {
+    private fun drawPlayerInventory(
+        spriteBatch: SpriteBatch,
+        shapeRenderer: ShapeRenderer,
+        inventoryX: Float,
+        inventoryY: Float
+    ) {
         mobsController.player.inventory.asSequence()
-            .map(InventoryItem::item)
             .forEachIndexed { index, item ->
-                if (item.isNone()) {
+                if (item.item.isNone()) {
                     return@forEachIndexed
                 }
 
                 val itemX = inventoryX + index * CreativeWindowConfig.itemsGridColWidth
 
-                spriteBatch.draw(item.sprite, itemX, inventoryY)
+                item.draw(spriteBatch, shapeRenderer, itemX, inventoryY)
             }
     }
 
-    private fun drawCreative(spriteBatch: SpriteBatch, viewport: Rectangle) {
+    private fun drawCreative(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle) {
         val creativeWindow = creativeWindowTexture
 
         val windowX = viewport.width / 2 - creativeWindow.regionWidth / 2
@@ -88,13 +92,14 @@ class CreativeWindowRenderer @Inject constructor(
 
         drawPlayerInventory(
             spriteBatch = spriteBatch,
+            shapeRenderer = shapeRenderer,
             inventoryX = windowX + CreativeWindowConfig.itemsGridMarginLeft,
             inventoryY = windowY + creativeWindow.regionHeight - CreativeWindowConfig.playerInventoryOffsetFromBottom
         )
     }
 
     override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
-            drawCreative(spriteBatch, viewport)
+        drawCreative(spriteBatch, shapeRenderer, viewport)
     }
 
     companion object {
index 32fef769bed2b89c4e1d71e55d68c2eb37cd04eb..f8a5cc970e1749d34eb8abeb7f0f7acacb8df382 100644 (file)
@@ -5,6 +5,8 @@ import ru.deadsoftware.cavedroid.game.GameItemsHolder;
 import ru.deadsoftware.cavedroid.game.GameScope;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.model.block.Block;
+import ru.deadsoftware.cavedroid.game.model.item.InventoryItem;
+import ru.deadsoftware.cavedroid.game.model.item.Item;
 import ru.deadsoftware.cavedroid.game.model.world.generator.WorldGeneratorConfig;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
 import ru.deadsoftware.cavedroid.misc.utils.MeasureUnitsUtilsKt;
@@ -151,34 +153,63 @@ public class GameWorld {
         setMap(x, y, 1, block);
     }
 
-    public void placeToForeground(int x, int y, Block value) {
+    public boolean placeToForeground(int x, int y, Block value) {
         if (!hasForeAt(x, y) || value == mGameItemsHolder.getFallbackBlock() || !getForeMap(x, y).hasCollision()) {
             setForeMap(x, y, value);
+            return true;
         } else if (value instanceof Block.Slab && isSameSlab(value, getForeMap(x, y))) {
             setForeMap(x, y, mGameItemsHolder.getBlock(((Block.Slab) value).getFullBlockKey()));
+            return true;
         }
+        return false;
     }
 
-    public void placeToBackground(int x, int y, Block value) {
+    public boolean placeToBackground(int x, int y, Block value) {
         if (value == mGameItemsHolder.getFallbackBlock() || (getBackMap(x, y) == mGameItemsHolder.getFallbackBlock() && value.hasCollision()) &&
                 (!value.isTransparent() || value == mGameItemsHolder.getBlock("glass"))) {
             setBackMap(x, y, value);
+            return true;
         }
+        return false;
+    }
+
+    private void playerDurateTool() {
+        final InventoryItem playerCurrentItem = mMobsController.getPlayer().getCurrentItem();
+        if (mMobsController.getPlayer().getCurrentItem().getItem().isTool()) {
+            mMobsController.getPlayer().decreaseCurrentItemCount(mGameItemsHolder);
+        }
+    }
+
+    private boolean shouldDrop(Block block) {
+        final Item item = mMobsController.getPlayer().getCurrentItem().getItem();
+        int toolLevel = item.isTool() ? ((Item.Tool)item).getLevel() : 0;
+        if (item.isTool() && block.getParams().getToolType() != item.getClass()) {
+            toolLevel = 0;
+        }
+        return toolLevel >= block.getParams().getToolLevel();
     }
 
     public void destroyForeMap(int x, int y) {
         Block block = getForeMap(x, y);
-        if (block.hasDrop()) {
-            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
+        if (block.hasDrop() && shouldDrop(block)) {
+            for (int i = 0; i < block.getParams().getDropInfo().getCount(); i++) {
+                mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
+            }
         }
+        playerDurateTool();
         placeToForeground(x, y, mGameItemsHolder.getFallbackBlock());
     }
 
+
+
     public void destroyBackMap(int x, int y) {
         Block block = getBackMap(x, y);
-        if (block.hasDrop()) {
-            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
+        if (block.hasDrop() && shouldDrop(block)) {
+            for (int i = 0; i < block.getParams().getDropInfo().getCount(); i++) {
+                mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
+            }
         }
+        playerDurateTool();
         placeToBackground(x, y, mGameItemsHolder.getFallbackBlock());
     }
 }
\ No newline at end of file
index 28c38276650f23485ade46a73bccbe37fa4ac86a..5849f03c79f02356a2e14a3f3c58df7102421f0a 100644 (file)
@@ -1,6 +1,10 @@
 package ru.deadsoftware.cavedroid.misc.utils
 
+import com.badlogic.gdx.graphics.Color
+import com.badlogic.gdx.graphics.g2d.GlyphLayout
+import com.badlogic.gdx.graphics.g2d.SpriteBatch
 import com.badlogic.gdx.math.Rectangle
+import ru.deadsoftware.cavedroid.misc.Assets
 
 private fun Rectangle.shifted(shift: Float) = Rectangle(x + shift, y, width, height)
 
@@ -39,4 +43,10 @@ fun forEachBlockInArea(
             func(x, y)
         }
     }
-}
\ No newline at end of file
+}
+
+@JvmOverloads
+fun SpriteBatch.drawString(str: String, x: Float, y: Float, color: Color = Color.WHITE): GlyphLayout {
+    Assets.minecraftFont.color = color
+    return Assets.minecraftFont.draw(this, str, x, y)
+}