diff --git a/src/main/java/dev/hilligans/ourcraft/ClientMain.java b/src/main/java/dev/hilligans/ourcraft/ClientMain.java index 1ada1230..6c2fb689 100644 --- a/src/main/java/dev/hilligans/ourcraft/ClientMain.java +++ b/src/main/java/dev/hilligans/ourcraft/ClientMain.java @@ -13,12 +13,7 @@ public class ClientMain { - public static Client client; - - public static Client getClient() { - return client; - } - public static GameInstance gameInstance = Ourcraft.GAME_INSTANCE; + //public static GameInstance gameInstance = Ourcraft.GAME_INSTANCE; public static ArgumentContainer argumentContainer; @@ -29,7 +24,10 @@ public static Client getClient() { public static void main(String[] args) throws IOException { startTime = System.currentTimeMillis(); argumentContainer = new ArgumentContainer(args); + System.out.println(STR."Starting client with PID \{ProcessHandle.current().pid()}"); + + GameInstance gameInstance = Ourcraft.GAME_INSTANCE; gameInstance.handleArgs(args); gameInstance.side = Side.CLIENT; gameInstance.loadContent(); @@ -38,18 +36,22 @@ public static void main(String[] args) throws IOException { try { Thread thread = new Thread(() -> ServerMain.server(gameInstance, argumentContainer)); thread.setName("Server-Thread"); + thread.setDaemon(true); thread.start(); } catch (Exception e) { e.printStackTrace(); } } - client = new Client(gameInstance, argumentContainer); + Client client = new Client(gameInstance, argumentContainer); + Client client1 = new Client(gameInstance, argumentContainer); String graphicsEngine = argumentContainer.getString("--graphicsEngine", null); if(graphicsEngine != null) { System.out.println(graphicsEngine); client.setGraphicsEngine(gameInstance.GRAPHICS_ENGINES.get(graphicsEngine)); + client1.setGraphicsEngine(gameInstance.GRAPHICS_ENGINES.get(graphicsEngine)); } + client1.setupClient(); client.startClient(); } } diff --git a/src/main/java/dev/hilligans/ourcraft/Ourcraft.java b/src/main/java/dev/hilligans/ourcraft/Ourcraft.java index 17e92d59..56cd5309 100644 --- a/src/main/java/dev/hilligans/ourcraft/Ourcraft.java +++ b/src/main/java/dev/hilligans/ourcraft/Ourcraft.java @@ -326,7 +326,6 @@ public void press(RenderWindow renderWindow, float strength) { } }); } - Ourcraft.getResourceManager().gameInstance = modContent.gameInstance; } public static DoubleBuffer getMousePos(long window) { diff --git a/src/main/java/dev/hilligans/ourcraft/ServerMain.java b/src/main/java/dev/hilligans/ourcraft/ServerMain.java index 4fc957f9..9e5f80ee 100644 --- a/src/main/java/dev/hilligans/ourcraft/ServerMain.java +++ b/src/main/java/dev/hilligans/ourcraft/ServerMain.java @@ -39,10 +39,10 @@ public static void server(GameInstance gameInstance, ArgumentContainer argumentC //ServerWorld world = new ServerWorld(gameInstance); //world.worldBuilders.add(new OreBuilder("ore", Blocks.GRASS,Blocks.STONE).setFrequency(20)); - server = new MultiPlayerServer(); + server = new MultiPlayerServer(gameInstance); //server.addWorld(0,world); //server.addWorld(new SimpleServerWorld(0, "server_world")); - IServerWorld world1 = new ServerCubicWorld(0, "planet", 64, new PlanetWorldHeightBuilder(new IWorldHeightBuilder[]{ + IServerWorld world1 = new ServerCubicWorld(gameInstance, 0, "planet", 64, new PlanetWorldHeightBuilder(new IWorldHeightBuilder[]{ new SimpleHeightBuilder(), new SimpleHeightBuilder(), new SimpleHeightBuilder(), diff --git a/src/main/java/dev/hilligans/ourcraft/block/Block.java b/src/main/java/dev/hilligans/ourcraft/block/Block.java index 9a5c8873..4e76dd77 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/Block.java +++ b/src/main/java/dev/hilligans/ourcraft/block/Block.java @@ -298,7 +298,7 @@ public static int getSide(int side, int rotX, int rotY) { @Override public void load(GameInstance gameInstance) { if(blockProperties.path != null && blockProperties.fromFile) { - JSONObject jsonObject = (JSONObject) Ourcraft.GAME_INSTANCE.RESOURCE_LOADER.getResource(new ResourceLocation(blockProperties.path, modId)); + JSONObject jsonObject = (JSONObject) gameInstance.RESOURCE_LOADER.getResource(new ResourceLocation(blockProperties.path, modId)); if(jsonObject != null) { if (overrides != null) { BlockProperties.recursivelyOverride(jsonObject, overrides); diff --git a/src/main/java/dev/hilligans/ourcraft/client/ChatWindow.java b/src/main/java/dev/hilligans/ourcraft/client/ChatWindow.java index 079da5f0..2b0240d1 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/ChatWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/ChatWindow.java @@ -24,6 +24,8 @@ public class ChatWindow implements Screen { static boolean typing; + public RenderWindow renderWindow; + public ChatWindow() { messageIndex = -1; } @@ -33,6 +35,7 @@ public ChatWindow(String message) { string = message; } + /* static { KeyHandler.register(new KeyPress() { @Override @@ -154,18 +157,20 @@ public void onRepeat(char key) { }); } + */ + public static String getString() { return messageIndex == -1 ? string : sentMessages.size() > messageIndex ? sentMessages.get(sentMessages.size() - messageIndex - 1) : ""; } @Override public void setWindow(RenderWindow renderWindow) { - + this.renderWindow = renderWindow; } @Override public RenderWindow getWindow() { - return null; + return this.renderWindow; } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/Client.java b/src/main/java/dev/hilligans/ourcraft/client/Client.java index d7958d1a..f69c32ac 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/Client.java +++ b/src/main/java/dev/hilligans/ourcraft/client/Client.java @@ -14,6 +14,7 @@ import dev.hilligans.ourcraft.client.rendering.graphics.vulkan.VulkanEngine; import dev.hilligans.ourcraft.client.rendering.Screen; import dev.hilligans.ourcraft.client.rendering.ScreenBuilder; +import dev.hilligans.ourcraft.client.rendering.screens.JoinScreen; import dev.hilligans.ourcraft.client.rendering.screens.container.screens.CreativeInventoryScreen; import dev.hilligans.ourcraft.client.rendering.screens.container.screens.InventoryScreen; import dev.hilligans.ourcraft.ClientMain; @@ -69,13 +70,9 @@ public class Client implements IClientPacketHandler { public Screen screen; public SoundEngine soundEngine; - public int texture; - - public boolean refreshTexture = true; - public ClientPlayerData playerData = new ClientPlayerData(); //public IWorld newClientWorld = new SimpleWorld(0,""); - public IWorld newClientWorld = new CubicWorld(0,"", 64); + public IWorld newClientWorld; public MultiPlayerServer multiPlayerServer; public boolean rendering = false; @@ -95,6 +92,7 @@ public class Client implements IClientPacketHandler { public Client(GameInstance gameInstance, ArgumentContainer argumentContainer) { this.gameInstance = gameInstance; + this.newClientWorld = new CubicWorld(gameInstance, 0,"", 64); logger = gameInstance.LOGGER.withKey("client"); graphicsEngine = gameInstance.GRAPHICS_ENGINES.get("ourcraft:openglEngine"); ((OpenGLEngine)graphicsEngine).client = this; @@ -114,9 +112,9 @@ public Client setGraphicsEngine(IGraphicsEngine graphicsEngine) { return this; } - public void startClient() { + public void setupClient() { network = new ClientNetwork(gameInstance.PROTOCOLS.get("Play")).debug(argumentContainer.getBoolean("--packetTrace", false)); - authNetwork = new ClientNetwork(gameInstance.PROTOCOLS.get("Auth")); + /*authNetwork = new ClientNetwork(gameInstance.PROTOCOLS.get("Auth")); CompoundNBTTag tag = WorldLoader.loadTag("clientData.dat"); if(tag != null) { @@ -126,30 +124,43 @@ public void startClient() { } catch (Exception e) {} }); thread.setName("authenticate"); + thread.setDaemon(true); thread.start(); } if(tag != null) { readUsernameAndPassword(tag); } authNetwork.sendPacket(new CGetToken(playerData.userName, playerData.login_token)); + */ + RenderWindow window = graphicsEngine.startEngine(); + window.setClient(this); + client.screen = new JoinScreen(); + client.screen.setWindow(window); + window.setClearColor(0.2f, 0.3f, 0.3f, 1.0f); - soundEngine.init(window.getCamera()); - soundEngine.setAttenuationModel(AL11.AL_LINEAR_DISTANCE_CLAMPED); - registerKeyHandlers(); + if(soundEngine.camera == null) { + soundEngine.init(window.getCamera()); + soundEngine.setAttenuationModel(AL11.AL_LINEAR_DISTANCE_CLAMPED); + } + //registerKeyHandlers(); - // SplitWindow splitWindow = new SplitWindow(graphicsEngine, window); - // SubWindow subWindow = new SubWindow(graphicsEngine, splitWindow, window.getWindowWidth()/2, window.getWindowHeight()/2, graphicsEngine.getContext()); - // subWindow.setRenderPipeline(window.renderPipeline); - // splitWindow.setRenderPipeline("ourcraft:split_window_pipeline"); - // splitWindow.addWindow(subWindow); + // SplitWindow splitWindow = new SplitWindow(graphicsEngine, window); + // SubWindow subWindow = new SubWindow(graphicsEngine, splitWindow, window.getWindowWidth()/2, window.getWindowHeight()/2, graphicsEngine.getContext()); + // subWindow.setRenderPipeline(window.renderPipeline); + // splitWindow.setRenderPipeline("ourcraft:split_window_pipeline"); + // splitWindow.addWindow(subWindow); rWindow = window; + } + + public void startClient() { + setupClient(); + System.err.println("Time to start running: " + (System.currentTimeMillis() - ClientMain.startTime)); - graphicsEngine.createRenderLoop(gameInstance, window).run(); + graphicsEngine.createRenderLoop(gameInstance, rWindow).run(); graphicsEngine.close(); cleanUp(); - System.exit(1); } public RenderWindow rWindow; @@ -414,4 +425,9 @@ public Client getClient() { public IWorld getWorld() { return newClientWorld; } + + @Override + public GameInstance getGameInstance() { + return gameInstance; + } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/PlayerMovementThread.java b/src/main/java/dev/hilligans/ourcraft/client/PlayerMovementThread.java deleted file mode 100644 index f7abc3db..00000000 --- a/src/main/java/dev/hilligans/ourcraft/client/PlayerMovementThread.java +++ /dev/null @@ -1,32 +0,0 @@ -package dev.hilligans.ourcraft.client; - -import dev.hilligans.ourcraft.client.input.key.KeyHandler; -import dev.hilligans.ourcraft.ClientMain; - -public class PlayerMovementThread implements Runnable { - - long window; - - public PlayerMovementThread(long window) { - this.window = window; - - } - - @Override - public void run() { - if(ClientMain.getClient().valid) { - if(Camera.sprintDelay > 0) { - Camera.sprintDelay--; - } - if(Camera.sprintTimeout == 0) { - Camera.sprinting = false; - } - if(KeyHandler.keyPressed[KeyHandler.GLFW_KEY_LEFT_CONTROL] && Camera.sprintDelay == 0) { - Camera.sprinting = true; - } - Camera.sprintTimeout = 0; - // ClientMain.getClient().processInput(window); - //Camera.tick(); - } - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/client/input/key/KeyHandler.java b/src/main/java/dev/hilligans/ourcraft/client/input/key/KeyHandler.java index 15f7c0ed..4271a3aa 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/input/key/KeyHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/client/input/key/KeyHandler.java @@ -94,11 +94,14 @@ private static void onRepeat(int id) { } private static char getChar(int id) { - if(glfwGetKey(ClientMain.getClient().window,GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(ClientMain.getClient().window,GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS) { + /* if(glfwGetKey(ClientMain.getClient().window,GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(ClientMain.getClient().window,GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS) { return shiftMappedKeys.getOrDefault(id,mappedKeys.getOrDefault(id,Character.MIN_VALUE)); } else { return mappedKeys.getOrDefault(id,Character.MIN_VALUE); } + + */ + throw new RuntimeException(); } private static void setCallback(long window) { @@ -128,11 +131,11 @@ private static void putName(int id, String name) { } static { - if(ClientMain.getClient().glStarted) { + // if(ClientMain.getClient().glStarted) { //setCallback(ClientMain.getClient().window); - } else { + // } else { // Ourcraft.GAME_INSTANCE.EVENT_BUS.register(GLInitEvent.class,KeyHandler::setCallback); - } + // } mappedKeys.put(32,' '); mappedKeys.put(39, '\''); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/ContainerScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/ContainerScreen.java index 05769ddd..e33da5a6 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/ContainerScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/ContainerScreen.java @@ -27,7 +27,7 @@ public void setContainer(Container container) { public ContainerScreen() { } - public RecipeHelper recipeHelper = new RecipeHelper(Ourcraft.GAME_INSTANCE); + //public RecipeHelper recipeHelper = new RecipeHelper(Ourcraft.GAME_INSTANCE); @Override public void render(RenderWindow window, MatrixStack matrixStack, GraphicsContext graphicsContext) { diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/culling/PlaneTestCullingEngine.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/culling/PlaneTestCullingEngine.java index 94de238f..b815e8ce 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/culling/PlaneTestCullingEngine.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/culling/PlaneTestCullingEngine.java @@ -49,7 +49,7 @@ public static int getSolidChunkFaces(ISubChunk chunk) { for(int x = 0; x < 16; x++) { for(int y = 0; y < 16; y++) { for(int z = 0; z < 16; z++) { - if(chunk.getBlockState(x,y,z).getBlock().blockProperties.transparent) { + if(chunk.getBlockState(null, x,y,z).getBlock().blockProperties.transparent) { vals[x][y] |= 1 << z; recursivelyCheck(chunk,vals,x,y,z); if(checkFace(vals,0,true,false,false) && checkFace(vals,15,true,false,false)) { @@ -100,37 +100,37 @@ public static boolean checkFace(short[][] vals, int pos, boolean addX, boolean a public static void recursivelyCheck(ISubChunk chunk, short[][] vals, int x, int y, int z) { boolean posZ = false, negZ = false, posX = false, negX = false, posY = false, negY = false; - if(z != 15 && chunk.getBlockState(x,y,z + 1).getBlock().blockProperties.transparent) { + if(z != 15 && chunk.getBlockState(null, x,y,z + 1).getBlock().blockProperties.transparent) { if ((vals[x][y] & (1 << z + 1)) == 0) { vals[x][y] |= 1 << z + 1; posZ = true; } } - if(z != 0 && chunk.getBlockState(x,y,z - 1).getBlock().blockProperties.transparent) { + if(z != 0 && chunk.getBlockState(null, x,y,z - 1).getBlock().blockProperties.transparent) { if ((vals[x][y] & (1 << z - 1)) == 0) { vals[x][y] |= 1 << z - 1; negZ = true; } } - if(x != 15 && chunk.getBlockState(x + 1,y,z).getBlock().blockProperties.transparent) { + if(x != 15 && chunk.getBlockState(null, x + 1,y,z).getBlock().blockProperties.transparent) { if ((vals[x + 1][y] & (1 << z)) == 0) { vals[x + 1][y] |= 1 << z; posX = true; } } - if(x != 0 && chunk.getBlockState(x - 1,y,z).getBlock().blockProperties.transparent) { + if(x != 0 && chunk.getBlockState(null, x - 1,y,z).getBlock().blockProperties.transparent) { if ((vals[x - 1][y] & (1 << z)) == 0) { vals[x - 1][y] |= 1 << z; negX = true; } } - if(y != 15 && chunk.getBlockState(x,y + 1,z).getBlock().blockProperties.transparent) { + if(y != 15 && chunk.getBlockState(null, x,y + 1,z).getBlock().blockProperties.transparent) { if ((vals[x][y + 1] & (1 << z)) == 0) { vals[x][y + 1] |= 1 << z; posY = true; } } - if(y != 0 && chunk.getBlockState(x,y - 1,z).getBlock().blockProperties.transparent) { + if(y != 0 && chunk.getBlockState(null, x,y - 1,z).getBlock().blockProperties.transparent) { if ((vals[x][y - 1] & (1 << z)) == 0) { vals[x][y - 1] |= 1 << z; negY = true; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java index 37b0d3e2..f7056b12 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderPipeline.java @@ -15,7 +15,7 @@ public class RenderPipeline implements IRegistryElement, IGraphicsElement { public String name; public ModContent modContent; - public RenderWindow window; + // public RenderWindow window; public ArrayList renderTargets = new ArrayList<>(); public ArrayList renderTasks = new ArrayList<>(); @@ -25,7 +25,7 @@ public RenderPipeline(String name) { } public void render(Client client, MatrixStack worldStack, MatrixStack screenStack, GraphicsContext graphicsContext) { - window.render(graphicsContext, client, worldStack, screenStack); + client.rWindow.render(graphicsContext, client, worldStack, screenStack); } public void addRenderTarget(RenderTarget renderTarget) { @@ -57,7 +57,7 @@ public void addRenderTarget(RenderTarget renderTarget) { } public void build(RenderWindow window) { - this.window = window; + //this.window = window; } public void buildTargets(IGraphicsEngine graphicsEngine) { @@ -103,7 +103,7 @@ public String getResourceType() { public String toString() { return "RenderPipeline{" + "name='" + name + '\'' + - ", window=" + window + + // ", window=" + window + ", renderTargets=" + renderTargets + ", renderTasks=" + renderTasks + '}'; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java index a202b893..737cb3a4 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/RenderWindow.java @@ -17,6 +17,8 @@ import org.joml.Vector2f; import org.joml.Vector4f; +import java.util.concurrent.atomic.AtomicInteger; + public abstract class RenderWindow { public FrameTracker frameTracker = new FrameTracker(); @@ -29,6 +31,9 @@ public abstract class RenderWindow { public Client client; public String queuedPipeline; public Vector4f clearColor = new Vector4f(); + public String windowName; + + public static AtomicInteger windowID = new AtomicInteger(); public RenderWindow(IGraphicsEngine graphicsEngine) { this.graphicsEngine = graphicsEngine; @@ -40,6 +45,7 @@ public RenderWindow(IGraphicsEngine graphicsEngine) { } setRenderPipeline("ourcraft:menu_pipeline"); camera = new FreeCamera(this); + this.windowName = STR."window \{windowID.getAndIncrement()}"; } public void renderPipeline(Client client, MatrixStack worldStack, MatrixStack screenStack, GraphicsContext graphicsContext) { @@ -56,7 +62,7 @@ public void render(GraphicsContext graphicsContext, Client client, MatrixStack w graphicsEngine.getDefaultImpl().setState(graphicsContext, pipelineState); graphicsContext.setPipelineState(true); } - renderTask.draw(this, graphicsContext, this.getGraphicsEngine(), client, worldStack, screenStack, 1); + renderTask.draw(this, graphicsContext, this.getGraphicsEngine(), getClient(), worldStack, screenStack, 1); } } } @@ -114,6 +120,10 @@ public InputHandler getInputProvider() { public abstract String getWindowingName(); + public String getWindowName() { + return windowName; + } + public Logger getLogger() { return logger; } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/GraphicsEngineBase.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/GraphicsEngineBase.java index fd36e07c..ba6f8131 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/GraphicsEngineBase.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/GraphicsEngineBase.java @@ -12,6 +12,7 @@ public abstract class GraphicsEngineBase windows = new ArrayList<>(); public GameInstance gameInstance; + public boolean running = false; public GraphicsEngineBase() { @@ -33,6 +34,11 @@ public ArrayList getWindows() { return windows; } + @Override + public boolean isRunning() { + return running; + } + @Override public void load(GameInstance gameInstance) { this.gameInstance = gameInstance; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java index 8fd6479e..98e38f5a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/api/IGraphicsEngine.java @@ -36,19 +36,30 @@ public interface IGraphicsEngine { try { GraphicsContext graphicsContext = getGraphicsContext(); ISection section = graphicsContext.getSection(); try(var $0 = section.startSection("base")) { - while (!window.shouldClose()) { - try (var $1 = section.startSection("loop")) { - try (var $2 = section.startSection("render")) { - render(window, graphicsContext); - } - try (var $2 = section.startSection("swapBuffers")) { - window.swapBuffers(graphicsContext); + out: { + while (true) { + try (var $1 = section.startSection("loop")) { + for (RenderWindow window : getWindows()) { + if (window.shouldClose()) { + break out; + } + try (var $9 = section.startSection(window.getWindowName())) { + try (var $2 = section.startSection("render")) { + render(window, graphicsContext); + } + try (var $2 = section.startSection("swapBuffers")) { + window.swapBuffers(graphicsContext); + } + } + } } } } @@ -79,9 +90,11 @@ default void setWindowsFrameRate(int frameRate) { int getProgram(String name); default RenderWindow startEngine() { - RenderWindow window = setup(); - //getGameInstance().build(this); - return window; + if(!isRunning()) { + return setup(); + } else { + return createWindow(); + } } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java index 8bbd9da8..8b24f43a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLEngine.java @@ -44,11 +44,24 @@ public OpenGLEngine() { @Override public OpenGLWindow createWindow() { + OpenGLWindow renderWindow = new OpenGLWindow(this, "Ourcraft 1", 1600, 800, windows.get(0).window); + renderWindow.setRenderPipeline(gameInstance.ARGUMENTS.getString("--renderPipeline", "ourcraft:menu_pipeline")); + windows.add(renderWindow); + renderWindow.setup(); + GL.createCapabilities(); + + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + glFrontFace(GL_CW); + glEnable(GL_PROGRAM_POINT_SIZE); + return renderWindow; } - public static OpenGLWindow renderWindow; - @Override public void render(RenderWindow window, GraphicsContext graphicsContext) { window.frameTracker.count(); @@ -68,28 +81,26 @@ public void render(RenderWindow window, GraphicsContext graphicsContext) { MatrixStack matrixStack = window.camera.getMatrix(); MatrixStack screenStack = window.camera.getScreenStack(); - window.renderPipeline(client, matrixStack, screenStack, graphicsContext); + window.renderPipeline(window.getClient(), matrixStack, screenStack, graphicsContext); } @Override public OpenGLWindow setup() { + running = true; System.setProperty("java.awt.headless", "true"); - glfwInit(); + if(!glfwInit()) { + throw new RuntimeException("Failed to create window"); + } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - renderWindow = new OpenGLWindow(client, this, "Ourcraft", 1600, 800); + OpenGLWindow renderWindow = new OpenGLWindow( this, "Ourcraft", 1600, 800, 0); renderWindow.setRenderPipeline(gameInstance.ARGUMENTS.getString("--renderPipeline", "ourcraft:menu_pipeline")); windows.add(renderWindow); renderWindow.setup(); GL.createCapabilities(); - client.glStarted = true; - gameInstance.build(this, null); - - setupStringRenderer(""); - glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(new GLDebugMessageCallback() { @@ -102,10 +113,8 @@ public void invoke(int source, int type, int id, int severity, int length, long } } }, 0); - - - client.screen = new JoinScreen(); - client.screen.setWindow(renderWindow); + gameInstance.build(this, null); + setupStringRenderer(""); glfwWindowHint(GLFW_SAMPLES, 4); glEnable(GL_BLEND); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java index c8090954..93717d59 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenGLWindow.java @@ -1,6 +1,7 @@ package dev.hilligans.ourcraft.client.rendering.graphics.opengl; import dev.hilligans.ourcraft.client.Client; +import dev.hilligans.ourcraft.client.MatrixStack; import dev.hilligans.ourcraft.client.input.key.MouseHandler; import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; import dev.hilligans.ourcraft.client.rendering.graphics.implementations.FreeCamera; @@ -20,18 +21,20 @@ public class OpenGLWindow extends RenderWindow { public boolean windowFocused = true; public int width; public int height; + public boolean updatedSize = false; - public OpenGLWindow(Client client, OpenGLEngine engine, String name, int width, int height) { + public OpenGLWindow(OpenGLEngine engine, String name, int width, int height, long otherID) { super(engine); this.camera = new FreeCamera(this); - window = glfwCreateWindow(width,height,name,NULL,NULL); this.width = width; this.height = height; - if(window == NULL) { - //glfwTerminate(); + + window = glfwCreateWindow(width, height, name, NULL, otherID); + if (window == NULL) { + glfwTerminate(); throw new RuntimeException("Failed to create window"); } - this.client = client; + glfwMakeContextCurrent(window); registerCallbacks(); } @@ -41,6 +44,16 @@ public void setup() { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } + @Override + public void render(GraphicsContext graphicsContext, Client client, MatrixStack worldStack, MatrixStack screenStack) { + glfwMakeContextCurrent(window); + if(updatedSize) { + GL30.glViewport(0, 0, width, height); + updatedSize = false; + } + super.render(graphicsContext, client, worldStack, screenStack); + } + @Override public long getWindowID() { return window; @@ -53,7 +66,7 @@ public void close() { @Override public boolean shouldClose() { - return glfwWindowShouldClose(window) || shouldClose; + return (window != NULL && glfwWindowShouldClose(window)) || shouldClose; } @Override @@ -107,7 +120,7 @@ public void registerCallbacks() { glfwSetWindowSizeCallback(window, (window, w, h) -> { width = w; height = h; - GL30.glViewport(0,0,w,h); + updatedSize = true; }); glfwSetWindowFocusCallback(window, (window, focused) -> windowFocused = focused); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java index e6a25a4f..47f189ce 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/opengl/OpenglDefaultImpl.java @@ -41,6 +41,7 @@ public class OpenglDefaultImpl implements IDefaultEngineImpl textureAllocationTracker = new Int2ObjectOpenHashMap<>(); public final Int2ObjectOpenHashMap vertexArrayAllocationTracker = new Int2ObjectOpenHashMap<>(); public final Int2ObjectOpenHashMap programAllocationTracker = new Int2ObjectOpenHashMap<>(); + public final Int2ObjectOpenHashMap fboAllocationTracker = new Int2ObjectOpenHashMap<>(); public long boundTexture = -1; public long boundProgram = -1; @@ -287,12 +288,15 @@ public long createFrameBuffer(GraphicsContext graphicsContext, int width, int he glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); synchronized (fbos) { - fbos.put(fbo, texture); + fbos.put(texture, fbo); } synchronized (textureTypes) { textureTypes.put(texture, GL_TEXTURE_2D); } glBindFramebuffer(GL_FRAMEBUFFER, 0); + if(trackingResourceAllocations) { + fboAllocationTracker.put(fbo, new Exception()); + } return texture; } @@ -303,7 +307,10 @@ public void destroyFrameBuffer(GraphicsContext graphicsContext, long id) { fbo = fbos.remove((int) id); } synchronized (textureTypes) { - textureTypes.remove((int)fbo); + textureTypes.remove((int)id); + } + if(trackingResourceAllocations) { + fboAllocationTracker.remove(fbo); } glDeleteTextures((int) id); glDeleteFramebuffers(fbo); @@ -315,7 +322,8 @@ public void bindFrameBuffer(GraphicsContext graphicsContext, long id) { if(id == 0) { glBindFramebuffer(GL_FRAMEBUFFER, 0); } else { - glBindFramebuffer(GL_FRAMEBUFFER, fbos.get((int)id)); + int fbo = fbos.get((int)id); + glBindFramebuffer(GL_FRAMEBUFFER, fbos.get(fbo)); } } @@ -357,6 +365,9 @@ public void close() { for(Exception e : programAllocationTracker.values()) { throw new VideoMemoryLeakException("Missing shader deallocation allocated at:", e); } + for(Exception e : fboAllocationTracker.values()) { + throw new VideoMemoryLeakException("Missing FBO deallocation allocated at:", e); + } } @@ -378,14 +389,14 @@ public synchronized VertexFormat getFormat(String name) { cache[1] = f; return cache[0]; } - for(VertexFormat vertexFormat : engine.client.gameInstance.VERTEX_FORMATS.ELEMENTS) { + for(VertexFormat vertexFormat : engine.getGameInstance().VERTEX_FORMATS.ELEMENTS) { if(vertexFormat.formatName.equals(name)) { cache[1] = vertexFormat; return vertexFormat; } } - throw new UnknownResourceException("Failed to find resource in the registry by name: " + name, engine.client.gameInstance.VERTEX_FORMATS, name, engine.getGameInstance().OURCRAFT); + throw new UnknownResourceException("Failed to find resource in the registry by name: " + name, engine.getGameInstance().VERTEX_FORMATS, name, engine.getGameInstance().OURCRAFT); } public static class VideoMemoryLeakException extends RuntimeException { diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java index 7e46d7e8..5db4a426 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldRenderTask.java @@ -41,7 +41,7 @@ public WorldRenderTask() { public CullingEngine cullingEngine; public ExecutorService chunkBuilder = Executors.newFixedThreadPool(2); - TextAtlas textAtlas = new TextAtlas(); + TextAtlas textAtlas; @Override public RenderTask getDefaultTask() { @@ -310,6 +310,7 @@ public PipelineState getPipelineState() { @Override public void load(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) { + textAtlas = new TextAtlas(gameInstance); for(Block block : gameInstance.getBlocks()) { if(!block.blockProperties.translucent) { block.generateTextures(textAtlas); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldTransparentRenderTask.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldTransparentRenderTask.java index 9e491256..c0dceb7d 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldTransparentRenderTask.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/tasks/WorldTransparentRenderTask.java @@ -40,7 +40,7 @@ public WorldTransparentRenderTask() { public ExecutorService chunkBuilder = Executors.newFixedThreadPool(2); - TextAtlas textAtlas = new TextAtlas(); + TextAtlas textAtlas; @Override public RenderTask getDefaultTask() { @@ -217,6 +217,7 @@ public void load(GameInstance gameInstance) { @Override public void load(GameInstance gameInstance, IGraphicsEngine graphicsEngine, GraphicsContext graphicsContext) { + textAtlas = new TextAtlas(gameInstance); for(Block block : gameInstance.getBlocks()) { if(block.blockProperties.translucent) { block.generateTextures(textAtlas); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/TextAtlas.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/TextAtlas.java index 2020a12b..2b77ef98 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/TextAtlas.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/newrenderer/TextAtlas.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.client.rendering.newrenderer; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine; import dev.hilligans.ourcraft.Ourcraft; import dev.hilligans.ourcraft.resource.ResourceLocation; @@ -19,6 +20,7 @@ public class TextAtlas { public int size = 32; public int minWidth = 16; public ExecutorService executorService; + public GameInstance gameInstance; public ArrayList images = new ArrayList<>(); public Int2LongOpenHashMap ids = new Int2LongOpenHashMap(); @@ -30,7 +32,8 @@ public class TextAtlas { public int texture; int id = 0; - public TextAtlas() { + public TextAtlas(GameInstance gameInstance) { + this.gameInstance = gameInstance; image = new Image(size, size); } @@ -60,7 +63,7 @@ private long getLong(long size, int x, int y) { return ((long) (short) size << 32) | ((short)x << 16) | (short) y; } - public void assemble() { + public void assemble(GameInstance gameInstance) { long start = System.currentTimeMillis(); executorService = Executors.newFixedThreadPool(4,new NamedThreadFactory("texture_atlas_builder")); @@ -72,7 +75,7 @@ public void assemble() { long spot = -1; try (MemoryStack stack = MemoryStack.stackPush()) { try { - tempImage = (Image) Ourcraft.GAME_INSTANCE.RESOURCE_LOADER.getResource(new ResourceLocation(imageLocation.path, imageLocation.modId)); + tempImage = (Image) gameInstance.RESOURCE_LOADER.getResource(new ResourceLocation(imageLocation.path, imageLocation.modId)); if (tempImage == null) { System.out.println(new ResourceLocation(imageLocation.path, imageLocation.modId).toIdentifier()); return; @@ -105,7 +108,7 @@ public void assemble() { public int upload(IGraphicsEngine engine) { clear(); - assemble(); + assemble(engine.getGameInstance()); texture = (int) engine.getDefaultImpl().createTexture(null,image); return texture; } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/JoinScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/JoinScreen.java index c08451c4..8b00cebd 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/JoinScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/JoinScreen.java @@ -49,9 +49,9 @@ public void buildContentForWindow(RenderWindow window) { //ServerWorld world = new ServerWorld(ClientMain.gameInstance); //world.worldBuilders.add( new OreBuilder("stone", Blocks.GRASS,Blocks.STONE).setFrequency(20)); - client.multiPlayerServer = new MultiPlayerServer(); + // client.multiPlayerServer = new MultiPlayerServer(); //client.multiPlayerServer.addWorld(0,world); - ServerMain.server = client.multiPlayerServer; + // ServerMain.server = client.multiPlayerServer; int port = 0; try { port = PortUtil.getOpenPort(); @@ -60,9 +60,10 @@ public void buildContentForWindow(RenderWindow window) { return; } String portString = port + ""; - Thread thread = new Thread(() -> client.multiPlayerServer.startServer(portString)); - thread.setName("client_networking"); - thread.start(); + // Thread thread = new Thread(() -> client.multiPlayerServer.startServer(portString)); + // thread.setName("client_networking"); + // thread.setDaemon(true); + // thread.start(); this.portString = portString; })); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/ChestScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/ChestScreen.java index f0a395e4..e38c4c3a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/ChestScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/ChestScreen.java @@ -16,7 +16,7 @@ public ChestScreen() { @Override public ChestContainer getContainer() { - return new ChestContainer(); + return new ChestContainer(getClient()); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/CreativeInventoryScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/CreativeInventoryScreen.java index 8b82dad8..cad1e9ab 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/CreativeInventoryScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/CreativeInventoryScreen.java @@ -13,7 +13,7 @@ public class CreativeInventoryScreen extends ContainerScreen @Override public CreativeContainer getContainer() { - return new CreativeContainer(); + return new CreativeContainer(getClient()); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/InventoryScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/InventoryScreen.java index dd6d65be..c76e7816 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/InventoryScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/container/screens/InventoryScreen.java @@ -15,7 +15,7 @@ public class InventoryScreen extends ContainerScreen { @Override public InventoryContainer getContainer() { - return new InventoryContainer(); + return new InventoryContainer(getClient()); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/SearchField.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/SearchField.java index 4eab3fd1..a92df0c1 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/SearchField.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/SearchField.java @@ -51,7 +51,7 @@ public void onPress(char key) { if(key == 'v' && KeyHandler.keyPressed[GLFW.GLFW_KEY_LEFT_CONTROL]) { try { //System.out.println("adding clipboard"); - string += GLFW.glfwGetClipboardString(ClientMain.getClient().window); + //string += GLFW.glfwGetClipboardString(ClientMain.getClient().window); //string += Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); } catch (Exception ignored) { ignored.printStackTrace(); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/ServerSelectorWidget.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/ServerSelectorWidget.java index bf27fdd2..5996f263 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/ServerSelectorWidget.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/widgets/ServerSelectorWidget.java @@ -33,9 +33,7 @@ public void render(RenderWindow window, MatrixStack matrixStack, int xOffset, in public void joinServer() { try { - - - screenBase.getClient().network.joinServer(ip,port, ClientMain.getClient()); + screenBase.getClient().network.joinServer(ip,port, screenBase.getClient()); screenBase.getClient().closeScreen(); screenBase.getClient().serverIP = ip + ":" + port; screenBase.window.queueRenderPipeline("ourcraft:new_world_pipeline"); diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java index 2601d844..f751909a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/world/managers/BlockTextureManager.java @@ -55,9 +55,9 @@ public void generate(TextAtlas textAtlas) { if(location != null) { for(int x = 0; x < 6; x++) { if(textureNames != null) { - colors[x] = Ourcraft.getResourceManager().getColor("Blocks/" + (textureNames[x] == null ? location : textureNames[x])); + colors[x] = textAtlas.gameInstance.RESOURCE_MANAGER.getColor("Blocks/" + (textureNames[x] == null ? location : textureNames[x])); } else { - colors[x] = Ourcraft.getResourceManager().getColor("Blocks/" + location); + colors[x] = textAtlas.gameInstance.RESOURCE_MANAGER.getColor("Blocks/" + location); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/container/Container.java b/src/main/java/dev/hilligans/ourcraft/container/Container.java index 68892662..a079e6d4 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/Container.java +++ b/src/main/java/dev/hilligans/ourcraft/container/Container.java @@ -83,7 +83,7 @@ public int getInt(int slot) { public void addWidget(Widget widget) { if(widget instanceof Button && !Settings.isServer) { - ((Button) widget).buttonAction = () -> ClientMain.getClient().sendPacket(new CActivateButton(widgets.size())); + // ((Button) widget).buttonAction = () -> ClientMain.getClient().sendPacket(new CActivateButton(widgets.size())); } widgets.add(widget); } @@ -97,7 +97,7 @@ public void render(RenderWindow window, MatrixStack matrixStack) { for(Slot slot : slots) { slot.render(matrixStack); } - DoubleBuffer mousePos = ClientMain.getClient().getMousePos(); + DoubleBuffer mousePos = window.getClient().getMousePos(); Slot slot = getSlotAt((int)mousePos.get(0),(int)mousePos.get(1)); if(slot != null && !slot.getContents().isEmpty()) { window.getStringRenderer().drawStringWithBackgroundTranslated(window, matrixStack,slot.getContents().item.getName(),(int)mousePos.get(0) + 16,(int)mousePos.get(1),0.5f); @@ -185,11 +185,11 @@ public ItemStack copyStack(short slot, ItemStack heldStack) { public static final ArrayList CONTAINERS = new ArrayList<>(); - public static Container getContainer(int slot) { + public static Container getContainer(int slot, Client client) { if(slot >= CONTAINERS.size()) { return null; } else { - return CONTAINERS.get(slot).getContainer(); + return CONTAINERS.get(slot).getContainer(client); } } diff --git a/src/main/java/dev/hilligans/ourcraft/container/ContainerFetcher.java b/src/main/java/dev/hilligans/ourcraft/container/ContainerFetcher.java index 8f4b7fe2..746923aa 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/ContainerFetcher.java +++ b/src/main/java/dev/hilligans/ourcraft/container/ContainerFetcher.java @@ -1,6 +1,8 @@ package dev.hilligans.ourcraft.container; +import dev.hilligans.ourcraft.client.Client; + public interface ContainerFetcher { - Container getContainer(); + Container getContainer(Client client); } diff --git a/src/main/java/dev/hilligans/ourcraft/container/containers/ChestContainer.java b/src/main/java/dev/hilligans/ourcraft/container/containers/ChestContainer.java index e375ac71..17cc4216 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/containers/ChestContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/container/containers/ChestContainer.java @@ -11,8 +11,8 @@ public class ChestContainer extends Container { - public ChestContainer() { - this(new Inventory(27), ClientMain.getClient().playerData.inventory); + public ChestContainer(Client client) { + this(new Inventory(27), client.playerData.inventory); } public ChestContainer(Inventory inventory, Inventory playerInventory) { diff --git a/src/main/java/dev/hilligans/ourcraft/container/containers/ContainerBuilder.java b/src/main/java/dev/hilligans/ourcraft/container/containers/ContainerBuilder.java index fec0cd94..fbf051d9 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/containers/ContainerBuilder.java +++ b/src/main/java/dev/hilligans/ourcraft/container/containers/ContainerBuilder.java @@ -33,7 +33,7 @@ public ContainerBuilder(short id, String textureName, Slot[] slots, WidgetHolder @Override - public Container getContainer() { + public Container getContainer(Client client) { Inventory inventory = new Inventory(slots.length); Container container = new Container(id,inventory) { @Override diff --git a/src/main/java/dev/hilligans/ourcraft/container/containers/CreativeContainer.java b/src/main/java/dev/hilligans/ourcraft/container/containers/CreativeContainer.java index 0a3f6213..5264534d 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/containers/CreativeContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/container/containers/CreativeContainer.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.container.containers; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.rendering.ContainerScreen; import dev.hilligans.ourcraft.client.rendering.screens.container.screens.CreativeInventoryScreen; @@ -16,8 +17,8 @@ public class CreativeContainer extends Container { - public CreativeContainer() { - this(ClientMain.getClient().playerData.inventory,new Inventory(Math.max(Ourcraft.GAME_INSTANCE.ITEMS.ELEMENTS.size(),54))); + public CreativeContainer(Client client) { + this(client.playerData.inventory,new Inventory(Math.max(client.getGameInstance().ITEMS.ELEMENTS.size(),54))); } public CreativeContainer(IInventory playerInventory, IInventory creativeInventory) { @@ -61,10 +62,10 @@ public ContainerScreen getContainerScreen() { return new CreativeInventoryScreen(); } - public static IInventory createInventory() { - Inventory inventory = new Inventory(Math.max(Ourcraft.GAME_INSTANCE.ITEMS.ELEMENTS.size() ,54)); + public static IInventory createInventory(GameInstance gameInstance) { + Inventory inventory = new Inventory(Math.max(gameInstance.ITEMS.ELEMENTS.size() ,54)); int x = 0; - for(Item item : Ourcraft.GAME_INSTANCE.ITEMS.ELEMENTS) { + for(Item item : gameInstance.ITEMS.ELEMENTS) { if(!(item instanceof BlockItem) || !((BlockItem) item).block.blockProperties.airBlock) { inventory.setItem(x, new ItemStack(item, (byte) 1)); x++; diff --git a/src/main/java/dev/hilligans/ourcraft/container/containers/InventoryContainer.java b/src/main/java/dev/hilligans/ourcraft/container/containers/InventoryContainer.java index 4bb81bf8..db646d1e 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/containers/InventoryContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/container/containers/InventoryContainer.java @@ -10,8 +10,8 @@ public class InventoryContainer extends Container { - public InventoryContainer() { - this(ClientMain.getClient().playerData.inventory); + public InventoryContainer(Client client) { + this(client.playerData.inventory); } public InventoryContainer(Inventory inventory) { diff --git a/src/main/java/dev/hilligans/ourcraft/container/containers/SlabBlockContainer.java b/src/main/java/dev/hilligans/ourcraft/container/containers/SlabBlockContainer.java index 32de32a5..ff37fea9 100644 --- a/src/main/java/dev/hilligans/ourcraft/container/containers/SlabBlockContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/container/containers/SlabBlockContainer.java @@ -10,8 +10,8 @@ public class SlabBlockContainer extends Container { - public SlabBlockContainer() { - this(new Inventory(3), ClientMain.getClient().playerData.inventory); + public SlabBlockContainer(Client client) { + this(new Inventory(3), client.playerData.inventory); } public SlabBlockContainer(Inventory inventory, Inventory playerInventory) { diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java b/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java index 9e7932e2..042a5c84 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/server/ServerPlayerData.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.data.other.server; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.container.Container; import dev.hilligans.ourcraft.container.containers.InventoryContainer; import dev.hilligans.ourcraft.container.Slot; @@ -44,17 +45,17 @@ public class ServerPlayerData implements IServerPacketHandler { public UUID playerID; public ChannelId channelId; - public ServerPlayerData(PlayerEntity playerEntity, String id) { + public ServerPlayerData(GameInstance gameInstance, PlayerEntity playerEntity, String id) { this.playerEntity = playerEntity; this.id = id; playerInventory = playerEntity.inventory; openContainer = new InventoryContainer(playerInventory).setPlayerId(playerEntity.id); - playerInventory.setItem(0,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("chest"), (byte)2)); - playerInventory.setItem(1,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("slab"), (byte)10)); - playerInventory.setItem(2,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("weeping_vine"), (byte)64)); - playerInventory.setItem(3,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("stair"), (byte)63)); - playerInventory.setItem(4,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("grass_plant"), (byte)63)); - playerInventory.setItem(5,new ItemStack(Ourcraft.GAME_INSTANCE.getItem("blue"),(byte)63)); + playerInventory.setItem(0,new ItemStack(gameInstance.getItem("chest"), (byte)2)); + playerInventory.setItem(1,new ItemStack(gameInstance.getItem("slab"), (byte)10)); + playerInventory.setItem(2,new ItemStack(gameInstance.getItem("weeping_vine"), (byte)64)); + playerInventory.setItem(3,new ItemStack(gameInstance.getItem("stair"), (byte)63)); + playerInventory.setItem(4,new ItemStack(gameInstance.getItem("grass_plant"), (byte)63)); + playerInventory.setItem(5,new ItemStack(gameInstance.getItem("blue"),(byte)63)); } public ServerPlayerData(PlayerEntity playerEntity, String id, CompoundNBTTag tag) { @@ -103,10 +104,10 @@ public String getPlayerName() { return playerName; } - public static ServerPlayerData loadOrCreatePlayer(PlayerEntity playerEntity, String id) { + public static ServerPlayerData loadOrCreatePlayer(GameInstance gameInstance, PlayerEntity playerEntity, String id) { CompoundNBTTag tag = WorldLoader.loadTag(path + id + ".dat"); if(tag == null) { - return new ServerPlayerData(playerEntity,id); + return new ServerPlayerData(gameInstance, playerEntity,id); } else { return new ServerPlayerData(playerEntity,id,tag); } diff --git a/src/main/java/dev/hilligans/ourcraft/entity/entities/ItemEntity.java b/src/main/java/dev/hilligans/ourcraft/entity/entities/ItemEntity.java index e61ee592..5002f477 100644 --- a/src/main/java/dev/hilligans/ourcraft/entity/entities/ItemEntity.java +++ b/src/main/java/dev/hilligans/ourcraft/entity/entities/ItemEntity.java @@ -13,6 +13,7 @@ import dev.hilligans.ourcraft.item.ItemStack; import dev.hilligans.ourcraft.network.IPacketByteArray; import dev.hilligans.ourcraft.Ourcraft; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import static org.lwjgl.opengl.GL11.*; @@ -25,23 +26,23 @@ public class ItemEntity extends Entity { public int pickupDelay; - public ItemEntity(double x, double y, double z, int id, Block block) { + public ItemEntity(IWorld world, double x, double y, double z, int id, Block block) { super(x, y, z, id); this.block = block; type = 1; velY = 0.30f; - itemStack = new ItemStack(Ourcraft.GAME_INSTANCE.ITEMS.MAPPED_ELEMENTS.get(block.name),(byte)1); + itemStack = new ItemStack(world.getGameInstance().ITEMS.MAPPED_ELEMENTS.get(block.name),(byte)1); boundingBox = new BoundingBox(-0.25f,-0.25f,-0.25f,0.25f,0.25f,0.25f); pickupDelay = 10; } - public ItemEntity(double x, double y, double z, int id, ItemStack itemStack) { + public ItemEntity(IWorld world, double x, double y, double z, int id, ItemStack itemStack) { super(x,y,z,id); this.type = 1; this.itemStack = itemStack; boundingBox = new BoundingBox(-0.25f,-0.25f,-0.25f,0.25f,0.25f,0.25f); if(itemStack.item instanceof BlockItem) { - this.block = Ourcraft.GAME_INSTANCE.getBlock(itemStack.item.name); + this.block = world.getGameInstance().getBlock(itemStack.item.name); } pickupDelay = 40; } @@ -49,12 +50,15 @@ public ItemEntity(double x, double y, double z, int id, ItemStack itemStack) { public ItemEntity(IPacketByteArray packetData) { super(packetData); type = 1; + /* Item item = Ourcraft.GAME_INSTANCE.getItem(packetData.readInt()); if(item instanceof BlockItem) { this.block = Ourcraft.GAME_INSTANCE.getBlock(item.name); } + + */ boundingBox = new BoundingBox(-0.25f,-0.25f,-0.25f,0.25f,0.25f,0.25f); - itemStack = new ItemStack(item,(byte)1); + // itemStack = new ItemStack(item,(byte)1); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ContentPack.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ContentPack.java index 42e6975f..dc27b604 100644 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ContentPack.java +++ b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ContentPack.java @@ -1,6 +1,7 @@ package dev.hilligans.ourcraft.mod.handler.content; import dev.hilligans.ourcraft.block.Block; +import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.audio.SoundBuffer; import dev.hilligans.ourcraft.client.input.Input; import dev.hilligans.ourcraft.client.input.InputHandlerProvider; @@ -13,7 +14,6 @@ import dev.hilligans.ourcraft.data.primitives.Triplet; import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.item.Item; -import dev.hilligans.ourcraft.mod.handler.events.client.RenderEndEvent; import dev.hilligans.ourcraft.network.Protocol; import dev.hilligans.ourcraft.resource.registry.loaders.RegistryLoader; import dev.hilligans.ourcraft.resource.loaders.ResourceLoader; @@ -38,12 +38,14 @@ public class ContentPack { public ContentPack(GameInstance gameInstance) { this.gameInstance = gameInstance; - gameInstance.EVENT_BUS.register(t -> { + /* gameInstance.EVENT_BUS.register(t -> { if(waiting) { waiting = false; rebuild(); } }, RenderEndEvent.class); + + */ } public void load() { @@ -53,16 +55,16 @@ public void load() { } } - private boolean waiting = false; + //private boolean waiting = false; public void generateData() { gameInstance.REBUILDING.set(true); ///TODO Could potentially rebuild when rendering but very unlikely - if(!Settings.isServer && !(ClientMain.getClient() == null || ClientMain.getClient().rendering)) { - waiting = true; - } else { + //if(!Settings.isServer && !(ClientMain.getClient() == null || ClientMain.getClient().rendering)) { + // waiting = true; + //} else { rebuild(); - } + //} } public void registerModContent(ModContent modContent) { @@ -90,11 +92,6 @@ public void buildVital() { public boolean built = false; private void rebuild() { - if(!Settings.isServer) { - if(ClientMain.getClient() != null) { - ClientMain.getClient().refreshTexture = true; - } - } gameInstance.clear(); gameInstance.RESOURCE_MANAGER.clearData(); @@ -234,8 +231,8 @@ public void releaseMod(String mod) { } } - public void loadCachedMod(String name) { - ModContent modContent = ModContent.readLocal(name,gameInstance); + public void loadCachedMod(String name, Client client) { + ModContent modContent = ModContent.readLocal(name,gameInstance, client); if(modContent != null) { putMod(modContent); } diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java index 948ee34f..b7bdebe4 100644 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java +++ b/src/main/java/dev/hilligans/ourcraft/mod/handler/content/ModContent.java @@ -2,6 +2,7 @@ import dev.hilligans.ourcraft.biome.Biome; import dev.hilligans.ourcraft.block.Block; +import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.client.audio.SoundBuffer; import dev.hilligans.ourcraft.client.input.Input; import dev.hilligans.ourcraft.client.input.InputHandlerProvider; @@ -93,10 +94,10 @@ public ModContent(IByteArray packetData, GameInstance gameInstance) { readData(packetData); if(Settings.cacheDownloadedMods) { if(Settings.storeServerModsIndividually) { - String ip = ClientMain.getClient().serverIP.replace(':','_'); - if(!ip.equals("")) { + //String ip = ClientMain.getClient().serverIP.replace(':','_'); + //if(!ip.equals("")) { // WorldLoader.write("mod_cache/servers/" + ip + "/" + getModID() + "-" + version + ".dat",packetData.toByteBuffer()); - } + //} } else { // WorldLoader.write("mod_cache/mods/" + getModID() + "-" + version + ".dat",packetData.toByteBuffer()); } @@ -118,8 +119,8 @@ public ModContent addMainClass(Class classVal) { return this; } - public static ModContent readLocal(String name,GameInstance gameInstance) { - ByteBuffer buffer = WorldLoader.readBuffer("mod_cache/" + (Settings.storeServerModsIndividually ? "servers/" + ClientMain.getClient().serverIP.replace(':','_') + "/" : "mods/") + name + ".dat"); + public static ModContent readLocal(String name, GameInstance gameInstance, Client client) { + ByteBuffer buffer = WorldLoader.readBuffer("mod_cache/" + (Settings.storeServerModsIndividually ? "servers/" + client.serverIP.replace(':','_') + "/" : "mods/") + name + ".dat"); if(buffer != null) { ModContent modContent = new ModContent("", gameInstance); //modContent.readData(new PacketData(buffer,2)); diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/events/client/RenderEndEvent.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/events/client/RenderEndEvent.java deleted file mode 100644 index 419d270f..00000000 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/events/client/RenderEndEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.hilligans.ourcraft.mod.handler.events.client; - -import dev.hilligans.ourcraft.client.Client; -import dev.hilligans.ourcraft.client.MatrixStack; -import dev.hilligans.ourcraft.mod.handler.Event; - -public class RenderEndEvent extends Event { - - public MatrixStack worldStack; - public MatrixStack screenStack; - public Client client; - - public RenderEndEvent(MatrixStack worldStack, MatrixStack screenStack, Client client) { - this.worldStack = worldStack; - this.screenStack = screenStack; - this.client = client; - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/network/IClientPacketHandler.java b/src/main/java/dev/hilligans/ourcraft/network/IClientPacketHandler.java index 9ff4fe2c..ef64ff59 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/IClientPacketHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/IClientPacketHandler.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.network; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.world.newworldsystem.IWorld; @@ -9,4 +10,5 @@ public interface IClientPacketHandler extends IPacketHandler { IWorld getWorld(); + GameInstance getGameInstance(); } diff --git a/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java b/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java index 0148102e..ad03c759 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/network/IServerPacketHandler.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.network; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity; import dev.hilligans.ourcraft.network.debug.PacketTraceByteArray; @@ -32,6 +33,10 @@ public interface IServerPacketHandler extends IPacketHandler { ServerNetworkHandler getServerNetworkHandler(); + default GameInstance getGameInstance() { + return getServer().getGameInstance(); + } + default void handleDisconnect() { getWorld().removeEntity(getPlayerEntity().id, 0); } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java index 0522bca3..8c20c9f8 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CHandshakePacket.java @@ -77,7 +77,7 @@ public static synchronized void handlePlayer(String name, long version, ChannelH BlockPos spawn = new BlockPos(0, 100, 0); PlayerEntity playerEntity = new PlayerEntity(spawn.x,spawn.y,spawn.z,playerId); - ServerPlayerData serverPlayerData = ServerPlayerData.loadOrCreatePlayer(playerEntity,identifier); + ServerPlayerData serverPlayerData = ServerPlayerData.loadOrCreatePlayer(serverPacketHandler.getGameInstance(), playerEntity,identifier); playerEntity.setPlayerData(serverPlayerData); serverPlayerData.setServer(serverPacketHandler.getServer()).setNetworkHandler(serverPacketHandler.getServerNetworkHandler()).setName(name); serverPlayerData.setPlayerID(new UUID(playerId, 0)).setChannelID(ctx.channel().id()); @@ -87,7 +87,7 @@ public static synchronized void handlePlayer(String name, long version, ChannelH serverPacketHandler.getServerNetworkHandler().nameToPlayerData.put(name, serverPlayerData); //ServerNetworkHandler.playerData.put(playerId, serverPlayerData); serverPlayerData.getWorld().addEntity(playerEntity); - serverPacketHandler.sendPacket(new SHandshakePacket(playerId),ctx); + serverPacketHandler.sendPacket(new SHandshakePacket(playerId, serverPacketHandler.getGameInstance()),ctx); serverPlayerData.getWorld().sendChunksToPlayer((int) playerEntity.getX(), (int) playerEntity.getY(), (int) playerEntity.getZ(), serverPlayerData); serverPlayerData.getServer().sendPacket(new SChatMessage(name + " has joined the game")); //ServerMain.getServer().sendPacket(new SUpdatePlayer(serverPlayerData.)); diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java index c0f4ea25..9420ebf4 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/COpenScreen.java @@ -42,7 +42,7 @@ public void handle(IServerPacketHandler packetHandler) { if(id == 2) { ServerPlayerData serverPlayerData = packetHandler.getServerPlayerData(); if(serverPlayerData != null && serverPlayerData.isCreative) { - CreativeContainer creativeContainer = new CreativeContainer(serverPlayerData.playerInventory,CreativeContainer.createInventory()); + CreativeContainer creativeContainer = new CreativeContainer(serverPlayerData.playerInventory,CreativeContainer.createInventory(packetHandler.getGameInstance())); serverPlayerData.openContainer(creativeContainer); packetHandler.sendPacket(new SOpenContainer(creativeContainer), ctx); } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java index 72be53c7..22b10f30 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CRequestContent.java @@ -44,8 +44,8 @@ public void decode(IPacketByteArray packetData) { @Override public void handle(IServerPacketHandler serverPacketHandler) { for(String string : mods) { - ModContent modContent = Ourcraft.GAME_INSTANCE.CONTENT_PACK.mods.get(string.split(":::")[0]); - serverPacketHandler.sendPacket(new SSendModContentPacket(modContent), ctx); + ModContent modContent = serverPacketHandler.getGameInstance().CONTENT_PACK.mods.get(string.split(":::")[0]); + //serverPacketHandler.sendPacket(new SSendModContentPacket(modContent), ctx); } ServerPlayerData serverPlayerData = serverPacketHandler.getServerPlayerData(); diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java index d1d27eb7..d6ca6e58 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CSendBlockChanges.java @@ -54,7 +54,7 @@ public void handle(IServerPacketHandler serverPacketHandler) { Block droppedBlock = oldState.getBlock().droppedBlock; if(droppedBlock != Blocks.AIR) { if (serverPacketHandler.getWorld().getBlockState(x, y, z).getBlock() == Blocks.AIR) { - ItemEntity itemEntity = new ItemEntity(x + 0.5f, y + 1, z + 0.5f, Entity.getNewId(), droppedBlock); + ItemEntity itemEntity = new ItemEntity(serverPacketHandler.getWorld(), x + 0.5f, y + 1, z + 0.5f, Entity.getNewId(), droppedBlock); serverPacketHandler.getWorld().addEntity(itemEntity); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java index 1eac0737..90ecb5c2 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SHandshakePacket.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.network.packet.server; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.client.Client; import dev.hilligans.ourcraft.network.*; import dev.hilligans.ourcraft.Ourcraft; @@ -13,20 +14,22 @@ public class SHandshakePacket extends PacketBaseNew { public int playerId; public String[] mods; + public GameInstance gameInstance; public SHandshakePacket() { super(6); } - public SHandshakePacket(int playerId) { + public SHandshakePacket(int playerId, GameInstance gameInstance) { this(); + this.gameInstance = gameInstance; this.playerId = playerId; } @Override public void encode(IPacketByteArray packetData) { packetData.writeInt(playerId); - String[] mods = Ourcraft.GAME_INSTANCE.CONTENT_PACK.getModList(); + String[] mods = gameInstance.CONTENT_PACK.getModList(); packetData.writeInt(mods.length); for(String string : mods) { packetData.writeString(string); @@ -46,17 +49,18 @@ public void decode(IPacketByteArray packetData) { @Override public void handle(IClientPacketHandler clientPacketHandler) { Client client = clientPacketHandler.getClient(); + gameInstance = client.getGameInstance(); client.playerId = playerId; client.valid = true; - ArrayList localMods = new ArrayList<>(Arrays.asList(Ourcraft.GAME_INSTANCE.CONTENT_PACK.getModList())); + ArrayList localMods = new ArrayList<>(Arrays.asList(gameInstance.CONTENT_PACK.getModList())); ArrayList neededMods = new ArrayList<>(); for(String string : mods) { if(!localMods.contains(string)) { if(!new File("mod_cache/" + (Settings.storeServerModsIndividually ? "servers/" + client.serverIP.replace(':','_') + "/" : "mods/") + string.replace(":::","-") + ".dat").exists()) { neededMods.add(string); } else { - Ourcraft.GAME_INSTANCE.CONTENT_PACK.loadCachedMod(string.replace(":::","-")); + gameInstance.CONTENT_PACK.loadCachedMod(string.replace(":::","-"), client); } } } @@ -64,7 +68,7 @@ public void handle(IClientPacketHandler clientPacketHandler) { // ctx.channel().writeAndFlush(new PacketData(new CRequestContent(neededMods))); } else if(mods.length != 0) { - Ourcraft.GAME_INSTANCE.CONTENT_PACK.generateData(); + gameInstance.CONTENT_PACK.generateData(); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java index dc40fa37..06863409 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SOpenContainer.java @@ -6,6 +6,9 @@ public class SOpenContainer extends PacketBaseNew { + + public short containerID; + public int uniqueID; Container container; int uniqueId; @@ -31,8 +34,9 @@ public void encode(IPacketByteArray packetData) { @Override public void decode(IPacketByteArray packetData) { - container = Container.getContainer(packetData.readShort()); - container.uniqueId = packetData.readInt(); + containerID = packetData.readShort(); + // container = Container.getContainer(packetData.readShort(), packetData.); + uniqueId = packetData.readInt(); int slotCount = packetData.readShort(); for(int x = 0; x < slotCount; x++) { //ItemStack itemStack = packetData.readItemStack(); @@ -42,7 +46,9 @@ public void decode(IPacketByteArray packetData) { @Override public void handle(IClientPacketHandler clientPacketHandler) { + container = Container.getContainer(containerID, clientPacketHandler.getClient()); if(container != null) { + container.uniqueId = uniqueId; clientPacketHandler.getClient().openScreen(container); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java index 491e09e8..403887ba 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendModContentPacket.java @@ -25,12 +25,12 @@ public void encode(IPacketByteArray packetData) { @Override public void decode(IPacketByteArray packetData) { - modContent = new ModContent(packetData, Ourcraft.GAME_INSTANCE); + //modContent = new ModContent(packetData, Ourcraft.GAME_INSTANCE); } @Override public void handle() { - Ourcraft.GAME_INSTANCE.CONTENT_PACK.putMod(modContent); - Ourcraft.GAME_INSTANCE.CONTENT_PACK.generateData(); + //Ourcraft.GAME_INSTANCE.CONTENT_PACK.putMod(modContent); + //Ourcraft.GAME_INSTANCE.CONTENT_PACK.generateData(); } } diff --git a/src/main/java/dev/hilligans/ourcraft/resource/ResourceManager.java b/src/main/java/dev/hilligans/ourcraft/resource/ResourceManager.java index 9c81414c..95ea81a8 100644 --- a/src/main/java/dev/hilligans/ourcraft/resource/ResourceManager.java +++ b/src/main/java/dev/hilligans/ourcraft/resource/ResourceManager.java @@ -27,7 +27,6 @@ public class ResourceManager { public HashMap> models = new HashMap<>(); public ArrayList classLoaders = new ArrayList<>(); - public GameInstance gameInstance = Ourcraft.GAME_INSTANCE; public void setLanguageFile(String languageFile) { Languages.switchingLanguage.set(true); @@ -86,6 +85,7 @@ public InputStream getResource(String path) { return ResourceManager.class.getResourceAsStream(path); } + /* public static void reload() { for(String string : Ourcraft.GAME_INSTANCE.CONTENT_PACK.mods.keySet()) { if(!Ourcraft.GAME_INSTANCE.CONTENT_PACK.mods.get(string).isJar) { @@ -99,6 +99,8 @@ public static void reload() { } } + */ + public void clearData() { textures.clear(); models.clear(); diff --git a/src/main/java/dev/hilligans/ourcraft/save/Level.java b/src/main/java/dev/hilligans/ourcraft/save/Level.java index aac9c114..1942e7ac 100644 --- a/src/main/java/dev/hilligans/ourcraft/save/Level.java +++ b/src/main/java/dev/hilligans/ourcraft/save/Level.java @@ -35,9 +35,9 @@ public int getBlockID(String name) { return blocks.get(name).getTypeA(); } - public Block getBlock(int id) { - return Ourcraft.GAME_INSTANCE.BLOCKS.MAPPED_ELEMENTS.getOrDefault(idToNames.get(id),Blocks.AIR); - } + // public Block getBlock(int id) { + // return Ourcraft.GAME_INSTANCE.BLOCKS.MAPPED_ELEMENTS.getOrDefault(idToNames.get(id),Blocks.AIR); + //} public int ensureHasBlock(Block block) { if(blocks.get(block.getName()) == null) { diff --git a/src/main/java/dev/hilligans/ourcraft/server/IServer.java b/src/main/java/dev/hilligans/ourcraft/server/IServer.java index de8ef0d9..e91c17af 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/IServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/IServer.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.server; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity; import dev.hilligans.ourcraft.mod.handler.events.server.ServerTickEvent; @@ -26,6 +27,8 @@ public interface IServer { void sendPacket(PacketBase packetBase, PlayerEntity playerEntity); + GameInstance getGameInstance(); + class Server implements Runnable { public IServer server; //public IGameProcessor gameProcessor = new TE2GameProcessor(new TickEngineSettings()); diff --git a/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java b/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java index 2925eb44..1339f954 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/IntegratedServer.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.server; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.command.executors.ConsoleExecutor; import dev.hilligans.ourcraft.command.Commands; import dev.hilligans.ourcraft.data.other.server.ServerPlayerData; @@ -79,4 +80,9 @@ public void sendPacket(PacketBase packetBase) { public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { sendPacket(packetBase); } + + @Override + public GameInstance getGameInstance() { + return null; + } } diff --git a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java index 4476b6db..27192405 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java @@ -33,9 +33,13 @@ public class MultiPlayerServer implements IServer { public Int2ObjectOpenHashMap newWorlds = new Int2ObjectOpenHashMap<>(); public HashMap waitingPlayers = new HashMap<>(); public HashMap> playerQueue = new HashMap<>(); - public GameInstance gameInstance = Ourcraft.GAME_INSTANCE; + public GameInstance gameInstance; public ServerNetwork serverNetwork; + public MultiPlayerServer(GameInstance gameInstance) { + this.gameInstance = gameInstance; + } + public void startServer(String port) { gameInstance.EVENT_BUS.postEvent(new MultiPlayerServerStartEvent(this,port)); Server server = new Server(this); @@ -98,6 +102,11 @@ public void sendPacket(PacketBase packetBase, PlayerEntity playerEntity) { getServerNetworkHandler().sendPacket(packetBase,playerEntity); } + @Override + public GameInstance getGameInstance() { + return gameInstance; + } + static class PlayerHandler implements Runnable { MultiPlayerServer server; diff --git a/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java b/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java index d230fcb8..2e12e775 100644 --- a/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java +++ b/src/main/java/dev/hilligans/ourcraft/util/ConsoleReader.java @@ -9,6 +9,7 @@ public class ConsoleReader extends Thread { public ConsoleReader(Consumer consoleEvent) { this.consoleEvent = consoleEvent; + setDaemon(true); this.start(); } diff --git a/src/main/java/dev/hilligans/ourcraft/util/NamedThreadFactory.java b/src/main/java/dev/hilligans/ourcraft/util/NamedThreadFactory.java index 4e553bd2..efb2464c 100644 --- a/src/main/java/dev/hilligans/ourcraft/util/NamedThreadFactory.java +++ b/src/main/java/dev/hilligans/ourcraft/util/NamedThreadFactory.java @@ -23,7 +23,7 @@ public Thread newThread(Runnable r) { namePrefix + threadNumber.getAndIncrement(), 0); if (t.isDaemon()) - t.setDaemon(false); + t.setDaemon(true); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java index b0dc60ef..8d29f4d7 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java @@ -68,7 +68,7 @@ public IBlockState getBlockState1(long x, long y, long z) { if(subChunk == null) { return Blocks.AIR.getDefaultState(); } - return subChunk.getBlockState((int) (x % 15), (int) (y % 15), (int) (z % 15)); + return subChunk.getBlockState(world, (int) (x % 15), (int) (y % 15), (int) (z % 15)); } @Override @@ -80,7 +80,7 @@ public void setBlockState(long x, long y, long z, IBlockState blockState) { } subChunk = chunks[(int) (y >> 4)] = new SimpleSubChunkImpl(16,16); } - if(subChunk.setBlockState((int) (x % 15), (int)(y % 15), (int) (z % 15),blockState) != blockState) { + if(subChunk.setBlockState(world, (int) (x % 15), (int)(y % 15), (int) (z % 15),blockState) != blockState) { dirty = true; } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java index 03d2364d..215e5b22 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java @@ -88,7 +88,7 @@ public IBlockState getBlockState1(long x, long y, long z) { if(subChunks[index] == null) { return Blocks.AIR.getDefaultState(); } - return subChunks[index].getBlockState((int) (x & 15), (int) (y & 15), (int) (z & 15)); + return subChunks[index].getBlockState(world, (int) (x & 15), (int) (y & 15), (int) (z & 15)); } @Override @@ -106,11 +106,11 @@ public void setBlockState(long x, long y, long z, IBlockState blockState) { } ISubChunk repl = subChunk.canInsertOrGetNext(blockState); if(repl != null) { - repl.setBlockState((int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); + repl.setBlockState(world, (int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); subChunks[index] = repl; return; } - subChunk.setBlockState((int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); + subChunk.setBlockState(world, (int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); } @Override @@ -123,7 +123,7 @@ public void setBlockStateAtomic(Lock lock, long x, long y, long z, IBlockState b if(subChunk instanceof IAtomicSubChunk atomicSubChunk) { ISubChunk newChunk = subChunk.canInsertOrGetNext(blockState); if(newChunk != null) { - newChunk.setBlockState((int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); + newChunk.setBlockState(world, (int) (x & 15), (int) (y & 15), (int) (z & 15), blockState); if(ARRAY_HANDLE.weakCompareAndSet(subChunks, index, subChunk, newChunk)) { return; } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicWorld.java index be7b9692..c82b5dc3 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicWorld.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.world.newworldsystem; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.entity.Entity; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.joml.Vector3f; @@ -10,10 +11,12 @@ public class CubicWorld implements IWorld { public int radius; public String worldName; public int id; + public GameInstance gameInstance; public final IThreeDChunkContainer chunkContainer = new CubicChunkContainer(32, 32); public Int2ObjectOpenHashMap entities = new Int2ObjectOpenHashMap<>(); - public CubicWorld(int id, String worldName, int radius) { + public CubicWorld(GameInstance gameInstance, int id, String worldName, int radius) { + this.gameInstance = gameInstance; this.radius = radius; this.worldName = worldName; this.id = id; @@ -79,4 +82,9 @@ public void addEntity(Entity entity) { public Entity removeEntity(long l1, long l2) { return entities.remove((int)l1); } + + @Override + public GameInstance getGameInstance() { + return gameInstance; + } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteAtomicSubChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteAtomicSubChunk.java index 92111d54..9329561f 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteAtomicSubChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteAtomicSubChunk.java @@ -35,12 +35,12 @@ public int getHeight() { } @Override - public IBlockState getBlockState(int x, int y, int z) { + public IBlockState getBlockState(IWorld world, int x, int y, int z) { return blockStates.get((blocks[getIndex(x, y, z)])); } @Override - public IBlockState setBlockState(int x, int y, int z, IBlockState blockState) { + public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) { int id = blockState.getBlockStateID(); blocks[getIndex(x, y, z)] = (short) id; return blockStates.get(id); diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java index d5939139..89086ea5 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java @@ -27,13 +27,13 @@ public int getHeight() { } @Override - public IBlockState getBlockState(int x, int y, int z) { + public IBlockState getBlockState(IWorld world, int x, int y, int z) { if(blockStates == null) { return Blocks.AIR.getDefaultState(); } try { short b = blockStates[((x * width + y) * height + z)]; - return b == 0 ? Blocks.AIR.getDefaultState() : Ourcraft.GAME_INSTANCE.BLOCK_STATES.get(b); + return b == 0 ? Blocks.AIR.getDefaultState() : world.getGameInstance().BLOCK_STATES.get(b); } catch (Exception e) { // e.printStackTrace(); } @@ -41,7 +41,7 @@ public IBlockState getBlockState(int x, int y, int z) { } @Override - public IBlockState setBlockState(int x, int y, int z, IBlockState blockState) { + public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) { if(blockStates == null) { if(blockState.getBlock() != Blocks.AIR) { blockStates = new short[width * height * width]; diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ISubChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ISubChunk.java index 7a57c81f..10262da9 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ISubChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ISubChunk.java @@ -9,9 +9,9 @@ public interface ISubChunk { int getHeight(); - IBlockState getBlockState(int x, int y, int z); + IBlockState getBlockState(IWorld world, int x, int y, int z); - IBlockState setBlockState(int x, int y, int z, IBlockState blockState); + IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState); boolean isEmpty(); diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java index 8ebd8960..0b0c12dd 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.world.newworldsystem; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.block.blockstate.IBlockState; import dev.hilligans.ourcraft.block.Blocks; import dev.hilligans.ourcraft.data.other.BlockPos; @@ -17,7 +18,7 @@ public interface IWorld { String getName(); - + int getID(); void tick(); @@ -140,6 +141,8 @@ default Iterable getChunks(BlockPos min, BlockPos max) { return getChunks(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()); } + GameInstance getGameInstance(); + default Iterable getChunks(long minX, long minY, long minZ, long maxX, long maxY, long maxZ) { return new Iterable<>() { @NotNull diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/NewClientWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/NewClientWorld.java index cb8226e2..495c4e1d 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/NewClientWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/NewClientWorld.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.world.newworldsystem; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.entity.Entity; public class NewClientWorld implements IWorld { @@ -63,4 +64,9 @@ public void addEntity(Entity entity) { public Entity removeEntity(long l1, long l2) { return null; } + + @Override + public GameInstance getGameInstance() { + return null; + } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/PalettedSubChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/PalettedSubChunk.java index 4408648c..4cc60c78 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/PalettedSubChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/PalettedSubChunk.java @@ -33,12 +33,12 @@ public int getHeight() { } @Override - public IBlockState getBlockState(int x, int y, int z) { + public IBlockState getBlockState(IWorld world, int x, int y, int z) { return null; } @Override - public IBlockState setBlockState(int x, int y, int z, IBlockState blockState) { + public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) { return null; } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java index d09c85ad..bf28f916 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.world.newworldsystem; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.block.Blocks; import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.BoundingBox; @@ -26,8 +27,8 @@ public class ServerCubicWorld extends CubicWorld implements IServerWorldBase { public ConcurrentLinkedQueue> postTickFutures = new ConcurrentLinkedQueue<>(); - public ServerCubicWorld(int id, String worldName, int radius, IWorldHeightBuilder worldHeightBuilder) { - super(id, worldName, radius); + public ServerCubicWorld(GameInstance gameInstance, int id, String worldName, int radius, IWorldHeightBuilder worldHeightBuilder) { + super(gameInstance, id, worldName, radius); this.worldHeightBuilder = worldHeightBuilder; } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java index bc7a532d..1ccb533b 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java @@ -26,7 +26,7 @@ public int getHeight() { } @Override - public IBlockState getBlockState(int x, int y, int z) { + public IBlockState getBlockState(IWorld world, int x, int y, int z) { if(blockStates == null) { return Blocks.AIR.getDefaultState(); } @@ -40,7 +40,7 @@ public IBlockState getBlockState(int x, int y, int z) { } @Override - public IBlockState setBlockState(int x, int y, int z, IBlockState blockState) { + public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) { if(blockStates == null) { if(blockState.getBlock() != Blocks.AIR) { blockStates = new IBlockState[width * height * width]; diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleWorld.java index 3fb7e30f..e44b9352 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleWorld.java @@ -1,5 +1,6 @@ package dev.hilligans.ourcraft.world.newworldsystem; +import dev.hilligans.ourcraft.GameInstance; import dev.hilligans.ourcraft.block.blockstate.IBlockState; import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.entity.Entity; @@ -111,4 +112,9 @@ public void addEntity(Entity entity) { public Entity removeEntity(long l1, long l2) { return null; } + + @Override + public GameInstance getGameInstance() { + return null; + } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SingleBlockFinalSubChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SingleBlockFinalSubChunk.java index 055fea5b..f6b12f54 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SingleBlockFinalSubChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SingleBlockFinalSubChunk.java @@ -31,12 +31,12 @@ public int getHeight() { } @Override - public IBlockState getBlockState(int x, int y, int z) { + public IBlockState getBlockState(IWorld world, int x, int y, int z) { return blockState; } @Override - public IBlockState setBlockState(int x, int y, int z, IBlockState blockState) { + public IBlockState setBlockState(IWorld world, int x, int y, int z, IBlockState blockState) { if(CHECKED && blockState != this.blockState) { throw new EngineImplementationException("canInsertOrGetNext will always return a new subchunk when states dont match so a blockstate set should never be attempted here"); } diff --git a/src/main/java/dev/hilligans/ourcraft/world/tasks/ChunkTickTask.java b/src/main/java/dev/hilligans/ourcraft/world/tasks/ChunkTickTask.java index b3ab9c44..e5d5b187 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/tasks/ChunkTickTask.java +++ b/src/main/java/dev/hilligans/ourcraft/world/tasks/ChunkTickTask.java @@ -40,7 +40,7 @@ public void accept(ISubChunk iSubChunk) { pos /= width; int y = pos % height; int x = pos / width; - IBlockState blockState = iSubChunk.getBlockState(x, y, z); + IBlockState blockState = iSubChunk.getBlockState(world, x, y, z); blockState.getBlock().randomTick(lock, instance, blockState, chunk, world, new BlockPos(x, y, z), random); } }