Allow more blocks to have a place sound on standalone (#2183)

Items such as wall torch blocks currently do not have a place sound on standalone, as their block identifier differs from their item identifier. This commit uses the pick item logic in order to fix place sounds for such blocks.
This commit is contained in:
Camotoy 2021-05-09 01:19:06 -04:00 committed by GitHub
parent 2aa131f9dc
commit dda0172ded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -68,7 +68,7 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
// We need to check if the identifier is the same, else a packet with the sound of what the
// player has in their hand is played, despite if the block is being placed or not
boolean contains = false;
String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(packet.getRecord().getBlock()).split("\\[")[0];
String identifier = BlockTranslator.getBlockMapping(packet.getRecord().getBlock()).getItemIdentifier();
if (identifier.equals(session.getLastBlockPlacedId())) {
contains = true;
}

View file

@ -59,6 +59,18 @@ public class BlockMapping {
return javaIdentifier.split("\\[")[0];
}
/**
* @return the corresponding Java identifier for this item
*/
public String getItemIdentifier() {
if (pickItem != null && !pickItem.equals("minecraft:air")) {
// Spawners can have air as their pick item which we are not interested in.
return pickItem;
}
return getCleanJavaIdentifier();
}
/**
* Get the item a Java client would receive when pressing
* the Pick Block key on a specific Java block state.