Merge remote-tracking branch 'upstream/master' into client-vehicle

This commit is contained in:
AJ Ferguson 2024-07-09 19:45:15 -04:00
commit dae371fbbf
25 changed files with 336 additions and 86 deletions

View file

@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t
Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!
### Currently supporting Minecraft Bedrock 1.20.80 - 1.21.1 and Minecraft Java 1.21
### Currently supporting Minecraft Bedrock 1.20.80 - 1.21.2 and Minecraft Java 1.21
## Setting Up
Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser.

View file

@ -307,11 +307,11 @@ public final class EntityDefinitions {
.addTranslator(MetadataType.INT, TNTEntity::setFuseLength)
.build();
EntityDefinition<Entity> displayBase = EntityDefinition.inherited(entityBase.factory(), entityBase)
EntityDefinition<DisplayBaseEntity> displayBase = EntityDefinition.inherited(DisplayBaseEntity::new, entityBase)
.addTranslator(null) // Interpolation delay
.addTranslator(null) // Transformation interpolation duration
.addTranslator(null) // Position/Rotation interpolation duration
.addTranslator(null) // Translation
.addTranslator(MetadataType.VECTOR3, DisplayBaseEntity::setTranslation) // Translation
.addTranslator(null) // Scale
.addTranslator(null) // Left rotation
.addTranslator(null) // Right rotation

View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2024 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.geyser.entity.type;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.EntityUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import java.util.Optional;
import java.util.UUID;
public class DisplayBaseEntity extends Entity {
private @Nullable Vector3f baseTranslation;
public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
}
@Override
public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
// Don't allow the display name to be hidden - messes with our armor stand.
// On JE: Hiding the display name still shows the display entity text.
}
@Override
public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
// This would usually set EntityDataTypes.NAME, but we are instead using NAME for the text display.
// On JE: custom name does not override text display.
}
public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta){
this.baseTranslation = translationMeta.getValue();
if (this.baseTranslation == null) {
return;
}
if (this.vehicle == null) {
this.setRiderSeatPosition(this.baseTranslation);
this.moveRelative(this.baseTranslation.getX(), this.baseTranslation.getY(), this.baseTranslation.getZ(), yaw, pitch, headYaw, false);
} else {
EntityUtils.updateMountOffset(this, this.vehicle, true, true, false);
this.updateBedrockMetadata();
}
}
public Vector3f getTranslation() {
return baseTranslation;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
* Copyright (c) 2024 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
@ -32,13 +32,11 @@ import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import java.util.Optional;
import java.util.UUID;
// Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition
public class TextDisplayEntity extends Entity {
public class TextDisplayEntity extends DisplayBaseEntity {
public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
}
@ -51,18 +49,6 @@ public class TextDisplayEntity extends Entity {
this.dirtyMetadata.put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, (byte) 1);
}
@Override
public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
// Don't allow the display name to be hidden - messes with our armor stand.
// On JE: Hiding the display name still shows the display entity text.
}
@Override
public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
// This would usually set EntityDataTypes.NAME, but we are instead using NAME for the text display.
// On JE: custom name does not override text display.
}
public void setText(EntityMetadata<Component, ?> entityMetadata) {
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
}

View file

