Skip to content

Commit

Permalink
Refactoring static method accesses to use new api and implemented a n…
Browse files Browse the repository at this point in the history
…ew ray intersection method into world.
  • Loading branch information
Hilligans committed Nov 28, 2023
1 parent 0f46f18 commit 6bf5ede
Show file tree
Hide file tree
Showing 36 changed files with 194 additions and 204 deletions.
6 changes: 6 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import dev.hilligans.ourcraft.client.Client;
import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine;
import dev.hilligans.ourcraft.data.other.BoundingBox;
import dev.hilligans.ourcraft.util.ArgumentContainer;
import dev.hilligans.ourcraft.util.Side;
import org.joml.Intersectionf;
import org.joml.Math;
import org.joml.Vector2f;

import java.io.IOException;

Expand All @@ -29,6 +33,8 @@ public static void main(String[] args) throws IOException {
gameInstance.side = Side.CLIENT;
gameInstance.loadContent();

;

if(argumentContainer.getBoolean("--integratedServer", false)) {
try {
Thread thread = new Thread(() -> ServerMain.server(gameInstance, argumentContainer));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/hilligans/ourcraft/Ourcraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ public void press(RenderWindow renderWindow, float strength) {
modContent.registerKeybinds(new Input("ourcraft:mouse_handler::" + MouseHandler.MOUSE_X) {
@Override
public void press(RenderWindow window, float strength) {
window.getCamera().addRotation(0, strength/100);
window.getCamera().addRotation(0, strength/400);
GLFW.glfwSetCursorPos(window.getWindowID(), window.getWindowWidth()/2,window.getWindowHeight()/2);
}
}.onlyWithPipelines("ourcraft:new_world_pipeline"));

modContent.registerKeybinds(new Input("ourcraft:mouse_handler::" + MouseHandler.MOUSE_Y) {
@Override
public void press(RenderWindow window, float strength) {
window.getCamera().addRotation(-strength/100,0);
window.getCamera().addRotation(-strength/400,0);
GLFW.glfwSetCursorPos(window.getWindowID(), window.getWindowWidth()/2,window.getWindowHeight()/2);
}
}.onlyWithPipelines("ourcraft:new_world_pipeline"));
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/hilligans/ourcraft/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public void onPlace(World world, BlockPos blockPos) {}

public void onBreak(World world, BlockPos blockPos) {}

public void onUpdate(World world, BlockPos blockPos) {}

public void tick(World world, BlockPos pos) {}

//TODO fix
/*
Expand Down Expand Up @@ -158,6 +155,10 @@ public BoundingBox getBoundingBox(World world, BlockPos pos) {
return blockProperties.blockShape.getBoundingBox(world,pos);
}

public BoundingBox getBoundingBox(IBlockState blockState) {
return blockProperties.blockShape.getBoundingBox(blockState);
}

public void generateTextures(TextAtlas textAtlas) {
blockProperties.blockTextureManager.generate(textAtlas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public interface IBlockState {

int getBlockID();

short getBlockStateIndex();

IBlockState setBlockStateID(int val);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public IBlockStateBuilder getBuilder() {

public void build(int id) {
map = new Object[builder.getSize()];
this.blockData = (short) id;
int x = 0;
for(IBlockStateType<?> stateType : builder.getStateTypes()) {
int pos = Math.floorDiv(id, stateType.getCount());
Expand Down Expand Up @@ -75,6 +76,11 @@ public int getBlockID() {
return block.id;
}

@Override
public short getBlockStateIndex() {
return blockData;
}

@Override
public IBlockState setBlockStateID(int val) {
this.blockStateReferenceID = val;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/dev/hilligans/ourcraft/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class Client implements IClientPacketHandler {

public MouseHandler mouseHandler;
public Screen screen;
public ShaderManager shaderManager;
public SoundEngine soundEngine;

public int texture;
Expand Down Expand Up @@ -178,7 +177,7 @@ public void closeScreen() {
}

public void openScreen(Screen screen1) {
RenderWindow renderWindow = graphicsEngine.getWindows().get(0);
RenderWindow renderWindow = rWindow;
screen1.setWindow(renderWindow);
gameInstance.EVENT_BUS.postEvent(new OpenScreenEvent(screen1,screen));
//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public InputHandler getInputProvider() {
return inputHandler;
}

public abstract String getClipboardString();

public abstract void setMousePosition(int x, int y);

public abstract int getWindowWidth();

public abstract int getWindowHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public FixedFunctionGLWindow setup() {
GL.createCapabilities();

client.glStarted = true;
client.shaderManager = new ShaderManager();

glfwMakeContextCurrent(renderWindow.window);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public Client getClient() {
return client;
}

@Override
public String getClipboardString() {
return null;
}

@Override
public void setMousePosition(int x, int y) {

}

@Override
public int getWindowWidth() {
return width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public FreeCamera(RenderWindow renderWindow) {
public @NotNull RenderWindow getWindow() {
return window;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void move(float x, float y, float z) {
updateCameraForGravity(gravityVector);
}

getWindow().getClient().sendPacket(new CUpdatePlayerPacket(pos.x,pos.y,pos.z,pitch,yaw,ClientMain.getClient().playerId));
getWindow().getClient().sendPacket(new CUpdatePlayerPacket(pos.x,pos.y,pos.z,pitch,yaw,getWindow().getClient().playerId));
}

public void updateCameraForGravity(Vector3fc newVector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public Client getClient() {
return null;
}

@Override
public String getClipboardString() {
return null;
}

@Override
public void setMousePosition(int x, int y) {

}

@Override
public int getWindowWidth() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public Client getClient() {
return null;
}

@Override
public String getClipboardString() {
return null;
}

@Override
public void setMousePosition(int x, int y) {

}

@Override
public int getWindowWidth() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public OpenGLWindow setup() {
client.glStarted = true;
client.gameInstance.EVENT_BUS.postEvent(new GLInitEvent(window));
gameInstance.build(this, null);
client.shaderManager = new ShaderManager();

setupStringRenderer("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public Client getClient() {
return client;
}

@Override
public String getClipboardString() {
return glfwGetClipboardString(window);
}

@Override
public void setMousePosition(int x, int y) {
glfwSetCursorPos(window, x, y);
}

@Override
public int getWindowWidth() {
return width;
Expand Down Expand Up @@ -112,6 +122,5 @@ public void registerCallbacks() {
glfwSetWindowFocusCallback(window, (window, focused) -> windowFocused = focused);
MouseHandler mouseHandler = new MouseHandler(client);
glfwSetMouseButtonCallback(window, mouseHandler::invoke);
//inputHandler.add((IInputProvider) mouseHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ public InputHandler getInputProvider() {
return null;
}

@Override
public String getClipboardString() {
return GLFW.glfwGetClipboardString(window);
}

@Override
public void setMousePosition(int x, int y) {
GLFW.glfwSetCursorPos(window, x, y);
}

@Override
public int getWindowWidth() {
return glfwWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public class PrimitiveBuilder {
public int size = 0;
public int count = 0;

public Shader shader;

public PrimitiveBuilder(int type, Shader shader) {
this.type = type;
this.shader = shader;
}

public VertexFormat vertexFormat;

public PrimitiveBuilder(VertexFormat vertexFormat) {
Expand Down Expand Up @@ -131,68 +124,24 @@ public int getVerticesCount() {
}

public int getCount() {
if(shader == null) {
return (vertexFormat.getStride() / 4);
} else {
return shader.shaderElementCount;
}
}

public int[] createMesh() {
return createMesh(GL_STATIC_DRAW);
return (vertexFormat.getStride() / 4);
}

public int[] createMesh(int mode) {
float[] vertices = this.vertices.getElementData();
int[] indices = this.indices.getElementData();

int VAO = glGenVertexArrays();
int VBO = glGenBuffers();
int EBO = glGenBuffers();
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices, mode);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, mode);
int x = 0;
int pointer = 0;
for(Shader.ShaderElement shaderElement : shader.shaderElements) {
glVertexAttribPointer(x,shaderElement.count,shaderElement.type,shaderElement.normalised,shader.shaderElementCount * 4,pointer * 4);
glEnableVertexAttribArray(x);
x++;
pointer += shaderElement.count;
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
return new int[]{VAO,VBO,EBO};
}


public static int id = -1;

public void rotate(float degrees, Vector3f vector) {
rotate(degrees,vector,0);
}

public void rotate(float degrees, Vector3f vector, int startPos) {
Matrix3f matrix3f = new Matrix3f(1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f);
matrix3f.rotate(degrees,vector);
for(int x = startPos; x < vertices.size(); x+=shader.shaderElementCount) {
for(int x = startPos; x < vertices.size(); x+=vertexFormat.getStride()) {
Vector3f vector3f = new Vector3f(vertices.elementData[x],vertices.elementData[x] + 1, vertices.elementData[x] + 2).mul(matrix3f);
vertices.elementData[x] = vector3f.x;
vertices.elementData[x + 1] = vector3f.y;
vertices.elementData[x + 2] = vector3f.z;
}
}

public void translate(float x, float y, float z, int startPos) {
for(int i = startPos; i < vertices.size(); i+=shader.shaderElementCount) {
vertices.elementData[i] += x;
vertices.elementData[i + 1] += y;
vertices.elementData[i + 2] += z;
}
}


public void applyTransformation(Matrix4f matrix4f, int shaderId, String name) {
int trans = glGetUniformLocation(shaderId, name);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MiniMapScreen(Client client, MiniMap miniMap) {
public void drawScreen(RenderWindow window, MatrixStack matrixStack) {
super.drawScreen(window, matrixStack);
if(MouseHandler.instance.mousePressed) {
DoubleBuffer mousePos = ClientMain.getClient().getMousePos();
DoubleBuffer mousePos = window.getClient().getMousePos();
int x = (int) (mousePos.get(0) - mouseLastX);
int y = (int) (mousePos.get(1) - mouseLastY);
miniMap.addX(Math.round(x / getRatio(miniMap.zoom)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void drawHotbar(RenderWindow window, MatrixStack matrixStack) {
// Textures.HOTBAR.drawCenteredXTexture(matrixStack,startY, Settings.guiSize);

for(int x = 0; x < 9; x++) {
ItemStack itemStack = ClientMain.getClient().playerData.inventory.getItem(x);
ItemStack itemStack = window.getClient().playerData.inventory.getItem(x);
if(!itemStack.isEmpty()) {
itemStack.item.render(matrixStack,startX + x * width, startY, width / 2,itemStack);
}
Expand Down
Loading

0 comments on commit 6bf5ede

Please sign in to comment.