Added more team/item classes to core, and some refactoring of package structure.
This commit is contained in:
parent
33bacf0632
commit
de6e50264b
|
@ -5,7 +5,7 @@ import nl.andrewl.aos2_client.control.PlayerInputKeyCallback;
|
|||
import nl.andrewl.aos2_client.control.PlayerInputMouseClickCallback;
|
||||
import nl.andrewl.aos2_client.control.PlayerViewCursorCallback;
|
||||
import nl.andrewl.aos2_client.render.GameRenderer;
|
||||
import nl.andrewl.aos_core.model.ColorPalette;
|
||||
import nl.andrewl.aos_core.model.world.ColorPalette;
|
||||
import nl.andrewl.aos_core.net.*;
|
||||
import nl.andrewl.aos_core.net.udp.ChunkUpdateMessage;
|
||||
import nl.andrewl.aos_core.net.udp.PlayerUpdateMessage;
|
||||
|
|
|
@ -2,9 +2,9 @@ package nl.andrewl.aos2_client;
|
|||
|
||||
import nl.andrewl.aos2_client.render.chunk.ChunkMesh;
|
||||
import nl.andrewl.aos2_client.render.chunk.ChunkMeshGenerator;
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.aos_core.model.Player;
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import nl.andrewl.aos_core.net.ChunkDataMessage;
|
||||
import nl.andrewl.aos_core.net.PlayerJoinMessage;
|
||||
import nl.andrewl.aos_core.net.PlayerLeaveMessage;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package nl.andrewl.aos2_client.render.chunk;
|
||||
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package nl.andrewl.aos2_client.render.chunk;
|
||||
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
|
|
@ -2,16 +2,9 @@ package nl.andrewl.aos2_client.render.chunk;
|
|||
|
||||
import nl.andrewl.aos2_client.Camera;
|
||||
import nl.andrewl.aos2_client.render.ShaderProgram;
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3i;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import static org.lwjgl.opengl.GL46.*;
|
||||
|
||||
|
|
|
@ -42,7 +42,14 @@ public class Player {
|
|||
*/
|
||||
protected final Vector3f viewVector;
|
||||
|
||||
/**
|
||||
* The player's name.
|
||||
*/
|
||||
protected final String username;
|
||||
|
||||
/**
|
||||
* The player's unique id that it was assigned by the server.
|
||||
*/
|
||||
protected final int id;
|
||||
|
||||
public Player(int id, String username) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
* A team is a group of players in a world that should work together to
|
||||
* achieve some goal.
|
||||
*/
|
||||
public class Team {
|
||||
/**
|
||||
* The internal id that this team is assigned.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The name of the team.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The team's color, used to identify players and structures belonging to
|
||||
* this team.
|
||||
*/
|
||||
private final Vector3f color;
|
||||
|
||||
public Team(int id, String name, Vector3f color) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Vector3f getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package nl.andrewl.aos_core.model.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the contents and current state of a player's inventory.
|
||||
*/
|
||||
public class Inventory {
|
||||
/**
|
||||
* The list of item stacks in the inventory.
|
||||
*/
|
||||
private final List<ItemStack> itemStacks;
|
||||
|
||||
/**
|
||||
* The index of the selected item stack.
|
||||
*/
|
||||
private int selectedIndex;
|
||||
|
||||
public Inventory(List<ItemStack> itemStacks, int selectedIndex) {
|
||||
this.itemStacks = itemStacks;
|
||||
this.selectedIndex = selectedIndex;
|
||||
}
|
||||
|
||||
public ItemStack getSelectedItemStack() {
|
||||
return itemStacks.get(selectedIndex);
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int newIndex) {
|
||||
while (newIndex < 0) newIndex += itemStacks.size();
|
||||
while (newIndex > itemStacks.size() - 1) newIndex -= itemStacks.size();
|
||||
this.selectedIndex = newIndex;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package nl.andrewl.aos_core.model.item;
|
||||
|
||||
/**
|
||||
* Represents a stack of items in the player's inventory. This is generally
|
||||
* a type of item, and the amount of it.
|
||||
*/
|
||||
public class ItemStack {
|
||||
private final ItemType type;
|
||||
private int amount;
|
||||
|
||||
public ItemStack(ItemType type, int amount) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Object getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package nl.andrewl.aos_core.model.item;
|
||||
|
||||
/**
|
||||
* Represents a type of item that a player can have.
|
||||
*/
|
||||
public class ItemType {
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final int maxAmount;
|
||||
|
||||
public ItemType(int id, String name, int maxAmount) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.maxAmount = maxAmount;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMaxAmount() {
|
||||
return maxAmount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package nl.andrewl.aos_core.model.item;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Global constant set of registered item types.
|
||||
*/
|
||||
public final class ItemTypes {
|
||||
public static final Map<Integer, ItemType> TYPES_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerType(new ItemType(1, "Rifle", 1));
|
||||
registerType(new ItemType(2, "Block", 100));
|
||||
}
|
||||
|
||||
public static void registerType(ItemType type) {
|
||||
TYPES_MAP.put(type.getId(), type);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import net.openhft.hashing.LongHashFunction;
|
||||
import org.joml.Vector3i;
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector3ic;
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import nl.andrewl.aos_core.Directions;
|
||||
import nl.andrewl.aos_core.MathUtils;
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
|
@ -1,4 +1,4 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
package nl.andrewl.aos_core.model.world;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package nl.andrewl.aos_core.net;
|
||||
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.record_net.Message;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package nl.andrewl.aos_core.net;
|
||||
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.record_net.Message;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package nl.andrewl.aos_core.net;
|
||||
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import nl.andrewl.record_net.Message;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package nl.andrewl.aos_core.net.udp;
|
||||
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import nl.andrewl.record_net.Message;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import org.joml.Vector3i;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package nl.andrewl.aos_core.model;
|
||||
|
||||
import nl.andrewl.aos_core.Directions;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.Hit;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package nl.andrewl.aos2_server;
|
||||
|
||||
import nl.andrewl.aos_core.Net;
|
||||
import nl.andrewl.aos_core.model.Chunk;
|
||||
import nl.andrewl.aos_core.model.world.Chunk;
|
||||
import nl.andrewl.aos_core.net.*;
|
||||
import nl.andrewl.aos_core.net.udp.PlayerUpdateMessage;
|
||||
import nl.andrewl.record_net.Message;
|
||||
import nl.andrewl.record_net.util.ExtendedDataInputStream;
|
||||
import nl.andrewl.record_net.util.ExtendedDataOutputStream;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package nl.andrewl.aos2_server;
|
||||
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.WorldIO;
|
||||
import nl.andrewl.aos_core.model.Worlds;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import nl.andrewl.aos_core.model.world.WorldIO;
|
||||
import nl.andrewl.aos_core.model.world.Worlds;
|
||||
import nl.andrewl.aos_core.net.UdpReceiver;
|
||||
import nl.andrewl.aos_core.net.udp.ClientInputState;
|
||||
import nl.andrewl.aos_core.net.udp.ClientOrientationState;
|
||||
|
@ -36,8 +36,6 @@ public class Server implements Runnable {
|
|||
this.playerManager = new PlayerManager();
|
||||
this.worldUpdater = new WorldUpdater(this, 20);
|
||||
this.world = Worlds.testingWorld();
|
||||
WorldIO.write(world, Path.of("worlds", "testingWorld"));
|
||||
// this.world = WorldIO.read(Path.of("worlds", "testingWorld"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package nl.andrewl.aos2_server;
|
||||
|
||||
import nl.andrewl.aos_core.model.Player;
|
||||
import nl.andrewl.aos_core.model.World;
|
||||
import nl.andrewl.aos_core.model.world.World;
|
||||
import nl.andrewl.aos_core.net.udp.ChunkUpdateMessage;
|
||||
import nl.andrewl.aos_core.net.udp.ClientInputState;
|
||||
import org.joml.Math;
|
||||
|
|
Loading…
Reference in New Issue