3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Map most all missing sounds

Dieser Commit ist enthalten in:
RednedEpic 2020-05-03 23:56:07 -05:00
Ursprung 1aca44ec7f
Commit 25d3e0708f
6 geänderte Dateien mit 75 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.utils.SoundUtils;
@Translator(packet = ServerPlayBuiltinSoundPacket.class)
@ -72,22 +73,23 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayB
+ " was not a playable level sound, or has yet to be mapped to an enum in "
+ "NukkitX SoundEvent ");
} else {
session.getConnector().getLogger().debug("[Builtin] Sound for original " + packetSound + " to mappings " + soundPacket
+ " was not found in NukkitX SoundEvent, but original packet sound name was.");
}
soundPacket.setSound(sound);
soundPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
soundPacket.setIdentifier(soundMapping.getIdentifier());
if (sound == SoundEvent.NOTE) {
// Minecraft Wiki: 2^(x/12) = Java pitch where x is -12 to 12
// Java sends the note value as above starting with -12 and ending at 12
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
soundPacket.setExtraData(soundMapping.getExtraData() + (int)(Math.round((Math.log10(packet.getPitch()) / Math.log10(2)) * 12)) + 12);
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
soundPacket.setExtraData(BlockTranslator.getBedrockBlockId(BlockTranslator.getJavaBlockState(soundMapping.getIdentifier())));
soundPacket.setIdentifier(":");
} else {
soundPacket.setExtraData(soundMapping.getExtraData());
}
soundPacket.setIdentifier(soundMapping.getIdentifier()); // ???
soundPacket.setBabySound(false); // might need to adjust this in the future
soundPacket.setRelativeVolumeDisabled(false);
session.getUpstream().sendPacket(soundPacket);

Datei anzeigen

@ -57,7 +57,6 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
} else {
switch (particleEffect) {
// TODO: BREAK_SPLASH_POTION has additional data
// TODO: Block break doesn't work when you're the player.
case BONEMEAL_GROW:
effect.setType(LevelEventType.BONEMEAL);
BonemealGrowEffectData growEffectData = (BonemealGrowEffectData) packet.getData();
@ -69,7 +68,6 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
BreakBlockEffectData breakBlockEffectData = (BreakBlockEffectData) packet.getData();
effect.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState()));
break;
// TODO: Check these three
case EXPLOSION:
effect.setType(LevelEventType.PARTICLE_LARGE_EXPLOSION);
break;
@ -81,7 +79,24 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
// Might need to be SHOOT
effect.setType(LevelEventType.PARTICLE_SMOKE);
break;
case COMPOSTER:
effect.setType(LevelEventType.BONEMEAL);
ComposterEffectData composterEffectData = (ComposterEffectData) packet.getData();
LevelSoundEventPacket soundEvent = new LevelSoundEventPacket();
soundEvent.setSound(SoundEvent.valueOf("COMPOSTER_" + composterEffectData.name()));
soundEvent.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
soundEvent.setIdentifier(":");
soundEvent.setExtraData(-1);
soundEvent.setBabySound(false);
soundEvent.setRelativeVolumeDisabled(false);
session.getUpstream().sendPacket(soundEvent);
break;
case BLOCK_LAVA_EXTINGUISH:
effect.setType(LevelEventType.SHOOT);
effect.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY() + 1, packet.getPosition().getZ()));
session.getUpstream().sendPacket(effect);
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
soundEventPacket.setSound(SoundEvent.EXTINGUISH_FIRE);
soundEventPacket.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
@ -103,7 +118,6 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
if (geyserEffect != null) {
// Some events are LevelEventTypes, some are SoundEvents.
if (geyserEffect.getType().equals("soundLevel")) {
// TODO: Opening doors also does not work as the player
effect.setType(LevelEventType.valueOf(geyserEffect.getBedrockName()));
} else if (geyserEffect.getType().equals("soundEvent")) {
LevelSoundEventPacket soundEvent = new LevelSoundEventPacket();

Datei anzeigen

@ -0,0 +1,48 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/
package org.geysermc.connector.network.translators.sound.block;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler;
import org.geysermc.connector.network.translators.sound.SoundHandler;
@SoundHandler(blocks = "comparator")
public class ComparatorSoundInteractHandler implements BlockSoundInteractionHandler {
@Override
public void handleInteraction(GeyserSession session, Vector3f position, String identifier) {
boolean powered = identifier.contains("mode=compare");
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);
levelEventPacket.setType(LevelEventType.REDSTONE_TRIGGER);
levelEventPacket.setData(powered ? 500 : 550);
session.getUpstream().sendPacket(levelEventPacket);
}
}

Datei anzeigen

@ -33,7 +33,7 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler;
import org.geysermc.connector.network.translators.sound.SoundHandler;
@SoundHandler(blocks = "door")
@SoundHandler(blocks = {"door", "fence_gate"})
public class DoorSoundInteractionHandler implements BlockSoundInteractionHandler {
@Override

Datei anzeigen

@ -42,7 +42,7 @@ public class LeverSoundInteractionHandler implements BlockSoundInteractionHandle
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);
levelEventPacket.setType(LevelEventType.REDSTONE_TRIGGER);
levelEventPacket.setData(powered ? 500 : 600);
levelEventPacket.setData(powered ? 600 : 500);
session.getUpstream().sendPacket(levelEventPacket);
}
}

@ -1 +1 @@
Subproject commit 848984295e2b2223cda81fd8514d2dc29b5f1a47
Subproject commit 311b83fb85897531d5a803afc27f666bb5626b97