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.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);

View File

@ -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!");

View File

@ -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<Object> mods = new ArrayList<>();
ArrayList<File> 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<URL> 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<URL> urls = loader.findResources("CubeComputers");
System.out.println("URLs");
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
System.out.println("URL - " + url);
}
//Enumeration<URL> 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();
}

View File

@ -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);

View File

@ -1,8 +1,19 @@
package io.cubyz.ui;
import org.jungle.Window;
import java.util.Deque;
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.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);

View File

@ -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<Block, ArrayList<BlockInstance>> 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
}

View File

@ -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;

View File

@ -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 <code>instance</code>
*/
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());

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.List;
import io.cubyz.CubyzLogger;
public class Registry<T extends IRegistryElement> {
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"));
public IRegistryElement[] registered() { // can be casted to T
@ -35,7 +37,7 @@ public class Registry<T extends IRegistryElement> {
}
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());
}
}

View File

@ -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");
}
}

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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() {

View File

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

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

@ -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<Entity> upd = (Consumer<Entity>) renderPair.get("renderPairUpdate");
upd.accept(this);

View File

@ -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();
}

View File

@ -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() {

View File

@ -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> 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) {
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);
}
}

View File

@ -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;
}
}

View File

@ -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<Block> 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<Ore> 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) {

View File

@ -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<ChunkAction> 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<>());
}

View File

@ -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);