Some changes

This commit is contained in:
Randy 2019-03-23 19:30:53 +01:00
parent 0a76598bd2
commit 951cba6ce6
35 changed files with 187 additions and 163 deletions

View File

@ -1,3 +1,4 @@
{ {
"model": "base:models/3d/block.obj" "model": "block.obj", // appended to "base:models/3d/"
"texture": ""
} }

View File

@ -33,7 +33,8 @@ import org.reflections.Reflections;
import io.cubyz.ClientOnly; import io.cubyz.ClientOnly;
import io.cubyz.Constants; import io.cubyz.Constants;
import io.cubyz.CubzLogger; import io.cubyz.CubyzLogger;
import io.cubyz.api.CubzRegistries;
import io.cubyz.api.IRegistryElement; import io.cubyz.api.IRegistryElement;
import io.cubyz.api.Mod; import io.cubyz.api.Mod;
import io.cubyz.blocks.Block; import io.cubyz.blocks.Block;
@ -74,7 +75,7 @@ public class Cubyz implements IGameLogic {
private int breakCooldown = 10; private int breakCooldown = 10;
public static Logger log = CubzLogger.i; public static Logger log = CubyzLogger.i;
public static String serverIP = "localhost"; public static String serverIP = "localhost";
public static int serverPort = 58961; public static int serverPort = 58961;
@ -104,7 +105,7 @@ public class Cubyz implements IGameLogic {
@Override @Override
public void cleanup() { public void cleanup() {
renderer.cleanup(); renderer.cleanup();
CubzLogger.i.getHandlers()[0].close(); log.getHandlers()[0].close();
DiscordIntegration.closeRPC(); DiscordIntegration.closeRPC();
} }
@ -203,7 +204,7 @@ public class Cubyz implements IGameLogic {
}; };
// client-side init // client-side init
for (IRegistryElement ire : ModLoader.block_registry.registered()) { for (IRegistryElement ire : CubzRegistries.BLOCK_REGISTRY.registered()) {
Block b = (Block) ire; Block b = (Block) ire;
b.setBlockPair(new ClientBlockPair()); b.setBlockPair(new ClientBlockPair());
ClientOnly.createBlockMesh.accept(b); ClientOnly.createBlockMesh.accept(b);

View File

@ -2,6 +2,7 @@ package io.cubyz.client;
import org.jungle.game.Game; import org.jungle.game.Game;
import org.jungle.game.GameOptions; import org.jungle.game.GameOptions;
import org.jungle.game.GameOptionsPrompt;
public class GameLauncher extends Game { public class GameLauncher extends Game {
@ -11,20 +12,20 @@ public class GameLauncher extends Game {
GameLauncher.instance = new GameLauncher(); GameLauncher.instance = new GameLauncher();
instance.logic = new Cubyz(); instance.logic = new Cubyz();
// GameOptionsPrompt prompt = new GameOptionsPrompt(); GameOptionsPrompt prompt = new GameOptionsPrompt();
// prompt.setLocationRelativeTo(null); prompt.setLocationRelativeTo(null);
// prompt.setVisible(true); prompt.setVisible(true);
// while (prompt.isVisible()) { while (prompt.isVisible()) {
// System.out.print(""); // Avoid bugs System.out.print(""); // Avoid bugs
// } }
//
// GameOptions opt = prompt.generateOptions();
GameOptions opt = new GameOptions(); GameOptions opt = prompt.generateOptions();
opt.antialiasing = false;
opt.frustumCulling = true; // GameOptions opt = new GameOptions();
opt.showTriangles = false; // opt.antialiasing = false;
opt.cullFace = true; // opt.frustumCulling = true;
// opt.showTriangles = false;
// opt.cullFace = true;
instance.start(opt); instance.start(opt);
Cubyz.log.info("Stopped!"); Cubyz.log.info("Stopped!");

View File

@ -2,7 +2,6 @@ package io.cubyz.client.loading;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -10,8 +9,18 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Set; import java.util.Set;
import javax.swing.text.Utilities;
import org.reflections.Reflections; import org.reflections.Reflections;
import io.cubyz.Constants;
import io.cubyz.CubzLogger;
import io.cubyz.api.CubzRegistries;
import io.cubyz.api.Mod;
import io.cubyz.blocks.Block;
import io.cubyz.blocks.BlockInstance;
import io.cubyz.modding.ModLoader;
public class LoadThread extends Thread { public class LoadThread extends Thread {
static int i = -1; static int i = -1;
@ -19,7 +28,7 @@ public class LoadThread extends Thread {
public void run() { public void run() {
LoadingGUI l = LoadingGUI.getInstance(); LoadingGUI l = LoadingGUI.getInstance();
CubzLogger log = (CubzLogger) Cubz.log; CubzLogger log = CubzLogger.instance;
l.setStep(1, 0, 0); l.setStep(1, 0, 0);
// RPC temporaly disabled // RPC temporaly disabled
@ -39,7 +48,7 @@ public class LoadThread extends Thread {
ArrayList<Object> mods = new ArrayList<>(); ArrayList<Object> mods = new ArrayList<>();
ArrayList<File> modSearchPath = new ArrayList<>(); ArrayList<File> modSearchPath = new ArrayList<>();
modSearchPath.add(new File("mods")); modSearchPath.add(new File("mods"));
modSearchPath.add(new File("mods/" + Utilities.BUILD_TYPE + "_" + Utilities.VERSION)); modSearchPath.add(new File("mods/" + Constants.GAME_BUILD_TYPE + "_" + Constants.GAME_VERSION));
ArrayList<URL> modUrl = new ArrayList<>(); ArrayList<URL> modUrl = new ArrayList<>();
for (File sp : modSearchPath) { for (File sp : modSearchPath) {
@ -61,12 +70,12 @@ public class LoadThread extends Thread {
URLClassLoader loader = new URLClassLoader(modUrl.toArray(new URL[modUrl.size()]), LoadThread.class.getClassLoader()); URLClassLoader loader = new URLClassLoader(modUrl.toArray(new URL[modUrl.size()]), LoadThread.class.getClassLoader());
log.info("Seeking mods.."); log.info("Seeking mods..");
try { try {
Enumeration<URL> urls = loader.findResources("CubeComputers"); //Enumeration<URL> urls = loader.findResources("CubeComputers");
System.out.println("URLs"); //System.out.println("URLs");
while (urls.hasMoreElements()) { //while (urls.hasMoreElements()) {
URL url = urls.nextElement(); // URL url = urls.nextElement();
System.out.println("URL - " + url); // System.out.println("URL - " + url);
} //}
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -86,12 +95,13 @@ public class LoadThread extends Thread {
} }
log.info("Mod list complete"); log.info("Mod list complete");
// TODO re-add pre-init
l.setStep(2, 0, mods.size()); l.setStep(2, 0, mods.size());
for (int i = 0; i < mods.size(); i++) { for (int i = 0; i < mods.size(); i++) {
l.setStep(2, i+1, mods.size()); l.setStep(2, i+1, mods.size());
Object mod = mods.get(i); Object mod = mods.get(i);
log.info("Pre-initiating " + mod); log.info("Pre-initiating " + mod);
ModLoader.preInit(mod); //ModLoader.preInit(mod);
} }
// Between pre-init and init code // Between pre-init and init code
@ -109,23 +119,23 @@ public class LoadThread extends Thread {
//Cubz.setProfile(new UserProfile(new UserSession("CubzPublicTest", "publictest@cubz.io", "@zka71a".toCharArray()))); //Cubz.setProfile(new UserProfile(new UserSession("CubzPublicTest", "publictest@cubz.io", "@zka71a".toCharArray())));
//System.out.println("UserProfile Loaded: UserProfile Name = '" + Cubz.getProfile().getName() + "' , UserProfile UUID = '" + Cubz.getProfile().getUUID() + "'."); //System.out.println("UserProfile Loaded: UserProfile Name = '" + Cubz.getProfile().getName() + "' , UserProfile UUID = '" + Cubz.getProfile().getUUID() + "'.");
// Pre-loading meshes // TODO Pre-loading meshes
run = new Runnable() { run = new Runnable() {
public void run() { public void run() {
i++; i++;
Block b = (Block) ModLoader.block_registry.registered()[i]; Block b = (Block) CubzRegistries.BLOCK_REGISTRY.registered()[i];
System.out.println("Creating mesh of " + b.getFullID()); System.out.println("Creating mesh of " + b.getRegistryID());
BlockInstance bi = new BlockInstance(b); BlockInstance bi = new BlockInstance(b);
bi.getMesh(); bi.getMesh();
if (i < ModLoader.block_registry.registered().length-1) { if (i < CubzRegistries.BLOCK_REGISTRY.registered().length-1) {
Cubz.renderDeque.add(run); //Cubz.renderDeque.add(run);
l.setStep(4, i+1, ModLoader.block_registry.registered().length); l.setStep(4, i+1, CubzRegistries.BLOCK_REGISTRY.registered().length);
} else { } else {
l.finishLoading(); l.finishLoading();
} }
} }
}; };
Cubz.renderDeque.add(run); //Cubz.renderDeque.add(run);
System.gc(); System.gc();
} }

View File

@ -11,7 +11,7 @@ import org.lwjgl.nanovg.NVGColor;
import org.lwjgl.nanovg.NVGPaint; import org.lwjgl.nanovg.NVGPaint;
import org.lwjgl.nanovg.NanoVG; import org.lwjgl.nanovg.NanoVG;
import io.cubyz.CubzLogger; import io.cubyz.CubyzLogger;
public class NGraphics { public class NGraphics {
@ -20,7 +20,7 @@ public class NGraphics {
private static NVGPaint imagePaint = NVGPaint.create(); private static NVGPaint imagePaint = NVGPaint.create();
private static int textAlign = NVG_ALIGN_LEFT | NVG_ALIGN_TOP; private static int textAlign = NVG_ALIGN_LEFT | NVG_ALIGN_TOP;
private static final boolean LOG_OPERATIONS = false; private static final boolean LOG_OPERATIONS = Boolean.parseBoolean(System.getProperty("nanovg.logOperations", "false"));
private static Font font; private static Font font;
@ -30,7 +30,7 @@ public class NGraphics {
public static int loadImage(String path) { public static int loadImage(String path) {
if (LOG_OPERATIONS) if (LOG_OPERATIONS)
CubzLogger.instance.fine("[NGRAPHICS] Load Image " + path); CubyzLogger.instance.fine("[NGRAPHICS] Load Image " + path);
return nvgCreateImage(nvg, path, 0); return nvgCreateImage(nvg, path, 0);
} }
@ -44,7 +44,7 @@ public class NGraphics {
public static void fillCircle(int x, int y, int radius) { public static void fillCircle(int x, int y, int radius) {
if (LOG_OPERATIONS) if (LOG_OPERATIONS)
CubzLogger.instance.fine("[NGRAPHICS] fill circle at " + x + ", " + y + " with radius " + radius); CubyzLogger.instance.fine("[NGRAPHICS] fill circle at " + x + ", " + y + " with radius " + radius);
nvgBeginPath(nvg); nvgBeginPath(nvg);
nvgCircle(nvg, x, y, radius); nvgCircle(nvg, x, y, radius);
nvgFillColor(nvg, color); nvgFillColor(nvg, color);
@ -53,7 +53,7 @@ public class NGraphics {
public static void drawRect(int x, int y, int width, int height) { public static void drawRect(int x, int y, int width, int height) {
if (LOG_OPERATIONS) if (LOG_OPERATIONS)
CubzLogger.instance.fine("[NGRAPHICS] draw rect at " + x + ", " + y + " with size " + width + ", " + height); CubyzLogger.instance.fine("[NGRAPHICS] draw rect at " + x + ", " + y + " with size " + width + ", " + height);
nvgBeginPath(nvg); nvgBeginPath(nvg);
nvgRect(nvg, x, y, width, height); nvgRect(nvg, x, y, width, height);
nvgStrokeColor(nvg, color); nvgStrokeColor(nvg, color);
@ -62,7 +62,7 @@ public class NGraphics {
public static void fillRect(int x, int y, int width, int height) { public static void fillRect(int x, int y, int width, int height) {
if (LOG_OPERATIONS) if (LOG_OPERATIONS)
CubzLogger.instance.fine("[NGRAPHICS] fill rect at " + x + ", " + y + " with size " + width + ", " + height); CubyzLogger.instance.fine("[NGRAPHICS] fill rect at " + x + ", " + y + " with size " + width + ", " + height);
nvgBeginPath(nvg); nvgBeginPath(nvg);
nvgRect(nvg, x, y, width, height); nvgRect(nvg, x, y, width, height);
nvgFillColor(nvg, color); nvgFillColor(nvg, color);
@ -99,7 +99,7 @@ public class NGraphics {
public static void drawText(int x, int y, String text) { public static void drawText(int x, int y, String text) {
if (LOG_OPERATIONS) if (LOG_OPERATIONS)
CubzLogger.instance.fine("[NGRAPHICS] draw text \"" + text + "\" at " + x + ", " + y); CubyzLogger.instance.fine("[NGRAPHICS] draw text \"" + text + "\" at " + x + ", " + y);
nvgFontSize(nvg, font.getSize()); nvgFontSize(nvg, font.getSize());
nvgFontFaceId(nvg, font.getNVGId()); nvgFontFaceId(nvg, font.getNVGId());
nvgTextAlign(nvg, textAlign); nvgTextAlign(nvg, textAlign);

View File

@ -1,8 +1,19 @@
package io.cubyz.ui; package io.cubyz.ui;
import org.jungle.Window; import java.util.Deque;
public class ToastManager { public class ToastManager {
public static Deque<Toast> queuedToasts;
public static class Toast {
public String title;
public String text;
public Toast(String title, String text) {
this.title = title;
this.text = text;
}
}
} }

View File

@ -4,10 +4,12 @@ import java.util.Random;
import club.minnced.discord.rpc.DiscordEventHandlers; import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordEventHandlers.OnReady; import club.minnced.discord.rpc.DiscordEventHandlers.OnReady;
import io.cubyz.client.Cubyz;
import club.minnced.discord.rpc.DiscordRPC; import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence; import club.minnced.discord.rpc.DiscordRichPresence;
import club.minnced.discord.rpc.DiscordUser; import club.minnced.discord.rpc.DiscordUser;
import io.cubyz.client.Cubyz;
import io.cubyz.ui.ToastManager;
import io.cubyz.ui.ToastManager.Toast;
public class DiscordIntegration { public class DiscordIntegration {
@ -19,6 +21,7 @@ public class DiscordIntegration {
} }
public static void startRPC() { public static void startRPC() {
DiscordRPC lib = DiscordRPC.INSTANCE; DiscordRPC lib = DiscordRPC.INSTANCE;
String appID = "527033701343952896"; String appID = "527033701343952896";
String steamID = ""; String steamID = "";
@ -26,20 +29,20 @@ public class DiscordIntegration {
handlers.ready = new OnReady() { handlers.ready = new OnReady() {
@Override @Override
public void accept(DiscordUser arg0) { public void accept(DiscordUser user) {
System.out.println("Ready as user " + arg0.username); ToastManager.queuedToasts.push(new Toast("Discord Integration", user.username + " is linked to you!"));
} }
}; };
handlers.joinGame = (secret) -> { handlers.joinGame = (secret) -> {
String serverIP = secret.split(":")[0]; //NOTE: Normal > 0 String serverIP = secret.split(":")[0];
int serverPort = Integer.parseInt(secret.split(":")[1]); int serverPort = Integer.parseInt(secret.split(":")[1]);
System.out.println("Attempting to join server " + serverIP + " at port " + serverPort); System.out.println("Attempting to join server " + serverIP + " at port " + serverPort);
Cubyz.requestJoin(serverIP, serverPort); Cubyz.requestJoin(serverIP, serverPort);
}; };
handlers.joinRequest = (user) -> { handlers.joinRequest = (user) -> {
System.out.println("Join request from " + user.toString() + ", " + user.username); ToastManager.queuedToasts.push(new Toast("Discord Integration", "Join request from " + user.username));
if (Cubyz.serverOnline < Cubyz.serverCapacity) { if (Cubyz.serverOnline < Cubyz.serverCapacity) {
lib.Discord_Respond(user.userId, DiscordRPC.DISCORD_REPLY_YES); lib.Discord_Respond(user.userId, DiscordRPC.DISCORD_REPLY_YES);
} else { } else {
@ -66,7 +69,7 @@ public class DiscordIntegration {
presence.partyId = generatePartyID(); presence.partyId = generatePartyID();
setStatus("No status."); setStatus("Just started");
lib.Discord_UpdatePresence(presence); lib.Discord_UpdatePresence(presence);
@ -74,7 +77,7 @@ public class DiscordIntegration {
while (!Thread.currentThread().isInterrupted()) { while (!Thread.currentThread().isInterrupted()) {
lib.Discord_RunCallbacks(); lib.Discord_RunCallbacks();
try { try {
Thread.sleep(2000L); //NOTE: Normal > 2000L Thread.sleep(2000);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
break; break;
} }
@ -93,15 +96,15 @@ public class DiscordIntegration {
if (Cubyz.isIntegratedServer) { if (Cubyz.isIntegratedServer) {
presence.state = "Singleplayer"; presence.state = "Singleplayer";
//presence.joinSecret = null; //presence.joinSecret = null;
//presence.partySize = 0; //NOTE: Normal > 0 //presence.partySize = 0;
} }
else { else {
if (Cubyz.isOnlineServerOpened) { if (Cubyz.isOnlineServerOpened) {
presence.state = "Join me ;)"; presence.state = "Join me ;)";
presence.partyMax = 50; // temporary || NOTE: Normal > 50 presence.partyMax = 50; // temporary
} else { } else {
presence.state = "Multiplayer"; presence.state = "Multiplayer";
presence.partyMax = 50; // temporary || NOTE: Normal > 50 presence.partyMax = 50; // temporary
} }
} }
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence); DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);

View File

@ -8,6 +8,7 @@ import io.cubyz.blocks.BlockInstance;
import io.cubyz.entity.Entity; import io.cubyz.entity.Entity;
import io.cubyz.entity.Player; import io.cubyz.entity.Player;
// TODO
public class RemoteWorld extends World { public class RemoteWorld extends World {
@Override @Override
@ -24,22 +25,12 @@ public class RemoteWorld extends World {
public void markEdit() { public void markEdit() {
} }
@Override @Override
public Player getLocalPlayer() { public Player getLocalPlayer() {
return null; return null;
} }
@Override
public int getWidth() {
return 0; //NOTE: Normal > 0
}
@Override
public int getDepth() {
return 0; //NOTE: Normal > 0
}
@Override @Override
public Map<Block, ArrayList<BlockInstance>> visibleBlocks() { public Map<Block, ArrayList<BlockInstance>> visibleBlocks() {
return null; return null;
@ -65,19 +56,16 @@ public class RemoteWorld extends World {
@Override @Override
public void queueChunk(ChunkAction action) { public void queueChunk(ChunkAction action) {
// TODO Auto-generated method stub // LOAD would be loading from server, UNLOAD would be unloading from client, and GENERATE would do nothing
} }
@Override @Override
public void seek(int x, int z) { public void seek(int x, int z) {
// TODO Auto-generated method stub
} }
@Override @Override
public void synchronousSeek(int x, int z) { public void synchronousSeek(int x, int z) {
// TODO Auto-generated method stub
} }

View File

@ -4,7 +4,8 @@ import io.cubyz.api.Side;
public class Constants { public class Constants {
public static final String GAME_VERSION = "0.3-alpha"; public static final String GAME_BUILD_TYPE = "alpha";
public static final String GAME_VERSION = "0.3";
public static final String GAME_BRAND = "cubyz"; public static final String GAME_BRAND = "cubyz";
static Side currentSide = null; static Side currentSide = null;

View File

@ -14,20 +14,20 @@ import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
public class CubzLogger extends Logger { public class CubyzLogger extends Logger {
public static boolean useDefaultHandler = false; public static boolean useDefaultHandler = false;
/** /**
* Same as <code>instance</code> * Same as <code>instance</code>
*/ */
public static CubzLogger i; // instance public static CubyzLogger i; // instance
public static CubzLogger instance; public static CubyzLogger instance;
static { static {
new CubzLogger(); new CubyzLogger();
} }
protected CubzLogger() { protected CubyzLogger() {
super("Cubz", null); super("Cubz", null);
setUseParentHandlers(true); setUseParentHandlers(true);
this.setParent(Logger.getGlobal()); this.setParent(Logger.getGlobal());

View File

@ -0,0 +1,13 @@
package io.cubyz.api;
import io.cubyz.blocks.Block;
import io.cubyz.entity.EntityType;
import io.cubyz.items.Item;
public class CubzRegistries {
public static final Registry<Block> BLOCK_REGISTRY = new Registry<Block>();
public static final Registry<Item> ITEM_REGISTRY = new Registry<Item>();
public static final Registry<EntityType> ENTITY_REGISTRY = new Registry<EntityType>();
}

View File

@ -3,10 +3,12 @@ package io.cubyz.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import io.cubyz.CubyzLogger;
public class Registry<T extends IRegistryElement> { public class Registry<T extends IRegistryElement> {
private HashMap<String, T> hashMap = new HashMap<>(); private HashMap<String, T> hashMap = new HashMap<>();
private boolean debug = Boolean.parseBoolean(System.getProperty("registry.debugEnabled", "true")); private boolean debug = Boolean.parseBoolean(System.getProperty("registry.debugEnabled", "false"));
private boolean alwaysError = Boolean.parseBoolean(System.getProperty("registry.dumpAsError", "true")); private boolean alwaysError = Boolean.parseBoolean(System.getProperty("registry.dumpAsError", "true"));
public IRegistryElement[] registered() { // can be casted to T public IRegistryElement[] registered() { // can be casted to T
@ -35,7 +37,7 @@ public class Registry<T extends IRegistryElement> {
} }
hashMap.put(element.getRegistryID().toString(), element); hashMap.put(element.getRegistryID().toString(), element);
if (debug) { if (debug) {
//Cubyz.log.info("Registered " + getType(element.getClass()) + " as " + element.getFullID()); CubyzLogger.instance.info("Registered " + getType(element.getClass()) + " as " + element.getRegistryID());
} }
} }

View File

@ -77,6 +77,7 @@ public class BaseMod {
// Register // Register
reg.registerAll(bedrock, grass, dirt, oakLeaves, oakLog, sand, stone, coal, diamond, emerald, gold, iron, ruby, water); reg.registerAll(bedrock, grass, dirt, oakLeaves, oakLog, sand, stone, coal, diamond, emerald, gold, iron, ruby, water);
System.out.println("Added all");
} }
} }

View File

@ -4,7 +4,7 @@ public class Bedrock extends Block {
public Bedrock() { public Bedrock() {
setTexture("bedrock"); setTexture("bedrock");
setID("cubz:bedrock"); setID("cubyz:bedrock");
setUnbreakable(); setUnbreakable();
} }

View File

@ -4,7 +4,7 @@ public class CoalOre extends Ore {
public CoalOre() { public CoalOre() {
setTexture("coal_ore"); setTexture("coal_ore");
setID("cubz:coal_ore"); setID("cubyz:coal_ore");
setHeight(127); setHeight(127);
setChance(0.02F); setChance(0.02F);
} }

View File

@ -4,7 +4,7 @@ public class DiamondOre extends Ore {
public DiamondOre() { public DiamondOre() {
setTexture("diamond_ore"); setTexture("diamond_ore");
setID("cubz:diamond_ore"); setID("cubyz:diamond_ore");
setHeight(15); setHeight(15);
setChance(0.002F); setChance(0.002F);
} }

View File

@ -4,7 +4,7 @@ public class Dirt extends Block {
public Dirt() { public Dirt() {
setTexture("dirt"); setTexture("dirt");
setID("cubz:dirt"); setID("cubyz:dirt");
} }
} }

View File

@ -4,7 +4,7 @@ public class EmeraldOre extends Ore {
public EmeraldOre() { public EmeraldOre() {
setTexture("emerald_ore"); setTexture("emerald_ore");
setID("cubz:emerald_ore"); setID("cubyz:emerald_ore");
setHeight(25); setHeight(25);
setChance(0.001F); setChance(0.001F);
} }

View File

@ -4,7 +4,7 @@ public class GoldOre extends Ore {
public GoldOre() { public GoldOre() {
setTexture("gold_ore"); setTexture("gold_ore");
setID("cubz:gold_ore"); setID("cubyz:gold_ore");
setHeight(32); setHeight(32);
setChance(0.005F); setChance(0.005F);
} }

View File

@ -5,7 +5,7 @@ public class Grass extends Block {
public Grass() { public Grass() {
setTexture("grassblock"); setTexture("grassblock");
setID("cubz:grass"); setID("cubyz:grass");
texConverted = true; // texture arleady in runtime format texConverted = true; // texture arleady in runtime format
} }

View File

@ -4,7 +4,7 @@ public class IronOre extends Ore {
public IronOre() { public IronOre() {
setTexture("iron_ore"); setTexture("iron_ore");
setID("cubz:iron_ore"); setID("cubyz:iron_ore");
setHeight(63); setHeight(63);
setChance(0.03F); setChance(0.03F);
} }

View File

@ -4,7 +4,7 @@ public class OakLeaves extends Block {
public OakLeaves() { public OakLeaves() {
setTexture("oak_leaves"); setTexture("oak_leaves");
setID("cubz:oak_leaves"); setID("cubyz:oak_leaves");
} }
public void update() { public void update() {

View File

@ -4,7 +4,7 @@ public class OakLog extends Block {
public OakLog() { public OakLog() {
setTexture("oak_log"); setTexture("oak_log");
setID("cubz:oak_log"); setID("cubyz:oak_log");
} }
} }

View File

@ -4,7 +4,7 @@ public class RubyOre extends Ore {
public RubyOre() { public RubyOre() {
setTexture("ruby_ore"); setTexture("ruby_ore");
setID("cubz:ruby_ore"); setID("cubyz:ruby_ore");
setHeight(8); setHeight(8);
setChance(0.006F); setChance(0.006F);
} }

View File

@ -4,7 +4,7 @@ public class Sand extends Block {
public Sand() { public Sand() {
setTexture("sand"); setTexture("sand");
setID("cubz:sand"); setID("cubyz:sand");
} }
} }

View File

@ -4,7 +4,7 @@ public class Stone extends Block {
public Stone() { public Stone() {
setTexture("stone"); setTexture("stone");
setID("cubz:stone"); setID("cubyz:stone");
} }
} }

View File

@ -4,7 +4,7 @@ public class Water extends Block {
public Water() { public Water() {
setTexture("water"); setTexture("water");
setID("cubz:water"); setID("cubyz:water");
} }
} }

View File

@ -11,21 +11,24 @@ import io.cubyz.world.World;
public abstract class Entity { public abstract class Entity {
protected String registryName;
protected float entitySpeed;
protected World world; protected World world;
protected AABBf aabb = new AABBf();
protected Vector3f position = new Vector3f(); protected Vector3f position = new Vector3f();
protected Vector3f rotation = new Vector3f(); protected Vector3f rotation = new Vector3f();
public float vx, vy, vz; public float vx, vy, vz;
protected IRenderablePair renderPair; protected IRenderablePair renderPair;
private EntityType type;
protected int width = 1, height = 2, depth = 1; protected int width = 1, height = 2, depth = 1;
public float getSpeed() { public Entity(EntityType type) {
return entitySpeed; this.type = type;
}
public EntityType getType() {
return type;
} }
public World getWorld() { public World getWorld() {
@ -35,14 +38,6 @@ public abstract class Entity {
public void setWorld(World world) { public void setWorld(World world) {
this.world = world; this.world = world;
} }
public String getRegistryName() {
return registryName;
}
public void setRegistryName(String registryName) {
this.registryName = registryName;
}
public Vector3f getPosition() { public Vector3f getPosition() {
return position; return position;
@ -215,13 +210,6 @@ public abstract class Entity {
} }
public void update() { public void update() {
aabb.minX = position.x();
aabb.maxX = position.x() + width;
aabb.minY = position.y();
aabb.maxY = position.y() + height;
aabb.minZ = position.z();
aabb.maxZ = position.z() + width;
if (renderPair != null) { if (renderPair != null) {
Consumer<Entity> upd = (Consumer<Entity>) renderPair.get("renderPairUpdate"); Consumer<Entity> upd = (Consumer<Entity>) renderPair.get("renderPairUpdate");
upd.accept(this); upd.accept(this);

View File

@ -3,5 +3,7 @@ package io.cubyz.entity;
import io.cubyz.api.IRegistryElement; import io.cubyz.api.IRegistryElement;
public abstract class EntityType implements IRegistryElement { public abstract class EntityType implements IRegistryElement {
// nothing needed more than IRegistryElement's methods
public abstract Entity newEntity();
} }

View File

@ -4,6 +4,7 @@ import org.joml.AABBf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.joml.Vector3i; import org.joml.Vector3i;
import io.cubyz.api.CubzRegistries;
import io.cubyz.command.ICommandSource; import io.cubyz.command.ICommandSource;
//NOTE: Player is 2 Blocks Tall (2 Meters) //NOTE: Player is 2 Blocks Tall (2 Meters)
@ -21,6 +22,7 @@ public class Player extends Entity implements ICommandSource {
} }
public Player(boolean local) { public Player(boolean local) {
super(CubzRegistries.ENTITY_REGISTRY.getByID("cubyz:"));
this.local = local; this.local = local;
// try { // try {
// mesh = loadMesh("uglyplayer"); // mesh = loadMesh("uglyplayer");
@ -32,7 +34,6 @@ public class Player extends Entity implements ICommandSource {
// } // }
// spatial = new Spatial(mesh); // spatial = new Spatial(mesh);
// spatial.setScale(0.5F); // spatial.setScale(0.5F);
setRegistryName("cubz:player");
} }
public boolean isLocal() { public boolean isLocal() {

View File

@ -4,7 +4,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import io.cubyz.CubzLogger; import io.cubyz.CubyzLogger;
import io.cubyz.api.CubzRegistries;
import io.cubyz.api.EventHandler; import io.cubyz.api.EventHandler;
import io.cubyz.api.Registry; import io.cubyz.api.Registry;
import io.cubyz.api.Side; import io.cubyz.api.Side;
@ -15,10 +16,6 @@ import io.cubyz.items.Item;
// Most methods should ALWAYS be found as if it were on Side.SERVER // Most methods should ALWAYS be found as if it were on Side.SERVER
public class ModLoader { public class ModLoader {
public static Registry<Block> block_registry = new Registry<Block>();
public static Registry<Item> item_registry = new Registry<Item>();
public static Registry<EntityType> entity_registry = new Registry<EntityType>();
public static boolean isCorrectSide(Side currentSide, Method method) { public static boolean isCorrectSide(Side currentSide, Method method) {
boolean haveAnnot = false; boolean haveAnnot = false;
@ -42,7 +39,7 @@ public class ModLoader {
for (Method m : cl.getMethods()) { for (Method m : cl.getMethods()) {
if (m.isAnnotationPresent(EventHandler.class)) { if (m.isAnnotationPresent(EventHandler.class)) {
if (isCorrectSide(side, m)) { if (isCorrectSide(side, m)) {
if (m.getAnnotation(EventHandler.class).type().equals("init")) { if (m.getAnnotation(EventHandler.class).type().equals(eventType)) {
return m; return m;
} }
} }
@ -55,7 +52,7 @@ public class ModLoader {
Class<?> cl = mod.getClass(); Class<?> cl = mod.getClass();
for (Method m : cl.getMethods()) { for (Method m : cl.getMethods()) {
if (m.isAnnotationPresent(EventHandler.class)) { if (m.isAnnotationPresent(EventHandler.class)) {
if (m.getAnnotation(EventHandler.class).type().equals("init")) { if (m.getAnnotation(EventHandler.class).type().equals(eventType)) {
return m; return m;
} }
} }
@ -65,46 +62,38 @@ public class ModLoader {
public static void init(Object mod) { public static void init(Object mod) {
commonRegister(mod); commonRegister(mod);
Class<?> cl = mod.getClass();
safeMethodInvoke(true, eventHandlerMethodSided(mod, "init", Side.SERVER), mod); safeMethodInvoke(true, eventHandlerMethodSided(mod, "init", Side.SERVER), mod);
} }
static void safeMethodInvoke(boolean imp, Method m, Object o, Object... args) { static void safeMethodInvoke(boolean imp /* is it important (e.g. at init) */, Method m, Object o, Object... args) {
try { try {
m.invoke(o, args); m.invoke(o, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
if (e instanceof InvocationTargetException) { if (e instanceof InvocationTargetException) {
CubzLogger.i.warning("Error while invoking mod method (" + m + "):"); CubyzLogger.i.warning("Error while invoking mod method (" + m + "):");
e.getCause().printStackTrace(); e.getCause().printStackTrace();
} else { } else {
e.printStackTrace(); e.printStackTrace();
} }
System.err.flush(); System.err.flush();
if (imp) { if (imp) {
// fast exit System.exit(1);
//Cubz.instance.cleanup();
System.exit(1); //NOTE: Normal > 1
} }
} }
} }
public static void commonRegister(Object mod) { public static void commonRegister(Object mod) {
Class<?> cl = mod.getClass(); Method block_method = eventHandlerMethod(mod, "block/register");
for (Method m : cl.getMethods()) { Method item_method = eventHandlerMethod(mod, "item/register");
if (m.isAnnotationPresent(EventHandler.class)) { Method entity_method = eventHandlerMethod(mod, "entity/register");
if (isCorrectSide(Side.SERVER, m)) {
if (m.getAnnotation(EventHandler.class).type().equals("block/register")) { // invoke
safeMethodInvoke(true, m, mod, block_registry); if (block_method != null)
} safeMethodInvoke(true, block_method, mod, CubzRegistries.BLOCK_REGISTRY);
if (m.getAnnotation(EventHandler.class).type().equals("item/register")) { if (item_method != null)
safeMethodInvoke(true, m, mod, item_registry); safeMethodInvoke(true, item_method, mod, CubzRegistries.ITEM_REGISTRY);
} if (entity_method != null)
if (m.getAnnotation(EventHandler.class).type().equals("entity/register")) { safeMethodInvoke(true, entity_method, mod, CubzRegistries.ENTITY_REGISTRY);
safeMethodInvoke(true, m, mod, entity_registry);
}
}
}
}
} }
} }

View File

@ -10,7 +10,7 @@ public class EntityIO {
public static void saveEntity(Entity ent, DataOutputStream out) throws IOException { public static void saveEntity(Entity ent, DataOutputStream out) throws IOException {
// written as double to prepare future conversion from floats to doubles (for very large worlds) // written as double to prepare future conversion from floats to doubles (for very large worlds)
out.writeUTF(ent.getRegistryName()); out.writeUTF(ent.getType().getRegistryID().toString());
out.writeDouble(ent.getPosition().x); out.writeDouble(ent.getPosition().x);
out.writeDouble(ent.getPosition().y); out.writeDouble(ent.getPosition().y);
out.writeDouble(ent.getPosition().z); out.writeDouble(ent.getPosition().z);
@ -23,7 +23,7 @@ public class EntityIO {
} }
public static Entity loadEntity(DataInputStream dis) throws IOException { public static Entity loadEntity(DataInputStream dis) throws IOException {
return null;
} }
} }

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import org.joml.Vector3i; import org.joml.Vector3i;
import io.cubyz.api.CubzRegistries;
import io.cubyz.api.Registry;
import io.cubyz.blocks.Block; import io.cubyz.blocks.Block;
import io.cubyz.blocks.BlockInstance; import io.cubyz.blocks.BlockInstance;
import io.cubyz.blocks.Ore; import io.cubyz.blocks.Ore;
@ -17,26 +19,28 @@ public class Chunk {
private boolean generated; private boolean generated;
private boolean loaded; private boolean loaded;
private static Registry<Block> br = CubzRegistries.BLOCK_REGISTRY; // shortcut to BLOCK_REGISTRY
// Normal: // Normal:
private static Block grass = ModLoader.block_registry.getByID("cubz:grass"); private static Block grass = br.getByID("cubyz:grass");
private static Block sand = ModLoader.block_registry.getByID("cubz:sand"); private static Block sand = br.getByID("cubyz:sand");
private static Block dirt = ModLoader.block_registry.getByID("cubz:dirt"); private static Block dirt = br.getByID("cubyz:dirt");
private static Block stone = ModLoader.block_registry.getByID("cubz:stone"); private static Block stone = br.getByID("cubyz:stone");
private static Block bedrock = ModLoader.block_registry.getByID("cubz:bedrock"); private static Block bedrock = br.getByID("cubyz:bedrock");
// Ores: // Ores:
private static ArrayList<Ore> ores = new ArrayList<>(); private static ArrayList<Ore> ores = new ArrayList<>();
static { static {
ores.add((Ore) ModLoader.block_registry.getByID("cubz:coal_ore")); ores.add((Ore) br.getByID("cubyz:coal_ore"));
ores.add((Ore) ModLoader.block_registry.getByID("cubz:iron_ore")); ores.add((Ore) br.getByID("cubyz:iron_ore"));
ores.add((Ore) ModLoader.block_registry.getByID("cubz:ruby_ore")); ores.add((Ore) br.getByID("cubyz:ruby_ore"));
ores.add((Ore) ModLoader.block_registry.getByID("cubz:gold_ore")); ores.add((Ore) br.getByID("cubyz:gold_ore"));
ores.add((Ore) ModLoader.block_registry.getByID("cubz:diamond_ore")); ores.add((Ore) br.getByID("cubyz:diamond_ore"));
ores.add((Ore) ModLoader.block_registry.getByID("cubz:emerald_ore")); ores.add((Ore) br.getByID("cubyz:emerald_ore"));
} }
// Liquids: // Liquids:
private static Block water = ModLoader.block_registry.getByID("cubz:water"); private static Block water = br.getByID("cubyz:water");
public static final int SEA_LEVEL = 100; public static final int SEA_LEVEL = 100;
@ -150,6 +154,7 @@ public class Chunk {
for (int py = 0; py < 16; py++) { for (int py = 0; py < 16; py++) {
float value = map[px][py]; float value = map[px][py];
int y = (int) (value * World.WORLD_HEIGHT); int y = (int) (value * World.WORLD_HEIGHT);
y &= 255; // somehow it can go below it :/
for (int j = y > SEA_LEVEL ? y : SEA_LEVEL; j >= 0; j--) { for (int j = y > SEA_LEVEL ? y : SEA_LEVEL; j >= 0; j--) {
BlockInstance bi = null; BlockInstance bi = null;
if(j > y) { if(j > y) {

View File

@ -9,7 +9,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import io.cubyz.CubzLogger; import io.cubyz.CubyzLogger;
import io.cubyz.api.CubzRegistries;
import io.cubyz.api.IRegistryElement; import io.cubyz.api.IRegistryElement;
import io.cubyz.blocks.Block; import io.cubyz.blocks.Block;
import io.cubyz.blocks.BlockInstance; import io.cubyz.blocks.BlockInstance;
@ -37,11 +38,16 @@ public class LocalWorld extends World {
private class ChunkGenerationThread extends Thread { private class ChunkGenerationThread extends Thread {
Deque<ChunkAction> loadList = new ArrayDeque<>(); // FIFO order (First In, First Out) Deque<ChunkAction> loadList = new ArrayDeque<>(); // FIFO order (First In, First Out)
private static final int MAX_QUEUE_SIZE = 8;
public void queue(ChunkAction ca) { public void queue(ChunkAction ca) {
if (!isQueued(ca)) { if (!isQueued(ca)) {
//CubzLogger.instance.fine("Queued " + ca.type + " for chunk " + ca.chunk); if (loadList.size() > MAX_QUEUE_SIZE) {
CubyzLogger.instance.info("Hang on, the Local-Chunk-Thread's queue is full, blocking!");
while (!loadList.isEmpty()) {
System.out.print(""); // again, used as replacement to Thread.onSpinWait(), also necessary due to some JVM oddities
}
}
loadList.add(ca); loadList.add(ca);
} }
} }
@ -64,7 +70,7 @@ public class LocalWorld extends World {
if (!loadList.isEmpty()) { if (!loadList.isEmpty()) {
ChunkAction popped = loadList.pop(); ChunkAction popped = loadList.pop();
if (popped.type == ChunkActionType.GENERATE) { if (popped.type == ChunkActionType.GENERATE) {
CubzLogger.instance.fine("Generating " + popped.chunk.getX() + "," + popped.chunk.getZ()); CubyzLogger.instance.fine("Generating " + popped.chunk.getX() + "," + popped.chunk.getZ());
synchronousGenerate(popped.chunk); synchronousGenerate(popped.chunk);
popped.chunk.load(); popped.chunk.load();
} }
@ -74,7 +80,7 @@ public class LocalWorld extends World {
} }
} }
else if (popped.type == ChunkActionType.UNLOAD) { else if (popped.type == ChunkActionType.UNLOAD) {
CubzLogger.instance.fine("Unloading " + popped.chunk.getX() + "," + popped.chunk.getZ()); CubyzLogger.instance.fine("Unloading " + popped.chunk.getX() + "," + popped.chunk.getZ());
for (BlockInstance bi : popped.chunk.list()) { for (BlockInstance bi : popped.chunk.list()) {
Block b = bi.getBlock(); Block b = bi.getBlock();
visibleSpatials.get(b).remove(bi); visibleSpatials.get(b).remove(bi);
@ -229,7 +235,7 @@ public class LocalWorld extends World {
public void generate() { public void generate() {
Random r = new Random(); Random r = new Random();
seed = r.nextInt(); seed = r.nextInt();
for (IRegistryElement ire : ModLoader.block_registry.registered()) { for (IRegistryElement ire : CubzRegistries.BLOCK_REGISTRY.registered()) {
Block b = (Block) ire; Block b = (Block) ire;
visibleSpatials.put(b, new ArrayList<>()); visibleSpatials.put(b, new ArrayList<>());
} }

View File

@ -1,5 +1,6 @@
package io.cubyz.world; package io.cubyz.world;
import io.cubyz.api.CubzRegistries;
import io.cubyz.blocks.*; import io.cubyz.blocks.*;
import io.cubyz.modding.ModLoader; import io.cubyz.modding.ModLoader;
import io.cubyz.world.*; import io.cubyz.world.*;
@ -14,8 +15,8 @@ public class Structures {
public static void generateTree(Chunk ch, int x, int y, int z) { public static void generateTree(Chunk ch, int x, int y, int z) {
//Instances //Instances
Block wood = ModLoader.block_registry.getByID("cubz:oak_log"); Block wood = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_log");
Block leaves = ModLoader.block_registry.getByID("cubz:oak_leaves"); Block leaves = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_leaves");
//Position of the first block of wood //Position of the first block of wood
int height = 7 + random.nextInt(5); int height = 7 + random.nextInt(5);