@ -29,15 +29,19 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
import org.geysermc.geyser.inventory.item.Potion;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.level.block.type.Block;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
import org.geysermc.geyser.translator.item.CustomItemTranslator;
import org.geysermc.geyser.translator.item.ItemTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents;
import java.util.ArrayList;
import java.util.List;
@ -64,12 +68,35 @@ public class ShulkerBoxItem extends BlockItem {
}
ItemMapping boxMapping = session.getItemMappings().getMapping(item.getId());
NbtMapBuilder boxItemNbt = BedrockItemBuilder.createItemNbt(boxMapping, item.getAmount(), boxMapping.getBedrockData()); // Final item tag to add to the list
int bedrockData = boxMapping.getBedrockData();
String bedrockIdentifier = boxMapping.getBedrockIdentifier();
DataComponents boxComponents = item.getDataComponents();
if (boxComponents != null) {
// Check for custom items
ItemDefinition customItemDefinition = CustomItemTranslator.getCustomItem(boxComponents, boxMapping);
if (customItemDefinition != null) {
bedrockIdentifier = customItemDefinition.getIdentifier();
bedrockData = 0;
} else {
// Manual checks for potions/tipped arrows
if (boxMapping.getJavaItem() instanceof PotionItem || boxMapping.getJavaItem() instanceof ArrowItem) {
PotionContents potionContents = boxComponents.get(DataComponentType.POTION_CONTENTS);
if (potionContents != null) {
Potion potion = Potion.getByJavaId(potionContents.getPotionId());
if (potion != null) {
bedrockData = potion.getBedrockId();
}
}
}
}
}
NbtMapBuilder boxItemNbt = BedrockItemBuilder.createItemNbt(bedrockIdentifier, item.getAmount(), bedrockData); // Final item tag to add to the list
boxItemNbt.putByte("Slot", (byte) slot);
boxItemNbt.putByte("WasPickedUp", (byte) 0); // ??? TODO might not be needed
// Only the display name is what we have interest in, so just translate that if relevant
DataComponents boxComponents = item.getDataComponents();
if (boxComponents != null) {
String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7');
if (customName != null) {

View file

@ -37,9 +37,22 @@ public class DoorBlock extends Block {
@Override
public void updateBlock(GeyserSession session, BlockState state, Vector3i position) {
// Needed to check whether we must force the client to update the door state.
String doubleBlockHalf = state.getValue(Properties.DOUBLE_BLOCK_HALF);
if (!session.getGeyser().getWorldManager().hasOwnChunkCache() && doubleBlockHalf.equals("lower")) {
BlockState oldBlockState = session.getGeyser().getWorldManager().blockAt(session, position);
// If these are the same, it means that we already updated the lower door block (manually in the workaround below),
// and we do not need to update the block in the cache/on the client side using the super.updateBlock() method again.
// Otherwise, we send the door updates twice which will cause visual glitches on the client side
if (oldBlockState == state) {
return;
}
}
super.updateBlock(session, state, position);
if (state.getValue(Properties.DOUBLE_BLOCK_HALF).equals("upper")) {
if (doubleBlockHalf.equals("upper")) {
// Update the lower door block as Bedrock client doesn't like door to be closed from the top
// See https://github.com/GeyserMC/Geyser/issues/4358
Vector3i belowDoorPosition = position.sub(0, 1, 0);

View file

@ -43,13 +43,17 @@ import java.util.StringJoiner;
*/
public final class GameProtocol {
// Surprise protocol bump WOW
private static final BedrockCodec BEDROCK_V686 = Bedrock_v685.CODEC.toBuilder()
.protocolVersion(686)
.minecraftVersion("1.21.2")
.build();
/**
* Default Bedrock codec that should act as a fallback. Should represent the latest available
* release of the game that Geyser supports.
*/
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(Bedrock_v685.CODEC.toBuilder()
.minecraftVersion("1.21.1")
.build());
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = CodecProcessor.processCodec(BEDROCK_V686);
/**
* A list of all supported Bedrock versions that can join Geyser
@ -66,9 +70,10 @@ public final class GameProtocol {
SUPPORTED_BEDROCK_CODECS.add(CodecProcessor.processCodec(Bedrock_v671.CODEC.toBuilder()
.minecraftVersion("1.20.80/1.20.81")
.build()));
SUPPORTED_BEDROCK_CODECS.add(CodecProcessor.processCodec(DEFAULT_BEDROCK_CODEC.toBuilder()
.minecraftVersion("1.21.0/1.20.1")
SUPPORTED_BEDROCK_CODECS.add(CodecProcessor.processCodec(Bedrock_v685.CODEC.toBuilder()
.minecraftVersion("1.21.0/1.21.1")
.build()));
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
}
/**

View file

@ -145,8 +145,15 @@ public final class BedrockItemBuilder {
* Creates item NBT to nest within NBT with name, count, and damage set.
*/
public static NbtMapBuilder createItemNbt(ItemMapping mapping, int count, int damage) {
return createItemNbt(mapping.getBedrockIdentifier(), count, damage);
}
/**
* Creates item NBT to nest within NBT with name, count, and damage set.
*/
public static NbtMapBuilder createItemNbt(String bedrockIdentifier, int count, int damage) {
NbtMapBuilder builder = NbtMap.builder();
builder.putString("Name", mapping.getBedrockIdentifier());
builder.putString("Name", bedrockIdentifier);
builder.putByte("Count", (byte) count);
builder.putShort("Damage", (short) damage);
return builder;

View file

@ -52,6 +52,7 @@ import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.util.InventoryUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.*;
@ -209,7 +210,7 @@ public final class ItemTranslator {
Map<ItemAttributeModifiers.EquipmentSlotGroup, List<String>> slotsToModifiers = new HashMap<>();
for (ItemAttributeModifiers.Entry entry : modifiers.getModifiers()) {
// convert the modifier tag to a lore entry
String loreEntry = attributeToLore(entry.getModifier(), language);
String loreEntry = attributeToLore(entry.getAttribute(), entry.getModifier(), language);
if (loreEntry == null) {
continue; // invalid or failed
}
@ -254,13 +255,13 @@ public final class ItemTranslator {
}
@Nullable
private static String attributeToLore(ItemAttributeModifiers.AttributeModifier modifier, String language) {
private static String attributeToLore(int attribute, ItemAttributeModifiers.AttributeModifier modifier, String language) {
double amount = modifier.getAmount();
if (amount == 0) {
return null;
}
String name = modifier.getId().asMinimalString();
String name = AttributeType.Builtin.from(attribute).getIdentifier().asMinimalString();
// the namespace does not need to be present, but if it is, the java client ignores it as of pre-1.20.5
ModifierOperation operation = modifier.getOperation();

View file

@ -100,8 +100,8 @@ public class JavaBlockUpdateTranslator extends PacketTranslator<ClientboundBlock
|| lastInteractPos.getZ() != packet.getEntry().getPosition().getZ())) {
return;
}
String identifier = BlockState.of(packet.getEntry().getBlock()).toString(); // This will be yeeted soon. Thanks Chris.
BlockState state = BlockState.of(packet.getEntry().getBlock());
session.setInteracting(false);
BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), identifier);
BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), state);
}
}

View file

@ -28,9 +28,16 @@ package org.geysermc.geyser.translator.protocol.java.level;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.data.ParticleType;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket;
import org.cloudburstmc.protocol.bedrock.packet.SpawnParticleEffectPacket;
import org.cloudburstmc.protocol.bedrock.packet.StopSoundPacket;
import org.cloudburstmc.protocol.bedrock.packet.TextPacket;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.level.JukeboxSong;
import org.geysermc.geyser.registry.Registries;
@ -40,13 +47,27 @@ import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.level.event.LevelEventTranslator;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.DimensionUtils;
import org.geysermc.geyser.util.SoundUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.*;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.BonemealGrowEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.BreakBlockEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.BreakPotionEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.ComposterEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.DragonFireballEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.LevelEventType;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.RecordEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.SculkBlockChargeEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.SmokeEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.TrialSpawnerDetectEventData;
import org.geysermc.mcprotocollib.protocol.data.game.level.event.UnknownLevelEventData;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundLevelEventPacket;
import java.util.Collections;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
@Translator(packet = ClientboundLevelEventPacket.class)
public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelEventPacket> {
@ -291,6 +312,20 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
soundEventPacket.setRelativeVolumeDisabled(false);
session.sendUpstreamPacket(soundEventPacket);
}
case ANIMATION_SPAWN_COBWEB -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.ANIMATION_SPAWN_COBWEB);
case ANIMATION_VAULT_ACTIVATE -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.ANIMATION_VAULT_ACTIVATE);
case ANIMATION_VAULT_DEACTIVATE -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.ANIMATION_VAULT_DEACTIVATE);
case ANIMATION_VAULT_EJECT_ITEM -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.ANIMATION_VAULT_EJECT_ITEM);
case ANIMATION_TRIAL_SPAWNER_EJECT_ITEM -> {
Random random = ThreadLocalRandom.current();
PlaySoundPacket playSoundPacket = new PlaySoundPacket();
playSoundPacket.setSound("trial_spawner.eject_item");
playSoundPacket.setPosition(pos);
playSoundPacket.setVolume(1.0f);
playSoundPacket.setPitch(0.8f + random.nextFloat() * 0.3f);
session.sendUpstreamPacket(playSoundPacket);
return;
}
case DRIPSTONE_DRIP -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_DRIPSTONE_DRIP);
case PARTICLES_ELECTRIC_SPARK -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_ELECTRIC_SPARK); // Matches with a Bedrock server but doesn't seem to match up with Java
case PARTICLES_AND_SOUND_WAX_ON -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_WAX_ON);
@ -303,22 +338,22 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
if (eventData.getCharge() > 0) {
levelEventPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.SCULK_CHARGE);
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()
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.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.SCULK_CHARGE_POP);
levelEventPacket.setTag(
NbtMap.builder()
.putInt("x", packet.getPosition().getX())
.putInt("y", packet.getPosition().getY())
.putInt("z", packet.getPosition().getZ())
.build()
NbtMap.builder()
.putInt("x", packet.getPosition().getX())
.putInt("y", packet.getPosition().getY())
.putInt("z", packet.getPosition().getZ())
.build()
);
}
session.sendUpstreamPacket(levelEventPacket);
@ -328,11 +363,11 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
LevelEventGenericPacket levelEventPacket = new LevelEventGenericPacket();
levelEventPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_SCULK_SHRIEK);
levelEventPacket.setTag(
NbtMap.builder()
.putInt("originX", packet.getPosition().getX())
.putInt("originY", packet.getPosition().getY())
.putInt("originZ", packet.getPosition().getZ())
.build()
NbtMap.builder()
.putInt("originX", packet.getPosition().getX())
.putInt("originY", packet.getPosition().getY())
.putInt("originZ", packet.getPosition().getZ())
.build()
);
session.sendUpstreamPacket(levelEventPacket);
@ -346,6 +381,54 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
session.sendUpstreamPacket(soundEventPacket);
return;
}
case PARTICLES_TRIAL_SPAWNER_DETECT_PLAYER -> {
// Particles spawn here
TrialSpawnerDetectEventData eventData = (TrialSpawnerDetectEventData) packet.getData();
effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_DETECTION);
// 0.75 is used here for Y instead of 0.5 to match Java Positioning.
// 0.5 is what the BDS uses for positioning.
effectPacket.setPosition(pos.sub(0.5f, 0.75f, 0.5f));
effectPacket.setData(eventData.getDetectedPlayers());
}
case PARTICLES_TRIAL_SPAWNER_DETECT_PLAYER_OMINOUS -> {
effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_DETECTION_CHARGED);
effectPacket.setPosition(pos.sub(0.5f, 0.75f, 0.5f));
/*
Particles don't spawn here for some reason, only sound plays
This seems to be a bug in v1.21.0 and v1.21.1: see https://bugs.mojang.com/browse/MCPE-181465
If this gets fixed, the spawnOminousTrialSpawnerParticles function can be removed.
The positioning should be the same as normal activation.
*/
spawnOminousTrialSpawnerParticles(session, pos);
}
case PARTICLES_TRIAL_SPAWNER_BECOME_OMINOUS -> {
effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_BECOME_CHARGED);
effectPacket.setPosition(pos.sub(0.5f, 0.5f, 0.5f));
// Same issue as above here
spawnOminousTrialSpawnerParticles(session, pos);
}
case PARTICLES_TRIAL_SPAWNER_SPAWN_MOB_AT -> {
// This should be its own class in MCProtocolLib.
// if 0, use Orange Flames,
// if 1, use Blue Flames for ominous spawners
UnknownLevelEventData eventData = (UnknownLevelEventData) packet.getData();
effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_SPAWNING);
effectPacket.setData(eventData.getData());
}
case PARTICLES_TRIAL_SPAWNER_SPAWN -> {
UnknownLevelEventData eventData = (UnknownLevelEventData) packet.getData();
effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_SPAWNING);
effectPacket.setData(eventData.getData());
Random random = ThreadLocalRandom.current();
PlaySoundPacket playSoundPacket = new PlaySoundPacket();
playSoundPacket.setSound("trial_spawner.spawn_mob");
playSoundPacket.setPosition(pos);
playSoundPacket.setVolume(1.0f);
playSoundPacket.setPitch(0.8f + random.nextFloat() * 0.3f);
session.sendUpstreamPacket(playSoundPacket);
}
case PARTICLES_TRIAL_SPAWNER_SPAWN_ITEM -> effectPacket.setType(org.cloudburstmc.protocol.bedrock.data.LevelEvent.PARTICLE_TRIAL_SPAWNER_EJECTING);
case SOUND_STOP_JUKEBOX_SONG -> {
String bedrockSound = session.getWorldCache().removeActiveRecord(origin);
if (bedrockSound == null) {
@ -396,4 +479,15 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
}
return facing;
}
}
private static void spawnOminousTrialSpawnerParticles(GeyserSession session, Vector3f pos) {
int dimensionId = DimensionUtils.javaToBedrock(session.getDimension());
SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket();
stringPacket.setIdentifier("minecraft:trial_spawner_detection_ominous");
stringPacket.setDimensionId(dimensionId);
stringPacket.setPosition(pos.sub(0.5f, 0.75f, 0.5f));
stringPacket.setMolangVariablesJson(Optional.empty());
stringPacket.setUniqueEntityId(-1);
session.sendUpstreamPacket(stringPacket);
}
}

