diff --git a/src/main/java/dev/hilligans/ourcraft/Ourcraft.java b/src/main/java/dev/hilligans/ourcraft/Ourcraft.java index c6ad9507..17e92d59 100644 --- a/src/main/java/dev/hilligans/ourcraft/Ourcraft.java +++ b/src/main/java/dev/hilligans/ourcraft/Ourcraft.java @@ -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); diff --git a/src/main/java/dev/hilligans/ourcraft/ServerMain.java b/src/main/java/dev/hilligans/ourcraft/ServerMain.java index 09cd46e9..4fc957f9 100644 --- a/src/main/java/dev/hilligans/ourcraft/ServerMain.java +++ b/src/main/java/dev/hilligans/ourcraft/ServerMain.java @@ -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; @@ -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; } diff --git a/src/main/java/dev/hilligans/ourcraft/addons/worldedit/SetCommand.java b/src/main/java/dev/hilligans/ourcraft/addons/worldedit/SetCommand.java index 0a0a6581..c94f949f 100644 --- a/src/main/java/dev/hilligans/ourcraft/addons/worldedit/SetCommand.java +++ b/src/main/java/dev/hilligans/ourcraft/addons/worldedit/SetCommand.java @@ -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) { diff --git a/src/main/java/dev/hilligans/ourcraft/block/Block.java b/src/main/java/dev/hilligans/ourcraft/block/Block.java index 67bbe647..9a5c8873 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/Block.java +++ b/src/main/java/dev/hilligans/ourcraft/block/Block.java @@ -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; @@ -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 @@ -104,10 +103,6 @@ public void reload() { } */ - public BlockState getDefaultState() { - return new BlockState(this); - } - public boolean hasBlockState() { return blockProperties.blockStateSize != 0; } @@ -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)); @@ -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); } @@ -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); } diff --git a/src/main/java/dev/hilligans/ourcraft/block/Blocks.java b/src/main/java/dev/hilligans/ourcraft/block/Blocks.java index ecf88777..20fbf89e 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/Blocks.java +++ b/src/main/java/dev/hilligans/ourcraft/block/Blocks.java @@ -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")); diff --git a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ChestBlock.java b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ChestBlock.java index c8214613..39bdc8a7 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ChestBlock.java +++ b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ChestBlock.java @@ -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 { @@ -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); @@ -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)); } + + */ } } diff --git a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ColorBlock.java b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ColorBlock.java deleted file mode 100644 index 7cfee02c..00000000 --- a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/ColorBlock.java +++ /dev/null @@ -1,30 +0,0 @@ -package dev.hilligans.ourcraft.block.blocktypes; - -import dev.hilligans.ourcraft.block.Block; -import dev.hilligans.ourcraft.data.other.BlockProperties; -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; -import dev.hilligans.ourcraft.world.data.providers.ShortBlockState; - -import java.util.Random; - -public class ColorBlock extends Block { - public ColorBlock(String name, BlockProperties blockProperties) { - super(name, blockProperties); - } - - @Override - public boolean hasBlockState() { - return true; - } - - @Override - public BlockState getDefaultState() { - return new DataBlockState(this, new ShortBlockState((short) new Random().nextInt())); - } - - @Override - public BlockState getStateWithData(short data) { - return new DataBlockState(this, new ShortBlockState(data)); - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/OakSapling.java b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/OakSapling.java index 93e600fb..d6c91309 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/OakSapling.java +++ b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/OakSapling.java @@ -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 { @@ -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); } } diff --git a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/StairBlock.java b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/StairBlock.java index c03debf9..8c27f9a2 100644 --- a/src/main/java/dev/hilligans/ourcraft/block/blocktypes/StairBlock.java +++ b/src/main/java/dev/hilligans/ourcraft/block/blocktypes/StairBlock.java @@ -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) { diff --git a/src/main/java/dev/hilligans/ourcraft/client/Client.java b/src/main/java/dev/hilligans/ourcraft/client/Client.java index 35d964bc..d7958d1a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/Client.java +++ b/src/main/java/dev/hilligans/ourcraft/client/Client.java @@ -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; @@ -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); diff --git a/src/main/java/dev/hilligans/ourcraft/client/input/key/MouseHandler.java b/src/main/java/dev/hilligans/ourcraft/client/input/key/MouseHandler.java index 5d17a61f..8e0e563c 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/input/key/MouseHandler.java +++ b/src/main/java/dev/hilligans/ourcraft/client/input/key/MouseHandler.java @@ -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); @@ -74,5 +75,7 @@ public void onPress() { DoubleBuffer doubleBuffer = client.getMousePos(); client.screen.mouseClick((int) doubleBuffer.get(0), (int) doubleBuffer.get(1), button); } + + */ } } 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 60a3863d..94de238f 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 @@ -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; @@ -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)) { @@ -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; diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/WorldCamera.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/WorldCamera.java index fe10c1ec..4323e65b 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/WorldCamera.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/graphics/implementations/WorldCamera.java @@ -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; @@ -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; 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 0ec1b259..c8090954 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 @@ -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); } } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/GridChunk.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/GridChunk.java index 82da1777..b717742a 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/GridChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/GridChunk.java @@ -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; @@ -152,4 +141,6 @@ public void update(int X, int Z) { } } } + + */ } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/MiniMap.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/MiniMap.java index f6e1f298..8298f9e7 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/MiniMap.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/minimap/MiniMap.java @@ -1,11 +1,12 @@ package dev.hilligans.ourcraft.client.rendering.minimap; import dev.hilligans.ourcraft.client.MatrixStack; -import dev.hilligans.ourcraft.world.ClientWorld; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; + public class MiniMap { + /* public ClientWorld clientWorld; public int lastX = 0; public int lastY = 0; @@ -39,7 +40,7 @@ public void update(int x, int z) { //TODO fix public void draw(MatrixStack matrixStack, int chunkX, int chunkZ, int x, int y, int windowWidth, int windowHeight) { - /* + GL11.glDisable(GL11.GL_DEPTH_TEST); int size = zoom; @@ -69,7 +70,7 @@ public void draw(MatrixStack matrixStack, int chunkX, int chunkZ, int x, int y, //Textures.SHORT_ICON.drawTexture(matrixStack,getX((int) blockPos.getChunkX(),size,x,windowWidth), getZ((int) blockPos.getChunkZ(),size,y,windowHeight),10,10); GL11.glEnable(GL11.GL_DEPTH_TEST); - */ + } public int getX(int chunkX, int size, int x, int windowWidth) { @@ -93,6 +94,6 @@ public void addY(float y) { microZ -= extra * 256f / 16; lastY -= extra; } - + */ } diff --git a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/MiniMapScreen.java b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/MiniMapScreen.java index 15f04607..ecdcad58 100644 --- a/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/MiniMapScreen.java +++ b/src/main/java/dev/hilligans/ourcraft/client/rendering/screens/MiniMapScreen.java @@ -5,18 +5,15 @@ import dev.hilligans.ourcraft.client.input.key.MouseHandler; import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow; import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext; -import dev.hilligans.ourcraft.client.rendering.minimap.MiniMap; import dev.hilligans.ourcraft.client.rendering.ScreenBase; -import dev.hilligans.ourcraft.ClientMain; import java.nio.DoubleBuffer; public class MiniMapScreen extends ScreenBase { - MiniMap miniMap; + //MiniMap miniMap; - public MiniMapScreen(Client client, MiniMap miniMap) { - this.miniMap = miniMap; + public MiniMapScreen(Client client) { } int mouseLastX = 0; @@ -29,13 +26,13 @@ public void drawScreen(RenderWindow window, MatrixStack matrixStack, GraphicsCon 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))); - miniMap.addY(Math.round(y / getRatio(miniMap.zoom))); + // miniMap.addX(Math.round(x / getRatio(miniMap.zoom))); + // miniMap.addY(Math.round(y / getRatio(miniMap.zoom))); mouseLastX = (int) mousePos.get(0); mouseLastY = (int) mousePos.get(1); } - miniMap.draw(matrixStack,miniMap.lastX, miniMap.lastY,0,0, (int) window.getWindowWidth(), (int) window.getWindowHeight()); + // miniMap.draw(matrixStack,miniMap.lastX, miniMap.lastY,0,0, (int) window.getWindowWidth(), (int) window.getWindowHeight()); } @Override @@ -48,7 +45,7 @@ public void mouseClick(int x, int y, int mouseButton) { @Override public void mouseScroll(int x, int y, float amount) { super.mouseScroll(x, y, amount); - miniMap.zoom = (int) Math.max(Math.min(miniMap.zoom + amount * 10, 1000),10); + // miniMap.zoom = (int) Math.max(Math.min(miniMap.zoom + amount * 10, 1000),10); } public float getRatio(int size) { diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/BlockTemplate.java b/src/main/java/dev/hilligans/ourcraft/data/other/BlockTemplate.java index 618684cd..98252075 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/BlockTemplate.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/BlockTemplate.java @@ -2,7 +2,7 @@ import dev.hilligans.ourcraft.block.Block; import dev.hilligans.ourcraft.block.Blocks; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import java.util.Random; @@ -14,13 +14,13 @@ public BlockTemplate(BlockPos... positions) { this.positions = positions; } - public void placeTemplate(World world, BlockPos startPos, Block block) { + public void placeTemplate(IWorld world, BlockPos startPos, Block block) { for(BlockPos blockPos : positions) { world.setBlockState(startPos.x + blockPos.x, startPos.y + blockPos.y, startPos.z + blockPos.z,block.getDefaultState()); } } - public void placeTemplateOnAir(World world, BlockPos startPos, Block block) { + public void placeTemplateOnAir(IWorld world, BlockPos startPos, Block block) { for(BlockPos blockPos : positions) { BlockPos pos = new BlockPos(startPos.x + blockPos.x, startPos.y + blockPos.y, startPos.z + blockPos.z); if(world.getBlockState(pos).getBlock() == Blocks.AIR) { @@ -29,7 +29,7 @@ public void placeTemplateOnAir(World world, BlockPos startPos, Block block) { } } - public void placeTemplateOnAirChanced(World world, BlockPos startPos, Block block, Random random, float chance, int min) { + public void placeTemplateOnAirChanced(IWorld world, BlockPos startPos, Block block, Random random, float chance, int min) { for(BlockPos blockPos : positions) { BlockPos pos = new BlockPos(startPos.x + blockPos.x, startPos.y + blockPos.y, startPos.z + blockPos.z); if(random.nextFloat() * chance >= min) { @@ -40,7 +40,7 @@ public void placeTemplateOnAirChanced(World world, BlockPos startPos, Block bloc } } - public void placeTemplateOnAir(World world, BlockPos startPos, BlockPos worldPos, Block block, double ang, double cos, double sin) { + public void placeTemplateOnAir(IWorld world, BlockPos startPos, BlockPos worldPos, Block block, double ang, double cos, double sin) { for(BlockPos blockPos : positions) { BlockPos pos = blockPos.copy().rotateZ(Math.cos(ang),Math.sin(ang)).add(startPos.rotateY(cos,sin)).add(worldPos); if(world.getBlockState(pos).getBlock() == Blocks.AIR) { diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/Structure.java b/src/main/java/dev/hilligans/ourcraft/data/other/Structure.java index 5a324218..04b9661e 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/Structure.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/Structure.java @@ -8,7 +8,6 @@ import dev.hilligans.ourcraft.tag.IntegerNBTTag; import dev.hilligans.ourcraft.tag.ListNBTTag; import dev.hilligans.ourcraft.tag.ShortNBTTag; -import dev.hilligans.ourcraft.world.World; import dev.hilligans.ourcraft.save.WorldLoader; public class Structure { @@ -27,9 +26,6 @@ public Structure(int width, int height, int length) { this.length = length; } - public void placeInWorld(World world, BlockPos pos, int rotation) { - } - public CompoundNBTTag toTag() { CompoundNBTTag compoundTag = new CompoundNBTTag(); @@ -67,7 +63,8 @@ public static Structure fromPath(String path) { listSpot++; blockState = block.getStateWithData(blocks.tags.get(listSpot).val); } else { - blockState = block.getDefaultState(); + blockState = null; + // blockState = block.getDefaultState(); } structure.blocks[x][y][z] = blockState; listSpot++; diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/BlockShape.java b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/BlockShape.java index d5ee0356..ab67f2ac 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/BlockShape.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/BlockShape.java @@ -11,7 +11,7 @@ import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.BoundingBox; import dev.hilligans.ourcraft.GameInstance; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ShortOpenHashMap; import org.joml.Vector3f; @@ -42,9 +42,9 @@ public BlockShape(BlockModel model) { this.data = model; } - public BoundingBox getBoundingBox(World world, BlockPos pos) { - int val = world.getBlockState(pos).readData(); - return boundingBoxes.getOrDefault(val,defaultBoundingBox).duplicate(); + public BoundingBox getBoundingBox(IWorld world, BlockPos pos) { + //int val = world.getBlockState(pos).readData(); + return boundingBoxes.getOrDefault(0,defaultBoundingBox).duplicate(); } public BoundingBox getBoundingBox(IBlockState blockState) { @@ -124,7 +124,7 @@ public short getRotation(BlockState blockState) { return -1; } - public int generateOutline(World world, BlockPos pos) { + public int generateOutline(IWorld world, BlockPos pos) { BoundingBox boundingBox = getBoundingBox(world, pos); boundingBox.minX -= 0.001f; boundingBox.minY -= 0.001f; diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/SlabBlockShape.java b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/SlabBlockShape.java index ca37c365..fd2ff7c7 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/SlabBlockShape.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/SlabBlockShape.java @@ -7,7 +7,7 @@ import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.BoundingBox; import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import org.joml.Vector3f; public class SlabBlockShape extends BlockShape { @@ -49,7 +49,7 @@ public int getSide(BlockState blockState, int side) { } @Override - public BoundingBox getBoundingBox(World world, BlockPos pos) { + public BoundingBox getBoundingBox(IWorld world, BlockPos pos) { switch (((DataBlockState)world.getBlockState(pos)).readData()) { case 5: return new BoundingBox(0, 0, 0, 1f, 0.5f, 1f); diff --git a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/StairBlockShape.java b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/StairBlockShape.java index 147dd3c5..a20b51bd 100644 --- a/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/StairBlockShape.java +++ b/src/main/java/dev/hilligans/ourcraft/data/other/blockshapes/StairBlockShape.java @@ -3,7 +3,7 @@ import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.BoundingBox; import dev.hilligans.ourcraft.data.other.JoinedBoundingBox; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; public class StairBlockShape extends BlockShape { @@ -12,7 +12,7 @@ public StairBlockShape() { } @Override - public BoundingBox getBoundingBox(World world, BlockPos pos) { + public BoundingBox getBoundingBox(IWorld world, BlockPos pos) { return new JoinedBoundingBox(0,0,0,1,0.5f,1).addBox(0,0.5f,0.5f,1,1,1); } } 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 43f7ad91..9e7932e2 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 @@ -182,10 +182,10 @@ public void dropItem(short slot, byte count) { if(slot == -1) { if(!heldStack.isEmpty()) { if(count == -1 || count >= heldStack.count) { - ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), Entity.getNewId(), heldStack).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); + // ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), Entity.getNewId(), heldStack).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); heldStack = ItemStack.emptyStack(); } else { - ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(),playerEntity.getY(),playerEntity.getZ(),Entity.getNewId(),new ItemStack(heldStack.item,count)).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); + // ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(),playerEntity.getY(),playerEntity.getZ(),Entity.getNewId(),new ItemStack(heldStack.item,count)).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); heldStack.count -= count; } } @@ -194,10 +194,10 @@ public void dropItem(short slot, byte count) { if(itemSlot != null) { if(!itemSlot.getContents().isEmpty()) { if(count == -1 || count >= itemSlot.getContents().count) { - ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), Entity.getNewId(), itemSlot.getContents()).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); + // ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), Entity.getNewId(), itemSlot.getContents()).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); itemSlot.setContents(ItemStack.emptyStack()); } else { - ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(),playerEntity.getY(),playerEntity.getZ(),Entity.getNewId(),new ItemStack(itemSlot.getContents().item,count)).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); + // ServerMain.getWorld(getDimension()).addEntity(new ItemEntity(playerEntity.getX(),playerEntity.getY(),playerEntity.getZ(),Entity.getNewId(),new ItemStack(itemSlot.getContents().item,count)).setVel(playerEntity.getForeWard().mul(-0.5f).add(0, 0.25f, 0))); itemSlot.getContents().count -= count; } } diff --git a/src/main/java/dev/hilligans/ourcraft/entity/Entity.java b/src/main/java/dev/hilligans/ourcraft/entity/Entity.java index 0d0a63ff..7fc32962 100644 --- a/src/main/java/dev/hilligans/ourcraft/entity/Entity.java +++ b/src/main/java/dev/hilligans/ourcraft/entity/Entity.java @@ -12,7 +12,6 @@ import dev.hilligans.ourcraft.ServerMain; import dev.hilligans.ourcraft.util.EntityPosition; import dev.hilligans.ourcraft.world.newworldsystem.IWorld; -import dev.hilligans.ourcraft.world.World; import org.joml.Vector2f; import org.joml.Vector3d; import org.joml.Vector3f; @@ -155,7 +154,7 @@ private void move(float velX, float velY, float velZ) { boolean couldMove = false; int x; for(x = 0; x < 7; x++) { - if(!getAllowedMovement(tryMovement(x,velX,velY,velZ),ServerMain.getWorld(dimension))) { + if(!getAllowedMovement(tryMovement(x,velX,velY,velZ),ServerMain.getServer().getWorld(null))) { continue; } couldMove = true; @@ -204,7 +203,7 @@ private Vector3f tryMovement(int side, float velX, float velY, float velZ) { } - public boolean getAllowedMovement(Vector3f motion, World world) { + public boolean getAllowedMovement(Vector3f motion, IWorld world) { BlockPos pos = new BlockPos(position); int X = (int) Math.ceil(Math.abs(motion.x)) + 1; int Y = (int) Math.ceil(Math.abs(motion.y)) + 1; diff --git a/src/main/java/dev/hilligans/ourcraft/entity/living/entities/PlayerEntity.java b/src/main/java/dev/hilligans/ourcraft/entity/living/entities/PlayerEntity.java index 019da66f..4f5babc3 100644 --- a/src/main/java/dev/hilligans/ourcraft/entity/living/entities/PlayerEntity.java +++ b/src/main/java/dev/hilligans/ourcraft/entity/living/entities/PlayerEntity.java @@ -53,6 +53,7 @@ public PlayerEntity(IPacketByteArray packetData) { public void tick() { boolean updateInventory = false; + /* for(Entity entity : ServerMain.getWorld(dimension).entities.values()) { if(entity instanceof ItemEntity) { if (entity.boundingBox.intersectsBox(itemPickupBox, new Vector3d(entity.getX(), entity.getY(), entity.getZ()), new Vector3d(getX(), getY(), getZ()))) { @@ -69,6 +70,7 @@ public void tick() { } } } + */ if(updateInventory) { inventory.age++; ServerMain.getServer().sendPacket(new SUpdateInventory(inventory),this); diff --git a/src/main/java/dev/hilligans/ourcraft/item/BlockItem.java b/src/main/java/dev/hilligans/ourcraft/item/BlockItem.java index 45795912..ad32ecd0 100644 --- a/src/main/java/dev/hilligans/ourcraft/item/BlockItem.java +++ b/src/main/java/dev/hilligans/ourcraft/item/BlockItem.java @@ -12,8 +12,8 @@ import dev.hilligans.ourcraft.data.other.RayResult; import dev.hilligans.ourcraft.entity.Entity; import dev.hilligans.ourcraft.entity.living.entities.PlayerEntity; -import dev.hilligans.ourcraft.entity.LivingEntity; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IServerWorld; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import org.joml.Vector3d; import org.joml.Vector3f; @@ -27,12 +27,12 @@ public BlockItem(String name, Block block, String modID) { } @Override - public boolean onActivate(World world, PlayerEntity playerEntity) { - RayResult rayResult; - if (world.isServer()) { - rayResult = world.traceBlock(playerEntity.getX(), playerEntity.getY() + playerEntity.boundingBox.eyeHeight, playerEntity.getZ(), playerEntity.pitch, playerEntity.yaw); + public boolean onActivate(IWorld world, PlayerEntity playerEntity) { + RayResult rayResult = null; + if (world instanceof IServerWorld) { + // rayResult = world.traceBlock(playerEntity.getX(), playerEntity.getY() + playerEntity.boundingBox.eyeHeight, playerEntity.getZ(), playerEntity.pitch, playerEntity.yaw); } else { - rayResult = world.traceBlock(Camera.pos.x, Camera.pos.y + Camera.playerBoundingBox.eyeHeight, Camera.pos.z, Camera.pitch, Camera.yaw); + // rayResult = world.traceBlock(Camera.pos.x, Camera.pos.y + Camera.playerBoundingBox.eyeHeight, Camera.pos.z, Camera.pitch, Camera.yaw); } if (rayResult == null || rayResult.side == -1) { return false; @@ -44,6 +44,7 @@ public boolean onActivate(World world, PlayerEntity playerEntity) { return false; } } + /* BlockState oldState = world.getBlockState(pos); BlockState blockState; @@ -70,7 +71,9 @@ public boolean onActivate(World world, PlayerEntity playerEntity) { } } - block.onPlace(world,pos); + */ + + //block.onPlace(world,pos); return true; } @@ -86,7 +89,7 @@ public void render(MatrixStack matrixStack, int x, int y, int size, ItemStack it @Override public void addData(TextAtlas textAtlas, PrimitiveBuilder primitiveBuilder, float size) { for(int z = 0; z < 6; z++) { - block.addVertices(textAtlas, primitiveBuilder,z,size,block.getDefaultState(),new BlockPos(0,0,0),0,0); + //block.addVertices(textAtlas, primitiveBuilder,z,size,block.getDefaultState(),new BlockPos(0,0,0),0,0); } primitiveBuilder.translate(size / 3f,size / 1.3f,0); primitiveBuilder.rotate(0.785f,new Vector3f(0.5f,-1,0)); diff --git a/src/main/java/dev/hilligans/ourcraft/item/Item.java b/src/main/java/dev/hilligans/ourcraft/item/Item.java index f83f898d..1065c379 100644 --- a/src/main/java/dev/hilligans/ourcraft/item/Item.java +++ b/src/main/java/dev/hilligans/ourcraft/item/Item.java @@ -13,7 +13,7 @@ import dev.hilligans.ourcraft.recipe.IRecipeComponent; import dev.hilligans.ourcraft.util.registry.IRegistryElement; import dev.hilligans.ourcraft.util.Side; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; public class Item implements IRecipeComponent, IRegistryElement { @@ -123,7 +123,7 @@ public void addData(TextAtlas textAtlas, PrimitiveBuilder primitiveBuilder, floa //itemProperties.itemModel.addData(primitiveBuilder,itemProperties.itemTextureManager,0,size,null,0,0); } - public boolean onActivate(World world, PlayerEntity playerEntity) { + public boolean onActivate(IWorld world, PlayerEntity playerEntity) { return true; } diff --git a/src/main/java/dev/hilligans/ourcraft/mod/handler/events/common/BlockChangeEvent.java b/src/main/java/dev/hilligans/ourcraft/mod/handler/events/common/BlockChangeEvent.java deleted file mode 100644 index 1d41d7b3..00000000 --- a/src/main/java/dev/hilligans/ourcraft/mod/handler/events/common/BlockChangeEvent.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.hilligans.ourcraft.mod.handler.events.common; - -import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.mod.handler.Event; -import dev.hilligans.ourcraft.world.World; - -public class BlockChangeEvent extends Event { - - public World world; - public BlockPos pos; - - public BlockChangeEvent(World world, BlockPos pos) { - this.world = world; - this.pos = pos; - } -} 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 36614c8b..72be53c7 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 @@ -61,9 +61,12 @@ public void handle(IServerPacketHandler serverPacketHandler) { x++; } serverPacketHandler.getServer().sendPacket(new SSendPlayerList(players,ids)); + /* for(Entity entity : ServerMain.getWorld(serverPlayerData.getDimension()).entities.values()) { serverPacketHandler.sendPacket(new SCreateEntityPacket(entity),ctx); } + + */ serverPacketHandler.sendPacket(new SUpdatePlayer((float) playerEntity.getX(), (float) playerEntity.getY(), (float) playerEntity.getZ(),0,0),ctx); serverPlayerData.playerInventory.age++; 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 ee8b2dc3..d1d27eb7 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 @@ -7,7 +7,6 @@ import dev.hilligans.ourcraft.entity.Entity; import dev.hilligans.ourcraft.block.Blocks; import dev.hilligans.ourcraft.network.*; -import dev.hilligans.ourcraft.ServerMain; public class CSendBlockChanges extends PacketBaseNew { @@ -48,9 +47,10 @@ public void decode(IPacketByteArray packetData) { public void handle(IServerPacketHandler serverPacketHandler) { int dim = serverPacketHandler.getServerPlayerData().getDimension(); IBlockState oldState = serverPacketHandler.getWorld().getBlockState(x,y,z); - IBlockState newBlock = Blocks.getBlockWithID(blockId).getDefaultState1(); + IBlockState newBlock = Blocks.getBlockWithID(blockId).getDefaultState(); serverPacketHandler.getWorld().setBlockState(x,y,z,newBlock); - newBlock.getBlock().onPlace(ServerMain.getWorld(dim), new BlockPos(x,y,z)); + newBlock.getBlock().onPlace(serverPacketHandler.getWorld(), new BlockPos(x, y, z)); + //newBlock.getBlock().onPlace(ServerMain.getWorld(dim), new BlockPos(x,y,z)); Block droppedBlock = oldState.getBlock().droppedBlock; if(droppedBlock != Blocks.AIR) { if (serverPacketHandler.getWorld().getBlockState(x, y, z).getBlock() == Blocks.AIR) { diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java index 5db41adf..0b41c3d8 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/client/CUseItem.java @@ -38,20 +38,25 @@ public void handle(IServerPacketHandler serverPacketHandler) { int dim = serverPacketHandler.getServerPlayerData().getDimension(); ServerPlayerData serverPlayerData = serverPacketHandler.getServerPlayerData(); if(serverPlayerData != null) { - BlockPos blockPos = ServerMain.getWorld(dim).traceBlockToBreak(serverPlayerData.playerEntity.getX(), serverPlayerData.playerEntity.getY() + serverPlayerData.playerEntity.boundingBox.eyeHeight, serverPlayerData.playerEntity.getZ(), serverPlayerData.playerEntity.pitch, serverPlayerData.playerEntity.yaw); + //todo fix + BlockPos blockPos = null; + //BlockPos blockPos = ServerMain.getWorld(dim).traceBlockToBreak(serverPlayerData.playerEntity.getX(), serverPlayerData.playerEntity.getY() + serverPlayerData.playerEntity.boundingBox.eyeHeight, serverPlayerData.playerEntity.getZ(), serverPlayerData.playerEntity.pitch, serverPlayerData.playerEntity.yaw); if (blockPos != null) { + /* BlockState blockState = ServerMain.getWorld(dim).getBlockState(blockPos); - if (blockState != null && blockState.getBlock().activateBlock(ServerMain.getWorld(dim), serverPlayerData.playerEntity, blockPos)) { + if (blockState != null && blockState.getBlock().activateBlock(serverPacketHandler.getWorld(), serverPlayerData.playerEntity, blockPos)) { return; } ItemStack itemStack = serverPlayerData.playerInventory.getItem(slot); if (!itemStack.isEmpty()) { - if (itemStack.item.onActivate(ServerMain.getWorld(dim), serverPlayerData.playerEntity)) { + if (itemStack.item.onActivate(serverPacketHandler.getWorld(), serverPlayerData.playerEntity)) { if (!serverPlayerData.isCreative) { itemStack.removeCount(1); } } } + + */ } } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java index 7b875f3d..2fe43e5f 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SSendBlockChanges.java @@ -5,7 +5,6 @@ import dev.hilligans.ourcraft.data.other.BlockPos; import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; import dev.hilligans.ourcraft.network.*; -import dev.hilligans.ourcraft.world.ClientWorld; public class SSendBlockChanges extends PacketBaseNew { int x; @@ -61,6 +60,8 @@ public void decode(IPacketByteArray packetData) { @Override public void handle(IClientPacketHandler clientPacketHandler) { - clientPacketHandler.getClient().clientWorld.blockChanges.add(new ClientWorld.BlockChange(x,y,z, Blocks.getBlockWithID(blockId).getStateWithData(blockData))); + //todo implement + + // clientPacketHandler.getClient().clientWorld.blockChanges.add(new ClientWorld.BlockChange(x,y,z, Blocks.getBlockWithID(blockId).getStateWithData(blockData))); } } diff --git a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java index e4322fbc..3d8aa61e 100644 --- a/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java +++ b/src/main/java/dev/hilligans/ourcraft/network/packet/server/SUpdateEntityPacket.java @@ -53,10 +53,14 @@ public void decode(IPacketByteArray packetData) { @Override public void handle(IClientPacketHandler clientPacketHandler) { if(id != clientPacketHandler.getClient().playerId) { + //todo implement + /* Entity entity = clientPacketHandler.getClient().clientWorld.entities.get(id); if(entity != null) { entity.setPos(x,y,z).setRot(pitch,yaw); } + + */ } } } diff --git a/src/main/java/dev/hilligans/ourcraft/save/ChunkLoader.java b/src/main/java/dev/hilligans/ourcraft/save/ChunkLoader.java deleted file mode 100644 index 154943b9..00000000 --- a/src/main/java/dev/hilligans/ourcraft/save/ChunkLoader.java +++ /dev/null @@ -1,332 +0,0 @@ -package dev.hilligans.ourcraft.save; - -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; -import dev.hilligans.ourcraft.data.primitives.Tuple; -import dev.hilligans.ourcraft.tag.*; -import dev.hilligans.ourcraft.util.Settings; -import dev.hilligans.ourcraft.world.Chunk; -import dev.hilligans.ourcraft.world.DataProvider; -import dev.hilligans.ourcraft.world.newworldsystem.IChunk; -import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - -public class ChunkLoader { - - public static String pathToWorld = "world/" + Settings.worldName + "/dim-0/"; - public static String getPathToChunk(int x, int z) { - return pathToWorld + "chunks/" + "x" + x + "_z" + z + ".dat"; - } - - public static HashMap loadedGroups = new HashMap<>(); - public static HashMap levels = new HashMap<>(); - // public static HashMap loadedData = new HashMap<>(); - - // public static Level level = new Level(); - - - public static CompoundNBTTag createTag(Chunk chunk) { - CompoundNBTTag compoundTag = new CompoundNBTTag(); - int[] blocks = new int[16 * 16 * 256]; - - for(int i = 0; i < blocks.length; i++) { - int x = i & 15; - int y = i >> 4 & 255; - int z = i >> 12 & 15; - BlockState blockState = chunk.getBlockState(x,y,z); - if(blockState.getBlock().hasBlockState()) { - blocks[i] = blockState.getBlock().id << 16 | ((DataBlockState)blockState).readData(); - } else { - blocks[i] = blockState.getBlock().id << 16; - } - } - IntegerArrayNBTTag intArrayTag = new IntegerArrayNBTTag(blocks); - compoundTag.putTag("blocks", intArrayTag); - compoundTag.putTag("data",getDataProviderTag(chunk)); - - return compoundTag; - } - - public static CompoundNBTTag createTag2(Chunk chunk) { - CompoundNBTTag compoundTag = new CompoundNBTTag(); - ListNBTTag blocks = new ListNBTTag<>(); - - for(int i = 0; i < 65536; i++) { - int x = i & 15; - int y = i >> 4 & 255; - int z = i >> 12 & 15; - BlockState blockState = chunk.getBlockState(x,y,z); - if(blockState.getBlock().hasBlockState()) { - blocks.tags.add(new ShortNBTTag(blockState.getBlock().id)); - blocks.tags.add(new ShortNBTTag(((DataBlockState)blockState).readData())); - } else { - blocks.tags.add(new ShortNBTTag(blockState.getBlock().id)); - } - } - - compoundTag.putTag("blocks", blocks); - compoundTag.putTag("data",getDataProviderTag(chunk)); - - return compoundTag; - } - - public static CompoundNBTTag createTag3(Chunk chunk, Level level) { - CompoundNBTTag compoundTag = new CompoundNBTTag(); - - ListNBTTag blocks = new ListNBTTag<>(); - - ArrayList> blockList = chunk.getBlockChainedList(); - - for(Tuple block : blockList) { - int id = level.ensureHasBlock(block.typeA.getBlock()); - blocks.tags.add(new ShortNBTTag((short) id)); - if(block.getTypeA().getBlock().hasBlockState()) { - if(block.getTypeA() instanceof DataBlockState) { - blocks.tags.add(new ShortNBTTag(((DataBlockState) block.getTypeA()).readData())); - } else { - System.out.println(block.typeA.getBlock().name); - } - } - int val = block.getTypeB(); - blocks.tags.add(new ShortNBTTag((short)val)); - } - compoundTag.putTag("blocks", blocks); - compoundTag.putTag("data",getDataProviderTag(chunk)); - - - return compoundTag; - } - - public static CompoundNBTTag getDataProviderTag(Chunk chunk) { - CompoundNBTTag compoundTag = new CompoundNBTTag(); - int x = 0; - for(Short2ObjectMap.Entry set : chunk.dataProviders.short2ObjectEntrySet()) { - CompoundNBTTag compoundTag2 = new CompoundNBTTag(); - compoundTag2.putShort("pos",set.getShortKey()); - //TODO: sometimes returns null and causes an exception - if(set.getValue() != null) { - set.getValue().write(compoundTag2); - compoundTag.putTag(x + "", compoundTag2); - x++; - } - } - compoundTag.putInt("count",x); - return compoundTag; - } - - - /* - public static Chunk createChunk2(int X, int Z, CompoundNBTTag compoundTag) { - Chunk chunk = new Chunk(X, Z, null); - try { - ListNBTTag blocks = (ListNBTTag) compoundTag.getTag("blocks"); - - int listSpot = 0; - - for (int i = 0; i < 65536; i++) { - int x = i & 15; - int y = i >> 4 & 255; - int z = i >> 12 & 15; - - Block block = Blocks.getBlockWithID(blocks.tags.get(listSpot).val); - BlockState blockState; - if (block.hasBlockState()) { - listSpot++; - blockState = block.getStateWithData(blocks.tags.get(listSpot).val); - } else { - blockState = block.getDefaultState(); - } - chunk.setBlockState(x, y, z, blockState); - listSpot++; - } - - setDataProviders(compoundTag.getCompoundTag("data"), chunk); - } catch (Exception e) { - System.err.println("Failed to load chunk x:" + X + " z:" + Z); - e.printStackTrace(); - return null; - } - return chunk; - } - - */ - - /* - public static Chunk createChunk3(int X, int Z, CompoundNBTTag compoundTag, Level level) { - Chunk chunk = new Chunk(X, Z, null); - try { - ListNBTTag blocks = (ListNBTTag) compoundTag.getTag("blocks"); - ArrayList> blockList = new ArrayList<>(); - - int offset = 0; - - while(offset < blocks.tags.size()) { - short val = blocks.tags.get(offset).val; - Block block = level.getBlock(val); - offset++; - BlockState blockState; - if(level.getBlockStateSize(val) != 0) { - blockState = block.getStateWithData(val); - offset++; - } else { - blockState = block.getDefaultState(); - } - blockList.add(new Tuple<>(blockState,blocks.tags.get(offset).val & 0xFFFF)); - offset++; - } - - chunk.setFromChainedList(blockList); - - setDataProviders(compoundTag.getCompoundTag("data"), chunk); - } catch (Exception e) { - System.err.println("Failed to load chunk x:" + X + " z:" + Z); - e.printStackTrace(); - return null; - } - return chunk; - } - - */ - - public static IChunk loadChunk(IChunk chunk, CompoundNBTTag tag, Level level) { - - - return chunk; - } - - - public static void setDataProviders(CompoundNBTTag compoundTag, Chunk chunk) { - //CompoundTag compoundTag1 = (CompoundTag) compoundTag.getTag("data"); - int count = ((IntegerNBTTag)compoundTag.getTag("count")).val; - - for(int i = 0; i < count; i++) { - CompoundNBTTag compoundTag2 = (CompoundNBTTag) compoundTag.getTag(i + ""); - short key = ((ShortNBTTag)compoundTag2.getTag("pos")).val; - int x = key & 15; - int y = key >> 4 & 255; - int z = key >> 12 & 15; - - BlockState blockState = chunk.getBlockState(x,y,z); - DataProvider dataProvider = blockState.getBlock().getDataProvider(); - if(dataProvider != null) { - dataProvider.read(compoundTag2); - chunk.dataProviders.put(key,dataProvider); - } else { - System.out.println("EMPTY DATA PROVIDER"); - } - } - } - - public static void finishSave() { - new File(pathToWorld + "chunks/").mkdir(); - for(String string : loadedGroups.keySet()) { - CompoundNBTTag compoundTag = loadedGroups.get(string); - CompoundNBTTag levelTag = new CompoundNBTTag(); - Level level = levels.get(string); - level.write(levelTag); - compoundTag.putTag("level",levelTag); - WorldLoader.save(compoundTag, pathToWorld + "chunks/" + string + ".dat"); - } - loadedGroups.clear(); - levels.clear(); - } - - public static void finishSave1() { - new File(pathToWorld + "chunks/").mkdir(); - for(String string : loadedGroups.keySet()) { - CompoundNBTTag compoundTag = loadedGroups.get(string); - CompoundNBTTag levelTag = new CompoundNBTTag(); - Level level = levels.get(string); - level.write(levelTag); - compoundTag.putTag("level",levelTag); - WorldLoader.save(compoundTag, pathToWorld + "chunks/" + string + ".dat"); - } - loadedGroups.clear(); - } - - - - public static CompoundNBTTag fetchChunk(int x, int z) { - int X = x >> 3; - int Z = z >> 3; - CompoundNBTTag compoundTag = loadedGroups.get("x" + X + "_z" + Z); - if(compoundTag != null) { - return compoundTag.getCompoundTag("x" + x + "_z" + z); - } else { - compoundTag = loadTag(X,Z); - if(compoundTag == null) { - compoundTag = new CompoundNBTTag(); - loadedGroups.put("x" + X + "_z" + Z,compoundTag); - return null; - } else { - loadedGroups.put("x" + X + "_z" + Z,compoundTag); - return compoundTag.getCompoundTag("x" + x + "_z" + z); - } - } - } - - public static Level fetchLevel(int x, int z) { - int X = x >> 3; - int Z = z >> 3; - Level level = levels.get("x" + X + "_z" + Z); - if (level == null) { - CompoundNBTTag compoundTag = loadTag(X, Z); - if (compoundTag == null) { - level = new Level(); - } else { - level = new Level(compoundTag.getCompoundTag("level")); - } - levels.put("x" + X + "_z" + Z, level); - } - return level; - } - - public static void putTag(int x, int z, CompoundNBTTag compoundTag) { - int X = x >> 3; - int Z = z >> 3; - CompoundNBTTag groupTag = loadedGroups.get("x" + X + "_z" + Z); - if(groupTag == null) { - groupTag = loadTag(X,Z); - if(groupTag == null) { - groupTag = new CompoundNBTTag(); - } - loadedGroups.put("x" + X + "_z" + Z, groupTag); - } - groupTag.putTag("x" + x + "_z" + z,compoundTag); - } - - public static CompoundNBTTag loadTag(int x, int z) { - return WorldLoader.loadTag(getPathToChunk(x,z)); - } - - /* - public static synchronized Chunk readChunk(int x, int z) { - CompoundNBTTag compoundTag = fetchChunk(x,z); - if(compoundTag != null) { - return ChunkLoader.createChunk3(x, z, compoundTag,fetchLevel(x,z)); - } - return null; - } - - */ - - /* - public static synchronized void readWriteChunk(Chunk chunk) { - readChunk(chunk.x,chunk.z); - CompoundNBTTag compoundTag = ChunkLoader.createTag3(chunk,fetchLevel(chunk.x,chunk.z)); - putTag(chunk.x,chunk.z,compoundTag); - finishSave1(); - } - - */ - - public static void writeChunk(Chunk chunk) { - CompoundNBTTag compoundTag = ChunkLoader.createTag3(chunk,fetchLevel(chunk.x,chunk.z)); - putTag(chunk.x,chunk.z,compoundTag); - } - - -} diff --git a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java index 41f21695..4476b6db 100644 --- a/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java +++ b/src/main/java/dev/hilligans/ourcraft/server/MultiPlayerServer.java @@ -15,7 +15,6 @@ import dev.hilligans.ourcraft.Ourcraft; import dev.hilligans.ourcraft.ServerMain; import dev.hilligans.ourcraft.world.newworldsystem.IServerWorld; -import dev.hilligans.ourcraft.world.World; import dev.hilligans.ourcraft.util.ConsoleReader; import dev.hilligans.ourcraft.util.NamedThreadFactory; import dev.hilligans.ourcraft.util.Settings; @@ -31,7 +30,6 @@ public class MultiPlayerServer implements IServer { public long time = 0; - public Int2ObjectOpenHashMap worlds = new Int2ObjectOpenHashMap<>(); public Int2ObjectOpenHashMap newWorlds = new Int2ObjectOpenHashMap<>(); public HashMap waitingPlayers = new HashMap<>(); public HashMap> playerQueue = new HashMap<>(); diff --git a/src/main/java/dev/hilligans/ourcraft/world/Chunk.java b/src/main/java/dev/hilligans/ourcraft/world/Chunk.java deleted file mode 100644 index e7eefbea..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/Chunk.java +++ /dev/null @@ -1,288 +0,0 @@ -package dev.hilligans.ourcraft.world; - -import dev.hilligans.ourcraft.biome.Biome; -import dev.hilligans.ourcraft.block.blockstate.IBlockState; -import dev.hilligans.ourcraft.client.rendering.world.managers.VAOManager; -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.block.Blocks; -import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.data.primitives.Tuple; -import dev.hilligans.ourcraft.entity.Entity; -import dev.hilligans.ourcraft.util.Settings; -import dev.hilligans.ourcraft.world.newworldsystem.IChunk; -import dev.hilligans.ourcraft.world.newworldsystem.ISubChunk; -import dev.hilligans.ourcraft.world.newworldsystem.IWorld; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap; -import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; - -import java.util.ArrayList; -import java.util.function.Consumer; -import java.util.function.UnaryOperator; - -import static org.lwjgl.opengl.GL15.glGetBufferSubData; - -public class Chunk implements IChunk { - - public ArrayList chunks = new ArrayList<>(); - - public World world; - - public Short2ObjectOpenHashMap dataProviders = new Short2ObjectOpenHashMap<>(); - - public Int2ObjectOpenHashMap entities = new Int2ObjectOpenHashMap<>(); - //public Long2ObjectOpenHashMap> blockTicks = new Long2ObjectOpenHashMap<>(); - public Short2IntOpenHashMap heightMap = new Short2IntOpenHashMap(); - - public boolean needsSaving = false; - - - public int x; - public int z; - - public static int terrain = 64; - - public boolean populated = false; - - public void tick() { - /* - if(world.isServer()) { - ArrayList list = blockTicks.get(((ServerWorld) world).server.getTime()); - if(list != null) { - blockTicks.remove(((ServerWorld) world).server.getTime()); - for(BlockPos pos : list) { - world.getBlockState(pos).getBlock().tickBlock(world,pos); - } - } - } - - */ - } - - // public void scheduleTick(BlockPos pos, int time) { - // if(world.isServer()) { - // long futureTime = ((ServerWorld)world).server.getTime() + time; - // ArrayList list = blockTicks.computeIfAbsent(futureTime, k -> new ArrayList<>()); - // list.add(pos); - // } - // } - - - public void destroyMap(int newId) { - if(id != -1 && id != -2 && id != -3) { - VAOManager.destroyBuffer(id); - } - this.id = newId; - } - - public int getBlockHeight(int x, int z) { - Biome biome = getBiome1(x, z); - double val = world.simplexNoise.getHeight(x, z, biome.terrainHeights); - return (int) (val + terrain); - } - - public int interpolate(int height, int xHeight) { - return Math.round(((float)height + xHeight) / 2); - } - - public Biome getBiome1(int x, int z) { - return world.biomeMap.getBiome(x,z); - } - - @Override - public int getWidth() { - return 16; - } - - @Override - public int getHeight() { - return 256; - } - - @Override - public long getX() { - return x; - } - - @Override - public long getY() { - return 0; - } - - @Override - public long getZ() { - return z; - } - - @Override - public ISubChunk get(long blockX, long blockY, long blockZ) { - return null; - } - - @Override - public IBlockState getBlockState1(long x, long y, long z) { - return null; - } - - @Override - public void setBlockState(long x, long y, long z, IBlockState blockState) { - - } - - @Override - public void setChunkPosition(long x, long y, long z) { - - } - - @Override - public IWorld getWorld() { - return null; - } - - @Override - public IChunk setWorld(IWorld world) { - return this; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public int getSubChunkCount() { - return 0; - } - - @Override - public void forEach(Consumer consumer) { - - } - - @Override - public void replace(UnaryOperator replacer) { - - } - - @Override - public void setDirty(boolean value) { - - } - - @Override - public boolean isDirty() { - return false; - } - - @Override - public boolean isGenerated() { - return false; - } - - @Override - public boolean isPopulated() { - return false; - } - - @Override - public boolean isStructured() { - return false; - } - - public BlockState getBlockState(long x, long y, long z) { - if(y >= Settings.chunkHeight * 16 || y < 0) { - return Blocks.AIR.getDefaultState(); - } - int pos = (int) (y >> 4); - SubChunk subChunk = chunks.get(pos); - return subChunk.getBlock((int) (x & 15), (int) (y & 15), (int) (z & 15)); - } - - public BlockState getBlockState(BlockPos blockPos) { - return getBlockState(blockPos.x,blockPos.y,blockPos.z); - } - - public DataProvider getDataProvider(BlockPos pos) { - needsSaving = true; - //int height = pos.y >> 4; - //SubChunk subChunk = chunks.get(height); - return dataProviders.get((short)(pos.x & 15 | (pos.y & 255) << 4 | (pos.z & 15) << 12)); - //return subChunk.getDataProvider(pos.x & 15, pos.y & 15, pos.z & 15); - } - - public void setDataProvider(BlockPos pos, DataProvider dataProvider) { - needsSaving = true; - //int height = pos.y >> 4; - //SubChunk subChunk = chunks.get(height); - dataProviders.put((short)(pos.x & 15 | (pos.y & 255) << 4 | (pos.z & 15) << 12),dataProvider); - //subChunk.setDataProvider(pos.x & 15, pos.y & 15, pos.z & 15, dataProvider); - } - - public void setBlockState(long x, long y, long z, BlockState blockState) { - needsSaving = true; - if(y > Settings.chunkHeight * 16 || y < 0) { - return; - } - - if(populated) { - short height = (short) (x << 4 | z); - if (blockState.getBlock().blockProperties.airBlock) { - if (heightMap.get(height) == y) { - for (int i = (int) y; i > 0; i--) { - if (!getBlockState(x, i, z).getBlock().blockProperties.airBlock) { - heightMap.put(height, i); - } - } - } - } else { - if (heightMap.get(height) < y) { - heightMap.put(height, (int) y); - } - } - } - int pos = (int) (y >> 4); - chunks.get(pos).setBlockState((int) x, (int) y, (int) z,blockState); - } - - public BlockPos getHeight(int x, int z) { - return new BlockPos(x,heightMap.get((short)((x << 4) | z)),z); - } - - public int getHeightInt(int x, int z) { - return heightMap.get((short)(((x & 0xF ) << 4) | (z /*& 0xF */))); - } - - public ArrayList> getBlockChainedList() { - BlockState currentState = null; - ArrayList> values = new ArrayList<>(); - int count = 0; - for(int i = 0; i < 16 * 16 * Settings.chunkHeight * 16; i++) { - int x = i & 15; - int y = i >> 4 & 255; - int z = i >> 12 & 15; - BlockState newState = getBlockState(x, y, z); - if (!newState.equals(currentState)) { - if (currentState != null) { - values.add(new Tuple<>(currentState, count)); - count = 0; - } - currentState = newState; - } - count++; - } - return values; - } - - public int id = -1; - - @Override - public String toString() { - return "Chunk{" + - "chunks=" + chunks + - ", x=" + x + - ", z=" + z + - '}'; - } -} - - diff --git a/src/main/java/dev/hilligans/ourcraft/world/ChunkContainer.java b/src/main/java/dev/hilligans/ourcraft/world/ChunkContainer.java deleted file mode 100644 index 5559d74a..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/ChunkContainer.java +++ /dev/null @@ -1,110 +0,0 @@ -package dev.hilligans.ourcraft.world; - -import dev.hilligans.ourcraft.world.newworldsystem.IChunkContainer; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.function.Consumer; - -public class ChunkContainer implements IChunkContainer { - - public Int2ObjectOpenHashMap> chunks = new Int2ObjectOpenHashMap<>(); - - public int cacheSize; - public Chunk[] chunkCache; - - - public ChunkContainer() { - this(4); - } - - public ChunkContainer(int cacheSize) { - this.cacheSize = cacheSize; - chunkCache = new Chunk[cacheSize]; - } - - @Override - public Chunk getChunk(int x, int z) { - Chunk chunk = getCache(x, z); - if (chunk != null) { - return chunk; - } - try { - Int2ObjectOpenHashMap zMap = chunks.getOrDefault(x, null); - if (zMap != null) { - chunk = zMap.getOrDefault(z, null); - } - } catch(Exception e){} - return chunk; - } - - @Override - public Chunk setChunk(int x, int z, Chunk chunk) { - cache(chunk); - Int2ObjectOpenHashMap zMap = chunks.computeIfAbsent(x,a -> new Int2ObjectOpenHashMap<>()); - try { - return zMap.put(z,chunk); - } catch (Exception e) { - return null; - } - } - - @Override - public Chunk removeChunk(int x, int z) { - removeFromCache(x,z); - Int2ObjectOpenHashMap zMap = chunks.getOrDefault(x,null); - if(zMap != null) { - return zMap.remove(z); - } - return null; - } - - public Chunk removeChunk(long pos) { - return removeChunk((int)pos,(int)(pos >> 32)); - } - - @Override - public int getSize() { - int size = 0; - for(int val : chunks.keySet()) { - Int2ObjectOpenHashMap zMap = chunks.getOrDefault(val,null); - size += zMap.size(); - } - return size; - } - - @Override - public void forEach(Consumer consumer) { - for(int val : chunks.keySet()) { - Int2ObjectOpenHashMap zMap = chunks.getOrDefault(val,null); - zMap.forEach((integer, chunk) -> consumer.accept(chunk)); - } - } - - public void cache(Chunk chunk) { - for(int x = cacheSize - 1; x > 0; x--) { - chunkCache[x] = chunkCache[x - 1]; - } - chunkCache[0] = chunk; - } - - public Chunk getCache(int x, int z) { - for(int i = 0; i < cacheSize; i++) { - if(chunkCache[i] != null) { - if (chunkCache[i].x == x && chunkCache[i].z == z) { - return chunkCache[i]; - } - } - } - return null; - } - - public void removeFromCache(int x, int z) { - for(int i = 0; i < cacheSize; i++) { - if(chunkCache[i] != null) { - if (chunkCache[i].x == x && chunkCache[i].z == z) { - chunkCache[i] = null; - } - } - } - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/world/ClientWorld.java b/src/main/java/dev/hilligans/ourcraft/world/ClientWorld.java deleted file mode 100644 index 6cd29e5f..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/ClientWorld.java +++ /dev/null @@ -1,142 +0,0 @@ -package dev.hilligans.ourcraft.world; - - - -import dev.hilligans.ourcraft.client.audio.SoundBuffer; -import dev.hilligans.ourcraft.client.audio.Sounds; -import dev.hilligans.ourcraft.client.Client; -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.ClientMain; -import dev.hilligans.ourcraft.entity.Entity; -import dev.hilligans.ourcraft.util.Settings; -import org.joml.Vector3d; - -import java.util.concurrent.ConcurrentLinkedQueue; - -import static org.lwjgl.opengl.GL30.glGenVertexArrays; - -public class ClientWorld extends World { - - public Client client; - - public ClientWorld(Client client) { - super(client.gameInstance); - //getChunk(0,0); - this.client = client; - } - - @Override - public boolean isServer() { - return false; - } - - public ConcurrentLinkedQueue skippedBlockChanges = new ConcurrentLinkedQueue<>(); - - @Override - public void tick() { - for(BlockChange blockChange : blockChanges) { - if(getChunk(blockChange.x >> 4, blockChange.z >> 4) == null) { - skippedBlockChanges.add(blockChange); - continue; - } - setBlockStateDirect(blockChange.x,blockChange.y,blockChange.z,blockChange.blockState); - } - blockChanges.clear(); - blockChanges.addAll(skippedBlockChanges); - skippedBlockChanges.clear(); - if(purgeTime > 100) { - purgeTime = 0; - if(Settings.destroyChunkDistance != -1) { - //purgeChunks(Settings.destroyChunkDistance + 2); - } - } else { - - } - - } - - int purgeTime = 0; - - /* - public void purgeChunks(int distance) { - int cameraX = (int) Camera.pos.x >> 4; - int cameraZ = (int)Camera.pos.z >> 4; - ArrayList removedChunks = new ArrayList<>(); - chunkContainer.forEach(chunk -> { - if(Math.abs(cameraX - chunk.x) > distance || Math.abs(cameraZ - chunk.z) > distance) { - //TODO fix - // chunk.destroy(); - removedChunks.add((long)chunk.x & 4294967295L | ((long)chunk.z & 4294967295L) << 32); - } - }); - - //TODO: sometimes tries to remove -1 and causes crash - for(Long longVal : removedChunks) { - chunkContainer.removeChunk(longVal); - } - } - - */ - - public int vertices = 0; - public int count = 0; - - public void playSound(SoundBuffer soundBuffer, Vector3d pos) { - if(Settings.sounds) { - client.soundEngine.addSound(soundBuffer,pos); - } - } - - @Override - public void setBlockState(int x, int y, int z, BlockState blockState) { - playSound(Sounds.BLOCK_BREAK,new Vector3d(x,y,z)); - setBlockStateDirect(x,y,z,blockState); - } - - public void setBlockStateDirect(int x, int y, int z, BlockState blockState) { - if(y >= Settings.minHeight && y < Settings.maxHeight) { - super.setBlockState(x, y, z, blockState); - notifySubChunks(x >> 4, y >> 4, z >> 4); - } - } - - public void notifySubChunks(int chunkX, int chunkY, int chunkZ) { - Chunk chunk = getChunk(chunkX,chunkZ); - - Chunk[] chunks = new Chunk[] {getChunk(chunkX + 1,chunkZ),getChunk(chunkX - 1,chunkZ),getChunk(chunkX,chunkZ + 1),getChunk(chunkX,chunkZ - 1)}; - - chunk.chunks.get(chunkY).destroy(); - - SubChunk subChunk; - if(chunkY < Settings.chunkHeight - 1) { - subChunk = chunk.chunks.get(chunkY + 1); - if (subChunk != null) { - subChunk.destroy(); - } - } - if(chunkY != 0) { - subChunk = chunk.chunks.get(chunkY - 1); - if (subChunk != null) { - subChunk.destroy(); - } - } - - for(Chunk chunk1 : chunks) { - if(chunk1 != null) { - chunk1.chunks.get(chunkY).destroy(); - } - } - - } - - @Override - public void addEntity(Entity entity) { - entities.put(entity.id,entity); - } - - - @Override - public void removeEntity(int id) { - entities.remove(id).destroy(); - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/world/SubChunk.java b/src/main/java/dev/hilligans/ourcraft/world/SubChunk.java deleted file mode 100644 index ee8ea74b..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/SubChunk.java +++ /dev/null @@ -1,112 +0,0 @@ -package dev.hilligans.ourcraft.world; - -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.block.Blocks; -import dev.hilligans.ourcraft.client.rendering.world.managers.VAOManager; -import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.data.other.blockstates.DataBlockState; -import dev.hilligans.ourcraft.world.data.providers.ShortBlockState; - -import java.util.Arrays; - -public class SubChunk { - - public int id = -2; - World world; - public long y; - public long x; - public long z; - - public boolean empty = true; - - public int[] vals; - - public SubChunk(World world, long X, long Y, long Z) { - this.world = world; - this.y = Y; - this.x = X; - this.z = Z; - } - - public void fill() { - vals = new int[16*16*16]; - for(int x = 0; x < 16; x++) { - for(int i = 0; i < 16; i++) { - for(int z = 0; z < 16; z++) { - setBlockState(x,i,z, Blocks.AIR.getDefaultState()); - } - } - } - } - - public void destroy() { - if(id != -1 && id != -2 && id != -3) { - VAOManager.destroyBuffer(id); - id = -1; - } - world.getChunk((int)x >> 4,(int)z >> 4).destroyMap(-1); - } - - public BlockState getBlock(BlockPos pos) { - if(pos.isSubChunkValid()) { - return getBlock(pos.x,pos.y,pos.z); - } - pos.y += y; - pos.x += x; - pos.z += z; - - return world.getBlockState(pos); - } - - public BlockState getBlock(int pos) { - return getBlock(pos & 0xF,pos & 0x0F,pos & 0x00F); - } - - public BlockState getBlock(int x, int y, int z) { - if(empty) { - return Blocks.AIR.getDefaultState(); - } - if((vals[x | y << 4 | z << 8] & 65535) == 65535) { - return new BlockState((short) (vals[x | y << 4 | z << 8] >> 16)); - } else { - return new DataBlockState((short) (vals[x | y << 4 | z << 8] >> 16),new ShortBlockState((short) (vals[x | y << 4 | z << 8] & 65535))); - } - - // return blocks[x][y][z]; - } - - - public void setBlockState(int x, int y, int z, BlockState blockState) { - if(!blockState.getBlock().blockProperties.airBlock) { - getBlock(x & 15, y & 15, z & 15).getBlock().onBreak(world,new BlockPos(x,y,z)); - if (empty) { - empty = false; - fill(); - } - } - if(!empty) { - int i = (x & 15) | (y & 15) << 4 | (z & 15) << 8; - if (blockState instanceof DataBlockState) { - vals[i] = blockState.blockId << 16 | ((DataBlockState) blockState).blockData.write(); - } else { - vals[i] = blockState.blockId << 16 | 65535; - } - } - } - - public void set(int block) { - for(int x = 0; x < 4096; x++) { - vals[x] = block; - } - } - - @Override - public String toString() { - return "SubChunk{" + - "y=" + y + - ", x=" + x + - ", z=" + z + - ", vals=" + Arrays.toString(vals) + - '}'; - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/world/World.java b/src/main/java/dev/hilligans/ourcraft/world/World.java deleted file mode 100644 index 47e322ea..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/World.java +++ /dev/null @@ -1,262 +0,0 @@ -package dev.hilligans.ourcraft.world; - -import dev.hilligans.ourcraft.block.Block; -import dev.hilligans.ourcraft.data.other.blockstates.BlockState; -import dev.hilligans.ourcraft.block.Blocks; -import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.data.other.BoundingBox; -import dev.hilligans.ourcraft.data.other.RayResult; -import dev.hilligans.ourcraft.entity.entities.ItemEntity; -import dev.hilligans.ourcraft.entity.Entity; -import dev.hilligans.ourcraft.GameInstance; -import dev.hilligans.ourcraft.item.ItemStack; -import dev.hilligans.ourcraft.network.packet.server.SSendBlockChanges; -import dev.hilligans.ourcraft.ServerMain; -import dev.hilligans.ourcraft.world.builders.WorldBuilder; -import dev.hilligans.ourcraft.util.noises.BiomeNoise; -import dev.hilligans.ourcraft.util.noises.SimplexNoise; -import dev.hilligans.ourcraft.util.Settings; -import dev.hilligans.ourcraft.world.newworldsystem.IChunkContainer; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import org.joml.Vector3d; -import org.joml.Vector3f; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Random; -import java.util.concurrent.ConcurrentLinkedQueue; - -public abstract class World { - - public Int2ObjectOpenHashMap entities = new Int2ObjectOpenHashMap<>(); - public ConcurrentLinkedQueue blockChanges = new ConcurrentLinkedQueue<>(); - - public GameInstance gameInstance; - - long seed = 1342; - public BiomeNoise biomeMap; - - - SimplexNoise simplexNoise; - - public Random random; - public IChunkContainer chunkContainer = new ChunkContainer(); - - public World(GameInstance gameInstance) { - this.gameInstance = gameInstance; - random = new Random(seed); - biomeMap = new BiomeNoise(gameInstance,random); - simplexNoise = new SimplexNoise(random); - - } - - public abstract boolean isServer(); - - - public Chunk getChunk(int x, int z) { - return chunkContainer.getChunk(x,z); - } - - public BlockState getBlockState(int x, int y, int z) { - Chunk chunk = getChunk(x >> 4,z >> 4); - if(chunk == null) { - return Blocks.AIR.getDefaultState(); - } - return chunk.getBlockState(x,y,z); - } - - public void setBlockMatches(BlockPos pos, BlockState state, Block block) { - if(getBlockState(pos).getBlock() == block) { - setBlockState(pos,state); - } - } - - public DataProvider getDataProvider(BlockPos pos) { - Chunk chunk = getChunk(pos.x >> 4,pos.z >> 4); - if(chunk == null) { - return null; - } - return chunk.getDataProvider(pos); - } - - public void setDataProvider(BlockPos pos, DataProvider dataProvider) { - Chunk chunk = getChunk(pos.x >> 4,pos.z >> 4); - if(chunk != null) { - chunk.setDataProvider(pos,dataProvider); - } - } - - public BlockState getBlockState(BlockPos pos) { - return getBlockState(pos.x,pos.y,pos.z); - } - - public void setBlockState(int x, int y, int z, BlockState blockState) { - if(y >= Settings.minHeight && y < Settings.maxHeight) { - Chunk chunk = getChunk(x >> 4, z >> 4); - if (chunk == null) { - return; - } - chunk.setBlockState(x, y, z, blockState); - } - if (isServer()) { - ServerMain.getServer().sendPacket(new SSendBlockChanges(x,y,z,blockState)); - } - //updateBlock(new BlockPos(x,y,z)); - } - - public void spawnItemEntity(float x, float y, float z, ItemStack itemStack) { - if(!itemStack.isEmpty()) { - ItemEntity itemEntity = new ItemEntity(x, y, z, Entity.getNewId(), itemStack); - itemEntity.velY = 0.30f; - itemEntity.velX = (float) (Math.random() * 0.4 - 0.2f); - itemEntity.velZ = (float) (Math.random() * 0.4 - 0.2f); - itemEntity.pickupDelay = 10; - addEntity(itemEntity); - } - } - - public void setBlockState(BlockPos pos, BlockState blockState) { - setBlockState(pos.x,pos.y,pos.z,blockState); - } - - public void tick() { - } - - public static final double stepCount = 0.01; - public static final int distance = 5; - - static final float offSet = -0.5f; - - public RayResult traceBlock(double x, double y, double z, double pitch, double yaw) { - Vector3d vector3d = new Vector3d(); - boolean placed = false; - boolean isAir = true; - int side = -1; - - double addX = (Math.cos(yaw) * Math.cos(pitch)) * stepCount; - double addY = Math.sin(pitch) * stepCount; - double addZ = Math.sin(yaw) * Math.cos(pitch) * stepCount; - - double Z = z + offSet; - double Y = y + offSet; - double X = x + offSet; - - - for(int a = 0; a < distance / stepCount; a++) { - Z -= addZ; - Y -= addY; - X -= addX; - BlockPos pos = new BlockPos((int) Math.round(X), (int) Math.round(Y), (int) Math.round(Z)); - BlockState blockState = getBlockState(pos); - if(blockState.getBlock() != Blocks.AIR) { - Vector3f vector3f = new Vector3f((float)X - offSet,(float)Y - offSet,(float)Z - offSet); - if(blockState.getBlock().getBoundingBox(this,pos).intersectVector(vector3f, pos)) { - placed = true; - side = blockState.getBlock().getBoundingBox(this,pos).getHitSide(new Vector3f((float)vector3d.x - offSet,(float)vector3d.y - offSet,(float)vector3d.z - offSet), pos); - break; - } else { - isAir = false; - } - } else { - isAir = true; - } - vector3d.x = X; - vector3d.y = Y; - vector3d.z = Z; - } - - if(placed) { - Vector3f vector3f = new Vector3f((float)vector3d.x,(float)vector3d.y,(float)vector3d.z); - return new RayResult(vector3f,new BlockPos(vector3f),side); - } else { - return null; - } - } - - public BlockState traceBlockState(float x, float y, float z, double pitch, double yaw) { - for(int a = 0; a < distance / stepCount; a++) { - final double Z = z - Math.sin(yaw) * Math.cos(pitch) * a * 0.1 + offSet; - final double Y = y - Math.sin(pitch) * 0.1 * a + offSet; - final double X = (x - Math.cos(yaw) * Math.cos(pitch) * a * 0.1) + offSet; - BlockState blockState = getBlockState((int) Math.round(X), (int) Math.round(Y), (int) Math.round(Z)); - if(blockState.getBlock() != Blocks.AIR) { - return blockState; - } - } - return null; - } - - public BlockPos traceBlockToBreak(double x, double y, double z, double pitch, double yaw) { - try { - double addX = (Math.cos(yaw) * Math.cos(pitch)) * stepCount; - double addY = Math.sin(pitch) * stepCount; - double addZ = Math.sin(yaw) * Math.cos(pitch) * stepCount; - - double Z = z + offSet; - double Y = y + offSet; - double X = x + offSet; - for (int a = 0; a < distance / stepCount; a++) { - Z -= addZ; - Y -= addY; - X -= addX; - //final double Z = z - Math.sin(yaw) * Math.cos(pitch) * a * 0.1 + offSet; - //final double Y = y - Math.sin(pitch) * 0.1 * a + offSet; - //final double X = (x - Math.cos(yaw) * Math.cos(pitch) * a * 0.1) + offSet; - BlockPos pos = new BlockPos((int) Math.round(X), (int) Math.round(Y), (int) Math.round(Z)); - BlockState blockState = getBlockState(pos); - if (blockState.getBlock() != Blocks.AIR) { - if (blockState.getBlock().getBoundingBox(this, pos).intersectVector(new Vector3f((float) X - offSet, (float) Y - offSet, (float) Z - offSet), pos)) { - return pos; - } - } - } - } catch (Exception ignored) {} - return null; - } - - public Chunk[] getChunksAround(int x, int z, int radius) { - if(radius == 0) { - return new Chunk[] {getChunk(x + 1,z),getChunk(x - 1,z),getChunk(x,z + 1),getChunk(x,z - 1)}; - } - return null; - } - - public abstract void addEntity(Entity entity); - - public abstract void removeEntity(int id); - - public BlockPos getWorldSpawn(BoundingBox boundingBox) { - BlockPos pos = new BlockPos(0,Settings.chunkHeight * 16,0); - int y; - out: - for(y = 0; y < Settings.chunkHeight * 16 - 1; y++) { - for(int z = -1; z < 2; z++) { - for(int x = -1; x < 2; x++) { - BlockState blockState = getBlockState(new BlockPos(x,pos.y,z)); - if(blockState.getBlock() != Blocks.AIR) { - if (blockState.getBlock().blockProperties.canWalkThrough || boundingBox.intersectsBox(blockState.getBlock().getBoundingBox(this,new BlockPos(x,pos.y,z)), pos.get3d(), new Vector3d(x, pos.y, z))) { - break out; - } - } - } - } - pos.y -= 1; - } - return pos.add(0,3,0); - } - - - public static class BlockChange { - public int x; - public int z; - public int y; - public BlockState blockState; - - public BlockChange(int x, int y, int z, BlockState blockState) { - this.x = x; - this.y = y; - this.z = z; - this.blockState = blockState; - } - } -} diff --git a/src/main/java/dev/hilligans/ourcraft/world/WorldView.java b/src/main/java/dev/hilligans/ourcraft/world/WorldView.java new file mode 100644 index 00000000..21a72013 --- /dev/null +++ b/src/main/java/dev/hilligans/ourcraft/world/WorldView.java @@ -0,0 +1,69 @@ +package dev.hilligans.ourcraft.world; + +import dev.hilligans.ourcraft.block.blockstate.IBlockState; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; +import org.joml.Vector3f; + +/** + Represents a class to look at a world view the gravity direction normalized to always being -y + */ +public record WorldView(IWorld world, long offsetX, long offsetY, long offsetZ, short rot) { + + public IBlockState getBlockState(int x, int y, int z) { + return switch (rot) { + case 0 -> world.getBlockState(offsetX + y, offsetY + z, offsetZ + x); + case 1 -> world.getBlockState(offsetX - y, offsetY + z, offsetZ + x); + case 2 -> world.getBlockState(offsetX + x, offsetY + y, offsetZ + z); + case 3 -> world.getBlockState(offsetX + x, offsetY - y, offsetZ + z); + case 4 -> world.getBlockState(offsetX + z, offsetY + x, offsetZ + y); + default ->world.getBlockState(offsetX + z, offsetY + x, offsetZ - y); + }; + } + + public void setBlockState(IBlockState blockState, int x, int y, int z) { + switch (rot) { + case 0: + world.setBlockState(offsetX + y, offsetY + z, offsetZ + x, blockState); + break; + case 1: + world.setBlockState(offsetX - y, offsetY + z, offsetZ + x, blockState); + break; + case 2: + world.setBlockState(offsetX + x, offsetY + y, offsetZ + z, blockState); + break; + case 3: + world.setBlockState(offsetX + x, offsetY - y, offsetZ + z, blockState); + break; + case 4: + world.setBlockState(offsetX + z, offsetY + x, offsetZ + y, blockState); + break; + default: + world.setBlockState(offsetX + z, offsetY + x, offsetZ - y, blockState); + break; + } + } + + public static WorldView getWorldView(IWorld world, long offsetX, long offsetY, long offsetZ, Vector3f gravVector) { + float val = gravVector.x; + if(val > 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 0); + } else if(val < 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 1); + } + + val = gravVector.y; + if(val > 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 2); + } else if(val < 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 3); + } + + val = gravVector.z; + if(val > 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 4); + } else if(val < 0) { + return new WorldView(world, offsetX, offsetY, offsetZ, (short) 5); + } + throw new RuntimeException("No Gravity Vector"); + } +} diff --git a/src/main/java/dev/hilligans/ourcraft/world/builders/OreBuilder.java b/src/main/java/dev/hilligans/ourcraft/world/builders/OreBuilder.java index 245f7808..b37db829 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/builders/OreBuilder.java +++ b/src/main/java/dev/hilligans/ourcraft/world/builders/OreBuilder.java @@ -29,7 +29,7 @@ public void build(BlockPos pos) { public void replaceIfValid(BlockPos pos) { if(allowedBlocks.get(world.getBlockState(pos).getBlock().id)) { - world.setBlockState(pos,ore.getDefaultState()); + world.setBlockState(pos, ore.getDefaultState()); } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/builders/WorldBuilder.java b/src/main/java/dev/hilligans/ourcraft/world/builders/WorldBuilder.java index 2420946e..de5a6655 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/builders/WorldBuilder.java +++ b/src/main/java/dev/hilligans/ourcraft/world/builders/WorldBuilder.java @@ -1,15 +1,15 @@ package dev.hilligans.ourcraft.world.builders; import dev.hilligans.ourcraft.data.other.BlockPos; -import dev.hilligans.ourcraft.world.Chunk; import dev.hilligans.ourcraft.world.Feature; -import dev.hilligans.ourcraft.world.World; +import dev.hilligans.ourcraft.world.newworldsystem.IChunk; +import dev.hilligans.ourcraft.world.newworldsystem.IWorld; import java.util.Random; public abstract class WorldBuilder extends Feature { - public World world; + public IWorld world; public int frequency = 1; public int chance = 1; @@ -20,9 +20,9 @@ public WorldBuilder(String featureName) { } - public WorldBuilder setWorld(World world) { + public WorldBuilder setWorld(IWorld world) { this.world = world; - random = world.random; + random = new Random(); return this; } @@ -36,7 +36,8 @@ public WorldBuilder setChance(int chance) { return this; } - public void build(Chunk chunk) { + public void build(IChunk chunk) { + /* world = chunk.world; random = world.random; for(int a = 0; a < frequency; a++) { @@ -46,6 +47,8 @@ public void build(Chunk chunk) { build(x + chunk.x * 16, z + chunk.z * 16); } } + + */ } public abstract void build(int x, int z); diff --git a/src/main/java/dev/hilligans/ourcraft/world/builders/foliage/CustomTreeBuilder.java b/src/main/java/dev/hilligans/ourcraft/world/builders/foliage/CustomTreeBuilder.java index ecc8dcdd..e42bb960 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/builders/foliage/CustomTreeBuilder.java +++ b/src/main/java/dev/hilligans/ourcraft/world/builders/foliage/CustomTreeBuilder.java @@ -154,7 +154,7 @@ public void buildSphereLeavesVariance(BlockPos startPos, int size, int variance, public BlockPos buildBranch(BlockPos startPos, int length, Vector2d rotation, Block wood) { Ray ray = new Ray(rotation.x,rotation.y,1f); for(int x = 0; x < length; x++) { - world.setBlockMatches(ray.getNextBlock(x).add(startPos),wood.getDefaultState(),Blocks.AIR); + world.swapBlockState(ray.getNextBlock(x).add(startPos), Blocks.AIR.getDefaultState(), wood.getDefaultState()); } return ray.getNextBlock(length).add(startPos); } diff --git a/src/main/java/dev/hilligans/ourcraft/world/features/TreeFeature.java b/src/main/java/dev/hilligans/ourcraft/world/features/TreeFeature.java index af47283b..7d9a2eb8 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/features/TreeFeature.java +++ b/src/main/java/dev/hilligans/ourcraft/world/features/TreeFeature.java @@ -11,13 +11,13 @@ public void place(IFeaturePlacerHelper placerHelper) { if(placerHelper.getState(1,0,0).getBlock().blockProperties.airBlock && placerHelper.getState(-1,0,0).getBlock().blockProperties.airBlock && placerHelper.getState(0,0,1).getBlock().blockProperties.airBlock && placerHelper.getState(0,0,-1).getBlock().blockProperties.airBlock) { for (int y = 0; y < 8; y++) { if (y != 6 && y != 7) { - placerHelper.setState(0, y, 0, Blocks.LOG.getDefaultState1()); + placerHelper.setState(0, y, 0, Blocks.LOG.getDefaultState()); } if (y >= 5) { for (int x = -2; x < 3; x++) { for (int z = -2; z < 3; z++) { if ((x != 0 && z != 0) || y >= 6) { - placerHelper.setState(x, y, z, Blocks.LEAVES.getDefaultState1()); + placerHelper.setState(x, y, z, Blocks.LEAVES.getDefaultState()); } } } 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 c2f6bd4c..b0dc60ef 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ClassicChunk.java @@ -62,11 +62,11 @@ public ISubChunk get(long blockX, long blockY, long blockZ) { @Override public IBlockState getBlockState1(long x, long y, long z) { if(y < 0) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } ISubChunk subChunk = chunks[(int) (y >> 4)]; if(subChunk == null) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } return subChunk.getBlockState((int) (x % 15), (int) (y % 15), (int) (z % 15)); } @@ -75,7 +75,7 @@ public IBlockState getBlockState1(long x, long y, long z) { public void setBlockState(long x, long y, long z, IBlockState blockState) { ISubChunk subChunk = chunks[(int) (y >> 4)]; if(subChunk == null) { - if(blockState == Blocks.AIR.getDefaultState1()) { + if(blockState == Blocks.AIR.getDefaultState()) { return; } subChunk = chunks[(int) (y >> 4)] = new SimpleSubChunkImpl(16,16); 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 871eb3e0..03d2364d 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/CubicChunk.java @@ -81,12 +81,12 @@ public ISubChunk get(long blockX, long blockY, long blockZ) { @Override public IBlockState getBlockState1(long x, long y, long z) { if(subChunks == null) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } //TODO fix int index = getIndex(x & 31, y & 31, z & 31); if(subChunks[index] == null) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } return subChunks[index].getBlockState((int) (x & 15), (int) (y & 15), (int) (z & 15)); } 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 382abd3b..d5939139 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/GlobalPaletteImpl.java @@ -29,15 +29,15 @@ public int getHeight() { @Override public IBlockState getBlockState(int x, int y, int z) { if(blockStates == null) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } try { short b = blockStates[((x * width + y) * height + z)]; - return b == 0 ? Blocks.AIR.getDefaultState1() : Ourcraft.GAME_INSTANCE.BLOCK_STATES.get(b); + return b == 0 ? Blocks.AIR.getDefaultState() : Ourcraft.GAME_INSTANCE.BLOCK_STATES.get(b); } catch (Exception e) { // e.printStackTrace(); } - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } @Override diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunk.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunk.java index 3b0887ff..91127c65 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunk.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunk.java @@ -77,6 +77,14 @@ default IBlockState getBlockState1(BlockPos pos) { return getBlockState1(pos.getX(),pos.getY(),pos.getZ()); } + default boolean swapBlockState(long x, long y, long z, IBlockState expected, IBlockState to) { + if(getBlockState1(x, y, z) == expected) { + setBlockState(x, y, z, to); + return true; + } + return false; + } + void setBlockState(long x, long y, long z, IBlockState blockState); void setChunkPosition(long x, long y, long z); diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunkContainer.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunkContainer.java deleted file mode 100644 index 2b4afcb8..00000000 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IChunkContainer.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.hilligans.ourcraft.world.newworldsystem; - -import dev.hilligans.ourcraft.world.Chunk; - -import java.util.function.Consumer; - -public interface IChunkContainer { - - Chunk getChunk(int x, int z); - Chunk setChunk(int x, int z, Chunk chunk); - Chunk removeChunk(int x, int z); - Chunk removeChunk(long pos); - int getSize(); - void forEach(Consumer consumer); - -} 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 88af7b7a..8ebd8960 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/IWorld.java @@ -8,7 +8,6 @@ import dev.hilligans.ourcraft.util.Immutable; import dev.hilligans.ourcraft.util.MathUtil; import org.jetbrains.annotations.NotNull; -import org.joml.Intersectionf; import org.joml.Vector2f; import org.joml.Vector3f; import org.joml.Vector3fc; @@ -28,7 +27,7 @@ default IBlockState getBlockState(long x, long y, long z) { if(chunk != null) { return chunk.getBlockState1(x, y, z); } else { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } } @@ -45,6 +44,18 @@ default void setBlockState(BlockPos pos, IBlockState newState) { setBlockState(pos.getX(),pos.getY(),pos.getZ(),newState); } + default boolean swapBlockState(long blockX, long blockY, long blockZ, IBlockState expected, IBlockState to) { + IChunk chunk = getChunk(blockX, blockY, blockZ); + if(chunk != null) { + return chunk.swapBlockState(blockX, blockY, blockZ, expected, to); + } + return false; + } + + default boolean swapBlockState(BlockPos pos, IBlockState expected, IBlockState to) { + return swapBlockState(pos.getX(), pos.getY(), pos.getZ(), expected, to); + } + IChunk getChunk(long blockX, long blockY, long blockZ); IChunk getChunkNonNull(long blockX, long blockY, long blockZ); 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 d6fcea45..d09c85ad 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/ServerCubicWorld.java @@ -73,7 +73,7 @@ public void generateWorld() { for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { - setBlockState(x, y, z, Blocks.STONE.getDefaultState1()); + setBlockState(x, y, z, Blocks.STONE.getDefaultState()); } } } @@ -85,10 +85,10 @@ public void generateWorld() { for (int b = -radius; b <= radius; b++) { int height = worldHeightBuilder.getWorldHeight(a, b, radius + 1); for (int c = 0; c < height; c++) { - setBlockState(a, b, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b, radius + c, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(a, b, radius + c, Blocks.AIR.getDefaultState1()); + setBlockState(a, b, radius + c, Blocks.AIR.getDefaultState()); } if (a == radius) { int h = height; @@ -97,7 +97,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a + ptr, b, radius + 1 + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a + ptr, b, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a + ptr, b, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + ptr, b, radius + h - 1); } @@ -109,7 +109,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, b + ptr, radius + 1 + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, b + ptr, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b + ptr, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, b + ptr, radius + h - 1); } @@ -121,7 +121,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a - ptr, b, radius + 1 + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a - ptr, b, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a - ptr, b, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - ptr, b, radius + h - 1); } @@ -133,7 +133,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, b - ptr, radius + 1 + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, b - ptr, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b - ptr, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, b - ptr, radius + h - 1); } @@ -148,7 +148,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, b + length, radius + 1 + Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, b + length, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, b + length, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, b + length, radius + h - 1); } @@ -164,7 +164,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, b - length, radius + 1 + Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, b - length, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, b - length, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, b - length, radius + h - 1); } @@ -180,7 +180,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, b + length, radius + 1 + Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, b + length, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, b + length, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, b + length, radius + h - 1); } @@ -196,7 +196,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, b - length, radius + 1 + Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, b - length, radius + c, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, b - length, radius + c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, b - length, radius + h - 1); } @@ -206,10 +206,10 @@ public void generateWorld() { height = worldHeightBuilder.getWorldHeight(a, b, -radius - 1); for (int c = 0; c < height; c++) { - setBlockState(a, b, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b, -radius - c, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(a, b, -radius - c, Blocks.AIR.getDefaultState1()); + setBlockState(a, b, -radius - c, Blocks.AIR.getDefaultState()); } if (a == radius) { int h = height; @@ -218,7 +218,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a + ptr, b, -radius - 1 - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a + ptr, b, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a + ptr, b, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + ptr, b, -radius - h + 1); } @@ -230,7 +230,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, b + ptr, -radius - 1 - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, b + ptr, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b + ptr, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, b + ptr, -radius - h + 1); } @@ -242,7 +242,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a - ptr, b, -radius - 1 - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a - ptr, b, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a - ptr, b, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - ptr, b, -radius - h + 1); } @@ -254,7 +254,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, b - ptr, -radius - 1 - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, b - ptr, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a, b - ptr, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, b - ptr, -radius - h + 1); } @@ -269,7 +269,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, b + length, -radius - 1 - Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, b + length, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, b + length, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, b + length, -radius - h + 1); } @@ -285,7 +285,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, b - length, -radius - 1 - Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, b - length, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, b - length, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, b - length, -radius - h + 1); } @@ -301,7 +301,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, b + length, -radius - 1 - Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, b + length, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, b + length, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, b + length, -radius - h + 1); } @@ -317,7 +317,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, b - length, -radius - 1 - Math.max(length, width)); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, b - length, -radius - c, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, b - length, -radius - c, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, b - length, -radius - h + 1); } @@ -327,10 +327,10 @@ public void generateWorld() { height = worldHeightBuilder.getWorldHeight(a, radius + 1, b); for (int c = 0; c < height; c++) { - setBlockState(a, radius + c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a, radius + c, b, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(a, radius + c, b, Blocks.AIR.getDefaultState1()); + setBlockState(a, radius + c, b, Blocks.AIR.getDefaultState()); } if (a == radius) { @@ -340,7 +340,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a + ptr, radius + 1 + ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(a + ptr, radius + c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a + ptr, radius + c, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + ptr, radius + h - 1, b); } @@ -352,7 +352,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, radius + 1 + ptr, b + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, radius + c, b + ptr, Blocks.STONE.getDefaultState1()); + setBlockState(a, radius + c, b + ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, radius + h - 1, b + ptr); } @@ -364,7 +364,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a - ptr, radius + 1 + ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(a - ptr, radius + c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a - ptr, radius + c, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - ptr, radius + h - 1, b); } @@ -376,7 +376,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, radius + 1 + ptr, b - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, radius + c, b - ptr, Blocks.STONE.getDefaultState1()); + setBlockState(a, radius + c, b - ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, radius + h - 1, b - ptr); } @@ -391,7 +391,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, radius + 1 + Math.max(length, width), b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, radius + c, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, radius + c, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, radius + h - 1, b + length); } @@ -407,7 +407,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, radius + 1 + Math.max(length, width), b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, radius + c, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, radius + c, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, radius + h - 1, b - length); } @@ -423,7 +423,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, radius + 1 + Math.max(length, width), b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, radius + c, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, radius + c, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, radius + h - 1, b + length); } @@ -439,7 +439,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, radius + 1 + Math.max(length, width), b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, radius + c, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, radius + c, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, radius + h - 1, b - length); } @@ -449,10 +449,10 @@ public void generateWorld() { height = worldHeightBuilder.getWorldHeight(a, -radius - 1, b); for (int c = 0; c < height; c++) { - setBlockState(a, -radius - c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a, -radius - c, b, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(a, -radius - c, b, Blocks.AIR.getDefaultState1()); + setBlockState(a, -radius - c, b, Blocks.AIR.getDefaultState()); } if (a == radius) { int h = height; @@ -461,7 +461,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a + ptr, -radius - 1 - ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(a + ptr, -radius - c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a + ptr, -radius - c, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + ptr, -radius - h + 1, b); } @@ -473,7 +473,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, -radius - 1 - ptr, b + ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, -radius - c, b + ptr, Blocks.STONE.getDefaultState1()); + setBlockState(a, -radius - c, b + ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, -radius - h + 1, b + ptr); } @@ -485,7 +485,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a - ptr, -radius - 1 - ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(a - ptr, -radius - c, b, Blocks.STONE.getDefaultState1()); + setBlockState(a - ptr, -radius - c, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - ptr, -radius - h + 1, b); } @@ -497,7 +497,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(a, -radius - 1 - ptr, b - ptr); for (int c = ptr; c < h; c++) { - setBlockState(a, -radius - c, b - ptr, Blocks.STONE.getDefaultState1()); + setBlockState(a, -radius - c, b - ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a, -radius - h + 1, b - ptr); } @@ -512,7 +512,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, -radius - 1 - Math.max(length, width), b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, -radius - c, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, -radius - c, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, -radius - h + 1, b + length); } @@ -528,7 +528,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a + width, -radius - 1 - Math.max(length, width), b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a + width, -radius - c, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(a + width, -radius - c, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, -radius - h + 1, b - length); } @@ -544,7 +544,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, -radius - 1 - Math.max(length, width), b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, -radius - c, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, -radius - c, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a - width, -radius - h + 1, b + length); } @@ -560,7 +560,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(a - width, -radius - 1 - Math.max(length, width), b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(a - width, -radius - c, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(a - width, -radius - c, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(a + width, -radius - h + 1, b - length); } @@ -570,10 +570,10 @@ public void generateWorld() { height = worldHeightBuilder.getWorldHeight(radius + 1, a, b); for (int c = 0; c < height; c++) { - setBlockState(radius + c, a, b, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a, b, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(radius + c, a, b, Blocks.AIR.getDefaultState1()); + setBlockState(radius + c, a, b, Blocks.AIR.getDefaultState()); } if (a == radius) { int h = height; @@ -582,7 +582,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(radius + 1 + ptr, a + ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(radius + c, a + ptr, b, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a + ptr, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a + ptr, b); } @@ -594,7 +594,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(radius + 1 + ptr, a, b + ptr); for (int c = ptr; c < h; c++) { - setBlockState(radius + c, a, b + ptr, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a, b + ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a, b + ptr); } @@ -606,7 +606,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(radius + 1 + ptr, a - ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(radius + c, a - ptr, b, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a - ptr, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a - ptr, b); } @@ -618,7 +618,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(radius + 1 + ptr, a, b - ptr); for (int c = ptr; c < h; c++) { - setBlockState(radius + c, a, b - ptr, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a, b - ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a, b - ptr); } @@ -633,7 +633,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(radius + 1 + Math.max(length, width), a + width, b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(radius + c, a + width, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a + width, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a + width, b + length); } @@ -649,7 +649,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(radius + 1 + Math.max(length, width), a + width, b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(radius + c, a + width, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a + width, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a + width, b - length); } @@ -665,7 +665,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(radius + 1 + Math.max(length, width), a - width, b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(radius + c, a - width, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a - width, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a - width, b + length); } @@ -681,7 +681,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(radius + 1 + Math.max(length, width), a - width, b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(radius + c, a - width, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(radius + c, a - width, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(radius + h - 1, a - width, b - length); } @@ -691,10 +691,10 @@ public void generateWorld() { height = worldHeightBuilder.getWorldHeight(-radius - 1, a, b); for (int c = 0; c < height; c++) { - setBlockState(-radius - c, a, b, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a, b, Blocks.STONE.getDefaultState()); } for (int c = height; c <= 0; c++) { - setBlockState(-radius - c, a, b, Blocks.AIR.getDefaultState1()); + setBlockState(-radius - c, a, b, Blocks.AIR.getDefaultState()); } if (a == radius) { @@ -704,7 +704,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - ptr, a + ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(-radius - c, a + ptr, b, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a + ptr, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a + ptr, b); } @@ -716,7 +716,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - ptr, a, b + ptr); for (int c = ptr; c < h; c++) { - setBlockState(-radius - c, a, b + ptr, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a, b + ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a, b + ptr); } @@ -728,7 +728,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - ptr, a - ptr, b); for (int c = ptr; c < h; c++) { - setBlockState(-radius - c, a - ptr, b, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a - ptr, b, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a - ptr, b); } @@ -740,7 +740,7 @@ public void generateWorld() { ptr++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - ptr, a, b - ptr); for (int c = ptr; c < h; c++) { - setBlockState(-radius - c, a, b - ptr, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a, b - ptr, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a, b - ptr); } @@ -756,7 +756,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - Math.max(length, width), a + width, b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(-radius - c, a + width, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a + width, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a + width, b + length); } @@ -772,7 +772,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - Math.max(length, width), a + width, b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(-radius - c, a + width, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a + width, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a + width, b - length); } @@ -788,7 +788,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - Math.max(length, width), a - width, b + length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(-radius - c, a - width, b + length, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a - width, b + length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a - width, b + length); } @@ -804,7 +804,7 @@ public void generateWorld() { length++; h = worldHeightBuilder.getWorldHeight(-radius - 1 - Math.max(length, width), a - width, b - length); for (int c = Math.max(length, width); c < h; c++) { - setBlockState(-radius - c, a - width, b - length, Blocks.STONE.getDefaultState1()); + setBlockState(-radius - c, a - width, b - length, Blocks.STONE.getDefaultState()); } boundingBox.resizeForPoint(-radius - h + 1, a - width, b - length); } @@ -823,7 +823,7 @@ public void generateWorld() { boolean zRad = z < water_radius && z > -water_radius; if((zRad && yRad && xRad)) { if (getBlockState(x, y, z).getBlock() == Blocks.AIR) { - setBlockState(x, y, z, Blocks.WATER.getDefaultState1()); + setBlockState(x, y, z, Blocks.WATER.getDefaultState()); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleChunkGenerator.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleChunkGenerator.java index c7431122..22bb4e36 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleChunkGenerator.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleChunkGenerator.java @@ -54,7 +54,7 @@ public void generateChunk(IChunk chunk, IWorld world) { for(long y = chunk.getChunkYBlockPos(); y < terrainMin; y++) { for(int x = 0; x < chunk.getWidth(); x++) { for(int z = 0; z < chunk.getWidth(); z++) { - chunk.setBlockState(x,y,z, Blocks.STONE.getDefaultState1()); + chunk.setBlockState(x,y,z, Blocks.STONE.getDefaultState()); } } } diff --git a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleServerWorld.java b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleServerWorld.java index 003d5c3d..1095f0bf 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleServerWorld.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleServerWorld.java @@ -30,12 +30,12 @@ public IChunk getGeneratedChunk(int xx, int zz) { for(int y = 0; y < chunk.getHeight(); y++) { for(int z = 0; z < 16; z++) { if(y < 60) { - chunk.setBlockState(x, y, z, Blocks.STONE.getDefaultState1()); + chunk.setBlockState(x, y, z, Blocks.STONE.getDefaultState()); } else { if(y % 2 == 0) { - chunk.setBlockState(x, y, z, Blocks.RED.getDefaultState1()); + chunk.setBlockState(x, y, z, Blocks.RED.getDefaultState()); } else { - chunk.setBlockState(x, y, z, Blocks.AIR.getDefaultState1()); + chunk.setBlockState(x, y, z, Blocks.AIR.getDefaultState()); } } 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 dfaecc44..bc7a532d 100644 --- a/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java +++ b/src/main/java/dev/hilligans/ourcraft/world/newworldsystem/SimpleSubChunkImpl.java @@ -28,15 +28,15 @@ public int getHeight() { @Override public IBlockState getBlockState(int x, int y, int z) { if(blockStates == null) { - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } try { IBlockState b = blockStates[(int) ((x * width + y) * height + z)]; - return b == null ? Blocks.AIR.getDefaultState1() : b; + return b == null ? Blocks.AIR.getDefaultState() : b; } catch (Exception e) { // e.printStackTrace(); } - return Blocks.AIR.getDefaultState1(); + return Blocks.AIR.getDefaultState(); } @Override