3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Check if bucket sounds should be played in adventure mode

Fixes #2608
Dieser Commit ist enthalten in:
Camotoy 2021-11-01 21:49:20 -04:00
Ursprung 6da6636a98
Commit 6cda15cb8d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 46 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -25,10 +25,16 @@
package org.geysermc.connector.network.translators.sound; package org.geysermc.connector.network.translators.sound;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.inventory.GeyserItemStack; import org.geysermc.connector.inventory.GeyserItemStack;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.registry.Registries; import org.geysermc.connector.registry.Registries;
import org.geysermc.connector.utils.BlockUtils;
import java.util.Map; import java.util.Map;
@ -88,4 +94,38 @@ public interface BlockSoundInteractionHandler extends SoundInteractionHandler<St
((BlockSoundInteractionHandler) interactionEntry.getValue()).handleInteraction(session, position, identifier); ((BlockSoundInteractionHandler) interactionEntry.getValue()).handleInteraction(session, position, identifier);
} }
} }
/**
* Determines if the adventure gamemode would prevent this item from actually succeeding
*/
static boolean canInteract(GeyserSession session, GeyserItemStack itemInHand, String blockIdentifier) {
if (session.getGameMode() != GameMode.ADVENTURE) {
// There are no restrictions on the item
return true;
}
CompoundTag tag = itemInHand.getNbt();
if (tag == null) {
// No CanPlaceOn tag can exist
return false;
}
ListTag canPlaceOn = tag.get("CanPlaceOn");
if (canPlaceOn == null || canPlaceOn.size() == 0) {
return false;
}
String cleanIdentifier = BlockUtils.getCleanIdentifier(blockIdentifier);
for (Tag t : canPlaceOn) {
if (t instanceof StringTag stringTag) {
if (cleanIdentifier.equals(stringTag.getValue())) {
// This operation would/could be a success!
return true;
}
}
}
// The block in world is not present in the CanPlaceOn tag on the item
return false;
}
} }

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.sound.block;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.connector.inventory.GeyserItemStack;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler;
import org.geysermc.connector.network.translators.sound.SoundHandler; import org.geysermc.connector.network.translators.sound.SoundHandler;
@ -40,7 +41,11 @@ public class BucketSoundInteractionHandler implements BlockSoundInteractionHandl
if (session.getBucketScheduledFuture() == null) { if (session.getBucketScheduledFuture() == null) {
return; // No bucket was really interacted with return; // No bucket was really interacted with
} }
String handItemIdentifier = session.getPlayerInventory().getItemInHand().getMapping(session).getJavaIdentifier(); GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
String handItemIdentifier = itemStack.getMapping(session).getJavaIdentifier();
if (!BlockSoundInteractionHandler.canInteract(session, itemStack, identifier)) {
return;
}
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket(); LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
soundEventPacket.setPosition(position); soundEventPacket.setPosition(position);
soundEventPacket.setIdentifier(":"); soundEventPacket.setIdentifier(":");