1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-23 16:59:33 +00:00

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

@@ -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)

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.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<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) {
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) {
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) {
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
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);

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.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<ClientboundEntit
armadilloEntity.onPeeking();
}
break;
case SHAKE:
if (entity instanceof CreakingEntity creakingEntity) {
creakingEntity.createParticleBeam();
}
break;
}
if (entityEventPacket.getType() != null) {