Skip to content

自動車Entityの実装の続き#2

Merged
Builder256 merged 16 commits intodevelopfrom
feature/car-entity
Mar 18, 2026
Merged

自動車Entityの実装の続き#2
Builder256 merged 16 commits intodevelopfrom
feature/car-entity

Conversation

@Builder256
Copy link
Owner

@Builder256 Builder256 commented Mar 18, 2026

最低限の動作と、テスト用の外見を設定

VertexConsumerのテストのために、ポリゴン二枚だけの外見を追加

EntityModelは使用しない予定だが、使用方法のメモのためにコードはコメントのまま保持コメントは削除

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

このプルリクエストは、自動車Entityの実装を継続し、特にそのクライアントサイドでのレンダリング機能に焦点を当てています。VertexConsumerを直接利用してテスト用の外観を設定し、Entityの基本的な動作とモデル構造を確立しました。これにより、今後の本格的なモデル統合に向けた基盤が構築されています。

Highlights

  • Car Entityの基本レンダリング: Car Entityのレンダリングを実装し、VertexConsumerを直接使用してテスト用のシンプルなポリゴン形状(2枚のポリゴン)を表示するようにしました。これは、将来的にEntityModelを使用する前のテスト段階です。
  • Car Entityのモデルとレンダラーの追加: Car Entity用のCarModelクラスと、そのレンダリングを担うCarRendererクラスが追加されました。CarModelはシンプルな立方体と頭部で構成されていますが、CarRendererでは現在、このモデルではなく直接ポリゴンを描画しています。
  • Car Entityの挙動調整: Car Entityのプレイヤー入力処理を調整し、旋回方向を修正しました。また、Entityのサイズが3.0f x 2.0fに設定されました。
  • コメントアウトされたコード: EntityModelの登録や使用に関するコード(PolygonTrainModClientとPolygonTrainModEntityRendererLayers、およびCarRenderer内の一部)は、現時点ではコメントアウトされており、将来的な実装のメモとして残されています。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new CarModel and CarRenderer for a CarEntity, defining its 3D model and rendering logic. The CarEntity now has a defined size and updated Javadoc comments. However, several critical issues were identified: the CarRenderer's buildQuad method uses incorrect and unnormalized normal vectors, leading to improper lighting, and the CarEntity's movement logic does not account for its orientation, causing it to always move along the world's Z-axis. Additionally, the CarModel's texture size is too small for its texture offsets, potentially causing rendering artifacts. The reviewer also suggested removing commented-out code for better maintainability and simplifying the normal vector calculation in CarRenderer.

@Builder256
Copy link
Owner Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

このプルリクエストは、自動車Entityの基本的な実装とレンダリングを追加するもので、うまく進んでいると思います。いくつかの改善点とバグの可能性がある箇所を指摘しました。特に、CarEntityの移動ロジックは、現在の実装では車両が常にワールドのZ軸に沿って移動してしまうため、修正が必要です。また、CarRendererのコードは、いくつかのマジックナンバーや繰り返しコードを定数やヘルパーメソッドにまとめることで、より保守しやすくなるでしょう。

this.setYRot(this.getYRot() + turn);
this.setYRot(this.getYRot() - turn);
// TODO: 旋回に対応
this.setDeltaMovement(this.getDeltaMovement().x, this.getDeltaMovement().y, -forward);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

現在の実装では、setDeltaMovementのz成分に-forwardを直接設定しているため、自動車は向きに関わらず常にワールド座標のZ軸方向にしか移動しません。TODOコメントで旋回への対応が示されていますが、これは車両の挙動として重大なバグです。車両の向き(Y-Rot)を考慮して移動ベクトルを計算する必要があります。

Suggested change
this.setDeltaMovement(this.getDeltaMovement().x, this.getDeltaMovement().y, -forward);
float yawRad = this.getYRot() * ((float)Math.PI / 180F);
double dx = -Mth.sin(yawRad) * forward;
double dz = Mth.cos(yawRad) * forward;
this.setDeltaMovement(dx, this.getDeltaMovement().y, dz);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応不要

}

private void buildQuad(VertexConsumer buffer, Matrix4f matrix, int light) {
Vector3f testNormalVector = new Vector3f(1, 0, 1).normalize();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

testNormalVector は定数なので、renderメソッドが呼ばれるたびにインスタンス化と計算を行うのは非効率です。static finalなフィールドとしてクラスレベルで宣言することをお勧めします。

例:

private static final Vector3f SMOOTH_NORMAL = new Vector3f(1, 0, 1).normalize();

そして、buildQuadメソッド内でこの定数を直接使用します。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Comment on lines +55 to +66
buffer.addVertex(matrix, 0, 1, 0).setColor(255, 255, 255, 255).setUv(0, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, 1);
buffer.addVertex(matrix, 0, 0, 0).setColor(255, 255, 255, 255).setUv(0, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, 1);
buffer.addVertex(matrix, 1, 0, 0).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);
buffer.addVertex(matrix, 1, 1, 0).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);

// 両ポリゴンの重なる2頂点について、ナナメ45度の方向の法線ベクトルを追加して、簡易的なスムースシェーディング処理を行う

// ポリゴン2
buffer.addVertex(matrix, 1, 1, 0).setColor(255, 255, 255, 255).setUv(0, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);
buffer.addVertex(matrix, 1, 0, 0).setColor(255, 255, 255, 255).setUv(0, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);
buffer.addVertex(matrix, 1, 0, -1).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(1, 0, 0);
buffer.addVertex(matrix, 1, 1, -1).setColor(255, 255, 255, 255).setUv(1, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(1, 0, 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

buildQuadメソッド内の頂点追加コードは、.setColor(...), .setOverlay(...), .setLight(...) の部分が何度も繰り返されています。コードの可読性と保守性を向上させるために、これらの共通部分をカプセル化するプライベートヘルパーメソッドを作成することを検討してください。

例えば、以下のようなヘルパーメソッドを定義できます。

private void addVertexWithDefaultParams(VertexConsumer buffer, Matrix4f matrix, float x, float y, float z, float u, float v, int light, float nx, float ny, float nz) {
    buffer.addVertex(matrix, x, y, z)
          .setColor(255, 255, 255, 255)
          .setUv(u, v)
          .setOverlay(OverlayTexture.NO_OVERLAY)
          .setLight(light)
          .setNormal(nx, ny, nz);
}

これにより、buildQuadメソッドの記述が簡潔になります。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応不要

buffer.addVertex(matrix, 0, 1, 0).setColor(255, 255, 255, 255).setUv(0, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, 1);
buffer.addVertex(matrix, 0, 0, 0).setColor(255, 255, 255, 255).setUv(0, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, 1);
buffer.addVertex(matrix, 1, 0, 0).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);
buffer.addVertex(matrix, 1, 1, 0).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ポリゴン1の4番目の頂点のUV座標が (1, 1) に設定されていますが、これは3番目の頂点と同じです。これによりテクスチャが歪んで表示される可能性があります。四角形を正しくマッピングするには、UV座標を (1, 0) に変更する必要があると思われます。

Suggested change
buffer.addVertex(matrix, 1, 1, 0).setColor(255, 255, 255, 255).setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);
buffer.addVertex(matrix, 1, 1, 0).setColor(255, 255, 255, 255).setUv(1, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(x, y, z);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正: 932bc59

@Builder256 Builder256 merged commit b2edace into develop Mar 18, 2026
1 check passed
@Builder256 Builder256 deleted the feature/car-entity branch March 18, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant