Skip to content

Commit

Permalink
Texture updated/created: water, grass, lantern
Browse files Browse the repository at this point in the history
  • Loading branch information
kismama committed Sep 23, 2024
1 parent 57e42dc commit 5bd8c3d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions BlockGame.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector3_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ffe687a889bb3a9242cce1cee2fd3ef7fd8dca8c5f1dba87cb758dd3de14737_003FVector3_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector64_005F1_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F8644d89cbcd587e5fecd872ee1c7e4045996db76a464ffa4dfc81c137a92a_003FVector64_005F1_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVertex_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0875e3e537714cbe9553e6a2a0e88549a9e00_003Fcc_003F3f5ba028_003FVertex_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AViewImplementationBase_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F77b6093498874e5590363bcf1d64746ed3a0_003F11_003Fedea32f4_003FViewImplementationBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AViewImplementationBase_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F77b6093498874e5590363bcf1d64746ed3a0_003F11_003Fedea32f4_003FViewImplementationBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindowExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F77b6093498874e5590363bcf1d64746ed3a0_003F9f_003Ff2ddaa26_003FWindowExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindowOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F77b6093498874e5590363bcf1d64746ed3a0_003F9d_003F41f44569_003FWindowOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
Expand Down
2 changes: 1 addition & 1 deletion src/GL/BTextureAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void Dispose() {
}

