From d5ccab5997f2131f67ca97c0398a5d6dca557fd6 Mon Sep 17 00:00:00 2001
From: BenCheung0422 <74168521+BenCheung0422@users.noreply.github.com>
Date: Mon, 14 Oct 2024 19:42:26 +0800
Subject: [PATCH 1/3] Fix issues regarding entity moving
---
src/client/java/minicraft/entity/Entity.java | 12 ++++---
.../java/minicraft/entity/FireSpark.java | 34 +++++++++++--------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/client/java/minicraft/entity/Entity.java b/src/client/java/minicraft/entity/Entity.java
index 5fb210357..5105bb58f 100644
--- a/src/client/java/minicraft/entity/Entity.java
+++ b/src/client/java/minicraft/entity/Entity.java
@@ -156,12 +156,14 @@ public boolean interact(Player player, @Nullable Item item, Direction attackDir)
* Moves an entity horizontally and vertically. Returns whether entity was unimpeded in it's movement.
*/
public boolean move(int xd, int yd) {
+ // TODO Validate existence of `Updater.saving` here, may potentially cause issue
if (Updater.saving || (xd == 0 && yd == 0)) return true; // Pretend that it kept moving
boolean stopped = true; // Used to check if the entity has BEEN stopped, COMPLETELY; below checks for a lack of collision.
+ // Either xd or yd must be non-zero, so at least either one of them is invoked.
//noinspection RedundantIfStatement
- if (moveX(xd)) stopped = false; // Becomes false if horizontal movement was successful.
- if (moveY(yd)) stopped = false; // Becomes false if vertical movement was successful.
+ if (xd != 0 && moveX(xd)) stopped = false; // Becomes false if horizontal movement was successful.
+ if (yd != 0 && moveY(yd)) stopped = false; // Becomes false if vertical movement was successful.
if (!stopped) {
int xt = x >> 4; // The x tile coordinate that the entity is standing on.
int yt = y >> 4; // The y tile coordinate that the entity is standing on.
@@ -172,7 +174,8 @@ public boolean move(int xd, int yd) {
/**
* Moves the entity a long only on X axis without "teleporting".
- * Will throw exception otherwise.
+ * Will throw exception otherwise.
+ * Note that this should only be invoked by {@link #move(int, int)}.
* @param d Displacement relative to the axis.
* @return true if the move was successful, false if not.
*/
@@ -205,7 +208,8 @@ protected boolean moveX(int d) {
/**
* Moves the entity a long only on X axis without "teleporting".
- * Will throw exception otherwise.
+ * Will throw exception otherwise.
+ * Note that this should only be invoked by {@link #move(int, int)}.
* @param d Displacement relative to the axis.
* @return true if the move was successful, false if not.
*/
diff --git a/src/client/java/minicraft/entity/FireSpark.java b/src/client/java/minicraft/entity/FireSpark.java
index 6a67764de..962fcadc0 100644
--- a/src/client/java/minicraft/entity/FireSpark.java
+++ b/src/client/java/minicraft/entity/FireSpark.java
@@ -11,7 +11,7 @@ public class FireSpark extends Entity {
private static final SpriteLinker.LinkedSprite sprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "spark");
private final int lifeTime; // How much time until the spark disappears
- private final double xa, ya; // The x and y acceleration
+ private final double xa, ya; // The x and y velocities
private double xx, yy; // The x and y positions
private int time; // The amount of time that has passed
private int stoppedTime;
@@ -52,19 +52,7 @@ public void tick() {
return;
}
} else {
- // Move the spark:
- int x0 = (int) xx; // Original position
- int y0 = (int) yy;
- xx += xa; // Final position
- yy += ya;
- boolean stopped = true;
- //noinspection RedundantIfStatement
- if (moveX(((int) xx) - x0))
- stopped = false; // This kind of difference is handled due to errors by flooring.
- if (moveY(((int) yy) - y0)) stopped = false;
- if (stopped) {
- this.stopped = true;
- }
+ move();
}
Player player = getClosestPlayer();
@@ -75,6 +63,24 @@ public void tick() {
}
}
+ public boolean move() {
+ // Moving the spark:
+ // Real coordinate (int) fields: x, y
+ // Virtual coordinate (double) fields: xx, yy
+ // Entity real movement on the world is based on real coordinates,
+ // but this entity moves in a smaller scale, thus double virtual coordinates are used.
+ // However, practically it may have not moved a full unit/"pixel",
+ // so this is not quite perfect, but should be enough and negligible
+ // at the moment, to simply the situation.
+ xx += xa; // Final position
+ yy += ya;
+ // This kind of difference is handled due to errors by flooring.
+ // New real coordinates are calculated and saved by #move
+ boolean moved = move((int) xx - x, (int) yy - y);
+ if (!moved) this.stopped = true; // Suppose and assume it is fully stopped
+ return moved;
+ }
+
/**
* Can this entity block you? Nope.
*/
From e9f799867cd912aa6036be5d5dff7c5b1df3f206 Mon Sep 17 00:00:00 2001
From: BenCheung0422 <74168521+BenCheung0422@users.noreply.github.com>
Date: Mon, 14 Oct 2024 20:01:41 +0800
Subject: [PATCH 2/3] Remove "if zero" in moveX and moveY
---
src/client/java/minicraft/entity/Entity.java | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/client/java/minicraft/entity/Entity.java b/src/client/java/minicraft/entity/Entity.java
index 5105bb58f..f8c3b5d93 100644
--- a/src/client/java/minicraft/entity/Entity.java
+++ b/src/client/java/minicraft/entity/Entity.java
@@ -176,12 +176,10 @@ public boolean move(int xd, int yd) {
* Moves the entity a long only on X axis without "teleporting".
* Will throw exception otherwise.
* Note that this should only be invoked by {@link #move(int, int)}.
- * @param d Displacement relative to the axis.
+ * @param d Displacement relative to the axis; should be non-zero
* @return true if the move was successful, false if not.
*/
protected boolean moveX(int d) {
- if (d == 0) return true; // Was not stopped
-
//boolean interact = true;//!Game.isValidClient() || this instanceof ClientTickable;
// Taking the axis of movement (towards) as the front axis, and the horizontal axis with another axis.
@@ -210,12 +208,10 @@ protected boolean moveX(int d) {
* Moves the entity a long only on X axis without "teleporting".
* Will throw exception otherwise.
* Note that this should only be invoked by {@link #move(int, int)}.
- * @param d Displacement relative to the axis.
- * @return true if the move was successful, false if not.
+ * @param d Displacement relative to the axis; should be non-zero
+ * @return true if there is movement, false if not.
*/
protected boolean moveY(int d) {
- if (d == 0) return true; // Was not stopped
-
//boolean interact = true;//!Game.isValidClient() || this instanceof ClientTickable;
// Taking the axis of movement (towards) as the front axis, and the horizontal axis with another axis.
From 49a04d54c47f0e24319222d56a1dce160e4efcf1 Mon Sep 17 00:00:00 2001
From: BenCheung0422 <74168521+BenCheung0422@users.noreply.github.com>
Date: Fri, 25 Oct 2024 18:06:20 +0800
Subject: [PATCH 3/3] Fix a typo of "France" in languages
---
src/client/resources/pack.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/client/resources/pack.json b/src/client/resources/pack.json
index 6ca860678..3b0f72369 100644
--- a/src/client/resources/pack.json
+++ b/src/client/resources/pack.json
@@ -9,7 +9,7 @@
},
"fr-fr": {
"name": "French",
- "region": "Frence"
+ "region": "France"
},
"hu-hu": {
"name": "Hungarian",