Skip to content

Commit

Permalink
chores: hasGravity hasCollision直接使用metadata存储结果
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Aug 8, 2023
1 parent 71b5525 commit a26128f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cn.allay.api.entity.type.EntityType;
import cn.allay.api.math.Location3dc;
import cn.allay.api.client.Client;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket;
import org.jetbrains.annotations.UnmodifiableView;
Expand Down Expand Up @@ -44,8 +45,9 @@ public interface EntityBaseComponent {
@Inject
void setAABB(AABBd aabb);

@Inject
boolean hasCollision();
default boolean hasCollision() {
return getMetadata().getFlag(EntityFlag.HAS_COLLISION);
}

@Inject
void setHasCollision(boolean hasCollision);
Expand Down Expand Up @@ -115,6 +117,12 @@ default double getGravity() {
return 0.08;
}

default boolean hasGravity() {
return getMetadata().getFlag(EntityFlag.HAS_GRAVITY);
}

void setHasGravity(boolean hasGravity);

double SPRINTING_MOVEMENT_FACTOR = 1.3;
double WALKING_MOVEMENT_FACTOR = 1;
double SNEAKING_MOVEMENT_FACTOR = 0.3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class EntityBaseComponentImpl<T extends Entity> implements EntityBaseComp
protected EntityType<T> entityType;
protected AABBdc aabb;
protected Function<T, AABBdc> aabbGetter;
protected boolean hasCollision = true;
protected Map<Long, Client> viewers = new Long2ObjectOpenHashMap<>();
protected Vector3d motion = new Vector3d();
protected boolean onGround = true;
Expand Down Expand Up @@ -177,16 +176,9 @@ public void setAABB(AABBd aabb) {
sendEntityData(EntityDataTypes.HITBOX, EntityDataTypes.COLLISION_BOX);
}

@Override
@Impl
public boolean hasCollision() {
return hasCollision;
}

@Override
@Impl
public void setHasCollision(boolean hasCollision) {
this.hasCollision = hasCollision;
metadata.setFlag(EntityFlag.HAS_COLLISION, hasCollision);
sendEntityFlags(EntityFlag.HAS_COLLISION);
}
Expand Down Expand Up @@ -221,6 +213,13 @@ public void setOnGround(boolean onGround) {
this.onGround = onGround;
}

@Override
@Impl
public void setHasGravity(boolean hasGravity) {
metadata.setFlag(EntityFlag.HAS_GRAVITY, hasGravity);
sendEntityFlags(EntityFlag.HAS_GRAVITY);
}

@Override
@Impl
public void spawnTo(Client client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void tick() {
var updatedEntities = new Long2ObjectNonBlockingMap<Entity>();
entities.values().parallelStream().forEach(entity -> {
if (!entity.computeMovementServerSide()) return;
//TODO: 水流作用 etc...
//TODO: 水流作用 方块推出作用 etc...
if (entity.hasCollision()) computeCollisionMotion(entity);
if (applyMotion(entity)) {
updatedEntities.put(entity.getUniqueId(), entity);
Expand Down

0 comments on commit a26128f

Please sign in to comment.