diff --git a/cubyz-client/assets/cubyz/models/block.json b/cubyz-client/assets/cubyz/models/block.json index d9b12c2c..6125664f 100644 --- a/cubyz-client/assets/cubyz/models/block.json +++ b/cubyz-client/assets/cubyz/models/block.json @@ -1,3 +1,4 @@ { - "model": "base:models/3d/block.obj" + "model": "block.obj", // appended to "base:models/3d/" + "texture": "" } \ No newline at end of file diff --git a/cubyz-client/src/io/cubyz/client/Cubyz.java b/cubyz-client/src/io/cubyz/client/Cubyz.java index 5414f710..85f8d47b 100644 --- a/cubyz-client/src/io/cubyz/client/Cubyz.java +++ b/cubyz-client/src/io/cubyz/client/Cubyz.java @@ -33,7 +33,8 @@ import org.reflections.Reflections; import io.cubyz.ClientOnly; 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.Mod; import io.cubyz.blocks.Block; @@ -74,7 +75,7 @@ public class Cubyz implements IGameLogic { private int breakCooldown = 10; - public static Logger log = CubzLogger.i; + public static Logger log = CubyzLogger.i; public static String serverIP = "localhost"; public static int serverPort = 58961; @@ -104,7 +105,7 @@ public class Cubyz implements IGameLogic { @Override public void cleanup() { renderer.cleanup(); - CubzLogger.i.getHandlers()[0].close(); + log.getHandlers()[0].close(); DiscordIntegration.closeRPC(); } @@ -203,7 +204,7 @@ public class Cubyz implements IGameLogic { }; // client-side init - for (IRegistryElement ire : ModLoader.block_registry.registered()) { + for (IRegistryElement ire : CubzRegistries.BLOCK_REGISTRY.registered()) { Block b = (Block) ire; b.setBlockPair(new ClientBlockPair()); ClientOnly.createBlockMesh.accept(b); diff --git a/cubyz-client/src/io/cubyz/client/GameLauncher.java b/cubyz-client/src/io/cubyz/client/GameLauncher.java index bc839827..cc0f5d06 100644 --- a/cubyz-client/src/io/cubyz/client/GameLauncher.java +++ b/cubyz-client/src/io/cubyz/client/GameLauncher.java @@ -2,6 +2,7 @@ package io.cubyz.client; import org.jungle.game.Game; import org.jungle.game.GameOptions; +import org.jungle.game.GameOptionsPrompt; public class GameLauncher extends Game { @@ -11,20 +12,20 @@ public class GameLauncher extends Game { GameLauncher.instance = new GameLauncher(); instance.logic = new Cubyz(); -// GameOptionsPrompt prompt = new GameOptionsPrompt(); -// prompt.setLocationRelativeTo(null); -// prompt.setVisible(true); -// while (prompt.isVisible()) { -// System.out.print(""); // Avoid bugs -// } -// -// GameOptions opt = prompt.generateOptions(); + GameOptionsPrompt prompt = new GameOptionsPrompt(); + prompt.setLocationRelativeTo(null); + prompt.setVisible(true); + while (prompt.isVisible()) { + System.out.print(""); // Avoid bugs + } - GameOptions opt = new GameOptions(); - opt.antialiasing = false; - opt.frustumCulling = true; - opt.showTriangles = false; - opt.cullFace = true; + GameOptions opt = prompt.generateOptions(); + +// GameOptions opt = new GameOptions(); +// opt.antialiasing = false; +// opt.frustumCulling = true; +// opt.showTriangles = false; +// opt.cullFace = true; instance.start(opt); Cubyz.log.info("Stopped!"); diff --git a/cubyz-client/src/io/cubyz/client/loading/LoadThread.java b/cubyz-client/src/io/cubyz/client/loading/LoadThread.java index ec7bb603..3cedced1 100644 --- a/cubyz-client/src/io/cubyz/client/loading/LoadThread.java +++ b/cubyz-client/src/io/cubyz/client/loading/LoadThread.java @@ -2,7 +2,6 @@ package io.cubyz.client.loading; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -10,8 +9,18 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.Set; +import javax.swing.text.Utilities; + 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 { static int i = -1; @@ -19,7 +28,7 @@ public class LoadThread extends Thread { public void run() { LoadingGUI l = LoadingGUI.getInstance(); - CubzLogger log = (CubzLogger) Cubz.log; + CubzLogger log = CubzLogger.instance; l.setStep(1, 0, 0); // RPC temporaly disabled @@ -39,7 +48,7 @@ public class LoadThread extends Thread { ArrayList mods = new ArrayList<>(); ArrayList modSearchPath = new ArrayList<>(); 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 modUrl = new ArrayList<>(); 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()); log.info("Seeking mods.."); try { - Enumeration urls = loader.findResources("CubeComputers"); - System.out.println("URLs"); - while (urls.hasMoreElements()) { - URL url = urls.nextElement(); - System.out.println("URL - " + url); - } + //Enumeration urls = loader.findResources("CubeComputers"); + //System.out.println("URLs"); + //while (urls.hasMoreElements()) { + // URL url = urls.nextElement(); + // System.out.println("URL - " + url); + //} } catch (IOException e1) { e1.printStackTrace(); } @@ -86,12 +95,13 @@ public class LoadThread extends Thread { } log.info("Mod list complete"); + // TODO re-add pre-init l.setStep(2, 0, mods.size()); for (int i = 0; i < mods.size(); i++) { l.setStep(2, i+1, mods.size()); Object mod = mods.get(i); log.info("Pre-initiating " + mod); - ModLoader.preInit(mod); + //ModLoader.preInit(mod); } // 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()))); //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() { public void run() { i++; - Block b = (Block) ModLoader.block_registry.registered()[i]; - System.out.println("Creating mesh of " + b.getFullID()); + Block b = (Block) CubzRegistries.BLOCK_REGISTRY.registered()[i]; + System.out.println("Creating mesh of " + b.getRegistryID()); BlockInstance bi = new BlockInstance(b); bi.getMesh(); - if (i < ModLoader.block_registry.registered().length-1) { - Cubz.renderDeque.add(run); - l.setStep(4, i+1, ModLoader.block_registry.registered().length); + if (i < CubzRegistries.BLOCK_REGISTRY.registered().length-1) { + //Cubz.renderDeque.add(run); + l.setStep(4, i+1, CubzRegistries.BLOCK_REGISTRY.registered().length); } else { l.finishLoading(); } } }; - Cubz.renderDeque.add(run); + //Cubz.renderDeque.add(run); System.gc(); } diff --git a/cubyz-client/src/io/cubyz/ui/NGraphics.java b/cubyz-client/src/io/cubyz/ui/NGraphics.java index 16a85b56..0abb0b31 100644 --- a/cubyz-client/src/io/cubyz/ui/NGraphics.java +++ b/cubyz-client/src/io/cubyz/ui/NGraphics.java @@ -11,7 +11,7 @@ import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; import org.lwjgl.nanovg.NanoVG; -import io.cubyz.CubzLogger; +import io.cubyz.CubyzLogger; public class NGraphics { @@ -20,7 +20,7 @@ public class NGraphics { private static NVGPaint imagePaint = NVGPaint.create(); 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; @@ -30,7 +30,7 @@ public class NGraphics { public static int loadImage(String path) { if (LOG_OPERATIONS) - CubzLogger.instance.fine("[NGRAPHICS] Load Image " + path); + CubyzLogger.instance.fine("[NGRAPHICS] Load Image " + path); return nvgCreateImage(nvg, path, 0); } @@ -44,7 +44,7 @@ public class NGraphics { public static void fillCircle(int x, int y, int radius) { 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); nvgCircle(nvg, x, y, radius); nvgFillColor(nvg, color); @@ -53,7 +53,7 @@ public class NGraphics { public static void drawRect(int x, int y, int width, int height) { 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); nvgRect(nvg, x, y, width, height); nvgStrokeColor(nvg, color); @@ -62,7 +62,7 @@ public class NGraphics { public static void fillRect(int x, int y, int width, int height) { 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); nvgRect(nvg, x, y, width, height); nvgFillColor(nvg, color); @@ -99,7 +99,7 @@ public class NGraphics { public static void drawText(int x, int y, String text) { 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()); nvgFontFaceId(nvg, font.getNVGId()); nvgTextAlign(nvg, textAlign); diff --git a/cubyz-client/src/io/cubyz/ui/ToastManager.java b/cubyz-client/src/io/cubyz/ui/ToastManager.java index 8b16106a..21ba2db1 100644 --- a/cubyz-client/src/io/cubyz/ui/ToastManager.java +++ b/cubyz-client/src/io/cubyz/ui/ToastManager.java @@ -1,8 +1,19 @@ package io.cubyz.ui; -import org.jungle.Window; +import java.util.Deque; public class ToastManager { + public static Deque queuedToasts; + + public static class Toast { + public String title; + public String text; + + public Toast(String title, String text) { + this.title = title; + this.text = text; + } + } } diff --git a/cubyz-client/src/io/cubyz/utils/DiscordIntegration.java b/cubyz-client/src/io/cubyz/utils/DiscordIntegration.java index f170229a..a6cb5cad 100644 --- a/cubyz-client/src/io/cubyz/utils/DiscordIntegration.java +++ b/cubyz-client/src/io/cubyz/utils/DiscordIntegration.java @@ -4,10 +4,12 @@ import java.util.Random; import club.minnced.discord.rpc.DiscordEventHandlers; import club.minnced.discord.rpc.DiscordEventHandlers.OnReady; -import io.cubyz.client.Cubyz; import club.minnced.discord.rpc.DiscordRPC; import club.minnced.discord.rpc.DiscordRichPresence; 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 { @@ -19,6 +21,7 @@ public class DiscordIntegration { } public static void startRPC() { + DiscordRPC lib = DiscordRPC.INSTANCE; String appID = "527033701343952896"; String steamID = ""; @@ -26,20 +29,20 @@ public class DiscordIntegration { handlers.ready = new OnReady() { @Override - public void accept(DiscordUser arg0) { - System.out.println("Ready as user " + arg0.username); + public void accept(DiscordUser user) { + ToastManager.queuedToasts.push(new Toast("Discord Integration", user.username + " is linked to you!")); } }; handlers.joinGame = (secret) -> { - String serverIP = secret.split(":")[0]; //NOTE: Normal > 0 + String serverIP = secret.split(":")[0]; int serverPort = Integer.parseInt(secret.split(":")[1]); System.out.println("Attempting to join server " + serverIP + " at port " + serverPort); Cubyz.requestJoin(serverIP, serverPort); }; 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) { lib.Discord_Respond(user.userId, DiscordRPC.DISCORD_REPLY_YES); } else { @@ -66,7 +69,7 @@ public class DiscordIntegration { presence.partyId = generatePartyID(); - setStatus("No status."); + setStatus("Just started"); lib.Discord_UpdatePresence(presence); @@ -74,7 +77,7 @@ public class DiscordIntegration { while (!Thread.currentThread().isInterrupted()) { lib.Discord_RunCallbacks(); try { - Thread.sleep(2000L); //NOTE: Normal > 2000L + Thread.sleep(2000); } catch (InterruptedException ignored) { break; } @@ -93,15 +96,15 @@ public class DiscordIntegration { if (Cubyz.isIntegratedServer) { presence.state = "Singleplayer"; //presence.joinSecret = null; - //presence.partySize = 0; //NOTE: Normal > 0 + //presence.partySize = 0; } else { if (Cubyz.isOnlineServerOpened) { presence.state = "Join me ;)"; - presence.partyMax = 50; // temporary || NOTE: Normal > 50 + presence.partyMax = 50; // temporary } else { presence.state = "Multiplayer"; - presence.partyMax = 50; // temporary || NOTE: Normal > 50 + presence.partyMax = 50; // temporary } } DiscordRPC.INSTANCE.Discord_UpdatePresence(presence); diff --git a/cubyz-client/src/io/cubyz/world/RemoteWorld.java b/cubyz-client/src/io/cubyz/world/RemoteWorld.java index 0a8f276c..e1be2345 100644 --- a/cubyz-client/src/io/cubyz/world/RemoteWorld.java +++ b/cubyz-client/src/io/cubyz/world/RemoteWorld.java @@ -8,6 +8,7 @@ import io.cubyz.blocks.BlockInstance; import io.cubyz.entity.Entity; import io.cubyz.entity.Player; +// TODO public class RemoteWorld extends World { @Override @@ -24,22 +25,12 @@ public class RemoteWorld extends World { public void markEdit() { } - + @Override public Player getLocalPlayer() { return null; } - @Override - public int getWidth() { - return 0; //NOTE: Normal > 0 - } - - @Override - public int getDepth() { - return 0; //NOTE: Normal > 0 - } - @Override public Map> visibleBlocks() { return null; @@ -65,19 +56,16 @@ public class RemoteWorld extends World { @Override 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 public void seek(int x, int z) { - // TODO Auto-generated method stub } @Override public void synchronousSeek(int x, int z) { - // TODO Auto-generated method stub } diff --git a/cubyz-common/src/io/cubyz/Constants.java b/cubyz-common/src/io/cubyz/Constants.java index 250c7c71..fec8c3c8 100644 --- a/cubyz-common/src/io/cubyz/Constants.java +++ b/cubyz-common/src/io/cubyz/Constants.java @@ -4,7 +4,8 @@ import io.cubyz.api.Side; 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"; static Side currentSide = null; diff --git a/cubyz-common/src/io/cubyz/CubzLogger.java b/cubyz-common/src/io/cubyz/CubyzLogger.java similarity index 93% rename from cubyz-common/src/io/cubyz/CubzLogger.java rename to cubyz-common/src/io/cubyz/CubyzLogger.java index 15771c4f..7ebe322a 100644 --- a/cubyz-common/src/io/cubyz/CubzLogger.java +++ b/cubyz-common/src/io/cubyz/CubyzLogger.java @@ -14,20 +14,20 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -public class CubzLogger extends Logger { +public class CubyzLogger extends Logger { public static boolean useDefaultHandler = false; /** * Same as instance */ - public static CubzLogger i; // instance - public static CubzLogger instance; + public static CubyzLogger i; // instance + public static CubyzLogger instance; static { - new CubzLogger(); + new CubyzLogger(); } - protected CubzLogger() { + protected CubyzLogger() { super("Cubz", null); setUseParentHandlers(true); this.setParent(Logger.getGlobal()); diff --git a/cubyz-common/src/io/cubyz/api/CubzRegistries.java b/cubyz-common/src/io/cubyz/api/CubzRegistries.java new file mode 100644 index 00000000..fececb01 --- /dev/null +++ b/cubyz-common/src/io/cubyz/api/CubzRegistries.java @@ -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_REGISTRY = new Registry(); + public static final Registry ITEM_REGISTRY = new Registry(); + public static final Registry ENTITY_REGISTRY = new Registry(); + +} diff --git a/cubyz-common/src/io/cubyz/api/Registry.java b/cubyz-common/src/io/cubyz/api/Registry.java index dd06e1c6..a464a0b7 100644 --- a/cubyz-common/src/io/cubyz/api/Registry.java +++ b/cubyz-common/src/io/cubyz/api/Registry.java @@ -3,10 +3,12 @@ package io.cubyz.api; import java.util.HashMap; import java.util.List; +import io.cubyz.CubyzLogger; + public class Registry { private HashMap 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")); public IRegistryElement[] registered() { // can be casted to T @@ -35,7 +37,7 @@ public class Registry { } hashMap.put(element.getRegistryID().toString(), element); if (debug) { - //Cubyz.log.info("Registered " + getType(element.getClass()) + " as " + element.getFullID()); + CubyzLogger.instance.info("Registered " + getType(element.getClass()) + " as " + element.getRegistryID()); } } diff --git a/cubyz-common/src/io/cubyz/api/base/BaseMod.java b/cubyz-common/src/io/cubyz/api/base/BaseMod.java index 036a1a59..3f07f234 100644 --- a/cubyz-common/src/io/cubyz/api/base/BaseMod.java +++ b/cubyz-common/src/io/cubyz/api/base/BaseMod.java @@ -77,6 +77,7 @@ public class BaseMod { // Register reg.registerAll(bedrock, grass, dirt, oakLeaves, oakLog, sand, stone, coal, diamond, emerald, gold, iron, ruby, water); + System.out.println("Added all"); } } diff --git a/cubyz-common/src/io/cubyz/blocks/Bedrock.java b/cubyz-common/src/io/cubyz/blocks/Bedrock.java index 478f6788..4d0a673a 100644 --- a/cubyz-common/src/io/cubyz/blocks/Bedrock.java +++ b/cubyz-common/src/io/cubyz/blocks/Bedrock.java @@ -4,7 +4,7 @@ public class Bedrock extends Block { public Bedrock() { setTexture("bedrock"); - setID("cubz:bedrock"); + setID("cubyz:bedrock"); setUnbreakable(); } diff --git a/cubyz-common/src/io/cubyz/blocks/CoalOre.java b/cubyz-common/src/io/cubyz/blocks/CoalOre.java index e9b399d6..d04e0971 100644 --- a/cubyz-common/src/io/cubyz/blocks/CoalOre.java +++ b/cubyz-common/src/io/cubyz/blocks/CoalOre.java @@ -4,7 +4,7 @@ public class CoalOre extends Ore { public CoalOre() { setTexture("coal_ore"); - setID("cubz:coal_ore"); + setID("cubyz:coal_ore"); setHeight(127); setChance(0.02F); } diff --git a/cubyz-common/src/io/cubyz/blocks/DiamondOre.java b/cubyz-common/src/io/cubyz/blocks/DiamondOre.java index 50732827..bf1318f5 100644 --- a/cubyz-common/src/io/cubyz/blocks/DiamondOre.java +++ b/cubyz-common/src/io/cubyz/blocks/DiamondOre.java @@ -4,7 +4,7 @@ public class DiamondOre extends Ore { public DiamondOre() { setTexture("diamond_ore"); - setID("cubz:diamond_ore"); + setID("cubyz:diamond_ore"); setHeight(15); setChance(0.002F); } diff --git a/cubyz-common/src/io/cubyz/blocks/Dirt.java b/cubyz-common/src/io/cubyz/blocks/Dirt.java index 49ea2599..c91a6f7e 100644 --- a/cubyz-common/src/io/cubyz/blocks/Dirt.java +++ b/cubyz-common/src/io/cubyz/blocks/Dirt.java @@ -4,7 +4,7 @@ public class Dirt extends Block { public Dirt() { setTexture("dirt"); - setID("cubz:dirt"); + setID("cubyz:dirt"); } } \ No newline at end of file diff --git a/cubyz-common/src/io/cubyz/blocks/EmeraldOre.java b/cubyz-common/src/io/cubyz/blocks/EmeraldOre.java index dccfae7b..e0eb5d44 100644 --- a/cubyz-common/src/io/cubyz/blocks/EmeraldOre.java +++ b/cubyz-common/src/io/cubyz/blocks/EmeraldOre.java @@ -4,7 +4,7 @@ public class EmeraldOre extends Ore { public EmeraldOre() { setTexture("emerald_ore"); - setID("cubz:emerald_ore"); + setID("cubyz:emerald_ore"); setHeight(25); setChance(0.001F); } diff --git a/cubyz-common/src/io/cubyz/blocks/GoldOre.java b/cubyz-common/src/io/cubyz/blocks/GoldOre.java index f4d62224..e08c3db1 100644 --- a/cubyz-common/src/io/cubyz/blocks/GoldOre.java +++ b/cubyz-common/src/io/cubyz/blocks/GoldOre.java @@ -4,7 +4,7 @@ public class GoldOre extends Ore { public GoldOre() { setTexture("gold_ore"); - setID("cubz:gold_ore"); + setID("cubyz:gold_ore"); setHeight(32); setChance(0.005F); } diff --git a/cubyz-common/src/io/cubyz/blocks/Grass.java b/cubyz-common/src/io/cubyz/blocks/Grass.java index 0d1c72f9..e7667d64 100644 --- a/cubyz-common/src/io/cubyz/blocks/Grass.java +++ b/cubyz-common/src/io/cubyz/blocks/Grass.java @@ -5,7 +5,7 @@ public class Grass extends Block { public Grass() { setTexture("grassblock"); - setID("cubz:grass"); + setID("cubyz:grass"); texConverted = true; // texture arleady in runtime format } diff --git a/cubyz-common/src/io/cubyz/blocks/IronOre.java b/cubyz-common/src/io/cubyz/blocks/IronOre.java index 78b397e6..8d70cfbe 100644 --- a/cubyz-common/src/io/cubyz/blocks/IronOre.java +++ b/cubyz-common/src/io/cubyz/blocks/IronOre.java @@ -4,7 +4,7 @@ public class IronOre extends Ore { public IronOre() { setTexture("iron_ore"); - setID("cubz:iron_ore"); + setID("cubyz:iron_ore"); setHeight(63); setChance(0.03F); } diff --git a/cubyz-common/src/io/cubyz/blocks/OakLeaves.java b/cubyz-common/src/io/cubyz/blocks/OakLeaves.java index 7dffdf12..18463f3e 100644 --- a/cubyz-common/src/io/cubyz/blocks/OakLeaves.java +++ b/cubyz-common/src/io/cubyz/blocks/OakLeaves.java @@ -4,7 +4,7 @@ public class OakLeaves extends Block { public OakLeaves() { setTexture("oak_leaves"); - setID("cubz:oak_leaves"); + setID("cubyz:oak_leaves"); } public void update() { diff --git a/cubyz-common/src/io/cubyz/blocks/OakLog.java b/cubyz-common/src/io/cubyz/blocks/OakLog.java index 601eba6e..fefeba9f 100644 --- a/cubyz-common/src/io/cubyz/blocks/OakLog.java +++ b/cubyz-common/src/io/cubyz/blocks/OakLog.java @@ -4,7 +4,7 @@ public class OakLog extends Block { public OakLog() { setTexture("oak_log"); - setID("cubz:oak_log"); + setID("cubyz:oak_log"); } } \ No newline at end of file diff --git a/cubyz-common/src/io/cubyz/blocks/RubyOre.java b/cubyz-common/src/io/cubyz/blocks/RubyOre.java index 24924fe4..c25a12ea 100644 --- a/cubyz-common/src/io/cubyz/blocks/RubyOre.java +++ b/cubyz-common/src/io/cubyz/blocks/RubyOre.java @@ -4,7 +4,7 @@ public class RubyOre extends Ore { public RubyOre() { setTexture("ruby_ore"); - setID("cubz:ruby_ore"); + setID("cubyz:ruby_ore"); setHeight(8); setChance(0.006F); } diff --git a/cubyz-common/src/io/cubyz/blocks/Sand.java b/cubyz-common/src/io/cubyz/blocks/Sand.java index 480b05bf..aefda69a 100644 --- a/cubyz-common/src/io/cubyz/blocks/Sand.java +++ b/cubyz-common/src/io/cubyz/blocks/Sand.java @@ -4,7 +4,7 @@ public class Sand extends Block { public Sand() { setTexture("sand"); - setID("cubz:sand"); + setID("cubyz:sand"); } } \ No newline at end of file diff --git a/cubyz-common/src/io/cubyz/blocks/Stone.java b/cubyz-common/src/io/cubyz/blocks/Stone.java index c506e2c4..67797e4a 100644 --- a/cubyz-common/src/io/cubyz/blocks/Stone.java +++ b/cubyz-common/src/io/cubyz/blocks/Stone.java @@ -4,7 +4,7 @@ public class Stone extends Block { public Stone() { setTexture("stone"); - setID("cubz:stone"); + setID("cubyz:stone"); } } \ No newline at end of file diff --git a/cubyz-common/src/io/cubyz/blocks/Water.java b/cubyz-common/src/io/cubyz/blocks/Water.java index a7ef149a..7c8572a5 100644 --- a/cubyz-common/src/io/cubyz/blocks/Water.java +++ b/cubyz-common/src/io/cubyz/blocks/Water.java @@ -4,7 +4,7 @@ public class Water extends Block { public Water() { setTexture("water"); - setID("cubz:water"); + setID("cubyz:water"); } } diff --git a/cubyz-common/src/io/cubyz/entity/Entity.java b/cubyz-common/src/io/cubyz/entity/Entity.java index ae99d2e5..e6a84ba9 100644 --- a/cubyz-common/src/io/cubyz/entity/Entity.java +++ b/cubyz-common/src/io/cubyz/entity/Entity.java @@ -11,21 +11,24 @@ import io.cubyz.world.World; public abstract class Entity { - protected String registryName; - protected float entitySpeed; protected World world; - protected AABBf aabb = new AABBf(); protected Vector3f position = new Vector3f(); protected Vector3f rotation = new Vector3f(); public float vx, vy, vz; protected IRenderablePair renderPair; + private EntityType type; + protected int width = 1, height = 2, depth = 1; - public float getSpeed() { - return entitySpeed; + public Entity(EntityType type) { + this.type = type; + } + + public EntityType getType() { + return type; } public World getWorld() { @@ -35,14 +38,6 @@ public abstract class Entity { public void setWorld(World world) { this.world = world; } - - public String getRegistryName() { - return registryName; - } - - public void setRegistryName(String registryName) { - this.registryName = registryName; - } public Vector3f getPosition() { return position; @@ -215,13 +210,6 @@ public abstract class Entity { } 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) { Consumer upd = (Consumer) renderPair.get("renderPairUpdate"); upd.accept(this); diff --git a/cubyz-common/src/io/cubyz/entity/EntityType.java b/cubyz-common/src/io/cubyz/entity/EntityType.java index c5232618..7f7e7403 100644 --- a/cubyz-common/src/io/cubyz/entity/EntityType.java +++ b/cubyz-common/src/io/cubyz/entity/EntityType.java @@ -3,5 +3,7 @@ package io.cubyz.entity; import io.cubyz.api.IRegistryElement; public abstract class EntityType implements IRegistryElement { - // nothing needed more than IRegistryElement's methods + + public abstract Entity newEntity(); + } diff --git a/cubyz-common/src/io/cubyz/entity/Player.java b/cubyz-common/src/io/cubyz/entity/Player.java index 89a74b6a..a1d8b3e4 100644 --- a/cubyz-common/src/io/cubyz/entity/Player.java +++ b/cubyz-common/src/io/cubyz/entity/Player.java @@ -4,6 +4,7 @@ import org.joml.AABBf; import org.joml.Vector3f; import org.joml.Vector3i; +import io.cubyz.api.CubzRegistries; import io.cubyz.command.ICommandSource; //NOTE: Player is 2 Blocks Tall (2 Meters) @@ -21,6 +22,7 @@ public class Player extends Entity implements ICommandSource { } public Player(boolean local) { + super(CubzRegistries.ENTITY_REGISTRY.getByID("cubyz:")); this.local = local; // try { // mesh = loadMesh("uglyplayer"); @@ -32,7 +34,6 @@ public class Player extends Entity implements ICommandSource { // } // spatial = new Spatial(mesh); // spatial.setScale(0.5F); - setRegistryName("cubz:player"); } public boolean isLocal() { diff --git a/cubyz-common/src/io/cubyz/modding/ModLoader.java b/cubyz-common/src/io/cubyz/modding/ModLoader.java index b2eadfa7..52d06007 100644 --- a/cubyz-common/src/io/cubyz/modding/ModLoader.java +++ b/cubyz-common/src/io/cubyz/modding/ModLoader.java @@ -4,7 +4,8 @@ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; 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.Registry; 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 public class ModLoader { - - public static Registry block_registry = new Registry(); - public static Registry item_registry = new Registry(); - public static Registry entity_registry = new Registry(); public static boolean isCorrectSide(Side currentSide, Method method) { boolean haveAnnot = false; @@ -42,7 +39,7 @@ public class ModLoader { for (Method m : cl.getMethods()) { if (m.isAnnotationPresent(EventHandler.class)) { if (isCorrectSide(side, m)) { - if (m.getAnnotation(EventHandler.class).type().equals("init")) { + if (m.getAnnotation(EventHandler.class).type().equals(eventType)) { return m; } } @@ -55,7 +52,7 @@ public class ModLoader { Class cl = mod.getClass(); for (Method m : cl.getMethods()) { if (m.isAnnotationPresent(EventHandler.class)) { - if (m.getAnnotation(EventHandler.class).type().equals("init")) { + if (m.getAnnotation(EventHandler.class).type().equals(eventType)) { return m; } } @@ -65,46 +62,38 @@ public class ModLoader { public static void init(Object mod) { commonRegister(mod); - Class cl = mod.getClass(); 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 { m.invoke(o, args); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 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(); } else { e.printStackTrace(); } System.err.flush(); if (imp) { - // fast exit - //Cubz.instance.cleanup(); - System.exit(1); //NOTE: Normal > 1 + System.exit(1); } } } public static void commonRegister(Object mod) { - Class cl = mod.getClass(); - for (Method m : cl.getMethods()) { - if (m.isAnnotationPresent(EventHandler.class)) { - if (isCorrectSide(Side.SERVER, m)) { - if (m.getAnnotation(EventHandler.class).type().equals("block/register")) { - safeMethodInvoke(true, m, mod, block_registry); - } - if (m.getAnnotation(EventHandler.class).type().equals("item/register")) { - safeMethodInvoke(true, m, mod, item_registry); - } - if (m.getAnnotation(EventHandler.class).type().equals("entity/register")) { - safeMethodInvoke(true, m, mod, entity_registry); - } - } - } - } + Method block_method = eventHandlerMethod(mod, "block/register"); + Method item_method = eventHandlerMethod(mod, "item/register"); + Method entity_method = eventHandlerMethod(mod, "entity/register"); + + // invoke + if (block_method != null) + safeMethodInvoke(true, block_method, mod, CubzRegistries.BLOCK_REGISTRY); + if (item_method != null) + safeMethodInvoke(true, item_method, mod, CubzRegistries.ITEM_REGISTRY); + if (entity_method != null) + safeMethodInvoke(true, entity_method, mod, CubzRegistries.ENTITY_REGISTRY); } } diff --git a/cubyz-common/src/io/cubyz/save/EntityIO.java b/cubyz-common/src/io/cubyz/save/EntityIO.java index 2556f90a..350b7600 100644 --- a/cubyz-common/src/io/cubyz/save/EntityIO.java +++ b/cubyz-common/src/io/cubyz/save/EntityIO.java @@ -10,7 +10,7 @@ public class EntityIO { 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) - out.writeUTF(ent.getRegistryName()); + out.writeUTF(ent.getType().getRegistryID().toString()); out.writeDouble(ent.getPosition().x); out.writeDouble(ent.getPosition().y); out.writeDouble(ent.getPosition().z); @@ -23,7 +23,7 @@ public class EntityIO { } public static Entity loadEntity(DataInputStream dis) throws IOException { - + return null; } } diff --git a/cubyz-common/src/io/cubyz/world/Chunk.java b/cubyz-common/src/io/cubyz/world/Chunk.java index c661d4ef..58b3f262 100644 --- a/cubyz-common/src/io/cubyz/world/Chunk.java +++ b/cubyz-common/src/io/cubyz/world/Chunk.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import org.joml.Vector3i; +import io.cubyz.api.CubzRegistries; +import io.cubyz.api.Registry; import io.cubyz.blocks.Block; import io.cubyz.blocks.BlockInstance; import io.cubyz.blocks.Ore; @@ -17,26 +19,28 @@ public class Chunk { private boolean generated; private boolean loaded; + private static Registry br = CubzRegistries.BLOCK_REGISTRY; // shortcut to BLOCK_REGISTRY + // Normal: - private static Block grass = ModLoader.block_registry.getByID("cubz:grass"); - private static Block sand = ModLoader.block_registry.getByID("cubz:sand"); - private static Block dirt = ModLoader.block_registry.getByID("cubz:dirt"); - private static Block stone = ModLoader.block_registry.getByID("cubz:stone"); - private static Block bedrock = ModLoader.block_registry.getByID("cubz:bedrock"); + private static Block grass = br.getByID("cubyz:grass"); + private static Block sand = br.getByID("cubyz:sand"); + private static Block dirt = br.getByID("cubyz:dirt"); + private static Block stone = br.getByID("cubyz:stone"); + private static Block bedrock = br.getByID("cubyz:bedrock"); // Ores: private static ArrayList ores = new ArrayList<>(); static { - ores.add((Ore) ModLoader.block_registry.getByID("cubz:coal_ore")); - ores.add((Ore) ModLoader.block_registry.getByID("cubz:iron_ore")); - ores.add((Ore) ModLoader.block_registry.getByID("cubz:ruby_ore")); - ores.add((Ore) ModLoader.block_registry.getByID("cubz:gold_ore")); - ores.add((Ore) ModLoader.block_registry.getByID("cubz:diamond_ore")); - ores.add((Ore) ModLoader.block_registry.getByID("cubz:emerald_ore")); + ores.add((Ore) br.getByID("cubyz:coal_ore")); + ores.add((Ore) br.getByID("cubyz:iron_ore")); + ores.add((Ore) br.getByID("cubyz:ruby_ore")); + ores.add((Ore) br.getByID("cubyz:gold_ore")); + ores.add((Ore) br.getByID("cubyz:diamond_ore")); + ores.add((Ore) br.getByID("cubyz:emerald_ore")); } // 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; @@ -150,6 +154,7 @@ public class Chunk { for (int py = 0; py < 16; py++) { float value = map[px][py]; 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--) { BlockInstance bi = null; if(j > y) { diff --git a/cubyz-common/src/io/cubyz/world/LocalWorld.java b/cubyz-common/src/io/cubyz/world/LocalWorld.java index 0d69c5b5..99bd687f 100644 --- a/cubyz-common/src/io/cubyz/world/LocalWorld.java +++ b/cubyz-common/src/io/cubyz/world/LocalWorld.java @@ -9,7 +9,8 @@ import java.util.HashMap; import java.util.Map; 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.blocks.Block; import io.cubyz.blocks.BlockInstance; @@ -37,11 +38,16 @@ public class LocalWorld extends World { private class ChunkGenerationThread extends Thread { Deque loadList = new ArrayDeque<>(); // FIFO order (First In, First Out) + private static final int MAX_QUEUE_SIZE = 8; public void queue(ChunkAction 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); } } @@ -64,7 +70,7 @@ public class LocalWorld extends World { if (!loadList.isEmpty()) { ChunkAction popped = loadList.pop(); 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); popped.chunk.load(); } @@ -74,7 +80,7 @@ public class LocalWorld extends World { } } 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()) { Block b = bi.getBlock(); visibleSpatials.get(b).remove(bi); @@ -229,7 +235,7 @@ public class LocalWorld extends World { public void generate() { Random r = new Random(); seed = r.nextInt(); - for (IRegistryElement ire : ModLoader.block_registry.registered()) { + for (IRegistryElement ire : CubzRegistries.BLOCK_REGISTRY.registered()) { Block b = (Block) ire; visibleSpatials.put(b, new ArrayList<>()); } diff --git a/cubyz-common/src/io/cubyz/world/Structures.java b/cubyz-common/src/io/cubyz/world/Structures.java index 10525f64..83949740 100644 --- a/cubyz-common/src/io/cubyz/world/Structures.java +++ b/cubyz-common/src/io/cubyz/world/Structures.java @@ -1,5 +1,6 @@ package io.cubyz.world; +import io.cubyz.api.CubzRegistries; import io.cubyz.blocks.*; import io.cubyz.modding.ModLoader; import io.cubyz.world.*; @@ -14,8 +15,8 @@ public class Structures { public static void generateTree(Chunk ch, int x, int y, int z) { //Instances - Block wood = ModLoader.block_registry.getByID("cubz:oak_log"); - Block leaves = ModLoader.block_registry.getByID("cubz:oak_leaves"); + Block wood = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_log"); + Block leaves = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_leaves"); //Position of the first block of wood int height = 7 + random.nextInt(5);