Skip to content

Commit

Permalink
Merge branch 'main' into lokalise
Browse files Browse the repository at this point in the history
  • Loading branch information
Litorom authored Nov 1, 2024
2 parents 77011e4 + 478c266 commit db56950
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
22 changes: 11 additions & 11 deletions src/client/java/minicraft/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.<br>
* 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.
Expand All @@ -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.<br>
* 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.
Expand Down
34 changes: 20 additions & 14 deletions src/client/java/minicraft/entity/FireSpark.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/client/resources/pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"fr-fr": {
"name": "French",
"region": "Frence"
"region": "France"
},
"hu-hu": {
"name": "Hungarian",
Expand Down

0 comments on commit db56950

Please sign in to comment.