Skip to content

Commit

Permalink
makehalfcube blockmodel texture coordinates updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kismama committed Jul 11, 2024
1 parent dfb266a commit 9d79e32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
34 changes: 17 additions & 17 deletions src/util/BlockModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static BlockModel makeLiquid(UVPair[] uvs) {
var model = new BlockModel();
model.faces = new Face[6];

const float offset = 0.0005f;
const float offset = 0;

const float height = 15 / 16f;

Expand Down Expand Up @@ -106,22 +106,22 @@ public static BlockModel makeStairs(UVPair[] uvs) {

//make a 8x8 pixel half cube
public static BlockModel makeHalfCube(UVPair[] uvs) {
var model = new BlockModel();
model.faces = new Face[6];
// west
model.faces[0] = new(0.25f, 0.5f, 0.75f, 0.25f, 0, 0.75f, 0.25f, 0, 0.25f, 0.25f, 0.5f, 0.25f, uvs[0], uvs[0] + 0.5f, RawDirection.WEST, true, true);
// east
model.faces[1] = new(0.75f, 0.5f, 0.25f, 0.75f, 0, 0.25f, 0.75f, 0, 0.75f, 0.75f, 0.5f, 0.75f, uvs[1], uvs[1] + 0.5f, RawDirection.EAST, true, true);
// south
model.faces[2] = new(0.25f, 0.5f, 0.25f, 0.25f, 0, 0.25f, 0.75f, 0, 0.25f, 0.75f, 0.5f, 0.25f, uvs[2], uvs[2] + 0.5f, RawDirection.SOUTH, true, true);
// north
model.faces[3] = new(0.75f, 0.5f, 0.75f, 0.75f, 0, 0.75f, 0.25f, 0, 0.75f, 0.25f, 0.5f, 0.75f, uvs[3],uvs[3] + 0.5f, RawDirection.NORTH, true, true);
// down
model.faces[4] = new(0.75f, 0, 0.75f, 0.75f, 0, 0.25f, 0.25f, 0, 0.25f, 0.25f, 0, 0.75f, uvs[4], uvs[4] + 0.5f, RawDirection.DOWN, true, true);
// up
model.faces[5] = new(0.25f, 0.5f, 0.75f, 0.25f, 0.5f, 0.25f, 0.75f, 0.5f, 0.25f, 0.75f, 0.5f, 0.75f, uvs[5], uvs[5] + 0.5f, RawDirection.UP, true, true);
return model;
var model = new BlockModel();
model.faces = new Face[6];
// west
model.faces[0] = new(0.25f, 0.5f, 0.75f, 0.25f, 0, 0.75f, 0.25f, 0, 0.25f, 0.25f, 0.5f, 0.25f, uvs[0], uvs[0] + 0.5f, RawDirection.WEST, true, true);
// east
model.faces[1] = new(0.75f, 0.5f, 0.25f, 0.75f, 0, 0.25f, 0.75f, 0, 0.75f, 0.75f, 0.5f, 0.75f, uvs[0] + new UVPair(0.5f, 0), uvs[0] + new UVPair(1, 0.5f), RawDirection.EAST, true, true);
// south
model.faces[2] = new(0.25f, 0.5f, 0.25f, 0.25f, 0, 0.25f, 0.75f, 0, 0.25f, 0.75f, 0.5f, 0.25f, uvs[0] + new UVPair(0, 0.5f), uvs[0] + new UVPair(0.5f, 1), RawDirection.SOUTH, true, true);
// north
model.faces[3] = new(0.75f, 0.5f, 0.75f, 0.75f, 0, 0.75f, 0.25f, 0, 0.75f, 0.25f, 0.5f, 0.75f, uvs[0] + new UVPair(0.5f, 0.5f), uvs[0] + new UVPair(1, 1), RawDirection.NORTH, true, true);
// down
model.faces[4] = new(0.75f, 0, 0.75f, 0.75f, 0, 0.25f, 0.25f, 0, 0.25f, 0.25f, 0, 0.75f, uvs[1], uvs[1] + 0.5f, RawDirection.DOWN, true, true);
// up
model.faces[5] = new(0.25f, 0.5f, 0.75f, 0.25f, 0.5f, 0.25f, 0.75f, 0.5f, 0.25f, 0.75f, 0.5f, 0.75f, uvs[1]+ new UVPair(0, 0.5f), uvs[1] + new UVPair(0.5f, 1), RawDirection.UP, true, true);
return model;

}

public static BlockModel emptyBlock() {
Expand Down
21 changes: 12 additions & 9 deletions src/util/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static bool isBlacklisted(int block) {
public static Block BASALT = register(new Block(4, "Basalt", BlockModel.makeCube(Block.cubeUVs(4, 0))));
public static Block STONE = register(new Block(5, "Stone", BlockModel.makeCube(Block.cubeUVs(5, 0))));
public static Block GRAVEL = register(new Block(33, "Gravel", BlockModel.makeCube(Block.cubeUVs(15, 0))));
public static Block HELLSTONE = register(new Block(34, "Hellstone", BlockModel.makeCube(Block.grassUVs(1, 1,2,1,2,1))).light(15));
public static Block HELLSTONE = register(new Block(34, "Hellstone", BlockModel.makeCube(Block.grassUVs(1, 1, 2, 1, 2, 1))).light(15));

public static Block GLASS = register(new Block(6, "Glass", BlockModel.makeCube(Block.cubeUVs(6, 0)))
.transparency()
);
Expand Down Expand Up @@ -95,9 +95,8 @@ public static bool isBlacklisted(int block) {
public static Block CANDY_WHITE = register(new Block(29, "White Candy", BlockModel.makeCube(Block.cubeUVs(13, 2))));
public static Block CANDY_GREY = register(new Block(30, "Grey Candy", BlockModel.makeCube(Block.cubeUVs(14, 2))));
public static Block CANDY_BLACK = register(new Block(31, "Black Candy", BlockModel.makeCube(Block.cubeUVs(15, 2))));
//public static Block HEAD = register(new Block(32, "Head", BlockModel.makeHalfCube(Block.HeadUVs(0, 3,1, 3, 2, 3, 3, 3,4, 3, 5, 3))).partialBlock());
public static Block HEAD = register(new Block(32, "Head", BlockModel.makeHalfCube(Block.HeadUVs(0, 3,1, 3, 2, 3, 3, 3,4, 3, 5, 3))).partialBlock());

public static Block HEAD = register(new Block(32, "Head", BlockModel.makeHalfCube(Block.HeadUVs(0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 5, 3))).partialBlock());

public static bool isSolid(int block) {
return block != 0 && get(block).type == BlockType.SOLID;
}
Expand Down Expand Up @@ -244,10 +243,10 @@ public static UVPair[] crossUVs(int x, int y) {
return [new(x, y), new(x, y)];
}

public static UVPair[] HeadUVs(int frontX, int frontY, int leftX, int leftY, int rightX, int rightY, int topX, int topY, int bottomX, int bottomY, int backX, int backY) {
return [
new(leftX, leftY), new(rightX, rightY), new(frontX, frontY), new(backX, backY), new(bottomX, bottomY), new(topX, topY)
];
public static UVPair[] HeadUVs(int leftX, int leftY, int rightX, int rightY, int frontX, int frontY, int backX, int backY, int bottomX, int bottomY, int topX, int topY) {
return [
new(leftX, leftY), new(rightX, rightY), new(frontX, frontY), new(backX, backY), new(bottomX, bottomY), new(topX, topY)
];
}

// this will pack the data into the uint
Expand Down Expand Up @@ -410,6 +409,10 @@ public readonly record struct UVPair(float u, float v) {
return new UVPair(uv.u + q, uv.v + q);
}

public static UVPair operator -(UVPair uv, float q) {
return new UVPair(uv.u - q, uv.v - q);
}

public static UVPair operator +(UVPair uv, UVPair other) {
return new UVPair(uv.u + other.u, uv.v + other.v);
}
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 9d79e32

Please sign in to comment.