Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Litorom authored Nov 6, 2023
2 parents b7d02b9 + dc7c3d5 commit d9c793d
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 97 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
64 changes: 52 additions & 12 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 @@ -124,11 +127,6 @@ public boolean move(int xd, int yd) {
//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 (!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.
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 @@ -153,8 +151,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 @@ -177,8 +184,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 @@ -189,16 +205,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 @@ -214,7 +248,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
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
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
9 changes: 4 additions & 5 deletions src/client/resources/assets/localization/es-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
"Leather": "Cuero",
"Wheat": "Trigo",
"Key": "Llave",
"arrow": "flecha",
"string": "cuerda",
"Arrow": "Flecha",
"String": "Cuerda",
"Coal": "Carbón",
"Iron Ore": "Mena de Hierro",
"Lapis": "Lapis",
Expand All @@ -136,9 +136,8 @@
"Rose": "Rosa",
"GunPowder": "Pólvora",
"Slime": "Slime",
"glass": "cristal",
"cloth": "paño",
"gem": "gema",
"Glass": "Cristal",
"Cloth": "Paño",
"Scale": "Escala",
"Shard": "Élitro",
"Flower": "Flor",
Expand Down
9 changes: 4 additions & 5 deletions src/client/resources/assets/localization/fr-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
"Leather": "Cuir",
"Wheat": "Ble",
"Key": "Cle",
"arrow": "fleche",
"string": "fil",
"Arrow": "Fleche",
"String": "Fil",
"Coal": "Charbon",
"Iron Ore": "Minerai de Fer",
"Lapis": "Lapis",
Expand All @@ -133,9 +133,8 @@
"Rose": "Rose",
"GunPowder": "PoudreACanon",
"Slime": "Slime",
"glass": "verre",
"cloth": "chiffon",
"gem": "gemme",
"Glass": "Verre",
"Cloth": "Chiffon",
"Scale": "Echelle",
"Shard": "Tesson",
"Flower": "Fleur",
Expand Down
9 changes: 4 additions & 5 deletions src/client/resources/assets/localization/hu-hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
"Leather": "Bőr",
"Wheat": "Búza",
"Key": "Kulcs",
"arrow": "Nyíl",
"string": "Fonál",
"Arrow": "Nyíl",
"String": "Fonál",
"Coal": "Szén",
"Iron Ore": "Vasérc",
"Lapis": "Lazurit",
Expand All @@ -136,9 +136,8 @@
"Rose": "Rózsa",
"GunPowder": "Puskapor",
"Slime": "Nyálka",
"glass": "Üveg",
"cloth": "Szövet",
"gem": "Kristály",
"Glass": "Üveg",
"Cloth": "Szövet",
"Scale": "Pikkely",
"Shard": "Szilánk",
"Flower": "Virág",
Expand Down
Loading

0 comments on commit d9c793d

Please sign in to comment.