Add cancel-block-sounds option for 1.8->1.9 place/break fix (#4011)

This commit is contained in:
EnZaXD 2024-07-12 00:11:11 +02:00 committed by GitHub
parent 323f0fa087
commit 20f7738f08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 21 deletions

View File

@ -457,4 +457,11 @@ public interface ViaVersionConfig extends Config {
* @return true if enabled
*/
boolean handleInvalidItemCount();
/**
* Tries to cancel block break/place sounds sent by 1.8 servers to 1.9+ clients to prevent them from playing twice
*
* @return true if enabled
*/
boolean cancelBlockSounds();
}

View File

@ -87,7 +87,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
if (serverProtocolVersion.olderThan(ProtocolVersion.v1_9)) {
new ArmorListener(plugin).register();
new DeathListener(plugin).register();
new BlockListener(plugin).register();
if (plugin.getConf().cancelBlockSounds()) {
new BlockListener(plugin).register();
}
if (plugin.getConf().isItemCache()) {
handItemCache = new HandItemCache();

View File

@ -93,6 +93,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private boolean translateOcelotToCat;
private boolean enforceSecureChat;
private boolean handleInvalidItemCount;
private boolean cancelBlockSounds;
protected AbstractViaConfig(final File configFile, final Logger logger) {
super(configFile, logger);
@ -159,6 +160,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
translateOcelotToCat = getBoolean("translate-ocelot-to-cat", true);
enforceSecureChat = getBoolean("enforce-secure-chat", false);
handleInvalidItemCount = getBoolean("handle-invalid-item-count", false);
cancelBlockSounds = getBoolean("cancel-block-sounds", true);
}
private BlockedProtocolVersions loadBlockedProtocolVersions() {
@ -535,4 +537,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public boolean handleInvalidItemCount() {
return handleInvalidItemCount;
}
@Override
public boolean cancelBlockSounds() {
return cancelBlockSounds;
}
}

View File

@ -112,6 +112,10 @@ public class WorldPacketRewriter1_9 {
}
wrapper.set(Types.STRING, 0, newname);
wrapper.write(Types.VAR_INT, catid); // Write Category ID
if (!Via.getConfig().cancelBlockSounds()) {
return;
}
if (effect != null && effect.isBreakSound()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
int x = wrapper.passthrough(Types.INT); //Position X
@ -358,7 +362,27 @@ public class WorldPacketRewriter1_9 {
map(Types.UNSIGNED_BYTE); // 5 - Y
map(Types.UNSIGNED_BYTE); // 6 - Z
//Register block place to fix sounds
// Handle CommandBlocks
handler(wrapper -> {
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
BlockPosition pos = wrapper.get(Types.BLOCK_POSITION1_8, 0);
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
// Send the Update Block Entity packet if present
if (tag.isPresent()) {
PacketWrapper updateBlockEntity = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, null, wrapper.user());
updateBlockEntity.write(Types.BLOCK_POSITION1_8, pos);
updateBlockEntity.write(Types.UNSIGNED_BYTE, (short) 2);
updateBlockEntity.write(Types.NAMED_COMPOUND_TAG, tag.get());
updateBlockEntity.scheduleSend(Protocol1_8To1_9.class);
}
});
if (!Via.getConfig().cancelBlockSounds()) {
return;
}
handler(wrapper -> {
int face = wrapper.get(Types.UNSIGNED_BYTE, 0);
if (face == 255)
@ -378,25 +402,6 @@ public class WorldPacketRewriter1_9 {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class);
tracker.addBlockInteraction(new BlockPosition(x, y, z));
});
// Handle CommandBlocks
handler(wrapper -> {
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
BlockPosition pos = wrapper.get(Types.BLOCK_POSITION1_8, 0);
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
// Send the Update Block Entity packet if present
if (tag.isPresent()) {
PacketWrapper updateBlockEntity = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, null, wrapper.user());
updateBlockEntity.write(Types.BLOCK_POSITION1_8, pos);
updateBlockEntity.write(Types.UNSIGNED_BYTE, (short) 2);
updateBlockEntity.write(Types.NAMED_COMPOUND_TAG, tag.get());
updateBlockEntity.scheduleSend(Protocol1_8To1_9.class);
}
});
}
});
}

View File

@ -207,3 +207,5 @@ replacement-piston-id: 0
chunk-border-fix: false
# Allows 1.9+ left-handedness (main hand) on 1.8 servers
left-handed-handling: true
# Tries to cancel block break/place sounds sent by 1.8 servers to 1.9+ clients to prevent them from playing twice
cancel-block-sounds: true