3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

SoundEvent and ParticleEvent are now combined

Dieser Commit ist enthalten in:
davchoo 2022-05-26 19:57:45 -04:00
Ursprung 4a9eec4c54
Commit 41cd7f4574
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: A0168C8E45799B7D
3 geänderte Dateien mit 175 neuen und 177 gelöschten Zeilen

Datei anzeigen

@ -27,7 +27,7 @@ package org.geysermc.geyser.registry;
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType;
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent; import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
import com.github.steveice10.mc.protocol.data.game.level.particle.ParticleType; import com.github.steveice10.mc.protocol.data.game.level.particle.ParticleType;
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType; import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -155,9 +155,9 @@ public final class Registries {
public static final SimpleMappedRegistry<String, SoundMapping> SOUNDS = SimpleMappedRegistry.create("mappings/sounds.json", SoundRegistryLoader::new); public static final SimpleMappedRegistry<String, SoundMapping> SOUNDS = SimpleMappedRegistry.create("mappings/sounds.json", SoundRegistryLoader::new);
/** /**
* A mapped registry holding {@link SoundEvent}s to their corresponding {@link LevelEventTranslator}. * A mapped registry holding {@link LevelEvent}s to their corresponding {@link LevelEventTranslator}.
*/ */
public static final SimpleMappedRegistry<SoundEvent, LevelEventTranslator> SOUND_EVENTS = SimpleMappedRegistry.create("mappings/effects.json", SoundEventsRegistryLoader::new); public static final SimpleMappedRegistry<LevelEvent, LevelEventTranslator> SOUND_LEVEL_EVENTS = SimpleMappedRegistry.create("mappings/effects.json", SoundEventsRegistryLoader::new);
/** /**
* A mapped registry holding {@link SoundTranslator}s to their corresponding {@link SoundInteractionTranslator}. * A mapped registry holding {@link SoundTranslator}s to their corresponding {@link SoundInteractionTranslator}.

Datei anzeigen

@ -26,7 +26,7 @@
package org.geysermc.geyser.registry.loader; package org.geysermc.geyser.registry.loader;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent; import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
@ -41,37 +41,37 @@ import java.util.Map;
/** /**
* Loads sound effects from the given resource path. * Loads sound effects from the given resource path.
*/ */
public class SoundEventsRegistryLoader extends EffectRegistryLoader<Map<SoundEvent, LevelEventTranslator>> { public class SoundEventsRegistryLoader extends EffectRegistryLoader<Map<LevelEvent, LevelEventTranslator>> {
@Override @Override
public Map<SoundEvent, LevelEventTranslator> load(String input) { public Map<LevelEvent, LevelEventTranslator> load(String input) {
this.loadFile(input); this.loadFile(input);
Iterator<Map.Entry<String, JsonNode>> effectsIterator = this.get(input).fields(); Iterator<Map.Entry<String, JsonNode>> effectsIterator = this.get(input).fields();
Map<SoundEvent, LevelEventTranslator> soundEffects = new Object2ObjectOpenHashMap<>(); Map<LevelEvent, LevelEventTranslator> soundEffects = new Object2ObjectOpenHashMap<>();
while (effectsIterator.hasNext()) { while (effectsIterator.hasNext()) {
Map.Entry<String, JsonNode> entry = effectsIterator.next(); Map.Entry<String, JsonNode> entry = effectsIterator.next();
JsonNode node = entry.getValue(); JsonNode node = entry.getValue();
try { try {
String type = node.get("type").asText(); String type = node.get("type").asText();
SoundEvent javaEffect = null; LevelEvent javaEffect = null;
LevelEventTranslator transformer = null; LevelEventTranslator transformer = null;
switch (type) { switch (type) {
case "soundLevel" -> { case "soundLevel" -> {
javaEffect = SoundEvent.valueOf(entry.getKey()); javaEffect = LevelEvent.valueOf(entry.getKey());
LevelEventType levelEventType = LevelEventType.valueOf(node.get("name").asText()); LevelEventType levelEventType = LevelEventType.valueOf(node.get("name").asText());
int data = node.has("data") ? node.get("data").intValue() : 0; int data = node.has("data") ? node.get("data").intValue() : 0;
transformer = new SoundLevelEventTranslator(levelEventType, data); transformer = new SoundLevelEventTranslator(levelEventType, data);
} }
case "soundEvent" -> { case "soundEvent" -> {
javaEffect = SoundEvent.valueOf(entry.getKey()); javaEffect = LevelEvent.valueOf(entry.getKey());
com.nukkitx.protocol.bedrock.data.SoundEvent soundEvent = com.nukkitx.protocol.bedrock.data.SoundEvent.valueOf(node.get("name").asText()); com.nukkitx.protocol.bedrock.data.SoundEvent soundEvent = com.nukkitx.protocol.bedrock.data.SoundEvent.valueOf(node.get("name").asText());
String identifier = node.has("identifier") ? node.get("identifier").asText() : ""; String identifier = node.has("identifier") ? node.get("identifier").asText() : "";
int extraData = node.has("extraData") ? node.get("extraData").intValue() : -1; int extraData = node.has("extraData") ? node.get("extraData").intValue() : -1;
transformer = new SoundEventEventTranslator(soundEvent, identifier, extraData); transformer = new SoundEventEventTranslator(soundEvent, identifier, extraData);
} }
case "playSound" -> { case "playSound" -> {
javaEffect = SoundEvent.valueOf(entry.getKey()); javaEffect = LevelEvent.valueOf(entry.getKey());
String name = node.get("name").asText(); String name = node.get("name").asText();
float volume = node.has("volume") ? node.get("volume").floatValue() : 1.0f; float volume = node.has("volume") ? node.get("volume").floatValue() : 1.0f;
boolean pitchSub = node.has("pitch_sub") && node.get("pitch_sub").booleanValue(); boolean pitchSub = node.has("pitch_sub") && node.get("pitch_sub").booleanValue();
@ -85,7 +85,7 @@ public class SoundEventsRegistryLoader extends EffectRegistryLoader<Map<SoundEve
soundEffects.put(javaEffect, transformer); soundEffects.put(javaEffect, transformer);
} }
} catch (Exception e) { } catch (Exception e) {
GeyserImpl.getInstance().getLogger().warning("Failed to map sound effect " + entry.getKey() + " : " + e.toString()); GeyserImpl.getInstance().getLogger().warning("Failed to map sound effect " + entry.getKey() + " : " + e);
} }
} }
return soundEffects; return soundEffects;

Datei anzeigen

@ -51,7 +51,7 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
@Override @Override
public void translate(GeyserSession session, ClientboundLevelEventPacket packet) { public void translate(GeyserSession session, ClientboundLevelEventPacket packet) {
// Separate case since each RecordEventData in Java is an individual track in Bedrock // Separate case since each RecordEventData in Java is an individual track in Bedrock
if (packet.getEvent() == com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent.RECORD) { if (packet.getEvent() == LevelEvent.RECORD) {
RecordEventData recordEventData = (RecordEventData) packet.getData(); RecordEventData recordEventData = (RecordEventData) packet.getData();
SoundEvent soundEvent = Registries.RECORDS.getOrDefault(recordEventData.getRecordId(), SoundEvent.STOP_RECORD); SoundEvent soundEvent = Registries.RECORDS.getOrDefault(recordEventData.getRecordId(), SoundEvent.STOP_RECORD);
Vector3i origin = packet.getPosition(); Vector3i origin = packet.getPosition();
@ -82,21 +82,20 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
return; return;
} }
if (packet.getEvent() instanceof com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent soundEvent) { // Check for a sound event translator
LevelEventTranslator transformer = Registries.SOUND_EVENTS.get(soundEvent); LevelEventTranslator transformer = Registries.SOUND_LEVEL_EVENTS.get(packet.getEvent());
if (transformer != null) { if (transformer != null) {
transformer.translate(session, packet); transformer.translate(session, packet);
return; return;
} }
GeyserImpl.getInstance().getLogger().debug("Unhandled sound event: " + soundEvent.name());
} else if (packet.getEvent() instanceof ParticleEvent particleEvent) {
Vector3i origin = packet.getPosition(); Vector3i origin = packet.getPosition();
Vector3f pos = Vector3f.from(origin.getX() + 0.5f, origin.getY() + 0.5f, origin.getZ() + 0.5f); Vector3f pos = Vector3f.from(origin.getX() + 0.5f, origin.getY() + 0.5f, origin.getZ() + 0.5f);
LevelEventPacket effectPacket = new LevelEventPacket(); LevelEventPacket effectPacket = new LevelEventPacket();
effectPacket.setPosition(pos); effectPacket.setPosition(pos);
effectPacket.setData(0); effectPacket.setData(0);
switch (particleEvent) { switch (packet.getEvent()) {
case COMPOSTER -> { case COMPOSTER -> {
effectPacket.setType(LevelEventType.PARTICLE_CROP_GROWTH); effectPacket.setType(LevelEventType.PARTICLE_CROP_GROWTH);
@ -194,7 +193,7 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
BreakBlockEventData breakBlockEventData = (BreakBlockEventData) packet.getData(); BreakBlockEventData breakBlockEventData = (BreakBlockEventData) packet.getData();
effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakBlockEventData.getBlockState())); effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakBlockEventData.getBlockState()));
} }
case BREAK_SPLASH_POTION -> { case BREAK_SPLASH_POTION, BREAK_SPLASH_POTION2 -> {
effectPacket.setType(LevelEventType.PARTICLE_POTION_SPLASH); effectPacket.setType(LevelEventType.PARTICLE_POTION_SPLASH);
effectPacket.setPosition(pos.add(0, -0.5f, 0)); effectPacket.setPosition(pos.add(0, -0.5f, 0));
@ -213,7 +212,7 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
case BREAK_EYE_OF_ENDER -> effectPacket.setType(LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH); case BREAK_EYE_OF_ENDER -> effectPacket.setType(LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH);
case MOB_SPAWN -> effectPacket.setType(LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); // TODO: Check, but I don't think I really verified this ever went into effect on Java case MOB_SPAWN -> effectPacket.setType(LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); // TODO: Check, but I don't think I really verified this ever went into effect on Java
case BONEMEAL_GROW_WITH_SOUND, BONEMEAL_GROW -> { case BONEMEAL_GROW_WITH_SOUND, BONEMEAL_GROW -> {
effectPacket.setType(particleEvent == ParticleEvent.BONEMEAL_GROW ? LevelEventType.PARTICLE_TURTLE_EGG : LevelEventType.PARTICLE_CROP_GROWTH); effectPacket.setType(packet.getEvent() == LevelEvent.BONEMEAL_GROW ? LevelEventType.PARTICLE_TURTLE_EGG : LevelEventType.PARTICLE_CROP_GROWTH);
BonemealGrowEventData growEventData = (BonemealGrowEventData) packet.getData(); BonemealGrowEventData growEventData = (BonemealGrowEventData) packet.getData();
effectPacket.setData(growEventData.getParticleCount()); effectPacket.setData(growEventData.getParticleCount());
@ -259,11 +258,10 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
case WAX_OFF -> effectPacket.setType(LevelEventType.PARTICLE_WAX_OFF); case WAX_OFF -> effectPacket.setType(LevelEventType.PARTICLE_WAX_OFF);
case SCRAPE -> effectPacket.setType(LevelEventType.PARTICLE_SCRAPE); case SCRAPE -> effectPacket.setType(LevelEventType.PARTICLE_SCRAPE);
default -> { default -> {
GeyserImpl.getInstance().getLogger().debug("Unhandled particle event: " + particleEvent.name()); GeyserImpl.getInstance().getLogger().debug("Unhandled level event: " + packet.getEvent());
return; return;
} }
} }
session.sendUpstreamPacket(effectPacket); session.sendUpstreamPacket(effectPacket);
} }
} }
}