diff --git a/src/client/java/minicraft/entity/Entity.java b/src/client/java/minicraft/entity/Entity.java index 5fb210357..f8c3b5d93 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,13 +174,12 @@ public boolean move(int xd, int yd) { /** * Moves the entity a long only on X axis without "teleporting". - * Will throw exception otherwise. - * @param d Displacement relative to the axis. + * Will throw exception otherwise.
+ * Note that this should only be invoked by {@link #move(int, int)}. + * @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. @@ -205,13 +206,12 @@ protected boolean moveX(int d) { /** * Moves the entity a long only on X axis without "teleporting". - * Will throw exception otherwise. - * @param d Displacement relative to the axis. - * @return true if the move was successful, false if not. + * Will throw exception otherwise.
+ * Note that this should only be invoked by {@link #move(int, int)}. + * @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. 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. */ 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",