public void update(double dt) {
if (ticks % 5 == 0) {
if (ticks % 8 == 0) {
updateTexture(0, 4 * 16, 16, 16, (i % 16) * 16, 4 * 16);
i++;
}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ public Vector2 measureStringSmall(ReadOnlySpan<char> text) {
public void drawBlock(Block block, int x, int y, int size) {
//GD.Clear(ClearBuffers.Color);
var viewport = GD.Viewport;
var dt = GD.DepthTestingEnabled;
GD.DepthTestingEnabled = true;
GD.VertexArray = buffer;
GD.ShaderProgram = guiBlockShader;
WorldRenderer.meshBlockTinted(block, ref guiBlock, ref guiBlockI, 15);
Expand Down Expand Up @@ -387,6 +389,9 @@ public void drawBlock(Block block, int x, int y, int size) {
// it no longer thinks we have vertex arrays bound when we actually trashed it in our renderer
//GL.BindVertexArray(buffer.VertexArray.Handle);
GD.DrawElements(PrimitiveType.Triangles, 0, (uint)spI.Length);

// restore
GD.DepthTestingEnabled = dt;
GD.Viewport = viewport;
}

Expand Down
34 changes: 33 additions & 1 deletion src/util/BlockModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static BlockModel makeGrass(UVPair[] uvs) {
model.faces = new Face[4];

// offset from edge
var offset = 1 / (8 * MathF.Sqrt(2));
var offset = 1 / 16*mathsqrt(2);

// x1
model.faces[0] = new(0 + offset, 1, 1 - offset, 0 + offset, 0, 1 - offset, 1 - offset, 0, 0 + offset, 1 - offset, 1, 0 + offset,
Expand All @@ -77,6 +77,10 @@ public static BlockModel makeGrass(UVPair[] uvs) {
return model;
}

private static int mathsqrt(int i) {
return 0;
}

public static BlockModel makeStairs(UVPair[] uvs) {
var model = new BlockModel();
model.faces = new Face[10];
Expand Down Expand Up @@ -124,6 +128,34 @@ public static BlockModel makeHalfCube(UVPair[] uvs) {

}

//make a 12x14 pixel partial cube
public static BlockModel makePartialCube(UVPair[] uvs) {
var model = new BlockModel();
var offset = 2 / 16f;
var offset1 = 6 / 16f;

model.faces = new Face[11];
// west
model.faces[0] = new(0+offset, 1-offset, 1-offset, 0+offset, 0, 1-offset, 0+offset, 0, 0+offset, 0+offset, 1-offset, 0+offset, uvs[1] + offset, uvs[1] + new UVPair(1-offset, 1), RawDirection.WEST, true, true);
// east
model.faces[1] = new(1-offset, 1-offset, 0+offset, 1-offset, 0, 0+offset, 1-offset, 0, 1-offset, 1-offset, 1-offset, 1-offset, uvs[1] + offset, uvs[1] + new UVPair(1-offset, 1), RawDirection.EAST, true, true);
// south
model.faces[2] = new(0+offset, 1-offset, 0+offset, 0+offset, 0, 0+offset, 1-offset, 0, 0+offset, 1-offset, 1-offset, 0+offset, uvs[1] + offset, uvs[1] + new UVPair(1-offset, 1), RawDirection.SOUTH, true, true);
// north
model.faces[3] = new(1-offset, 1-offset, 1-offset, 1-offset, 0, 1-offset, 0+offset, 0, 1-offset, 0+offset, 1-offset, 1-offset, uvs[1] + offset, uvs[1] + new UVPair(1-offset, 1), RawDirection.NORTH, true, true);
// down
model.faces[4] = new(1-offset, 0, 1-offset, 1-offset, 0, 0+offset, 0+offset, 0, 0+offset, 0+offset, 0, 1-offset, uvs[4] + offset, uvs[4]+(1-offset), RawDirection.DOWN, true, true);
// up
model.faces[5] = new(0+offset, 1-offset, 1-offset, 0+offset, 1-offset, 0+offset, 1-offset, 1-offset, 0+offset, 1-offset, 1-offset, 1-offset, uvs[5] + offset, uvs[5]+(1-offset), RawDirection.UP, true, true);

model.faces[6] = new(0+offset1, 1, 1-offset1, 0+offset1, 1-offset, 1-offset1, 0+offset1, 1-offset, 0+offset1, 0+offset1, 1, 0+offset1, uvs[2] + new UVPair(offset1,0), uvs[2]+new UVPair(1-offset1, offset) , RawDirection.WEST, true, true);
model.faces[7] = new(1-offset1, 1, 0+offset1, 1-offset1, 1-offset, 0+offset1, 1-offset1, 1-offset, 1-offset1, 1-offset1, 1, 1-offset1, uvs[2] + new UVPair(offset1,0), uvs[2]+new UVPair(1-offset1, offset), RawDirection.EAST, true, true);
model.faces[8] = new(0+offset1, 1, 0+offset1, 0+offset1, 1-offset, 0+offset1, 1-offset1, 1-offset, 0+offset1, 1-offset1, 1, 0+offset1, uvs[2] + new UVPair(offset1,0), uvs[2]+new UVPair(1-offset1, offset), RawDirection.SOUTH, true, true);
model.faces[9] = new(1-offset1, 1, 1-offset1, 1-offset1, 1-offset, 1-offset1, 0+offset1, 1-offset, 1-offset1, 0+offset1, 1, 1-offset1, uvs[2] + new UVPair(offset1,0), uvs[2]+new UVPair(1-offset1, offset), RawDirection.NORTH, true, true);
model.faces[10] = new(0+offset1, 1, 1-offset1, 0+offset1, 1, 0+offset1, 1-offset1, 1, 0+offset1, 1-offset1, 1, 1-offset1, uvs[4] + new UVPair(offset1,offset1), uvs[4]+new UVPair(1-offset1, 1-offset1), RawDirection.UP, true, true);
return model;
}

public static BlockModel emptyBlock() {
var model = new BlockModel();
model.faces = [];
Expand Down
26 changes: 18 additions & 8 deletions src/util/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Blocks {
public static bool[] translucentCache = new bool[MAXBLOCKS];
public static bool[] inventoryBlacklist = new bool[MAXBLOCKS];

public static readonly int maxBlock = 42;
public static readonly int maxBlock = 44;

public static Block register(Block block) {
return blocks[block.id] = block;
Expand Down Expand Up @@ -62,12 +62,16 @@ public static bool isBlacklisted(int block) {
public static Block STONE = register(new Block(5, "Stone", BlockModel.makeCube(Block.cubeUVs(5, 0))));
public static Block GRAVEL = register(new Block(6, "Gravel", BlockModel.makeCube(Block.cubeUVs(7, 0))));
public static Block HELLSTONE = register(new Block(7, "Hellstone", BlockModel.makeCube(Block.grassUVs(8, 0, 9, 0, 9, 0))).light(15));

public static Block GLASS = register(new Block(8, "Glass", BlockModel.makeCube(Block.cubeUVs(6, 0))).transparency());
public static Block LANTERN = register(new Block(9, "Lantern", BlockModel.makeCube(Block.grassUVs(15, 1, 13, 1, 14, 1))).light(15));
public static Block YELLOW_FLOWER = register(new Flower(10, "Yellow Flower", BlockModel.makeGrass(Block.crossUVs(2, 3)))).transparency().flowerAABB().noCollision();
public static Block RED_FLOWER = register(new Flower(11, "Red Flower", BlockModel.makeGrass(Block.crossUVs(3, 3)))).transparency().flowerAABB().noCollision();
//public static Block TALL_GRASS = register(new Flower(12, "Tall Grass", BlockModel.makeGrass(Block.crossUVs( , )))).transparency().flowerAABB().noCollision();

public static Block LANTERN = register(new Block(9, "Lantern", BlockModel.makePartialCube(Block.grassUVs(15, 1, 13, 1, 14, 1))).light(15).partialBlock());

public static Block TALL_GRASS = register(new Flower(43, "Tall Grass", BlockModel.makeGrass(Block.crossUVs(9,1)))).transparency().noCollision();
public static Block SHORT_GRASS = register(new Flower(44, "Short Grass", BlockModel.makeGrass(Block.crossUVs(8,1)))).transparency().shortGrassAABB().noCollision();

public static Block YELLOW_FLOWER = register(new Flower(10, "Yellow Flower", BlockModel.makeGrass(Block.crossUVs(10,1))).transparency().flowerAABB().noCollision());
public static Block RED_FLOWER = register(new Flower(11, "Red Flower", BlockModel.makeGrass(Block.crossUVs(11,1))).transparency().flowerAABB().noCollision());


public static Block PLANKS = register(new Block(12, "Planks", BlockModel.makeCube(Block.cubeUVs(0, 5))));
public static Block STAIRS = register(new Block(13, "Stairs", BlockModel.makeStairs(Block.cubeUVs(0, 5))).partialBlock());
Expand Down Expand Up @@ -276,11 +280,17 @@ public static AABB fullBlock() {
}

public Block flowerAABB() {
var offset = 3 / 8f;
var offset = 6 / 16f;
selectionAABB = new AABB(new Vector3D(0 + offset, 0, 0 + offset), new Vector3D(1 - offset, 0.5, 1 - offset));
return this;
}

public Block shortGrassAABB() {
var offset = 4 / 16f;
selectionAABB = new AABB(new Vector3D(0, 0, 0), new Vector3D(1, offset, 1));
return this;
}

public Block(ushort id, string name, BlockModel model) {
this.id = id;
this.name = name;
Expand Down Expand Up @@ -496,7 +506,7 @@ public readonly record struct Face(
float x4, float y4, float z4,
UVPair min, UVPair max, RawDirection direction, bool noAO = false, bool nonFullFace = false) {

public const int MAX_FACES = 10;
public const int MAX_FACES = 12;

public readonly float x1 = x1;
public readonly float y1 = y1;
Expand Down
2 changes: 1 addition & 1 deletion src/world/chunk/SubChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tick(Random random, int x, int y, int z) {
var worldPos = World.toWorldPos(chunkX, chunkY, chunkZ, x, y, z);

if (block == Blocks.GRASS.id) {
if (y < 127 && world.getBlock(worldPos.X, worldPos.Y + 1, worldPos.Z) != 0) {
if (y < 127 && Blocks.isFullBlock(world.getBlock(worldPos.X, worldPos.Y + 1, worldPos.Z))) {
blocks[x, y, z] = Blocks.DIRT.id;
renderer.meshChunk();
}
Expand Down
Binary file modified textures/blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5bd8c3d

Please sign in to comment.