mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add effects for sculk shrieker and sculk catalyst. Translate vibration particle
Bumps NBT version to 2.2.1 for LevelEventGenericPacket
This commit is contained in:
parent
f079ee430b
commit
528e8d6f67
5 changed files with 126 additions and 8 deletions
|
@ -72,7 +72,7 @@
|
||||||
<groupId>com.nukkitx</groupId>
|
<groupId>com.nukkitx</groupId>
|
||||||
<artifactId>nbt</artifactId>
|
<artifactId>nbt</artifactId>
|
||||||
<!-- Used for key/value interning -->
|
<!-- Used for key/value interning -->
|
||||||
<version>2.1.0</version>
|
<version>2.2.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -25,15 +25,15 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.java.level;
|
package org.geysermc.geyser.translator.protocol.java.level;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.event.*;
|
import com.github.steveice10.mc.protocol.data.game.level.event.*;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelEventPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelEventPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import com.nukkitx.nbt.NbtMap;
|
||||||
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;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
@ -44,6 +44,7 @@ import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Translator(packet = ClientboundLevelEventPacket.class)
|
@Translator(packet = ClientboundLevelEventPacket.class)
|
||||||
public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelEventPacket> {
|
public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelEventPacket> {
|
||||||
|
@ -257,6 +258,56 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
|
||||||
case WAX_ON -> effectPacket.setType(LevelEventType.PARTICLE_WAX_ON);
|
case WAX_ON -> effectPacket.setType(LevelEventType.PARTICLE_WAX_ON);
|
||||||
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);
|
||||||
|
case SCULK_BLOCK_CHARGE -> {
|
||||||
|
SculkBlockChargeEventData eventData = (SculkBlockChargeEventData) packet.getData();
|
||||||
|
LevelEventGenericPacket levelEventPacket = new LevelEventGenericPacket();
|
||||||
|
// TODO add SCULK_BLOCK_CHARGE sound
|
||||||
|
if (eventData.getCharge() > 0) {
|
||||||
|
levelEventPacket.setEventId(2037);
|
||||||
|
levelEventPacket.setTag(
|
||||||
|
NbtMap.builder()
|
||||||
|
.putInt("x", packet.getPosition().getX())
|
||||||
|
.putInt("y", packet.getPosition().getY())
|
||||||
|
.putInt("z", packet.getPosition().getZ())
|
||||||
|
.putShort("charge", (short) eventData.getCharge())
|
||||||
|
.putShort("facing", encodeFacing(eventData.getBlockFaces())) // TODO check if this is actually correct
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
levelEventPacket.setEventId(2038);
|
||||||
|
levelEventPacket.setTag(
|
||||||
|
NbtMap.builder()
|
||||||
|
.putInt("x", packet.getPosition().getX())
|
||||||
|
.putInt("y", packet.getPosition().getY())
|
||||||
|
.putInt("z", packet.getPosition().getZ())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
session.sendUpstreamPacket(levelEventPacket);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case SCULK_SHRIEKER_SHRIEK -> {
|
||||||
|
LevelEventGenericPacket levelEventPacket = new LevelEventGenericPacket();
|
||||||
|
levelEventPacket.setEventId(2035);
|
||||||
|
levelEventPacket.setTag(
|
||||||
|
NbtMap.builder()
|
||||||
|
.putInt("originX", packet.getPosition().getX())
|
||||||
|
.putInt("originY", packet.getPosition().getY())
|
||||||
|
.putInt("originZ", packet.getPosition().getZ())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
session.sendUpstreamPacket(levelEventPacket);
|
||||||
|
|
||||||
|
LevelSoundEventPacket soundEventPacket = new LevelSoundEventPacket();
|
||||||
|
soundEventPacket.setSound(SoundEvent.SCULK_SHRIEKER_SHRIEK);
|
||||||
|
soundEventPacket.setPosition(packet.getPosition().toFloat());
|
||||||
|
soundEventPacket.setExtraData(-1);
|
||||||
|
soundEventPacket.setIdentifier("");
|
||||||
|
soundEventPacket.setBabySound(false);
|
||||||
|
soundEventPacket.setRelativeVolumeDisabled(false);
|
||||||
|
session.sendUpstreamPacket(soundEventPacket);
|
||||||
|
return;
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
GeyserImpl.getInstance().getLogger().debug("Unhandled level event: " + packet.getEvent());
|
GeyserImpl.getInstance().getLogger().debug("Unhandled level event: " + packet.getEvent());
|
||||||
return;
|
return;
|
||||||
|
@ -264,4 +315,27 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
|
||||||
}
|
}
|
||||||
session.sendUpstreamPacket(effectPacket);
|
session.sendUpstreamPacket(effectPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private short encodeFacing(Set<Direction> blockFaces) {
|
||||||
|
short facing = 0;
|
||||||
|
if (blockFaces.contains(Direction.DOWN)) {
|
||||||
|
facing |= 1;
|
||||||
|
}
|
||||||
|
if (blockFaces.contains(Direction.UP)) {
|
||||||
|
facing |= 1 << 1;
|
||||||
|
}
|
||||||
|
if (blockFaces.contains(Direction.SOUTH)) {
|
||||||
|
facing |= 1 << 2;
|
||||||
|
}
|
||||||
|
if (blockFaces.contains(Direction.WEST)) {
|
||||||
|
facing |= 1 << 3;
|
||||||
|
}
|
||||||
|
if (blockFaces.contains(Direction.NORTH)) {
|
||||||
|
facing |= 1 << 4;
|
||||||
|
}
|
||||||
|
if (blockFaces.contains(Direction.EAST)) {
|
||||||
|
facing |= 1 << 5;
|
||||||
|
}
|
||||||
|
return facing;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,13 +27,18 @@ package org.geysermc.geyser.translator.protocol.java.level;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.particle.*;
|
import com.github.steveice10.mc.protocol.data.game.level.particle.*;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.BlockPositionSource;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.EntityPositionSource;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelParticlesPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelParticlesPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.nbt.NbtMap;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockPacket;
|
import com.nukkitx.protocol.bedrock.BedrockPacket;
|
||||||
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.LevelEventGenericPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SpawnParticleEffectPacket;
|
import com.nukkitx.protocol.bedrock.packet.SpawnParticleEffectPacket;
|
||||||
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
|
@ -131,6 +136,39 @@ public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLe
|
||||||
return packet;
|
return packet;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case VIBRATION -> {
|
||||||
|
VibrationParticleData data = (VibrationParticleData) particle.getData();
|
||||||
|
|
||||||
|
Vector3f target;
|
||||||
|
if (data.getPositionSource() instanceof BlockPositionSource blockPositionSource) {
|
||||||
|
target = blockPositionSource.getPosition().toFloat().add(0.5f, 0.5f, 0.5f);
|
||||||
|
} else if (data.getPositionSource() instanceof EntityPositionSource entityPositionSource) {
|
||||||
|
Entity entity = session.getEntityCache().getEntityByJavaId(entityPositionSource.getEntityId());
|
||||||
|
if (entity != null) {
|
||||||
|
target = entity.getPosition().up(entityPositionSource.getYOffset());
|
||||||
|
} else {
|
||||||
|
session.getGeyser().getLogger().debug("Unable to find entity with Java Id: " + entityPositionSource.getEntityId() + " for vibration particle.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session.getGeyser().getLogger().debug("Unknown position source " + data.getPositionSource() + " for vibration particle.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (position) -> {
|
||||||
|
LevelEventGenericPacket packet = new LevelEventGenericPacket();
|
||||||
|
packet.setEventId(2027);
|
||||||
|
packet.setTag(
|
||||||
|
NbtMap.builder()
|
||||||
|
.putCompound("origin", buildVec3PositionTag(position))
|
||||||
|
.putCompound("target", buildVec3PositionTag(target)) // There is a way to target an entity but that takes an attachPos instead of a y offset
|
||||||
|
.putFloat("speed", 20f)
|
||||||
|
.putFloat("timeToLive", data.getArrivalTicks() / 20f)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return packet;
|
||||||
|
};
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
ParticleMapping particleMapping = Registries.PARTICLES.get(particle.getType());
|
ParticleMapping particleMapping = Registries.PARTICLES.get(particle.getType());
|
||||||
if (particleMapping == null) { //TODO ensure no particle can be null
|
if (particleMapping == null) { //TODO ensure no particle can be null
|
||||||
|
@ -160,4 +198,13 @@ public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NbtMap buildVec3PositionTag(Vector3f position) {
|
||||||
|
return NbtMap.builder()
|
||||||
|
.putString("type", "vec3")
|
||||||
|
.putFloat("x", position.getX())
|
||||||
|
.putFloat("y", position.getY())
|
||||||
|
.putFloat("z", position.getZ())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -63,9 +63,6 @@ public class JavaSoundTranslator extends PacketTranslator<ClientboundSoundPacket
|
||||||
}
|
}
|
||||||
LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
|
LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
|
||||||
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
|
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
|
||||||
if (sound == null) {
|
|
||||||
sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
|
|
||||||
}
|
|
||||||
if (sound == null) {
|
if (sound == null) {
|
||||||
sound = SoundUtils.toSoundEvent(packetSound);
|
sound = SoundUtils.toSoundEvent(packetSound);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit dbd6e29245843f8a2469a282c01b4de6157ba4e4
|
Subproject commit 5986579c2c243455843a59a64c43f5869efc771a
|
Loading…
Reference in a new issue