start on implementing creaking

This commit is contained in:
onebeastchris 2024-12-06 21:18:42 +08:00
parent 92c7f9895b
commit a2184e4fae
8 changed files with 110 additions and 5 deletions

View file

@ -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! 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 ## 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 ## Setting Up
Take a look [here](https://geysermc.org/wiki/geyser/setup/) for how to set up Geyser. Take a look [here](https://geysermc.org/wiki/geyser/setup/) for how to set up Geyser.

View file

@ -25,6 +25,6 @@
"depends": { "depends": {
"fabricloader": ">=0.16.7", "fabricloader": ">=0.16.7",
"fabric": "*", "fabric": "*",
"minecraft": ">=1.21.2" "minecraft": ">=1.21.4"
} }
} }

View file

@ -13,7 +13,7 @@ modrinth {
versionNumber.set(projectVersion(project)) versionNumber.set(projectVersion(project))
versionType.set("beta") versionType.set("beta")
changelog.set(System.getenv("CHANGELOG") ?: "") 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) failSilently.set(true)
syncBodyFrom.set(rootProject.file("README.md").readText()) syncBodyFrom.set(rootProject.file("README.md").readText())

View file

@ -684,6 +684,15 @@ public final class EntityDefinitions {
.addTranslator(MetadataType.BOOLEAN, CreakingEntity::setActive) .addTranslator(MetadataType.BOOLEAN, CreakingEntity::setActive)
.addTranslator(MetadataType.BOOLEAN, CreakingEntity::setIsTearingDown) .addTranslator(MetadataType.BOOLEAN, CreakingEntity::setIsTearingDown)
.addTranslator(MetadataType.OPTIONAL_POSITION, CreakingEntity::setHomePos) .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(); .build();
CREEPER = EntityDefinition.inherited(CreeperEntity::new, mobEntityBase) CREEPER = EntityDefinition.inherited(CreeperEntity::new, mobEntityBase)
.type(EntityType.CREEPER) .type(EntityType.CREEPER)

View file

@ -27,6 +27,12 @@ package org.geysermc.geyser.entity.type.living.monster;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i; 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.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
@ -36,19 +42,100 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class CreakingEntity extends MonsterEntity { 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) { 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); 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<Boolean,? extends MetadataType<Boolean>> booleanEntityMetadata) { public void setCanMove(EntityMetadata<Boolean,? extends MetadataType<Boolean>> 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<Boolean,? extends MetadataType<Boolean>> booleanEntityMetadata) { public void setActive(EntityMetadata<Boolean,? extends MetadataType<Boolean>> 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<Boolean,? extends MetadataType<Boolean>> booleanEntityMetadata) { public void setIsTearingDown(EntityMetadata<Boolean,? extends MetadataType<Boolean>> 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<Optional<Vector3i>,? extends MetadataType<Optional<Vector3i>>> optionalEntityMetadata) { public void setHomePos(EntityMetadata<Optional<Vector3i>,? extends MetadataType<Optional<Vector3i>>> 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);
}
} }
} }

View file

@ -1153,7 +1153,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Override @Override
public void packetError(PacketErrorEvent event) { 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()) if (geyser.getConfig().isDebugMode())
event.getCause().printStackTrace(); event.getCause().printStackTrace();
event.setSuppress(true); event.setSuppress(true);

View file

@ -43,6 +43,7 @@ import org.geysermc.geyser.entity.type.EvokerFangsEntity;
import org.geysermc.geyser.entity.type.FishingHookEntity; import org.geysermc.geyser.entity.type.FishingHookEntity;
import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.entity.type.LivingEntity;
import org.geysermc.geyser.entity.type.living.animal.ArmadilloEntity; 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.entity.type.living.monster.WardenEntity;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@ -288,6 +289,11 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
armadilloEntity.onPeeking(); armadilloEntity.onPeeking();
} }
break; break;
case SHAKE:
if (entity instanceof CreakingEntity creakingEntity) {
creakingEntity.createParticleBeam();
}
break;
} }
if (entityEventPacket.getType() != null) { if (entityEventPacket.getType() != null) {

View file

@ -15,7 +15,7 @@ protocol-common = "3.0.0.Beta5-20241203.200249-19"
protocol-codec = "3.0.0.Beta5-20241203.200249-19" protocol-codec = "3.0.0.Beta5-20241203.200249-19"
raknet = "1.0.0.CR3-20240416.144209-1" raknet = "1.0.0.CR3-20240416.144209-1"
minecraftauth = "4.1.1" minecraftauth = "4.1.1"
mcprotocollib = "1.21.4-20241205.121506-8" mcprotocollib = "1.21.4-SNAPSHOT"
adventure = "4.14.0" adventure = "4.14.0"
adventure-platform = "4.3.0" adventure-platform = "4.3.0"
junit = "5.9.2" junit = "5.9.2"