Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBigEye committed Sep 10, 2021
2 parents 23fb5e5 + fad7555 commit 78e3935
Show file tree
Hide file tree
Showing 24 changed files with 619 additions and 614 deletions.
1 change: 1 addition & 0 deletions src/minicraft/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public static boolean isConnectedClient() {

public static MinicraftServer server = null;


/** Checks if you are a host and the game is a server */
public static boolean isValidServer() {
return ISONLINE && ISHOST && server != null;
Expand Down
2 changes: 1 addition & 1 deletion src/minicraft/core/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private Network() {

private static final Random random = new Random();

static boolean autoclient = false; // used in the initScreen method; jumps to multiplayer menu as client
static boolean autoclient = false; // Used in the initScreen method; jumps to multiplayer menu as client

private static VersionInfo latestVersion = null;

Expand Down
2 changes: 1 addition & 1 deletion src/minicraft/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void initScreen() {
/** Renders the current screen. Called in game loop, a bit after tick(). */
public static void render() {
if (!HAS_GUI || screen == null)
return; // no point in this if there's no gui... :P
return; // No point in this if there's no gui... :P

if (readyToRenderGameplay) {
if (isValidServer()) {
Expand Down
407 changes: 185 additions & 222 deletions src/minicraft/core/io/ConsoleReader.java

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/minicraft/entity/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ public String getData() {
@Override
public void tick() {
if (x < 0 || x>>4 > level.w || y < 0 || y>>4 > level.h) {
remove(); // remove when out of bounds
remove(); // Remove when out of bounds
return;
}

x += dir.getX() * speed;
y += dir.getY() * speed;

// TODO I think I can just use the xr yr vars, and the normal system with touchedBy(entity) to detect collisions instead.
List<Entity> entitylist = level.getEntitiesInRect(new Rectangle(x, y, 0, 0, Rectangle.CENTER_DIMS));
boolean criticalHit = random.nextInt(11) < 9;
for (int i = 0; i < entitylist.size(); i++) {
Entity hit = entitylist.get(i);

for (Entity hit : entitylist) {

if (hit instanceof Mob && hit != owner) {
Mob mob = (Mob) hit;
Expand Down
33 changes: 21 additions & 12 deletions src/minicraft/entity/Boat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import java.util.List;
import java.util.Random;

import org.jetbrains.annotations.Nullable;

import minicraft.core.Game;
import minicraft.core.Updater;
import minicraft.core.io.Sound;
import minicraft.entity.mob.Player;
import minicraft.entity.mob.RemotePlayer;
import minicraft.entity.particle.SplashParticle;
import minicraft.gfx.Rectangle;
import minicraft.gfx.Screen;
import minicraft.gfx.Sprite;
import minicraft.item.BoatItem;
import minicraft.item.Item;
import minicraft.item.PowerGloveItem;

public class Boat extends Entity {
Expand Down Expand Up @@ -121,18 +125,23 @@ public boolean blocks(Entity e) {
return true;
}

public void take(Player player) {
remove(); // remove this from the world
if (!Game.ISONLINE) {
if (!Game.isMode("creative") && player.activeItem != null && !(player.activeItem instanceof PowerGloveItem))
player.getInventory().add(0, player.activeItem); // put whatever item the player is holding into their inventory (should never be a power glove, since it is put in a taken out again all in the same frame).
player.activeItem = new BoatItem("Boat"); // make this the player's current item.
} else if (Game.isValidServer() && player instanceof RemotePlayer)
Game.server.getAssociatedThread((RemotePlayer) player).updatePlayerActiveItem(new BoatItem("Boat"));
else
System.out.println("WARNING: undefined behavior; online game was not server and ticked furniture: " + this + "; and/or player in online game found that isn't a RemotePlayer: " + player);

// if (Game.debug) System.out.println("set active item of player " + player + " to " + player.activeItem + "; picked up furniture: " + this);
public boolean interact(Player player, @Nullable Item item, Direction attackDir) {
if (item instanceof PowerGloveItem) {
Sound.Mob_generic_hurt.play();
if (!Game.ISONLINE) {
remove();
if (!Game.isMode("creative") && player.activeItem != null && !(player.activeItem instanceof PowerGloveItem))
player.getInventory().add(0, player.activeItem); // put whatever item the player is holding into their inventory
player.activeItem = new BoatItem("Boat"); // make this the player's current item.
return true;
} else if (Game.isValidServer() && player instanceof RemotePlayer) {
remove();
Game.server.getAssociatedThread((RemotePlayer) player).updatePlayerActiveItem(new BoatItem("Boat"));
return true;
} else
System.out.println("WARNING: undefined behavior; online game was not server and ticked furniture: " + this + "; and/or player in online game found that isn't a RemotePlayer: " + player);
}
return false;
}

public boolean move(double xa, double ya) {
Expand Down
Loading

0 comments on commit 78e3935

Please sign in to comment.