View file

@ -27,6 +27,7 @@ package org.geysermc.geyser.translator.sound;
import org.cloudburstmc.math.vector.Vector3f;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
@ -37,17 +38,16 @@ import java.util.Map;
/**
* Sound interaction handler for when a block is right-clicked.
*/
public interface BlockSoundInteractionTranslator extends SoundInteractionTranslator<String> {
public interface BlockSoundInteractionTranslator extends SoundInteractionTranslator<BlockState> {
/**
* Handles the block interaction when a player
* right-clicks a block.
*
* @param session the session interacting with the block
* @param position the position of the block
* @param identifier the identifier of the block
* @param state the state of the block
*/
static void handleBlockInteraction(GeyserSession session, Vector3f position, String identifier) {
static void handleBlockInteraction(GeyserSession session, Vector3f position, BlockState state) {
// If we need to get the hand identifier, only get it once and save it to a variable
String handIdentifier = null;
@ -58,7 +58,7 @@ public interface BlockSoundInteractionTranslator extends SoundInteractionTransla
if (interactionEntry.getKey().blocks().length != 0) {
boolean contains = false;
for (String blockIdentifier : interactionEntry.getKey().blocks()) {
if (identifier.contains(blockIdentifier)) {
if (state.toString().contains(blockIdentifier)) {
contains = true;
break;
}
@ -87,7 +87,7 @@ public interface BlockSoundInteractionTranslator extends SoundInteractionTransla
continue;
}
}
((BlockSoundInteractionTranslator) interactionEntry.getValue()).translate(session, position, identifier);
((BlockSoundInteractionTranslator) interactionEntry.getValue()).translate(session, position, state);
}
}

View file

@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
@ -37,7 +38,8 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class BucketSoundInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
if (!session.isPlacedBucket()) {
return; // No bucket was really interacted with
}

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
@ -36,7 +37,8 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class ComparatorSoundInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
boolean powered = identifier.contains("mode=compare");
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
@ -36,7 +37,7 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class FlintAndSteelInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position);
levelSoundEventPacket.setBabySound(false);

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
@ -37,7 +38,8 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class GrassPathInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position);
levelSoundEventPacket.setBabySound(false);

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
@ -37,7 +38,8 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class HoeInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position);
levelSoundEventPacket.setBabySound(false);

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
@ -36,7 +37,8 @@ import org.geysermc.geyser.translator.sound.SoundTranslator;
public class LeverSoundInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
boolean powered = identifier.contains("powered=true");
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);

