Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
GameJarne committed Nov 11, 2023
2 parents d9c793d + 0dd9ce1 commit b57791e
Show file tree
Hide file tree
Showing 93 changed files with 934 additions and 293 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ but some sections are changed to compliant this project.
* Added obsidian knight as the second boss
* Added limitation to inventories
* Added limitation to stackable items
* Added four new debug arguments - `--debug-log-time`, `--debug-log-thread`, `--debug-log-trace`, `--debug-filelog-full`
* Added seven new debug arguments - `--debug-log-time`, `--debug-log-thread`, `--debug-log-trace`, `--debug-filelog-full`, `--debug-level`, `--debug-locale`, `--debug-unloc-tracing`
* Added a new argument for disabling hardware acceleration - `--no-hardware-acceleration`
* Added a toggle for HUD display
* Added a toggle for simplified effect display
* Added a new menu for creative mode
Expand All @@ -36,6 +37,7 @@ but some sections are changed to compliant this project.
* Added coloured sheep (#445)
* Added ability to dye sheep and beds (#445)
* Cow and sheep now graze on grasses
* Added a trigger to auto-enable hardware acceleration

### Changes

Expand All @@ -51,6 +53,10 @@ but some sections are changed to compliant this project.
* Made languages fallback to English
* Improved the tile place indicator
* Overhauled debugging actions
* Overhauled the farming system
* Changed the languaging setting menu
* Optimized CPU usage
* Reduced food stamina cost

### Removals

Expand All @@ -62,6 +68,7 @@ but some sections are changed to compliant this project.
* Fixed rendering positioning problem of color code styled texts
* Fixed lights disappearing when out of screen
* Fixed animals and items destroying plants
* Fixed various old world loading crashes

## [2.1.3]

Expand Down
5 changes: 5 additions & 0 deletions src/client/java/minicraft/core/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void parseArgs(String[] args) {
// Parses command line arguments
@Nullable
String saveDir = null;
boolean enableHardwareAcceleration = true;
for (int i = 0; i < args.length; i++) {
if (args[i].equalsIgnoreCase("--savedir") && i + 1 < args.length) {
i++;
Expand All @@ -56,9 +57,13 @@ static void parseArgs(String[] args) {
Localization.isDebugLocaleEnabled = true;
} else if (args[i].equalsIgnoreCase("--debug-unloc-tracing")) {
Localization.unlocalizedStringTracing = true;
} else if (args[i].equalsIgnoreCase("--no-hardware-acceleration")) {
enableHardwareAcceleration = false;
}
}
((TinylogLoggingProvider) ProviderRegistry.getLoggingProvider()).init();
// Reference: https://stackoverflow.com/a/13832805
if (enableHardwareAcceleration) System.setProperty("sun.java2d.opengl", "true");

FileHandler.determineGameDir(saveDir);
}
Expand Down
10 changes: 10 additions & 0 deletions src/client/java/minicraft/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import minicraft.item.PotionType;
import minicraft.item.ToolItem;
import minicraft.item.ToolType;
import minicraft.item.WateringCanItem;
import minicraft.level.Level;
import minicraft.screen.LoadingDisplay;
import minicraft.screen.Menu;
Expand Down Expand Up @@ -324,6 +325,15 @@ private static void renderGui() {
Font.drawBackground(dura + "%", screen, 164, Screen.h - 16, Color.get(1, 255 - green, green, 0));
}

// WATERING CAN CONTAINER STATUS
if (player.activeItem instanceof WateringCanItem) {
// Draws the text
WateringCanItem tin = (WateringCanItem) player.activeItem;
int dura = tin.content * 100 / tin.CAPACITY;
int green = (int)(dura * 2.55f); // Let duration show as normal.
Font.drawBackground(dura + "%", screen, 164, Screen.h - 16, Color.get(1, 255 - green, green, 0));
}

// This renders the potions overlay
if (player.showpotioneffects && player.potioneffects.size() > 0) {

Expand Down
5 changes: 4 additions & 1 deletion src/client/java/minicraft/core/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public static void tick() {
// assert curDisplay == prevDisplay;
currentDisplay = displayQuery.peek();
assert currentDisplay != null;
currentDisplay.init(prevDisplay);
if (prevDisplay.getParent() == currentDisplay)
prevDisplay.onExit();
else
currentDisplay.init(prevDisplay);
}

Level level = levels[currentLevel];
Expand Down
2 changes: 1 addition & 1 deletion src/client/java/minicraft/entity/furniture/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Inventory getInventory() {
public void die() {
if (level != null) {
List<Item> items = inventory.getItems();
level.dropItem(x, y, items.toArray(new Item[items.size()]));
level.dropItem(x, y, items.toArray(new Item[0]));
}
super.die();
}
Expand Down
77 changes: 77 additions & 0 deletions src/client/java/minicraft/entity/furniture/Composter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package minicraft.entity.furniture;

import minicraft.entity.Direction;
import minicraft.entity.mob.Player;
import minicraft.gfx.SpriteLinker;
import minicraft.item.Item;
import minicraft.item.Items;
import minicraft.item.StackableItem;
import org.jetbrains.annotations.Nullable;

public class Composter extends Furniture {
private static final SpriteLinker.LinkedSprite sprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter");
private static final SpriteLinker.LinkedSprite spriteFilled = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter_filled");
private static final SpriteLinker.LinkedSprite spriteFull = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter_full");
private static final SpriteLinker.LinkedSprite itemSprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Item, "composter");

private static final int MAX_COMPOST = 7;
private int compost = 0;

public Composter() {
super("Composter", sprite, itemSprite);
}

@Override
public boolean interact(Player player, @Nullable Item item, Direction attackDir) {
if (compost == MAX_COMPOST) {
compost = 0;
StackableItem i = (StackableItem) Items.get("Fertilizer").copy();
i.count = 1;
player.getLevel().dropItem(x, y, i);
refreshStatus();
return true;
}

if (item instanceof StackableItem) {
// 100% compost as they are heavy food
if (item.getName().equalsIgnoreCase("Baked Potato") || item.getName().equalsIgnoreCase("Bread")) {
compost++;
((StackableItem) item).count--;
refreshStatus();
return true;

// 75% compost as they are crop food
} else if (item.getName().equalsIgnoreCase("Wheat") || item.getName().equalsIgnoreCase("Rose") ||
item.getName().equalsIgnoreCase("Flower") || item.getName().equalsIgnoreCase("Apple") ||
item.getName().equalsIgnoreCase("Potato") || item.getName().equalsIgnoreCase("Carrot")) {
if (random.nextInt(4) != 0) { // 75%
compost++;
((StackableItem) item).count--;
refreshStatus();
return true;
}

// 66.7& compost as they are seeds
} else if (item.getName().equalsIgnoreCase("Acorn") || item.getName().equalsIgnoreCase("Cactus") ||
item.getName().equalsIgnoreCase("Wheat Seeds") || item.getName().equalsIgnoreCase("Grass Seeds")) {
if (random.nextInt(3) != 0) { // 66.7%
compost++;
((StackableItem) item).count--;
refreshStatus();
return true;
}
}
}

return false;
}

private void refreshStatus() {
if (compost == 0)
super.sprite = sprite;
else if (compost < MAX_COMPOST)
super.sprite = spriteFilled;
else
super.sprite = spriteFull;
}
}
9 changes: 3 additions & 6 deletions src/client/java/minicraft/entity/mob/Cow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ public void die() {
@Override
public void tick() {
super.tick();
if (random.nextInt(1000) == 0) { // Grazing without any benefits.
Tile tile = level.getTile(x >> 4, y >> 4);
// If tall grasses are present, these are consumed and then turn into grass tiles.
if (tile instanceof GrassTile) {
level.setTile(x >> 4, y >> 4, Tiles.get("dirt"));
}
Tile tile = level.getTile(x >> 4, y >> 4);
if (tile instanceof GrassTile && random.nextInt(1000) == 0) { // Grazing without any benefits.
level.setTile(x >> 4, y >> 4, Tiles.get("dirt"));
}
}
}
4 changes: 2 additions & 2 deletions src/client/java/minicraft/entity/mob/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ private boolean move(int xd, int yd, boolean changeDir) { // Knockback shouldn't

/** The mob immediately despawns if the distance of the closest player is greater than the return value of this. */
protected int getDespawnDistance() {
return 80;
return 1280;
}

/** The mob randomly despawns if the distance of the closest player is greater than the return value of this. */
protected int getNoDespawnDistance() {
return 40;
return 640;
}

/** @see #handleDespawn() */
Expand Down
7 changes: 5 additions & 2 deletions src/client/java/minicraft/entity/mob/MobAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public void handleDespawn() {
*/
protected boolean isWithinLight() {
return Arrays.stream(level.getEntityArray()).anyMatch(e -> e instanceof Lantern && isWithin(e.getLightRadius(), e))
|| !level.getMatchingTiles((tile, x, y) -> Math.hypot(Math.abs(this.x - x), Math.abs(this.y - y)) <= tile.getLightRadius(level, x, y)).isEmpty();
|| !level.getMatchingTiles((tile, x, y) -> {
int xx = Math.abs(this.x - x), yy = Math.abs(this.y - y), l = tile.getLightRadius(level, x, y);
return xx * xx + yy * yy <= l * l;
}).isEmpty();
}

/**
Expand All @@ -84,7 +87,7 @@ public void tick() {
if (lifetime > 0) {
age++;
if (age > lifetime) {
boolean playerClose = getLevel().entityNearPlayer((Entity) this);
boolean playerClose = getLevel().entityNearPlayer(this);

if (!playerClose) {
remove();
Expand Down
16 changes: 8 additions & 8 deletions src/client/java/minicraft/entity/mob/ObsidianKnight.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import minicraft.gfx.SpriteLinker;
import minicraft.item.Items;
import minicraft.screen.AchievementsDisplay;
import org.jetbrains.annotations.Range;

public class ObsidianKnight extends EnemyMob {
private static final SpriteLinker.LinkedSprite[][][] armored = new SpriteLinker.LinkedSprite[][][] {
Expand All @@ -36,8 +37,9 @@ public class ObsidianKnight extends EnemyMob {
public static boolean beaten = false; // If the boss was beaten
public static boolean active = false; // If the boss is active

private static int phase = 0; // The phase of the boss. {0, 1}
private static int attackPhaseCooldown = 0; // Cooldown between attacks
@Range(from = 0, to = 1)
private int phase = 0; // The phase of the boss. {0, 1}
private int attackPhaseCooldown = 0; // Cooldown between attacks

private AttackPhase attackPhase = AttackPhase.Attacking;
private enum AttackPhase { Attacking, Dashing, Walking; } // Using fire sparks in attacking.
Expand Down Expand Up @@ -77,12 +79,10 @@ public void tick() {
this.remove();
}

//Achieve phase2
if (health <= 2500) {
// Achieve phase 2
if (health <= 2500 && phase == 0) { // Assume that phase would not turn back to phase 1
phase = 1;
}
if (phase == 1) {
lvlSprites = broken;
lvlSprites = broken; // Refreshing phased sprites
}

if (Game.isMode("minicraft.settings.mode.creative")) return; // Should not attack if player is in creative
Expand Down Expand Up @@ -134,7 +134,7 @@ public void tick() {
else if (atan2 < -67.5) attackDir = -90;
else if (atan2 < -22.5) attackDir = -45;
else attackDir = 0;
double speed = 1 + attackLevel * 0.2 + attackTime / 10 * 0.01; // speed is dependent on the attackType. (higher attackType, faster speeds)
double speed = 1 + attackLevel * 0.2 + attackTime / 10D * 0.01; // speed is dependent on the attackType. (higher attackType, faster speeds)
// The range of attack is 90 degrees. With little random factor.
int phi = attackDir - 36 + (attackTime % 5) * 18 + random.nextInt(7) - 3;
level.add(new FireSpark(this, Math.cos(Math.toRadians(phi)) * speed, Math.sin(Math.toRadians(phi)) * speed)); // Adds a spark entity with the cosine and sine of dir times speed.
Expand Down
6 changes: 5 additions & 1 deletion src/client/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,11 @@ protected void attack() {
}

// If the interaction between you and an entity is successful, then return.
if (interact(getInteractionBox(INTERACT_DIST))) return;
if (interact(getInteractionBox(INTERACT_DIST))) {
if (activeItem.isDepleted())
activeItem = null;
return;
}

// Attempt to interact with the tile.
Point t = getInteractionTile();
Expand Down
9 changes: 3 additions & 6 deletions src/client/java/minicraft/entity/mob/Sheep.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ public void render(Screen screen) {
public void tick() {
super.tick();
Tile tile = level.getTile(x >> 4, y >> 4);
// If tall grasses are present, these are consumed and then turn into grass tiles.
if (tile instanceof GrassTile) {
if (random.nextInt(1000) == 0) { // Grazing
level.setTile(x >> 4, y >> 4, Tiles.get("dirt"));
cut = false;
}
if (tile instanceof GrassTile && random.nextInt(1000) == 0) { // Grazing
level.setTile(x >> 4, y >> 4, Tiles.get("dirt"));
cut = false;
}
}

Expand Down
58 changes: 58 additions & 0 deletions src/client/java/minicraft/entity/particle/WaterParticle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package minicraft.entity.particle;

import minicraft.gfx.SpriteLinker;

public class WaterParticle extends Particle {
private final int destX;
private final int destY;
private int count;
private boolean stopped;

public WaterParticle(int x, int y, int lifetime, SpriteLinker.LinkedSprite sprite, int destX, int destY) {
super(x, y, lifetime, sprite);
this.destX = destX;
this.destY = destY;
count = 0;
stopped = false;
}

@Override
public void tick() {
move:
if (!stopped) {
count++;
if (x == destX && y == destY) {
stopped = true;
break move;
}
if (count == 2) {
int diffX = destX - x;
int diffY = destY - y;
if (Math.abs(diffX) < 3 && Math.abs(diffY) < 3) {
move(destX, destY);
stopped = true;
break move;
}

double phi = Math.atan2(diffY, diffX);
double moveX = Math.cos(phi);
double moveY = Math.sin(phi);
int moveXI = 0;
int moveYI = 0;
if (Math.abs(moveX / moveY) > 1.4) moveXI = (int) Math.signum(moveX); // Difference in X is greater.
else if (Math.abs(moveY / moveX) > 1.4)
moveYI = (int) Math.signum(moveY); // Difference in Y is greater.
else { // The difference is small.
moveXI = (int) Math.signum(moveX);
moveYI = (int) Math.signum(moveY);
}

if (!move(moveXI, moveYI))
stopped = true;
count = 0;
}
}

super.tick();
}
}
2 changes: 2 additions & 0 deletions src/client/java/minicraft/item/FurnitureItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import minicraft.entity.Direction;
import minicraft.entity.furniture.Bed;
import minicraft.entity.furniture.Chest;
import minicraft.entity.furniture.Composter;
import minicraft.entity.furniture.Crafter;
import minicraft.entity.furniture.DungeonChest;
import minicraft.entity.furniture.Furniture;
Expand Down Expand Up @@ -57,6 +58,7 @@ protected static ArrayList<Item> getAllInstances() {

items.add(new FurnitureItem(new Tnt()));
items.add(new FurnitureItem(new Bed()));
items.add(new FurnitureItem(new Composter()));

return items;
}
Expand Down
Loading

0 comments on commit b57791e

Please sign in to comment.