Set entity dimensions for goat long jumping

This commit is contained in:
Camotoy 2021-06-04 22:26:29 -04:00
parent c2be67bc3d
commit 249f04441d
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
4 changed files with 56 additions and 25 deletions

View File

@ -303,31 +303,7 @@ public class Entity {
metadata.getFlags().setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING));
// Triggered when crawling
metadata.getFlags().setFlag(EntityFlag.SWIMMING, pose.equals(Pose.SWIMMING));
float width = entityType.getWidth();
float height = entityType.getHeight();
switch (pose) {
case SLEEPING:
if (this instanceof LivingEntity) {
width = 0.2f;
height = 0.2f;
}
break;
case SNEAKING:
if (entityType == EntityType.PLAYER) {
height = 1.5f;
}
break;
case FALL_FLYING:
case SPIN_ATTACK:
case SWIMMING:
if (entityType == EntityType.PLAYER) {
// Seems like this is only cared about for players; nothing else
height = 0.6f;
}
break;
}
metadata.put(EntityData.BOUNDING_BOX_WIDTH, width);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, height);
setDimensions(pose);
break;
case 7:
//TODO check
@ -349,6 +325,15 @@ public class Entity {
session.sendUpstreamPacket(entityDataPacket);
}
/**
* Set the height and width of the entity's bounding box
*/
protected void setDimensions(Pose pose) {
// No flexibility options for basic entities
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight());
}
/**
* x = Pitch, y = HeadYaw, z = Yaw
*

View File

@ -26,6 +26,7 @@
package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
@ -111,6 +112,16 @@ public class LivingEntity extends Entity {
super.updateBedrockMetadata(entityMetadata, session);
}
@Override
protected void setDimensions(Pose pose) {
if (pose == Pose.SLEEPING) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f);
} else {
super.setDimensions(pose);
}
}
public void updateAllEquipment(GeyserSession session) {
if (!valid) return;

View File

@ -26,11 +26,16 @@
package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
public class GoatEntity extends AnimalEntity {
private static final float LONG_JUMPING_HEIGHT = 1.3f * 0.7f;
private static final float LONG_JUMPING_WIDTH = 0.9f * 0.7f;
public GoatEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}
@ -39,6 +44,15 @@ public class GoatEntity extends AnimalEntity {
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
super.updateBedrockMetadata(entityMetadata, session);
}
@Override
protected void setDimensions(Pose pose) {
if (pose == Pose.LONG_JUMPING) {
metadata.put(EntityData.BOUNDING_BOX_WIDTH, LONG_JUMPING_WIDTH);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, LONG_JUMPING_HEIGHT);
} else {
super.setDimensions(pose);
}
}
}

View File

@ -27,6 +27,7 @@ package org.geysermc.connector.entity.player;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
@ -334,6 +335,26 @@ public class PlayerEntity extends LivingEntity {
}
}
@Override
protected void setDimensions(Pose pose) {
float height;
switch (pose) {
case SNEAKING:
height = 1.5f;
break;
case FALL_FLYING:
case SPIN_ATTACK:
case SWIMMING:
height = 0.6f;
break;
default:
super.setDimensions(pose);
return;
}
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, height);
}
@Override
public void updateBedrockAttributes(GeyserSession session) { // TODO: Don't use duplicated code
if (!valid) return;