View file

@ -27,21 +27,42 @@ package org.geysermc.geyser.translator.sound.block;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
@SoundTranslator(blocks = {"door", "fence_gate"})
public class DoorSoundInteractionTranslator implements BlockSoundInteractionTranslator {
public class OpenableSoundInteractionTranslator implements BlockSoundInteractionTranslator {
@Override
public void translate(GeyserSession session, Vector3f position, String identifier) {
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
if (identifier.contains("iron")) return;
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setType(LevelEvent.SOUND_DOOR_OPEN);
levelEventPacket.setPosition(position);
levelEventPacket.setData(0);
session.sendUpstreamPacket(levelEventPacket);
SoundEvent event = getSound(identifier.contains("open=true"), identifier);
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position.add(0.5, 0.5, 0.5));
levelSoundEventPacket.setBabySound(false);
levelSoundEventPacket.setRelativeVolumeDisabled(false);
levelSoundEventPacket.setIdentifier(":");
levelSoundEventPacket.setSound(event);
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlock(state).getRuntimeId());
session.sendUpstreamPacket(levelSoundEventPacket);
}
private SoundEvent getSound(boolean open, String identifier) {
if (identifier.contains("_door")) {
return open ? SoundEvent.DOOR_OPEN : SoundEvent.DOOR_CLOSE;
}
if (identifier.contains("_trapdoor")) {
return open ? SoundEvent.TRAPDOOR_OPEN : SoundEvent.TRAPDOOR_CLOSE;
}
// Fence Gate
return open ? SoundEvent.FENCE_GATE_OPEN : SoundEvent.FENCE_GATE_CLOSE;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2024 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
@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.entity.type.BoatEntity;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.TextDisplayEntity;
import org.geysermc.geyser.entity.type.living.ArmorStandEntity;
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
import org.geysermc.geyser.entity.type.living.animal.horse.CamelEntity;
@ -172,11 +173,7 @@ public final class EntityUtils {
case BOAT -> {
// Without the X offset, more than one entity on a boat is stacked on top of each other
if (moreThanOneEntity) {
if (rider) {
xOffset = 0.2f;
} else {
xOffset = -0.6f;
}
xOffset = rider ? 0.2f : -0.6f;
if (passenger instanceof AnimalEntity) {
xOffset += 0.2f;
}
@ -203,6 +200,18 @@ public final class EntityUtils {
case CHEST_BOAT -> xOffset = 0.15F;
case CHICKEN -> zOffset = -0.1f;
case TRADER_LLAMA, LLAMA -> zOffset = -0.3f;
case TEXT_DISPLAY -> {
if (passenger instanceof TextDisplayEntity textDisplay) {
Vector3f displayTranslation = textDisplay.getTranslation();
if (displayTranslation == null) {
return;
}
xOffset = displayTranslation.getX();
yOffset = displayTranslation.getY() + 0.2f;
zOffset = displayTranslation.getZ();
}
}
}
/*
* Bedrock Differences
@ -228,8 +237,7 @@ public final class EntityUtils {
if (mount instanceof ArmorStandEntity armorStand) {
yOffset -= armorStand.getYOffset();
}
Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset);
passenger.setRiderSeatPosition(offset);
passenger.setRiderSeatPosition(Vector3f.from(xOffset, yOffset, zOffset));
}
}

View file

@ -133,7 +133,7 @@ public final class SoundUtils {
}
if (sound == null) {
session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + soundIdentifier + "' to mappings '" + soundMapping.getBedrock()
+ "' was not a playable level sound, or has yet to be mapped to an enum in SoundEvent.");
+ "' was not a playable level sound, or has yet to be mapped to an enum in SoundEvent.");
return;
}
@ -144,7 +144,7 @@ public final class SoundUtils {
// 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(pitch) / Math.log10(2)) * 12)) + 12);
soundPacket.setExtraData(soundMapping.getExtraData() + (int) (Math.round((Math.log10(pitch) / Math.log10(2)) * 12)) + 12);
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
if (!soundMapping.getIdentifier().equals(":")) {
int javaId = BlockRegistries.JAVA_IDENTIFIER_TO_ID.get().getOrDefault(soundMapping.getIdentifier(), Block.JAVA_AIR_ID);

@ -1 +1 @@
Subproject commit 69e302bf3a118e5274f86b23a1818c61dba84c64
Subproject commit aaf53d6953c927e5ac1b87fd6627ffbfd4aa7cf5

View file

@ -10,7 +10,7 @@ netty-io-uring = "0.0.25.Final-SNAPSHOT"
guava = "29.0-jre"
gson = "2.3.1" # Provided by Spigot 1.8.8
websocket = "1.5.1"
protocol = "3.0.0.Beta2-20240616.144648-10"
protocol = "3.0.0.Beta2-20240704.153116-14"
raknet = "1.0.0.CR3-20240416.144209-1"
mcauthlib = "e5b0bcc"
mcprotocollib = "1.21-20240616.154144-5"
@ -39,7 +39,7 @@ minecraft = "1.21"
indra = "3.1.3"
shadow = "8.1.1"
architectury-plugin = "3.4-SNAPSHOT"
architectury-loom = "1.6-SNAPSHOT"
architectury-loom = "1.7-SNAPSHOT"
minotaur = "2.8.7"
lombok = "8.4"
blossom = "2.1.0"

Binary file not shown.

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME