Skip to content

Commit

Permalink
SoundEvent and ParticleEvent are now combined
Browse files Browse the repository at this point in the history
  • Loading branch information
davchoo committed May 26, 2022
1 parent 4a9eec4 commit 41cd7f4
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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.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.recipe.RecipeType;
import com.github.steveice10.packetlib.packet.Packet;
Expand Down Expand Up @@ -155,9 +155,9 @@ public final class Registries {
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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.geysermc.geyser.registry.loader;

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 it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.geysermc.geyser.GeyserImpl;
Expand All @@ -41,37 +41,37 @@
/**
* 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
public Map<SoundEvent, LevelEventTranslator> load(String input) {
public Map<LevelEvent, LevelEventTranslator> load(String input) {
this.loadFile(input);

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()) {
Map.Entry<String, JsonNode> entry = effectsIterator.next();
JsonNode node = entry.getValue();
try {
String type = node.get("type").asText();
SoundEvent javaEffect = null;
LevelEvent javaEffect = null;
LevelEventTranslator transformer = null;
switch (type) {
case "soundLevel" -> {
javaEffect = SoundEvent.valueOf(entry.getKey());
javaEffect = LevelEvent.valueOf(entry.getKey());
LevelEventType levelEventType = LevelEventType.valueOf(node.get("name").asText());
int data = node.has("data") ? node.get("data").intValue() : 0;
transformer = new SoundLevelEventTranslator(levelEventType, data);
}
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());
String identifier = node.has("identifier") ? node.get("identifier").asText() : "";
int extraData = node.has("extraData") ? node.get("extraData").intValue() : -1;
transformer = new SoundEventEventTranslator(soundEvent, identifier, extraData);
}
case "playSound" -> {
javaEffect = SoundEvent.valueOf(entry.getKey());
javaEffect = LevelEvent.valueOf(entry.getKey());
String name = node.get("name").asText();
float volume = node.has("volume") ? node.get("volume").floatValue() : 1.0f;
boolean pitchSub = node.has("pitch_sub") && node.get("pitch_sub").booleanValue();
Expand All @@ -85,7 +85,7 @@ public Map<SoundEvent, LevelEventTranslator> load(String input) {
soundEffects.put(javaEffect, transformer);
}
} 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;
Expand Down
Loading

0 comments on commit 41cd7f4

Please sign in to comment.