Skip to content

Commit

Permalink
Tweak code
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCheung0422 committed Oct 10, 2024
1 parent aa71cb3 commit 65435f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
30 changes: 16 additions & 14 deletions src/client/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public class Player extends Mob implements ItemHolder, ClientTickable {

public int shirtColor = Color.get(1, 51, 51, 0); // Player shirt color.

public boolean isRiding = false;
public boolean isFishing = false;
public int maxFishingTicks = 120;
public int fishingTicks = maxFishingTicks;
Expand Down Expand Up @@ -999,7 +998,7 @@ public void render(Screen screen) {
int yo = y - 11; // Vertical

// Renders swimming
if (isSwimming() && onFallDelay <= 0 && !isRiding) {
if (isSwimming() && onFallDelay <= 0) {
yo += 4; // y offset is moved up by 4
if (level.getTile(x >> 4, y >> 4) == Tiles.get("water")) {

Expand Down Expand Up @@ -1050,16 +1049,19 @@ public void render(Screen screen) {
} else {
curSprite = spriteSet[dir.getDir()][(walkDist >> 3) & 1]; // Gets the correct sprite to render.
// Render each corner of the sprite
if (isSwimming() && !isRiding) { // Don't render the bottom half if swimming.
if (isSwimming()) { // Don't render the bottom half if swimming.
Sprite sprite = curSprite.getSprite();
screen.render(xo, yo, sprite.spritePixels[0][0], shirtColor);
screen.render(xo + 8, yo, sprite.spritePixels[0][1], shirtColor);
} else if (isRiding && (dir.equals(Direction.LEFT)||dir.equals(Direction.RIGHT))) { // If we are riding an entity
Sprite sprite = curSprite.getSprite();
screen.render(xo, yo + 2, sprite.spritePixels[0][0], shirtColor);
screen.render(xo + 8, yo + 2, sprite.spritePixels[0][1], shirtColor);
} else if (isRiding && (dir.equals(Direction.UP)||dir.equals(Direction.DOWN))) { // If we are riding an entity
screen.render(xo, yo, curSprite.setColor(shirtColor));
} else if (ride != null) { // If we are riding an entity
if (dir.getX() != 0) { // if direction is x-axis (left/right)
Sprite sprite = curSprite.getSprite();
screen.render(xo, yo + 2, sprite.spritePixels[0][0], shirtColor);
screen.render(xo + 8, yo + 2, sprite.spritePixels[0][1], shirtColor);
} else if (dir.getY() != 0) { // if direction is y-axis (up/down)
screen.render(xo, yo, curSprite.setColor(shirtColor));
} else // Other direction is invalid
throw new UnsupportedOperationException("dir should not be NONE");
} else {
screen.render(xo, yo - 4 * onFallDelay, curSprite.setColor(shirtColor));
}
Expand Down Expand Up @@ -1123,12 +1125,12 @@ public void render(Screen screen) {

// Renders the furniture if the player is holding one.
if (activeItem instanceof FurnitureItem) {
Furniture furniture = ((FurnitureItem) activeItem).furniture;
furniture.x = x;
furniture.y = yo - 4;
furniture.render(screen);
}
Furniture furniture = ((FurnitureItem) activeItem).furniture;
furniture.x = x;
furniture.y = yo - 4;
furniture.render(screen);
}
}

/** What happens when the player interacts with a itemEntity */
public void pickupItem(ItemEntity itemEntity) {
Expand Down
6 changes: 2 additions & 4 deletions src/client/java/minicraft/entity/vehicle/Boat.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void render(Screen screen) {
int xo = x - 8; // Horizontal
int yo = y - 8; // Vertical

if (Game.player.equals(passenger)) {
if (passenger != null) {
switch (((Player) passenger).dir) {
case UP: // if currently riding upwards...
screen.render(xo - 4, yo - 4, boatSprites[0][((((Player) passenger).walkDist >> 3) & 1) + 2].getSprite());
Expand Down Expand Up @@ -133,7 +133,7 @@ public boolean rideTick(Player passenger, Vector2 vec) {
int yd = (int) (vec.y * MOVE_SPEED);
dir = Direction.getDirection(xd, yd);
if (move(xd, yd)) {
walkDist += 1;
if (Updater.tickCount % 2 != 0) walkDist++; // Slower the animation
syncPassengerState(passenger);
}

Expand All @@ -145,7 +145,6 @@ public boolean startRiding(Player player) {
if (passenger == null) {
passenger = player;
syncPassengerState(passenger);
Game.player.isRiding = true;
return true;
} else
return false;
Expand All @@ -154,7 +153,6 @@ public boolean startRiding(Player player) {
@Override
public void stopRiding(Player player) {
if (passenger == player) {
Game.player.isRiding = false;
passenger = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/java/minicraft/item/FurnitureItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean canAttack() {
* What happens when you press the "Attack" key with the furniture in your hands
*/
public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, Direction attackDir) {
if (tile.mayPass(level, xt, yt, furniture)) { // IsRideable is looked at first to prevent unnecessary checking for if a boat can swim; If the furniture can go on the tile
if (tile.mayPass(level, xt, yt, furniture)) { // If the furniture can go on the tile
Sound.play("craft");

// Placed furniture's X and Y positions
Expand Down
4 changes: 2 additions & 2 deletions src/client/java/minicraft/saveload/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ private static Entity getEntity(String string, int mobLevel) {
return new KnightStatue(0);
case "ObsidianKnight":
return new ObsidianKnight(0);
case "Boat":
return new Boat(Direction.getDirection(0));
case "Boat":
return new Boat(Direction.NONE);
default:
Logging.SAVELOAD.error("LOAD ERROR: Unknown or outdated entity requested: " + string);
return null;
Expand Down

0 comments on commit 65435f2

Please sign in to comment.