From a2184e4faeb04e76d4bee216776dca876d701c0c Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Fri, 6 Dec 2024 21:18:42 +0800 Subject: [PATCH] start on implementing creaking --- README.md | 2 +- .../fabric/src/main/resources/fabric.mod.json | 2 +- ....modrinth-uploading-conventions.gradle.kts | 2 +- .../geyser/entity/EntityDefinitions.java | 9 ++ .../type/living/monster/CreakingEntity.java | 87 +++++++++++++++++++ .../geyser/session/GeyserSession.java | 5 +- .../entity/JavaEntityEventTranslator.java | 6 ++ gradle/libs.versions.toml | 2 +- 8 files changed, 110 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83a1d5c0b..9f5c9d8d5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,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! ## Supported Versions -Geyser is currently supporting Minecraft Bedrock 1.21.40 - 1.21.50 and Minecraft Java 1.21.2/1.21.3. For more information, please see [here](https://geysermc.org/wiki/geyser/supported-versions/). +Geyser is currently supporting Minecraft Bedrock 1.21.40 - 1.21.50 and Minecraft Java 1.21.4. For more information, please see [here](https://geysermc.org/wiki/geyser/supported-versions/). ## Setting Up Take a look [here](https://geysermc.org/wiki/geyser/setup/) for how to set up Geyser. diff --git a/bootstrap/mod/fabric/src/main/resources/fabric.mod.json b/bootstrap/mod/fabric/src/main/resources/fabric.mod.json index a801eb207..4f50768f4 100644 --- a/bootstrap/mod/fabric/src/main/resources/fabric.mod.json +++ b/bootstrap/mod/fabric/src/main/resources/fabric.mod.json @@ -25,6 +25,6 @@ "depends": { "fabricloader": ">=0.16.7", "fabric": "*", - "minecraft": ">=1.21.2" + "minecraft": ">=1.21.4" } } diff --git a/build-logic/src/main/kotlin/geyser.modrinth-uploading-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.modrinth-uploading-conventions.gradle.kts index 59f85d182..4f445f455 100644 --- a/build-logic/src/main/kotlin/geyser.modrinth-uploading-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.modrinth-uploading-conventions.gradle.kts @@ -13,7 +13,7 @@ modrinth { versionNumber.set(projectVersion(project)) versionType.set("beta") changelog.set(System.getenv("CHANGELOG") ?: "") - gameVersions.addAll("1.21.2", libs.minecraft.get().version as String) + gameVersions.add(libs.minecraft.get().version as String) failSilently.set(true) syncBodyFrom.set(rootProject.file("README.md").readText()) 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 8e485e14b..d284cba3f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -684,6 +684,15 @@ public final class EntityDefinitions { .addTranslator(MetadataType.BOOLEAN, CreakingEntity::setActive) .addTranslator(MetadataType.BOOLEAN, CreakingEntity::setIsTearingDown) .addTranslator(MetadataType.OPTIONAL_POSITION, CreakingEntity::setHomePos) + .properties(new GeyserEntityProperties.Builder() + .addEnum("minecraft:creaking_state", + "neutral", + "hostile_observed", + "hostile_unobserved", + "twitching", + "crumbling") + .addInt("minecraft:creaking_swaying_ticks", 0, 6) + .build()) .build(); CREEPER = EntityDefinition.inherited(CreeperEntity::new, mobEntityBase) .type(EntityType.CREEPER) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java index 8cfaf7428..a1861ca69 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java @@ -27,6 +27,12 @@ package org.geysermc.geyser.entity.type.living.monster; 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.entity.EntityFlag; +import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket; +import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -36,19 +42,100 @@ import java.util.Optional; import java.util.UUID; public class CreakingEntity extends MonsterEntity { + + private Vector3i homePosition; + public CreakingEntity(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 + protected void initializeMetadata() { + super.initializeMetadata(); + setFlag(EntityFlag.HIDDEN_WHEN_INVISIBLE, true); + setFlag(EntityFlag.FIRE_IMMUNE, true); + } + + @Override + public void addAdditionalSpawnData(AddEntityPacket addEntityPacket) { + propertyManager.add("minecraft:creaking_state", "neutral"); + propertyManager.add("minecraft:creaking_swaying_ticks", 0); + propertyManager.applyIntProperties(addEntityPacket.getProperties().getIntProperties()); + } + public void setCanMove(EntityMetadata> booleanEntityMetadata) { + if (booleanEntityMetadata.getValue()) { + setFlag(EntityFlag.BODY_ROTATION_BLOCKED, false); + + // unfreeze sound? SoundEvent.UNFREEZE + propertyManager.add("minecraft:creaking_state", "hostile_unobserved"); + updateBedrockEntityProperties(); + } else { + setFlag(EntityFlag.BODY_ROTATION_BLOCKED, true); + propertyManager.add("minecraft:creaking_state", "hostile_observed"); + updateBedrockEntityProperties(); + } + + GeyserImpl.getInstance().getLogger().warning("set can move; " + booleanEntityMetadata.toString()); } public void setActive(EntityMetadata> booleanEntityMetadata) { + if (booleanEntityMetadata.getValue()) { +// LevelSoundEvent2Packet addEntityPacket = new LevelSoundEvent2Packet(); +// addEntityPacket.setIdentifier("minecraft:creaking"); +// addEntityPacket.setPosition(position); +// addEntityPacket.setBabySound(false); +// addEntityPacket.setSound(SoundEvent.ACTIVATE); +// addEntityPacket.setExtraData(-1); +// session.sendUpstreamPacket(addEntityPacket); + +// setFlag(EntityFlag.HIDDEN_WHEN_INVISIBLE, true); +// setFlag(EntityFlag.BODY_ROTATION_BLOCKED, true); + } else { + propertyManager.add("minecraft:creaking_state", "neutral"); + } + GeyserImpl.getInstance().getLogger().warning("set active; " + booleanEntityMetadata.toString()); } public void setIsTearingDown(EntityMetadata> booleanEntityMetadata) { + GeyserImpl.getInstance().getLogger().warning("set isTearingDown; " + booleanEntityMetadata.toString()); + if (booleanEntityMetadata.getValue()) { + propertyManager.add("minecraft:creaking_state", "crumbling"); + updateBedrockEntityProperties(); +// LevelEventPacket levelEventPacket = new LevelEventPacket(); +// levelEventPacket.setType(ParticleType.CREAKING_CRUMBLE); +// levelEventPacket.setPosition(position); +// levelEventPacket.setData(0); + } } public void setHomePos(EntityMetadata,? extends MetadataType>> optionalEntityMetadata) { + if (optionalEntityMetadata.getValue().isPresent()) { + this.homePosition = optionalEntityMetadata.getValue().get(); + } else { + this.homePosition = null; + } + } + + public void createParticleBeam() { + if (this.homePosition != null) { + LevelEventGenericPacket levelEventGenericPacket = new LevelEventGenericPacket(); + levelEventGenericPacket.setType(LevelEvent.PARTICLE_CREAKING_HEART_TRIAL); + levelEventGenericPacket.setTag( + NbtMap.builder() + .putInt("CreakingAmount", 0) + .putFloat("CreakingX", position.getX()) + .putFloat("CreakingY", position.getY()) + .putFloat("CreakingZ", position.getZ()) + .putInt("HeartAmount", 20) + .putFloat("HeartX", homePosition.getX()) + .putFloat("HeartY", homePosition.getY()) + .putFloat("HeartZ", homePosition.getZ()) + .build() + ); + + GeyserImpl.getInstance().getLogger().warning(levelEventGenericPacket.toString()); + session.sendUpstreamPacket(levelEventGenericPacket); + } } } 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 d6fe6739b..cedf9ab66 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1153,7 +1153,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { @Override public void packetError(PacketErrorEvent event) { - geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.downstream_error", event.getCause().getMessage())); + geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.downstream_error", + (event.getPacketClass() != null ? "(" + event.getPacketClass().getSimpleName() + ")" : "") + + event.getCause().getMessage()) + ); if (geyser.getConfig().isDebugMode()) event.getCause().printStackTrace(); event.setSuppress(true); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 6c2e02cd3..d52a2b501 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -43,6 +43,7 @@ import org.geysermc.geyser.entity.type.EvokerFangsEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.entity.type.living.animal.ArmadilloEntity; +import org.geysermc.geyser.entity.type.living.monster.CreakingEntity; import org.geysermc.geyser.entity.type.living.monster.WardenEntity; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -288,6 +289,11 @@ public class JavaEntityEventTranslator extends PacketTranslator