Skip to content

Commit

Permalink
Merge branch 'main' into sign
Browse files Browse the repository at this point in the history
  • Loading branch information
Litorom authored Nov 8, 2023
2 parents a4d469c + dc7c3d5 commit 24808bf
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# dev savedir folder
run/

# Compiled class file
*.class

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You must first confirm that you have [Java](https://www.java.com/en/download/) (
## Localization
This project is running with an external localization platform called POEditor. You can contribute localization by clicking the image below!

[![Minicraft+ POEditor Stats](https://raw.githubusercontent.com/BenCheung0422/MinicraftPlus-POEditor-Stats/main/docs/poeditor_stats.svg)](https://poeditor.com/join/project/xvtwoWhNXe)
[![Minicraft+ POEditor Stats](https://minicraft-plus-poeditor-stats.vercel.app/api/card)](https://minicraft-plus-poeditor-stats.vercel.app)

## How to build/run in development
Because this project uses a build tool called gradle it is very easy to build or run the project from the source code.
Expand Down
60 changes: 52 additions & 8 deletions src/client/java/minicraft/entity/Entity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minicraft.entity;

import minicraft.core.Action;
import minicraft.core.Updater;
import minicraft.entity.mob.Player;
import minicraft.gfx.Rectangle;
Expand All @@ -14,6 +15,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.IntSupplier;

public abstract class Entity implements Tickable {
Expand Down Expand Up @@ -134,7 +137,6 @@ public boolean move(int xd, int yd) {
level.getTile(prevXt, prevYt).steppedOut(level, prevXt, prevYt, this);
level.getTile(xt, yt).steppedOn(level, xt, yt, this); // Calls the steppedOn() method in a tile's class. (used for tiles like sand (footprints) or lava (burning))
}

return !stopped;
}

Expand All @@ -158,8 +160,17 @@ protected boolean moveX(int d) {
int hitBoxFront = x + xr * sgn;
int maxFront = Level.calculateMaxFrontClosestTile(sgn, d, hitBoxLeft, hitBoxRight, hitBoxFront,
(front, horTile) -> level.getTile(front, horTile).mayPass(level, front, horTile, this)); // Maximum position can be reached with front hit box
if (maxFront == hitBoxFront) return false; // No movement can be made.
return moveByEntityHitBoxChecks(sgn, hitBoxFront, maxFront, () -> x + sgn, () -> y, () -> x += sgn);
if (maxFront == hitBoxFront) { // Bumping into the facing tile
int hitBoxRightTile = hitBoxRight >> 4;
int frontTile = (hitBoxFront + sgn) >> 4;
for (int horTile = hitBoxLeft >> 4; horTile <= hitBoxRightTile; horTile++) {
level.getTile(frontTile, horTile).bumpedInto(level, frontTile, horTile, this);
}
return false; // No movement can be made.
}
return moveByEntityHitBoxChecks(sgn, hitBoxFront, maxFront, () -> x + sgn, () -> y, () -> x += sgn, hitBoxLeft, hitBoxRight,
(front, horTile) -> level.getTile(front, horTile).bumpedInto(level, front, horTile, this),
(front, horTile) -> level.getTile(front, horTile).steppedOn(level, front, horTile, this));
}

/**
Expand All @@ -182,8 +193,17 @@ protected boolean moveY(int d) {
int hitBoxFront = y + yr * sgn;
int maxFront = Level.calculateMaxFrontClosestTile(sgn, d, hitBoxLeft, hitBoxRight, hitBoxFront,
(front, horTile) -> level.getTile(horTile, front).mayPass(level, horTile, front, this)); // Maximum position can be reached with front hit box
if (maxFront == hitBoxFront) return false; // No movement can be made.
return moveByEntityHitBoxChecks(sgn, hitBoxFront, maxFront, () -> x, () -> y + sgn, () -> y += sgn);
if (maxFront == hitBoxFront) { // Bumping into the facing tile
int hitBoxRightTile = hitBoxRight >> 4;
int frontTile = (hitBoxFront + sgn) >> 4;
for (int horTile = hitBoxLeft >> 4; horTile <= hitBoxRightTile; horTile++) {
level.getTile(horTile, frontTile).bumpedInto(level, horTile, frontTile, this);
}
return false; // No movement can be made.
}
return moveByEntityHitBoxChecks(sgn, hitBoxFront, maxFront, () -> x, () -> y + sgn, () -> y += sgn, hitBoxLeft, hitBoxRight,
(front, horTile) -> level.getTile(horTile, front).bumpedInto(level, horTile, front, this),
(front, horTile) -> level.getTile(horTile, front).steppedOn(level, horTile, front, this));
}

/**
Expand All @@ -194,16 +214,34 @@ protected boolean moveY(int d) {
* @param xMove The value of the willing x movement
* @param yMove The value of the willing y movement
* @param incrementMove The movement call when the movement is possible
* @param hitBoxLeft The left boundary of hit box
* @param hitBoxRight The right boundary of hit box
* @param bumpingHandler The consumer handling bumping into a new tile;
* the first parameter takes the front tile position and second one takes the horizontal position
* @param steppingHandler The consumer handling stepping on a new tile;
* the first parameter takes the front tile position and second one takes the horizontal position
* @return {@code true} if the movement is successful, {@code false} otherwise.
* @see #moveByEntityHitBoxChecks(int, int, int, IntSupplier, IntSupplier, Runnable)
* @see Level#calculateMaxFrontClosestTile(int, int, int, int, int, BiPredicate)
*/
protected boolean moveByEntityHitBoxChecks(int sgn, int hitBoxFront, int maxFront, IntSupplier xMove,
IntSupplier yMove, Runnable incrementMove) {
IntSupplier yMove, Action incrementMove, int hitBoxLeft, int hitBoxRight,
BiConsumer<Integer, Integer> bumpingHandler, BiConsumer<Integer, Integer> steppingHandler) {
boolean successful = false;

// These lists are named as if the entity has already moved-- it hasn't, though.
HashSet<Entity> wasInside = new HashSet<>(level.getEntitiesInRect(getBounds())); // Gets all the entities that are inside this entity (aka: colliding) before moving.
int frontTile = hitBoxFront << 4; // The original tile the front boundary hit box staying on
boolean handleSteppedOn = false; // Used together with frontTile
for (int front = hitBoxFront; sgn < 0 ? front > maxFront : front < maxFront; front += sgn) {
int newFrontTile = (front + sgn) >> 4;
if (newFrontTile != frontTile) { // New tile touched
int hitBoxRightTile = hitBoxRight >> 4;
for (int horTile = hitBoxLeft >> 4; horTile <= hitBoxRightTile; horTile++) {
bumpingHandler.accept(horTile, newFrontTile);
}
frontTile = newFrontTile;
handleSteppedOn = true;
}
boolean blocked = false; // If the entity prevents this one from movement, no movement.
for (Entity e : level.getEntitiesInRect(new Rectangle(xMove.getAsInt(), yMove.getAsInt(), xr * 2, yr * 2, Rectangle.CENTER_DIMS))) {
if (!wasInside.contains(e)) { // Skips entities that were touched.
Expand All @@ -219,7 +257,13 @@ protected boolean moveByEntityHitBoxChecks(int sgn, int hitBoxFront, int maxFron
}
}
if (blocked) break;
incrementMove.run(); // Movement successful
incrementMove.act(); // Movement successful
if (handleSteppedOn) { // When the movement to a new tile successes
int hitBoxRightTile = hitBoxRight >> 4;
for (int horTile = hitBoxLeft >> 4; horTile <= hitBoxRightTile; horTile++) {
steppingHandler.accept(horTile, frontTile); // Calls the steppedOn() method in a tile's class. (used for tiles like sand (footprints) or lava (burning))
}
}
successful = true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/client/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ protected void attack() {
activeItem.interactOn(Tiles.get("rock"), level, 0, 0, this, attackDir);
if (activeItem.isDepleted()) {
activeItem = null;
if (isFishing) {
isFishing = false;
fishingTicks = maxFishingTicks;
}
}
return;
}
Expand Down Expand Up @@ -663,6 +667,10 @@ protected void attack() {
if (activeItem.isDepleted()) {
// If the activeItem has 0 items left, then "destroy" it.
activeItem = null;
if (isFishing) {
isFishing = false;
fishingTicks = maxFishingTicks;
}
}
}
if (done) return; // Skip the rest if interaction was handled
Expand Down
13 changes: 7 additions & 6 deletions src/client/java/minicraft/gfx/Font.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package minicraft.gfx;

import minicraft.core.Renderer;
import minicraft.core.io.Localization;
import minicraft.gfx.SpriteLinker.SpriteType;

import java.util.ArrayList;
Expand All @@ -15,7 +14,10 @@ public class Font {
"6789.,!?'\"-+=/\\%()<>:;^@ÁÉÍÓÚÑ¿¡"+
"ÃÊÇÔÕĞÇÜİÖŞÆØÅŰŐ[]#|{}_АБВГДЕЁЖЗ"+
"ИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯÀÂÄÈÎÌÏÒ"+
"ÙÛÝ*«»£$&€§ªº";
"ÙÛÝ*«»£$&€§ªºabcdefghijklmnopqrs"+
"tuvwxyzáàãâäéèêëíìîïóòõôöúùûüçñý"+
"ÿабвгдеёжзийклмнопрстуфхцчшщъыьэ"+
"юяışő";

/* The order of the letters in the chars string is represented in the order that they appear in the sprite-sheet. */

Expand All @@ -24,7 +26,6 @@ public class Font {
/** Draws the message to the x & y coordinates on the screen. */
public static void
draw(String msg, Screen screen, int x, int y, int whiteTint) {
msg = msg.toUpperCase(Localization.getSelectedLocale()); //makes all letters uppercase.
for (int i = 0; i < msg.length(); i++) { // Loops through all the characters that you typed
int ix = chars.indexOf(msg.charAt(i)); // The current letter in the message loop
if (ix >= 0) {
Expand Down Expand Up @@ -66,9 +67,8 @@ public static void drawColor(String message, Screen screen, int x, int y) {
public static void drawBackground(String msg, Screen screen, int x, int y) { drawBackground(msg, screen, x, y, -1); }

public static void drawBackground(String msg, Screen screen, int x, int y, int whiteTint) {
String newMsg = msg.toUpperCase(Localization.getSelectedLocale());
for (int i = 0; i < newMsg.length(); i++) { // Renders the black boxes under the text
screen.render(x + i * textWidth(newMsg.substring(i, i+1)), y, 5, 2, 0, Renderer.spriteLinker.getSheet(SpriteType.Gui, "hud"));
for (int i = 0; i < msg.length(); i++) { // Renders the black boxes under the text
screen.render(x + i * textWidth(msg.substring(i, i+1)), y, 5, 2, 0, Renderer.spriteLinker.getSheet(SpriteType.Gui, "hud"));
}

// Renders the text
Expand All @@ -78,6 +78,7 @@ public static void drawBackground(String msg, Screen screen, int x, int y, int w
public static int textWidth(String text) { // Filtering out coloring codes.
return (int) (Math.max(text.length() - text.chars().filter(ch -> ch == Color.COLOR_CHAR).count() * 5, 0) * 8);
}

public static int textWidth(String[] para) {
// This returns the maximum length of all the lines.
if (para == null || para.length == 0) return 0;
Expand Down
17 changes: 10 additions & 7 deletions src/client/java/minicraft/item/ClothingItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minicraft.item;

import minicraft.core.Game;
import minicraft.entity.Direction;
import minicraft.entity.mob.Player;
import minicraft.gfx.Color;
Expand Down Expand Up @@ -42,13 +43,15 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player,
if (player.shirtColor == playerCol) {
return false;
} else {
ClothingItem lastClothing = (ClothingItem) getAllInstances().stream().filter(i -> i instanceof ClothingItem && ((ClothingItem) i).playerCol == player.shirtColor)
.findAny().orElse(null);
if (lastClothing == null)
lastClothing = (ClothingItem) Items.get("Reg Clothes");
lastClothing = lastClothing.copy();
lastClothing.count = 1;
player.tryAddToInvOrDrop(lastClothing);
if (!Game.isMode("minicraft.settings.mode.creative")) {
ClothingItem lastClothing = (ClothingItem) getAllInstances().stream().filter(i -> i instanceof ClothingItem && ((ClothingItem) i).playerCol == player.shirtColor)
.findAny().orElse(null);
if (lastClothing == null)
lastClothing = (ClothingItem) Items.get("Reg Clothes");
lastClothing = lastClothing.copy();
lastClothing.count = 1;
player.tryAddToInvOrDrop(lastClothing);
}
player.shirtColor = playerCol;
return super.interactOn(true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/java/minicraft/item/PotionItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minicraft.item;

import minicraft.core.Game;
import minicraft.entity.Direction;
import minicraft.entity.mob.Player;
import minicraft.gfx.SpriteLinker.LinkedSprite;
Expand Down Expand Up @@ -39,7 +40,7 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player,
}

protected boolean interactOn(boolean subClassSuccess, Player player) {
if (subClassSuccess)
if (subClassSuccess && !Game.isMode("minicraft.settings.mode.creative"))
player.tryAddToInvOrDrop(Items.get("glass bottle"));
return super.interactOn(subClassSuccess);
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/java/minicraft/item/StackableItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new StackableItem("Leather", new LinkedSprite(SpriteType.Item, "leather")));
items.add(new StackableItem("Wheat", new LinkedSprite(SpriteType.Item, "wheat")));
items.add(new StackableItem("Key", new LinkedSprite(SpriteType.Item, "key")));
items.add(new StackableItem("arrow", new LinkedSprite(SpriteType.Item, "arrow")));
items.add(new StackableItem("string", new LinkedSprite(SpriteType.Item, "string")));
items.add(new StackableItem("Arrow", new LinkedSprite(SpriteType.Item, "arrow")));
items.add(new StackableItem("String", new LinkedSprite(SpriteType.Item, "string")));
items.add(new StackableItem("Coal", new LinkedSprite(SpriteType.Item, "coal")));
items.add(new StackableItem("Iron Ore", new LinkedSprite(SpriteType.Item, "iron_ore")));
items.add(new StackableItem("Lapis", new LinkedSprite(SpriteType.Item, "lapis")));
Expand All @@ -30,9 +30,9 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new StackableItem("Rose", new LinkedSprite(SpriteType.Item, "red_flower")));
items.add(new StackableItem("Gunpowder", new LinkedSprite(SpriteType.Item, "gunpowder")));
items.add(new StackableItem("Slime", new LinkedSprite(SpriteType.Item, "slime")));
items.add(new StackableItem("glass", new LinkedSprite(SpriteType.Item, "glass")));
items.add(new StackableItem("cloth", new LinkedSprite(SpriteType.Item, "cloth")));
items.add(new StackableItem("gem", new LinkedSprite(SpriteType.Item, "gem")));
items.add(new StackableItem("Glass", new LinkedSprite(SpriteType.Item, "glass")));
items.add(new StackableItem("Cloth", new LinkedSprite(SpriteType.Item, "cloth")));
items.add(new StackableItem("Gem", new LinkedSprite(SpriteType.Item, "gem")));
items.add(new StackableItem("Scale", new LinkedSprite(SpriteType.Item, "scale")));
items.add(new StackableItem("Shard", new LinkedSprite(SpriteType.Item, "shard")));
items.add(new StackableItem("Cloud Ore", new LinkedSprite(SpriteType.Item, "cloud_ore")));
Expand Down
3 changes: 2 additions & 1 deletion src/client/java/minicraft/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,12 @@ public static int calculateMaxFrontClosestTile(int sgn, int d, int hitBoxLeft, i
int hitBoxFrontTile1 = hitBoxFront1 >> 4;
int maxFrontTile = hitBoxFrontTile1; // Value for full tile movement
// Skips the current tile by adding 1.
mainLoop:
for (int front = hitBoxFrontTile + sgn; sgn < 0 ? front >= hitBoxFrontTile1 : front <= hitBoxFrontTile1; front += sgn) {
for (int horTile = hitBoxLeftTile; horTile <= hitBoxRightTile; horTile++) {
if (!frontTilePassableCheck.test(front, horTile)) {
maxFrontTile = front - sgn; // Rolls back a tile by subtracting 1.
break; // Tile hit box check stops.
break mainLoop; // Tile hit box check stops.
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions src/client/java/minicraft/screen/TutorialDisplayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void loadTutorialElement(String criterionName, JSONObject json) {
private static ControlGuide currentGuide = null;

static {
controlGuides.add(new ControlGuide(120, "move-up|move-down|move-left|move-right",
controlGuides.add(new ControlGuide(300, "move-up|move-down|move-left|move-right",
() -> Localization.getLocalized("minicraft.control_guide.move",
String.format("%s|%s|%s|%s", Game.input.getMapping("move-up"),
Game.input.getMapping("move-left"), Game.input.getMapping("move-down"),
Expand Down Expand Up @@ -90,16 +90,11 @@ private ControlGuide(int duration, String key, Supplier<String> display) {
}

private void tick() {
if (this.key.contains("|")) {
InputHandler.Key key = new InputHandler.Key();
for (String keyposs: this.key.split("\\|")) {
InputHandler.Key aKey = Game.input.getKey(keyposs);
key.down = key.down || aKey.down;
key.clicked = key.clicked || aKey.clicked;
if (key.contains("|")) {
for (String k : key.split("\\|")) {
if (Game.input.inputDown(k)) interactedDuration++;
}

if (key.down) interactedDuration++;
} else if (Game.input.getKey(key).down)
} else if (Game.input.inputDown(key))
interactedDuration++;
}
}
Expand Down Expand Up @@ -188,7 +183,8 @@ public static void tick(InputHandler input) {
return;
}

currentGuide.tick();
if (Game.getDisplay() == null)
currentGuide.tick();
}

if (currentOngoingElement != null) {
Expand Down
5 changes: 1 addition & 4 deletions src/client/java/minicraft/screen/entry/ListEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import minicraft.gfx.Font;
import minicraft.gfx.Screen;

import java.util.Locale;

public abstract class ListEntry {

public static final int COL_UNSLCT = Color.GRAY;
Expand All @@ -30,8 +28,7 @@ public void render(Screen screen, int x, int y, boolean isSelected, String conta
return;
}

String string = toString().toLowerCase(Locale.ENGLISH);
contain = contain.toLowerCase(Locale.ENGLISH);
String string = toString();

Font.drawColor(string.replace(contain, Color.toStringCode(containColor) + contain + Color.WHITE_CODE), screen, x, y);
}
Expand Down
15 changes: 7 additions & 8 deletions src/client/resources/assets/localization/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"minicraft.display.options_display.change_key_bindings": "Change Key Bindings",
"minicraft.display.options_display.language": "Language",
"minicraft.display.options_display.resource_packs": "Resource packs",
"minicraft.display.popup.enter_confirm": "enter to confirm",
"minicraft.display.popup.escape_cancel": "escape to cancel",
"minicraft.display.popup.enter_confirm": "Enter to confirm",
"minicraft.display.popup.escape_cancel": "Escape to cancel",
"minicraft.display.popup.title_confirm": "Confirm Action",
"minicraft.displays.achievements": "Achievements",
"minicraft.displays.achievements.display.achieved": "Achieved!",
Expand Down Expand Up @@ -200,7 +200,7 @@
"minicraft.displays.world_gen.enter_world": "Enter World Name",
"minicraft.displays.world_gen.title": "World Gen Options",
"minicraft.displays.world_gen.troublesome_input": "Trouble with world name?",
"minicraft.displays.world_gen.troublesome_input.msg": "it seems you've set letters as the controls to move the cursor up and down, which is probably annoying. This can be changed in the key binding menu as the \"cursor-XXX\" keys. For now, to type the letter instead of moving the cursor, hold the shift key while typing.",
"minicraft.displays.world_gen.troublesome_input.msg": "It seems you've set letters as the controls to move the cursor up and down, which is probably annoying. This can be changed in the key binding menu as the \"cursor-XXX\" keys. For now, to type the letter instead of moving the cursor, hold the shift key while typing.",
"minicraft.displays.world_gen.world_seed": "World Seed",
"minicraft.displays.world_select.display.help.0": "%s to confirm",
"minicraft.displays.world_select.display.help.1": "%s to return",
Expand Down Expand Up @@ -385,8 +385,8 @@
"Leather": "Leather",
"Wheat": "Wheat",
"Key": "Key",
"arrow": "arrow",
"string": "string",
"Arrow": "Arrow",
"String": "String",
"Coal": "Coal",
"Iron Ore": "Iron Ore",
"Gold Ore": "Gold Ore",
Expand All @@ -398,9 +398,8 @@
"Rose": "Rose",
"GunPowder": "GunPowder",
"Slime": "Slime",
"glass": "glass",
"cloth": "cloth",
"gem": "gem",
"Glass": "Glass",
"Cloth": "Cloth",
"Scale": "Scale",
"Shard": "Shard",
"Flower": "Flower",
Expand Down
Loading

0 comments on commit 24808bf

Please sign in to comment.