From cc856b84b1462d00de4fc6abdd7c6fe457662f3f Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 11 May 2023 13:23:27 -0400 Subject: [PATCH] Initial sniffer code --- .../geyser/entity/EntityDefinitions.java | 6 +++ .../type/living/animal/SnifferEntity.java | 44 ++++++++++++++++++ .../geysermc/geyser/network/GameProtocol.java | 7 +++ .../network/GeyserServerInitializer.java | 5 -- .../geyser/network/UpstreamPacketHandler.java | 5 ++ .../geyser/session/GeyserSession.java | 6 +++ .../resources/bedrock/entity_identifiers.dat | Bin 7823 -> 7886 bytes 7 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 9c7e19853..b378a4310 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -133,6 +133,7 @@ public final class EntityDefinitions { public static final EntityDefinition SALMON; public static final EntityDefinition SHEEP; public static final EntityDefinition SHULKER; + public static final EntityDefinition SNIFFER; public static final EntityDefinition SHULKER_BULLET; public static final EntityDefinition SILVERFISH; public static final EntityDefinition SKELETON; @@ -842,6 +843,11 @@ public final class EntityDefinitions { .height(1.3f).width(0.9f) .addTranslator(MetadataType.BYTE, SheepEntity::setSheepFlags) .build(); + SNIFFER = EntityDefinition.inherited(SnifferEntity::new, ageableEntityBase) + .type(EntityType.SNIFFER) + .height(1.75f).width(1.9f) + .addTranslator(MetadataType.SNIFFER_STATE, SnifferEntity::setSnifferState) + .build(); STRIDER = EntityDefinition.inherited(StriderEntity::new, ageableEntityBase) .type(EntityType.STRIDER) .height(1.7f).width(0.9f) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java new file mode 100644 index 000000000..9cdd30bde --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019-2023 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.living.animal; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.SnifferState; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; +import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.session.GeyserSession; + +import java.util.UUID; + +public class SnifferEntity extends AnimalEntity { + public SnifferEntity(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); + } + + public void setSnifferState(ObjectEntityMetadata entityMetadata) { + + } +} diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 3e5b87e2c..fcb7cb36f 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.codec.PacketCodec; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; import org.cloudburstmc.protocol.bedrock.codec.v582.Bedrock_v582; import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec; +import org.geysermc.geyser.session.GeyserSession; import java.util.ArrayList; import java.util.List; @@ -77,6 +78,12 @@ public final class GameProtocol { return null; } + /* Bedrock convenience methods to gatekeep features and easily remove the check on version removal */ + + public static boolean isPre1_20(GeyserSession session) { + return session.getUpstream().getProtocolVersion() >= Bedrock_v582.CODEC.getProtocolVersion(); + } + /** * Gets the {@link PacketCodec} for Minecraft: Java Edition. * diff --git a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java index 002c236fb..35d2d7f33 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java +++ b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java @@ -47,11 +47,6 @@ public class GeyserServerInitializer extends BedrockServerInitializer { this.geyser = geyser; } - @Override - protected void postInitChannel(Channel channel) throws Exception { - super.postInitChannel(channel); - } - @Override public void initSession(@Nonnull BedrockServerSession bedrockServerSession) { try { diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 89a82fbbd..cfd293c26 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -225,6 +225,11 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { stackPacket.getExperiments().add(new ExperimentData("data_driven_items", true)); } + if (GameProtocol.isPre1_20(session)) { + stackPacket.getExperiments().add(new ExperimentData("next_major_update", true)); + stackPacket.getExperiments().add(new ExperimentData("sniffer", true)); + } + session.sendUpstreamPacket(stackPacket); break; diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index e841dd43c..696b6a4f6 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -124,6 +124,7 @@ import org.geysermc.geyser.item.Items; import org.geysermc.geyser.level.JavaDimension; import org.geysermc.geyser.level.WorldManager; import org.geysermc.geyser.level.physics.CollisionManager; +import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.network.netty.LocalSession; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.registry.type.BlockMappings; @@ -1540,6 +1541,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { startGamePacket.setRewindHistorySize(0); startGamePacket.setServerAuthoritativeBlockBreaking(false); + if (GameProtocol.isPre1_20(this)) { + startGamePacket.getExperiments().add(new ExperimentData("next_major_update", true)); + startGamePacket.getExperiments().add(new ExperimentData("sniffer", true)); + } + upstream.sendPacket(startGamePacket); } diff --git a/core/src/main/resources/bedrock/entity_identifiers.dat b/core/src/main/resources/bedrock/entity_identifiers.dat index 8f0c9ce8ef8f468bf6b1f2b530a131b33f6023c2..f55b49298cfa15bf35ad9512bc47a4ed43c69ff8 100644 GIT binary patch delta 808 zcmX|9J!n%=6mIhJ_j2=IUjF}EwTMF`z9enh{54IJRBNs1po`#?6av*k+ohs`qJu7) z@IgUws0xmyqlFY(5nPIhgRY{pwS&3{(R)v*!{z>*bH498=ev)J?~96kK(;jN3(e&f z`%eS*)M5ONmar8Y!9lo+J3)q(SQ1;|3BDL^MJG^*rZHq-C`NSJ4N)DpO$@t{VayIz za6KGE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