block.getDestroySpeed always returns 1.0

Kaelinator

New member
Nov 12, 2023
5
0
1
I'm trying to call the following method:


Code:
float destroySpeed = block.getDestroySpeed(player.getActiveItem())

but I always get 1.0, despite it being bedrock/wood/etc.

I also tried using spigot nms, but I also only ever get 1.0:

Code:
Block nmsBlock = CraftMagicNumbers.getBlock(block.getType());
ItemStack item = CraftItemStack.asNMSCopy(player.getActiveItem());
float destroySpeed = item.a(nmsBlock.n());

Anybody else have this issue?

I'm using Maven, here's my pom.xml:
Code:
  <repositories>
    <repository>
      <id>papermc</id>
      <url>https://repo.papermc.io/repository/maven-public/</url>
    </repository>
    <!-- <repository>
      <id>spigot-repo</id>
      <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository> -->
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.papermc.paper</groupId>
      <artifactId>paper-api</artifactId>
      <version>1.20.2-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
<!--
    <dependency>
      <groupId>org.spigotmc</groupId>
      <artifactId>spigot</artifactId>
      <version>1.20.2-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency> -->
  </dependencies>
 
Version Output
This server is running Paper version git-Paper-290 (MC: 1.20.2) (Implementing API version 1.20.2-R0.1-SNAPSHOT) (Git: f186318)
You are running the latest version
Previous version: git-Paper-280 (MC: 1.20.2)
Last edited:

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
135
6
21
18
California
The player's active item is not the item currently in their main hand. You want player.getInventory().getItemInMainHand(). Also, that will only return > 1.0 if the item is a tool of some sort, shovel, axe, hoe, sword, shears, or pickaxe as those are the only items that affect the breaking speed of blocks.
 
  • Like
Reactions: Kaelinator

Kaelinator

New member
Nov 12, 2023
5
0
1
The player's active item is not the item currently in their main hand. You want player.getInventory().getItemInMainHand(). Also, that will only return > 1.0 if the item is a tool of some sort, shovel, axe, hoe, sword, shears, or pickaxe as those are the only items that affect the breaking speed of blocks.
thank you very much :)