forked from GeyserMC/Geyser
Update effects mappings (#949)
* Update effects mappings * Use STOP_RECORD as the default record instead of null * Add comments * Update mappings submodule * Update MCProtocolLib and effects * Change level event used for EVAPORATE effect The bedrock client plays an additional sound when using CAULDRON_EXPLODE. The java client does not play any sound. * Update mappings submodule
This commit is contained in:
parent
11c713dc6f
commit
61dbcb0c80
8 changed files with 489 additions and 130 deletions
|
@ -105,7 +105,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.steveice10</groupId>
|
<groupId>com.github.steveice10</groupId>
|
||||||
<artifactId>mcprotocollib</artifactId>
|
<artifactId>mcprotocollib</artifactId>
|
||||||
<version>46b46001f6</version>
|
<version>f03b176e18</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
|
|
@ -25,19 +25,18 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.effect;
|
package org.geysermc.connector.network.translators.effect;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket;
|
||||||
import lombok.Getter;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
/**
|
||||||
@Setter
|
* Represents an effect capable of translating itself into bedrock
|
||||||
@AllArgsConstructor
|
*/
|
||||||
public class Effect {
|
public interface Effect {
|
||||||
|
/**
|
||||||
private String javaName;
|
* Translates the given {@link ServerPlayEffectPacket} into bedrock and sends it upstream.
|
||||||
private String bedrockName;
|
*
|
||||||
private String type;
|
* @param session GeyserSession
|
||||||
private int data;
|
* @param packet the effect packet to handle
|
||||||
private String identifier;
|
*/
|
||||||
|
void handleEffectPacket(GeyserSession session, ServerPlayEffectPacket packet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package org.geysermc.connector.network.translators.effect;
|
package org.geysermc.connector.network.translators.effect;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.world.effect.SoundEffect;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
|
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
|
||||||
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
||||||
|
@ -46,7 +47,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class EffectRegistry {
|
public class EffectRegistry {
|
||||||
|
|
||||||
public static final Map<String, Effect> EFFECTS = new HashMap<>();
|
public static final Map<SoundEffect, Effect> SOUND_EFFECTS = new HashMap<>();
|
||||||
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<SoundEvent> RECORDS = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
private static Map<ParticleType, LevelEventType> particleTypeMap = new HashMap<>();
|
private static Map<ParticleType, LevelEventType> particleTypeMap = new HashMap<>();
|
||||||
|
@ -97,19 +98,54 @@ public class EffectRegistry {
|
||||||
Iterator<Map.Entry<String, JsonNode>> effectsIterator = effects.fields();
|
Iterator<Map.Entry<String, JsonNode>> effectsIterator = effects.fields();
|
||||||
while (effectsIterator.hasNext()) {
|
while (effectsIterator.hasNext()) {
|
||||||
Map.Entry<String, JsonNode> entry = effectsIterator.next();
|
Map.Entry<String, JsonNode> entry = effectsIterator.next();
|
||||||
// Separate records database since they're handled differently between the two versions
|
JsonNode node = entry.getValue();
|
||||||
if (entry.getValue().has("records")) {
|
try {
|
||||||
JsonNode records = entry.getValue().get("records");
|
String type = node.get("type").asText();
|
||||||
Iterator<Map.Entry<String, JsonNode>> recordsIterator = records.fields();
|
SoundEffect javaEffect = null;
|
||||||
while (recordsIterator.hasNext()) {
|
Effect effect = null;
|
||||||
Map.Entry<String, JsonNode> recordEntry = recordsIterator.next();
|
switch (type) {
|
||||||
RECORDS.put(Integer.parseInt(recordEntry.getKey()), SoundEvent.valueOf(recordEntry.getValue().asText()));
|
case "soundLevel": {
|
||||||
|
javaEffect = SoundEffect.valueOf(entry.getKey());
|
||||||
|
LevelEventType levelEventType = LevelEventType.valueOf(node.get("name").asText());
|
||||||
|
int data = node.has("data") ? node.get("data").intValue() : 0;
|
||||||
|
effect = new SoundLevelEffect(levelEventType, data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "soundEvent": {
|
||||||
|
javaEffect = SoundEffect.valueOf(entry.getKey());
|
||||||
|
SoundEvent soundEvent = 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;
|
||||||
|
effect = new SoundEventEffect(soundEvent, identifier, extraData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "playSound": {
|
||||||
|
javaEffect = SoundEffect.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() : false;
|
||||||
|
float pitchMul = node.has("pitch_mul") ? node.get("pitch_mul").floatValue() : 1.0f;
|
||||||
|
float pitchAdd = node.has("pitch_add") ? node.get("pitch_add").floatValue() : 0.0f;
|
||||||
|
boolean relative = node.has("relative") ? node.get("relative").booleanValue() : true;
|
||||||
|
effect = new PlaySoundEffect(name, volume, pitchSub, pitchMul, pitchAdd, relative);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "record": {
|
||||||
|
JsonNode records = entry.getValue().get("records");
|
||||||
|
Iterator<Map.Entry<String, JsonNode>> recordsIterator = records.fields();
|
||||||
|
while (recordsIterator.hasNext()) {
|
||||||
|
Map.Entry<String, JsonNode> recordEntry = recordsIterator.next();
|
||||||
|
RECORDS.put(Integer.parseInt(recordEntry.getKey()), SoundEvent.valueOf(recordEntry.getValue().asText()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (javaEffect != null) {
|
||||||
|
SOUND_EFFECTS.put(javaEffect, effect);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
GeyserConnector.getInstance().getLogger().warning("Failed to map sound effect " + entry.getKey() + " : " + e.toString());
|
||||||
}
|
}
|
||||||
String identifier = (entry.getValue().has("identifier")) ? entry.getValue().get("identifier").asText() : "";
|
|
||||||
int data = (entry.getValue().has("data")) ? entry.getValue().get("data").asInt() : -1;
|
|
||||||
Effect effect = new Effect(entry.getKey(), entry.getValue().get("name").asText(), entry.getValue().get("type").asText(), data, identifier);
|
|
||||||
EFFECTS.put(entry.getKey(), effect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* 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.effect;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.PlaySoundPacket;
|
||||||
|
import lombok.Value;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class PlaySoundEffect implements Effect {
|
||||||
|
/**
|
||||||
|
* Bedrock playsound identifier
|
||||||
|
*/
|
||||||
|
String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volume of the sound
|
||||||
|
*/
|
||||||
|
float volume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, the initial value used for random pitch is the difference between two random floats.
|
||||||
|
* If false, it is a single random float
|
||||||
|
*/
|
||||||
|
boolean pitchSub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplier for random pitch value
|
||||||
|
*/
|
||||||
|
float pitchMul;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant addition to random pitch value after multiplier
|
||||||
|
*/
|
||||||
|
float pitchAdd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the sound is meant to be played in 3d space
|
||||||
|
*/
|
||||||
|
boolean relative;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEffectPacket(GeyserSession session, ServerPlayEffectPacket packet) {
|
||||||
|
Random rand = ThreadLocalRandom.current();
|
||||||
|
PlaySoundPacket playSoundPacket = new PlaySoundPacket();
|
||||||
|
playSoundPacket.setSound(name);
|
||||||
|
playSoundPacket.setPosition(!relative ? session.getPlayerEntity().getPosition() : Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f));
|
||||||
|
playSoundPacket.setVolume(volume);
|
||||||
|
playSoundPacket.setPitch((pitchSub ? (rand.nextFloat() - rand.nextFloat()) : rand.nextFloat()) * pitchMul + pitchAdd); //replicates java client randomness
|
||||||
|
session.sendUpstreamPacket(playSoundPacket);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* 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.effect;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
|
||||||
|
import lombok.Value;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class SoundEventEffect implements Effect {
|
||||||
|
/**
|
||||||
|
* Bedrock sound event
|
||||||
|
*/
|
||||||
|
SoundEvent soundEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity identifier. Usually an empty string
|
||||||
|
*/
|
||||||
|
String identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra data. Usually -1
|
||||||
|
*/
|
||||||
|
int extraData;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEffectPacket(GeyserSession session, ServerPlayEffectPacket packet) {
|
||||||
|
LevelSoundEventPacket levelSoundEvent = new LevelSoundEventPacket();
|
||||||
|
levelSoundEvent.setSound(soundEvent);
|
||||||
|
levelSoundEvent.setIdentifier(identifier);
|
||||||
|
levelSoundEvent.setExtraData(extraData);
|
||||||
|
levelSoundEvent.setRelativeVolumeDisabled(packet.isBroadcast());
|
||||||
|
levelSoundEvent.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f));
|
||||||
|
levelSoundEvent.setBabySound(false);
|
||||||
|
session.sendUpstreamPacket(levelSoundEvent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* 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.effect;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
||||||
|
import lombok.Value;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class SoundLevelEffect implements Effect {
|
||||||
|
/**
|
||||||
|
* Bedrock level event type
|
||||||
|
*/
|
||||||
|
LevelEventType levelEventType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event data. Usually 0
|
||||||
|
*/
|
||||||
|
int data;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEffectPacket(GeyserSession session, ServerPlayEffectPacket packet) {
|
||||||
|
LevelEventPacket eventPacket = new LevelEventPacket();
|
||||||
|
eventPacket.setType(levelEventType);
|
||||||
|
eventPacket.setData(data);
|
||||||
|
eventPacket.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f));
|
||||||
|
session.sendUpstreamPacket(eventPacket);
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,123 +45,246 @@ import org.geysermc.connector.utils.LocaleUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@Translator(packet = ServerPlayEffectPacket.class)
|
@Translator(packet = ServerPlayEffectPacket.class)
|
||||||
public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectPacket> {
|
public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectPacket> {
|
||||||
|
|
||||||
// TODO: Update mappings since they're definitely all going to be wrong now
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerPlayEffectPacket packet, GeyserSession session) {
|
public void translate(ServerPlayEffectPacket packet, GeyserSession session) {
|
||||||
LevelEventPacket effect = new LevelEventPacket();
|
// Separate case since each RecordEffectData in Java is an individual track in Bedrock
|
||||||
// Some things here are particles, others are not
|
if (packet.getEffect() == SoundEffect.RECORD) {
|
||||||
if (packet.getEffect() instanceof ParticleEffect) {
|
RecordEffectData recordEffectData = (RecordEffectData) packet.getData();
|
||||||
ParticleEffect particleEffect = (ParticleEffect) packet.getEffect();
|
SoundEvent soundEvent = EffectRegistry.RECORDS.getOrDefault(recordEffectData.getRecordId(), SoundEvent.STOP_RECORD);
|
||||||
Effect geyserEffect = EffectRegistry.EFFECTS.get(particleEffect.name());
|
Vector3f pos = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f);
|
||||||
|
|
||||||
|
LevelSoundEventPacket levelSoundEvent = new LevelSoundEventPacket();
|
||||||
|
levelSoundEvent.setIdentifier("");
|
||||||
|
levelSoundEvent.setSound(soundEvent);
|
||||||
|
levelSoundEvent.setPosition(pos);
|
||||||
|
levelSoundEvent.setRelativeVolumeDisabled(packet.isBroadcast());
|
||||||
|
levelSoundEvent.setExtraData(-1);
|
||||||
|
levelSoundEvent.setBabySound(false);
|
||||||
|
session.sendUpstreamPacket(levelSoundEvent);
|
||||||
|
|
||||||
|
if (soundEvent != SoundEvent.STOP_RECORD) {
|
||||||
|
// Send text packet as it seems to be handled in Java Edition client-side.
|
||||||
|
TextPacket textPacket = new TextPacket();
|
||||||
|
textPacket.setType(TextPacket.Type.JUKEBOX_POPUP);
|
||||||
|
textPacket.setNeedsTranslation(true);
|
||||||
|
textPacket.setXuid("");
|
||||||
|
textPacket.setPlatformChatId("");
|
||||||
|
textPacket.setSourceName(null);
|
||||||
|
textPacket.setMessage("record.nowPlaying");
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
String recordString = "%item." + soundEvent.name().toLowerCase(Locale.ROOT) + ".desc";
|
||||||
|
params.add(LocaleUtils.getLocaleString(recordString, session.getClientData().getLanguageCode()));
|
||||||
|
textPacket.setParameters(params);
|
||||||
|
session.sendUpstreamPacket(textPacket);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet.getEffect() instanceof SoundEffect) {
|
||||||
|
SoundEffect soundEffect = (SoundEffect) packet.getEffect();
|
||||||
|
Effect geyserEffect = EffectRegistry.SOUND_EFFECTS.get(soundEffect);
|
||||||
if (geyserEffect != null) {
|
if (geyserEffect != null) {
|
||||||
String name = geyserEffect.getBedrockName();
|
geyserEffect.handleEffectPacket(session, packet);
|
||||||
effect.setType(LevelEventType.valueOf(name));
|
return;
|
||||||
} else {
|
}
|
||||||
switch (particleEffect) {
|
GeyserConnector.getInstance().getLogger().debug("Unhandled sound effect: " + soundEffect.name());
|
||||||
// TODO: BREAK_SPLASH_POTION has additional data
|
} else if (packet.getEffect() instanceof ParticleEffect) {
|
||||||
case BONEMEAL_GROW:
|
ParticleEffect particleEffect = (ParticleEffect) packet.getEffect();
|
||||||
effect.setType(LevelEventType.PARTICLE_CROP_GROWTH);
|
Vector3f pos = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f);
|
||||||
BonemealGrowEffectData growEffectData = (BonemealGrowEffectData) packet.getData();
|
|
||||||
effect.setData(growEffectData.getParticleCount());
|
|
||||||
break;
|
|
||||||
//TODO: Block break particles when under fire
|
|
||||||
case BREAK_BLOCK:
|
|
||||||
effect.setType(LevelEventType.PARTICLE_DESTROY_BLOCK); // TODO: Check to make sure this is right
|
|
||||||
BreakBlockEffectData breakBlockEffectData = (BreakBlockEffectData) packet.getData();
|
|
||||||
effect.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState()));
|
|
||||||
break;
|
|
||||||
case EXPLOSION:
|
|
||||||
effect.setType(LevelEventType.PARTICLE_EXPLOSION);
|
|
||||||
break;
|
|
||||||
case MOB_SPAWN:
|
|
||||||
effect.setType(LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); // TODO: Check, but I don't think I really verified this ever went into effect on Java
|
|
||||||
break;
|
|
||||||
// Done with a dispenser
|
|
||||||
case SMOKE:
|
|
||||||
// Might need to be SHOOT
|
|
||||||
effect.setType(LevelEventType.PARTICLE_SMOKE);
|
|
||||||
break;
|
|
||||||
case COMPOSTER:
|
|
||||||
effect.setType(LevelEventType.PARTICLE_CROP_GROWTH);
|
|
||||||
|
|
||||||
ComposterEffectData composterEffectData = (ComposterEffectData) packet.getData();
|
LevelEventPacket effectPacket = new LevelEventPacket();
|
||||||
LevelSoundEventPacket soundEvent = new LevelSoundEventPacket();
|
effectPacket.setPosition(pos);
|
||||||
soundEvent.setSound(SoundEvent.valueOf("COMPOSTER_" + composterEffectData.name()));
|
effectPacket.setData(0);
|
||||||
soundEvent.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
|
switch (particleEffect) {
|
||||||
soundEvent.setIdentifier(":");
|
case COMPOSTER: {
|
||||||
soundEvent.setExtraData(-1);
|
effectPacket.setType(LevelEventType.PARTICLE_CROP_GROWTH);
|
||||||
soundEvent.setBabySound(false);
|
|
||||||
soundEvent.setRelativeVolumeDisabled(false);
|
|
||||||
session.sendUpstreamPacket(soundEvent);
|
|
||||||
break;
|
|
||||||
case BLOCK_LAVA_EXTINGUISH:
|
|
||||||
effect.setType(LevelEventType.PARTICLE_SHOOT);
|
|
||||||
effect.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY() + 1, packet.getPosition().getZ()));
|
|
||||||
session.sendUpstreamPacket(effect);
|
|
||||||
|
|
||||||
|
ComposterEffectData composterEffectData = (ComposterEffectData) packet.getData();
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
switch (composterEffectData) {
|
||||||
|
case FILL:
|
||||||
|
soundEventPacket.setSound(SoundEvent.COMPOSTER_FILL);
|
||||||
|
break;
|
||||||
|
case FILL_SUCCESS:
|
||||||
|
soundEventPacket.setSound(SoundEvent.COMPOSTER_FILL_LAYER);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BLOCK_LAVA_EXTINGUISH: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EVAPORATE);
|
||||||
|
effectPacket.setPosition(pos.add(-0.5f, 0.7f, -0.5f));
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.EXTINGUISH_FIRE);
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BLOCK_REDSTONE_TORCH_BURNOUT: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EVAPORATE);
|
||||||
|
effectPacket.setPosition(pos.add(-0.5f, 0, -0.5f));
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.EXTINGUISH_FIRE);
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BLOCK_END_PORTAL_FRAME_FILL: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EVAPORATE);
|
||||||
|
effectPacket.setPosition(pos.add(-0.5f, 0.3125f, -0.5f));
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.BLOCK_END_PORTAL_FRAME_FILL);
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SMOKE: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_SHOOT);
|
||||||
|
|
||||||
|
SmokeEffectData smokeEffectData = (SmokeEffectData) packet.getData();
|
||||||
|
int data = 0;
|
||||||
|
switch (smokeEffectData) {
|
||||||
|
case DOWN:
|
||||||
|
data = 4;
|
||||||
|
pos = pos.add(0, -0.9f, 0);
|
||||||
|
break;
|
||||||
|
case UP:
|
||||||
|
data = 4;
|
||||||
|
pos = pos.add(0, 0.5f, 0);
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 1;
|
||||||
|
pos = pos.add(0, -0.2f, -0.7f);
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
data = 7;
|
||||||
|
pos = pos.add(0, -0.2f, 0.7f);
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 3;
|
||||||
|
pos = pos.add(-0.7f, -0.2f, 0);
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 5;
|
||||||
|
pos = pos.add(0.7f, -0.2f, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
effectPacket.setPosition(pos);
|
||||||
|
effectPacket.setData(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//TODO: Block break particles when under fire
|
||||||
|
case BREAK_BLOCK: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_DESTROY_BLOCK);
|
||||||
|
|
||||||
|
BreakBlockEffectData breakBlockEffectData = (BreakBlockEffectData) packet.getData();
|
||||||
|
effectPacket.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BREAK_SPLASH_POTION: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_POTION_SPLASH);
|
||||||
|
effectPacket.setPosition(pos.add(0, -0.5f, 0));
|
||||||
|
|
||||||
|
BreakPotionEffectData splashPotionData = (BreakPotionEffectData) packet.getData();
|
||||||
|
effectPacket.setData(splashPotionData.getPotionId());
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.GLASS);
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BREAK_EYE_OF_ENDER: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
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
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BONEMEAL_GROW: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_CROP_GROWTH);
|
||||||
|
|
||||||
|
BonemealGrowEffectData growEffectData = (BonemealGrowEffectData) packet.getData();
|
||||||
|
effectPacket.setData(growEffectData.getParticleCount());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ENDERDRAGON_FIREBALL_EXPLODE: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EYE_OF_ENDER_DEATH); // TODO
|
||||||
|
|
||||||
|
DragonFireballEffectData fireballEffectData = (DragonFireballEffectData) packet.getData();
|
||||||
|
if (fireballEffectData == DragonFireballEffectData.HAS_SOUND) {
|
||||||
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
soundEventPacket.setSound(SoundEvent.EXTINGUISH_FIRE);
|
soundEventPacket.setSound(SoundEvent.EXPLODE);
|
||||||
soundEventPacket.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
|
soundEventPacket.setPosition(pos);
|
||||||
soundEventPacket.setIdentifier(":");
|
soundEventPacket.setIdentifier("");
|
||||||
soundEventPacket.setExtraData(-1);
|
soundEventPacket.setExtraData(-1);
|
||||||
soundEventPacket.setBabySound(false);
|
soundEventPacket.setBabySound(false);
|
||||||
soundEventPacket.setRelativeVolumeDisabled(false);
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
session.sendUpstreamPacket(soundEventPacket);
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
return;
|
|
||||||
default:
|
|
||||||
GeyserConnector.getInstance().getLogger().debug("No effect handling for particle effect: " + packet.getEffect());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
effect.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
|
|
||||||
session.sendUpstreamPacket(effect);
|
|
||||||
} else if (packet.getEffect() instanceof SoundEffect) {
|
|
||||||
SoundEffect soundEffect = (SoundEffect) packet.getEffect();
|
|
||||||
Effect geyserEffect = EffectRegistry.EFFECTS.get(soundEffect.name());
|
|
||||||
if (geyserEffect != null) {
|
|
||||||
// Some events are LevelEventTypes, some are SoundEvents.
|
|
||||||
if (geyserEffect.getType().equals("soundLevel")) {
|
|
||||||
effect.setType(LevelEventType.valueOf(geyserEffect.getBedrockName()));
|
|
||||||
} else if (geyserEffect.getType().equals("soundEvent")) {
|
|
||||||
LevelSoundEventPacket soundEvent = new LevelSoundEventPacket();
|
|
||||||
// Separate case since each RecordEffectData in Java is an individual track in Bedrock
|
|
||||||
if (geyserEffect.getJavaName().equals("RECORD")) {
|
|
||||||
RecordEffectData recordEffectData = (RecordEffectData) packet.getData();
|
|
||||||
soundEvent.setSound(EffectRegistry.RECORDS.get(recordEffectData.getRecordId()));
|
|
||||||
if (EffectRegistry.RECORDS.get(recordEffectData.getRecordId()) != SoundEvent.STOP_RECORD) {
|
|
||||||
// Send text packet as it seems to be handled in Java Edition client-side.
|
|
||||||
TextPacket textPacket = new TextPacket();
|
|
||||||
textPacket.setType(TextPacket.Type.JUKEBOX_POPUP);
|
|
||||||
textPacket.setNeedsTranslation(true);
|
|
||||||
textPacket.setXuid("");
|
|
||||||
textPacket.setPlatformChatId("");
|
|
||||||
textPacket.setSourceName(null);
|
|
||||||
textPacket.setMessage("record.nowPlaying");
|
|
||||||
List<String> params = new ArrayList<>();
|
|
||||||
String recordString = "%item." + EffectRegistry.RECORDS.get(recordEffectData.getRecordId()).name().toLowerCase() + ".desc";
|
|
||||||
params.add(LocaleUtils.getLocaleString(recordString, session.getClientData().getLanguageCode()));
|
|
||||||
textPacket.setParameters(params);
|
|
||||||
session.sendUpstreamPacket(textPacket);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
soundEvent.setSound(SoundEvent.valueOf(geyserEffect.getBedrockName()));
|
|
||||||
}
|
}
|
||||||
soundEvent.setExtraData(geyserEffect.getData());
|
break;
|
||||||
soundEvent.setIdentifier(geyserEffect.getIdentifier());
|
|
||||||
soundEvent.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
|
|
||||||
session.sendUpstreamPacket(soundEvent);
|
|
||||||
}
|
}
|
||||||
} else {
|
case EXPLOSION: {
|
||||||
GeyserConnector.getInstance().getLogger().debug("No effect handling for sound effect: " + packet.getEffect());
|
effectPacket.setType(LevelEventType.PARTICLE_GENERIC_SPAWN);
|
||||||
}
|
effectPacket.setData(61);
|
||||||
}
|
break;
|
||||||
if (effect.getType() != null) {
|
}
|
||||||
effect.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
|
case EVAPORATE: {
|
||||||
session.sendUpstreamPacket(effect);
|
effectPacket.setType(LevelEventType.PARTICLE_EVAPORATE_WATER);
|
||||||
}
|
effectPacket.setPosition(pos.add(-0.5f, 0.5f, -0.5f));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case END_GATEWAY_SPAWN: {
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_EXPLOSION);
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.EXPLODE);
|
||||||
|
soundEventPacket.setPosition(pos);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
GeyserConnector.getInstance().getLogger().debug("Unhandled particle effect: " + particleEffect.name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.sendUpstreamPacket(effectPacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
Subproject commit 47179bc5ee12cab11370b650ab5f3a641aba1390
|
Subproject commit 8d6400da19d07085d60c6bbc11b23c1d391c056f
|
Loading…
Reference in a new issue