Skip to content

Commit

Permalink
Merge branch 'main' into boat
Browse files Browse the repository at this point in the history
  • Loading branch information
Litorom authored Oct 31, 2024
2 parents c2dbe3e + 478c266 commit a8ff02a
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 @@ -175,12 +175,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 @@ -191,13 +193,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 @@ -224,13 +225,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 a8ff02a

Please sign in to comment.