Skip to content

Commit

Permalink
Set entity dimensions for goat long jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 5, 2021
1 parent c2be67b commit 249f044
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
35 changes: 10 additions & 25 deletions connector/src/main/java/org/geysermc/connector/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,31 +303,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
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
Expand All @@ -349,6 +325,15 @@ public void updateBedrockMetadata(GeyserSession session) {
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +112,16 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -39,6 +44,15 @@ public GoatEntity(long entityId, long geyserId, EntityType entityType, Vector3f
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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;
Expand Down Expand Up @@ -334,6 +335,26 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}
}

@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;
Expand Down

0 comments on commit 249f044

Please sign in to comment.