Skip to content

Commit

Permalink
Cleaned up all the old World, Chunk and SubChunk code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilligans committed Dec 26, 2023
1 parent f27ddec commit 8e2a2ce
Show file tree
Hide file tree
Showing 55 changed files with 297 additions and 1,519 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/hilligans/ourcraft/Ourcraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static void registerDefaultContent(ModContent modContent) {
modContent.registerResourceLoader(new JsonLoader(), new ImageLoader(), new StringLoader());
modContent.registerResourceLoader(new LitematicaSchematicLoader());

modContent.registerBlocks(Blocks.AIR, Blocks.STONE, Blocks.DIRT, Blocks.GRASS, Blocks.BEDROCK, Blocks.IRON_ORE, Blocks.LEAVES, Blocks.LOG, Blocks.SAND, Blocks.CACTUS, Blocks.CHEST, Blocks.COLOR_BLOCK, Blocks.STAIR_BLOCK, Blocks.GRASS_PLANT, Blocks.WEEPING_VINE, Blocks.MAPLE_LOG, Blocks.MAPLE_PLANKS, Blocks.PINE_LOG, Blocks.PINE_PLANKS, Blocks.SPRUCE_LOG, Blocks.SPRUCE_PLANKS, Blocks.BIRCH_LOG, Blocks.BIRCH_PLANKS, Blocks.OAK_LOG, Blocks.OAK_PLANKS, Blocks.WILLOW_LOG, Blocks.WILLOW_PLANKS, Blocks.ACACIA_LOG, Blocks.ACACIA_PLANKS, Blocks.POPLAR_LOG, Blocks.POPLAR_PLANKS, Blocks.ELM_LOG, Blocks.ELM_WOOD, Blocks.PALM_LOG, Blocks.PALM_WOOD, Blocks.REDWOOD_LOG, Blocks.REDWOOD_WOOD, Blocks.SAPLING);
modContent.registerBlocks(Blocks.AIR, Blocks.STONE, Blocks.DIRT, Blocks.GRASS, Blocks.BEDROCK, Blocks.IRON_ORE, Blocks.LEAVES, Blocks.LOG, Blocks.SAND, Blocks.CACTUS, Blocks.CHEST, Blocks.STAIR_BLOCK, Blocks.GRASS_PLANT, Blocks.WEEPING_VINE, Blocks.MAPLE_LOG, Blocks.MAPLE_PLANKS, Blocks.PINE_LOG, Blocks.PINE_PLANKS, Blocks.SPRUCE_LOG, Blocks.SPRUCE_PLANKS, Blocks.BIRCH_LOG, Blocks.BIRCH_PLANKS, Blocks.OAK_LOG, Blocks.OAK_PLANKS, Blocks.WILLOW_LOG, Blocks.WILLOW_PLANKS, Blocks.ACACIA_LOG, Blocks.ACACIA_PLANKS, Blocks.POPLAR_LOG, Blocks.POPLAR_PLANKS, Blocks.ELM_LOG, Blocks.ELM_WOOD, Blocks.PALM_LOG, Blocks.PALM_WOOD, Blocks.REDWOOD_LOG, Blocks.REDWOOD_WOOD, Blocks.SAPLING);
modContent.registerBlock(Blocks.RED);
modContent.registerBlock(Blocks.WATER);
modContent.registerBiome(Biomes.PLAINS,Biomes.SANDY_HILLS,Biomes.DESERT,Biomes.FOREST);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/dev/hilligans/ourcraft/ServerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.hilligans.ourcraft.util.Settings;
import dev.hilligans.ourcraft.util.Side;
import dev.hilligans.ourcraft.world.newworldsystem.*;
import dev.hilligans.ourcraft.world.World;
import dev.hilligans.ourcraft.world.gen.IWorldHeightBuilder;
import dev.hilligans.planets.gen.PlanetWorldHeightBuilder;

Expand Down Expand Up @@ -62,10 +61,6 @@ public static void newServer(GameInstance gameInstance) {

}

public static World getWorld(int id) {
return server.worlds.get(id);
}

public static MultiPlayerServer getServer() {
return server;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Object handle(CommandExecutor executor, String[] args) {
serverWorld.queuePostTickEvent(serverWorld1 -> {
BlockPos min = new BlockPos(f.minX(s), f.minY(s), f.minZ(s));
BlockPos max = new BlockPos(f.maxX(s), f.maxY(s), f.maxZ(s));
SetSingleModification modification = new SetSingleModification(min, max, b.getDefaultState1());
SetSingleModification modification = new SetSingleModification(min, max, b.getDefaultState());
try(Lock l = new Lock(serverWorld1.getChunkLocker())) {
for(IChunk chunk : serverWorld1.getChunks(min, max)) {
if(chunk != null) {
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/dev/hilligans/ourcraft/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import dev.hilligans.ourcraft.util.Side;
import dev.hilligans.ourcraft.world.DataProvider;
import dev.hilligans.ourcraft.world.data.providers.ShortBlockState;
import dev.hilligans.ourcraft.world.World;
import dev.hilligans.ourcraft.block.blockstate.IBlockStateTable;
import org.joml.Vector3d;
import org.joml.Vector3f;
Expand Down Expand Up @@ -84,13 +83,13 @@ public String getName() {
return "block." + modId + "." + name;
}

public boolean activateBlock(World world, PlayerEntity playerEntity, BlockPos pos) {
public boolean activateBlock(IWorld world, PlayerEntity playerEntity, BlockPos pos) {
return false;
}

public void onPlace(World world, BlockPos blockPos) {}
public void onPlace(IWorld world, BlockPos blockPos) {}

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


//TODO fix
Expand All @@ -104,10 +103,6 @@ public void reload() {
}
*/

public BlockState getDefaultState() {
return new BlockState(this);
}

public boolean hasBlockState() {
return blockProperties.blockStateSize != 0;
}
Expand All @@ -124,7 +119,8 @@ public BlockState getStateWithData(short data) {
public BlockState getStateForPlacement(Vector3d playerPos, RayResult rayResult) {
switch (blockProperties.placementMode) {
default -> {
return getDefaultState();
return null;
//return getDefaultState();
}
case "slab" -> {
return new DataBlockState(this, new ShortBlockState((short) rayResult.side));
Expand All @@ -147,11 +143,11 @@ public Item getBlockItem() {
return modContent.gameInstance.getItem(getName());
}

public boolean getAllowedMovement(Vector3d motion, Vector3d pos, BlockPos blockPos, BoundingBox boundingBox, World world) {
public boolean getAllowedMovement(Vector3d motion, Vector3d pos, BlockPos blockPos, BoundingBox boundingBox, IWorld world) {
return blockProperties.canWalkThrough || !getBoundingBox(world, blockPos).intersectsBox(boundingBox, blockPos.get3d(), pos, motion.x, motion.y, motion.z);
}

public BoundingBox getBoundingBox(World world, BlockPos pos) {
public BoundingBox getBoundingBox(IWorld world, BlockPos pos) {
return blockProperties.blockShape.getBoundingBox(world,pos);
}

Expand Down Expand Up @@ -252,11 +248,11 @@ public void onPlace(IMethodResult result, IBlockState state, IWorld world) {}

//TODO add placing context
public IBlockState getStateForPlacement() {
return getDefaultState1();
return getDefaultState();
}

//TODO pull state from table
public IBlockState getDefaultState1() {
public IBlockState getDefaultState() {
return table.getBlockState(0);
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/dev/hilligans/ourcraft/block/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class Blocks {

public static final Block CHEST = new ChestBlock("chest",new BlockProperties().withTexture("flex_tape.png"));

public static final Block COLOR_BLOCK = new ColorBlock("color_block", new BlockProperties().withTexture("white.png"));

public static final Block STAIR_BLOCK = new StairBlock("stair", new BlockProperties().withTexture("dirt.png"));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import dev.hilligans.ourcraft.ServerMain;
import dev.hilligans.ourcraft.world.DataProvider;
import dev.hilligans.ourcraft.world.data.providers.ChestDataProvider;
import dev.hilligans.ourcraft.world.World;
import dev.hilligans.ourcraft.world.newworldsystem.IServerWorld;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;

public class ChestBlock extends Block {

Expand All @@ -20,15 +21,16 @@ public ChestBlock(String name, BlockProperties blockProperties) {
}

@Override
public void onPlace(World world, BlockPos blockPos) {
public void onPlace(IWorld world, BlockPos blockPos) {
super.onPlace(world, blockPos);
world.setDataProvider(blockPos, new ChestDataProvider());
//world.setDataProvider(blockPos, new ChestDataProvider());
}

@Override
public boolean activateBlock(World world, PlayerEntity playerEntity, BlockPos pos) {
if(world.isServer()) {
ChestDataProvider chestDataProvider = (ChestDataProvider) world.getDataProvider(pos);
public boolean activateBlock(IWorld world, PlayerEntity playerEntity, BlockPos pos) {
if(world instanceof IServerWorld) {
ChestDataProvider chestDataProvider = null;
//ChestDataProvider chestDataProvider = (ChestDataProvider) world.getDataProvider(pos);
ChestContainer container = (ChestContainer) new ChestContainer(chestDataProvider.inventory,playerEntity.getPlayerData().playerInventory).setPlayerId(playerEntity.id);
playerEntity.getPlayerData().openContainer(container);
ServerMain.getServer().sendPacket(new SOpenContainer(container), playerEntity);
Expand All @@ -37,14 +39,17 @@ public boolean activateBlock(World world, PlayerEntity playerEntity, BlockPos po
}

@Override
public void onBreak(World world, BlockPos blockPos) {
public void onBreak(IWorld world, BlockPos blockPos) {
super.onBreak(world, blockPos);
if(world.isServer()) {
if(world instanceof IServerWorld) {
/*
Inventory inventory = ((ChestDataProvider) world.getDataProvider(blockPos)).inventory;
world.setDataProvider(blockPos, null);
for (int x = 0; x < inventory.getSize(); x++) {
world.spawnItemEntity(blockPos.x + 0.5f, blockPos.y + 0.5f, blockPos.z + 0.5f, inventory.getItem(x));
}
*/
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dev.hilligans.ourcraft.data.other.BlockPos;
import dev.hilligans.ourcraft.data.other.BlockProperties;
import dev.hilligans.ourcraft.world.builders.foliage.CustomTreeBuilder;
import dev.hilligans.ourcraft.world.World;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;
import org.joml.Vector2d;

public class OakSapling extends Block {
Expand All @@ -32,7 +32,7 @@ public void build (BlockPos startPos){
};

@Override
public void onPlace(World world, BlockPos blockPos) {
public void onPlace(IWorld world, BlockPos blockPos) {
customTreeBuilder.setWorld(world).build(blockPos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public boolean hasBlockState() {
return true;
}

/*
@Override
public BlockState getDefaultState() {
return new DataBlockState(this, new ShortBlockState((short)0));
}
*/

@Override
public BlockState getStateWithData(short data) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/dev/hilligans/ourcraft/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import dev.hilligans.ourcraft.save.WorldLoader;
import dev.hilligans.ourcraft.server.MultiPlayerServer;
import dev.hilligans.ourcraft.util.Settings;
import dev.hilligans.ourcraft.world.ClientWorld;
import org.lwjgl.BufferUtils;
import org.lwjgl.openal.AL11;

Expand Down Expand Up @@ -75,8 +74,6 @@ public class Client implements IClientPacketHandler {
public boolean refreshTexture = true;

public ClientPlayerData playerData = new ClientPlayerData();
public ClientWorld clientWorld;

//public IWorld newClientWorld = new SimpleWorld(0,"");
public IWorld newClientWorld = new CubicWorld(0,"", 64);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void invoke(long window, int button, int action, int mods) {
}

public void onPress() {
/*
if (client.screen == null) {
if (button == GLFW_MOUSE_BUTTON_1) {
BlockPos pos = client.clientWorld.traceBlockToBreak(Camera.pos.x, Camera.pos.y + Camera.playerBoundingBox.eyeHeight, Camera.pos.z, Camera.pitch, Camera.yaw);
Expand Down Expand Up @@ -74,5 +75,7 @@ public void onPress() {
DoubleBuffer doubleBuffer = client.getMousePos();
client.screen.mouseClick((int) doubleBuffer.get(0), (int) doubleBuffer.get(1), button);
}
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import dev.hilligans.ourcraft.client.rendering.graphics.api.ICamera;
import dev.hilligans.ourcraft.data.other.BoundingBox;
import dev.hilligans.ourcraft.world.newworldsystem.IChunk;
import dev.hilligans.ourcraft.world.newworldsystem.ISubChunk;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;
import dev.hilligans.ourcraft.world.SubChunk;
import org.joml.Vector3d;

import java.util.ArrayList;
Expand Down Expand Up @@ -43,13 +43,13 @@ public void build(ICamera pos) {

}

public static int getSolidChunkFaces(SubChunk chunk) {
public static int getSolidChunkFaces(ISubChunk chunk) {
int result = 0;
short[][] vals = new short[16][16];
for(int x = 0; x < 16; x++) {
for(int y = 0; y < 16; y++) {
for(int z = 0; z < 16; z++) {
if(chunk.getBlock(x,y,z).getBlock().blockProperties.transparent) {
if(chunk.getBlockState(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)) {
Expand Down Expand Up @@ -98,39 +98,39 @@ public static boolean checkFace(short[][] vals, int pos, boolean addX, boolean a
return false;
}

public static void recursivelyCheck(SubChunk chunk, short[][] vals, int x, int y, int z) {
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.getBlock(x,y,z + 1).getBlock().blockProperties.transparent) {
if(z != 15 && chunk.getBlockState(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.getBlock(x,y,z - 1).getBlock().blockProperties.transparent) {
if(z != 0 && chunk.getBlockState(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.getBlock(x + 1,y,z).getBlock().blockProperties.transparent) {
if(x != 15 && chunk.getBlockState(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.getBlock(x - 1,y,z).getBlock().blockProperties.transparent) {
if(x != 0 && chunk.getBlockState(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.getBlock(x,y + 1,z).getBlock().blockProperties.transparent) {
if(y != 15 && chunk.getBlockState(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.getBlock(x,y - 1,z).getBlock().blockProperties.transparent) {
if(y != 0 && chunk.getBlockState(x,y - 1,z).getBlock().blockProperties.transparent) {
if ((vals[x][y - 1] & (1 << z)) == 0) {
vals[x][y - 1] |= 1 << z;
negY = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import dev.hilligans.ourcraft.block.Block;
import dev.hilligans.ourcraft.client.MatrixStack;
import dev.hilligans.ourcraft.client.rendering.graphics.api.ICamera;
import dev.hilligans.ourcraft.ClientMain;
import dev.hilligans.ourcraft.network.packet.client.CUpdatePlayerPacket;
import dev.hilligans.ourcraft.util.Ray;
import dev.hilligans.ourcraft.world.newworldsystem.IWorld;
import dev.hilligans.ourcraft.world.World;
import org.joml.*;

import java.lang.Math;
Expand Down Expand Up @@ -44,7 +42,7 @@ public abstract class WorldCamera implements ICamera {
public float velY;
public float velZ;

public World world;
public IWorld world;

public float fov = 90;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void registerCallbacks() {
});

glfwSetWindowFocusCallback(window, (window, focused) -> windowFocused = focused);
MouseHandler mouseHandler = new MouseHandler(client);
glfwSetMouseButtonCallback(window, mouseHandler::invoke);
//MouseHandler mouseHandler = new MouseHandler(client);
//glfwSetMouseButtonCallback(window, mouseHandler::invoke);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package dev.hilligans.ourcraft.client.rendering.minimap;

import dev.hilligans.ourcraft.block.Block;
import dev.hilligans.ourcraft.data.other.BlockPos;
import dev.hilligans.ourcraft.world.Chunk;
import dev.hilligans.ourcraft.world.World;

import java.awt.*;
import java.nio.ByteBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL30.glGenerateMipmap;

public class GridChunk {
/*
int x;
int z;
Expand Down Expand Up @@ -152,4 +141,6 @@ public void update(int X, int Z) {
}
}
}
*/
}
Loading

0 comments on commit 8e2a2ce

Please sign in to comment.