Skip to content

Commit a320015

Browse files
committed
Add the stonecutter
1 parent 6d739b8 commit a320015

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

chunky/src/java/se/llbit/chunky/block/BlockSpec.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,7 @@ private Block blockFromTag(String name) {
14851485
case "smithing_table":
14861486
return new TexturedBlock(name, Texture.smithingTableFront, Texture.smithingTableFront, Texture.smithingTableSide, Texture.smithingTableSide, Texture.smithingTableTop, Texture.smithingTableBottom);
14871487
case "stonecutter":
1488-
// TODO
1489-
return new UnknownBlock(name);
1488+
return new Stonecutter(getFacing(tag, "north"));
14901489
case "bell":
14911490
// TODO
14921491
return new UnknownBlock(name);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package se.llbit.chunky.block;
2+
3+
import se.llbit.chunky.model.StonecutterModel;
4+
import se.llbit.chunky.renderer.scene.Scene;
5+
import se.llbit.chunky.resources.Texture;
6+
import se.llbit.math.Ray;
7+
8+
public class Stonecutter extends MinecraftBlockTranslucent {
9+
private final String facing;
10+
11+
public Stonecutter(String facing) {
12+
super("stonecutter", Texture.stonecutterSide);
13+
localIntersect = true;
14+
this.facing = facing;
15+
}
16+
17+
@Override
18+
public boolean intersect(Ray ray, Scene scene) {
19+
return StonecutterModel.intersect(ray, facing);
20+
}
21+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package se.llbit.chunky.model;
2+
3+
import se.llbit.chunky.resources.Texture;
4+
import se.llbit.math.Quad;
5+
import se.llbit.math.Ray;
6+
import se.llbit.math.Vector3;
7+
import se.llbit.math.Vector4;
8+
9+
public class StonecutterModel {
10+
private static final Texture bottom = Texture.stonecutterBottom;
11+
private static final Texture top = Texture.stonecutterTop;
12+
private static final Texture side = Texture.stonecutterSide;
13+
private static final Texture saw = Texture.stonecutterSaw;
14+
private static final Texture[] tex = new Texture[]{
15+
top, bottom, side, side, side, side, saw, saw
16+
};
17+
18+
private static final Quad[] quadsNorth = new Quad[]{
19+
new Quad(
20+
new Vector3(0 / 16.0, 9 / 16.0, 16 / 16.0),
21+
new Vector3(16 / 16.0, 9 / 16.0, 16 / 16.0),
22+
new Vector3(0 / 16.0, 9 / 16.0, 0 / 16.0),
23+
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
24+
),
25+
26+
new Quad(
27+
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
28+
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
29+
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
30+
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
31+
),
32+
new Quad(
33+
new Vector3(0 / 16.0, 9 / 16.0, 16 / 16.0),
34+
new Vector3(0 / 16.0, 9 / 16.0, 0 / 16.0),
35+
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
36+
new Vector4(16 / 16.0, 0 / 16.0, 9 / 16.0, 0 / 16.0)
37+
),
38+
new Quad(
39+
new Vector3(16 / 16.0, 9 / 16.0, 0 / 16.0),
40+
new Vector3(16 / 16.0, 9 / 16.0, 16 / 16.0),
41+
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
42+
new Vector4(16 / 16.0, 0 / 16.0, 9 / 16.0, 0 / 16.0)
43+
),
44+
new Quad(
45+
new Vector3(0 / 16.0, 9 / 16.0, 0 / 16.0),
46+
new Vector3(16 / 16.0, 9 / 16.0, 0 / 16.0),
47+
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
48+
new Vector4(16 / 16.0, 0 / 16.0, 9 / 16.0, 0 / 16.0)
49+
),
50+
new Quad(
51+
new Vector3(16 / 16.0, 9 / 16.0, 16 / 16.0),
52+
new Vector3(0 / 16.0, 9 / 16.0, 16 / 16.0),
53+
new Vector3(16 / 16.0, 0 / 16.0, 16 / 16.0),
54+
new Vector4(16 / 16.0, 0 / 16.0, 9 / 16.0, 0 / 16.0)
55+
),
56+
new Quad(
57+
new Vector3(1 / 16.0, 16 / 16.0, 8 / 16.0),
58+
new Vector3(15 / 16.0, 16 / 16.0, 8 / 16.0),
59+
new Vector3(1 / 16.0, 9 / 16.0, 8 / 16.0),
60+
new Vector4(15 / 16.0, 1 / 16.0, 7 / 16.0, 0 / 16.0)
61+
),
62+
new Quad(
63+
new Vector3(15 / 16.0, 16 / 16.0, 8 / 16.0),
64+
new Vector3(1 / 16.0, 16 / 16.0, 8 / 16.0),
65+
new Vector3(15 / 16.0, 9 / 16.0, 8 / 16.0),
66+
new Vector4(15 / 16.0, 1 / 16.0, 7 / 16.0, 0 / 16.0)
67+
)
68+
};
69+
70+
static final Quad[][] orientedQuads = new Quad[4][];
71+
72+
static {
73+
orientedQuads[0] = quadsNorth;
74+
orientedQuads[1] = Model.rotateY(orientedQuads[0]);
75+
orientedQuads[2] = Model.rotateY(orientedQuads[1]);
76+
orientedQuads[3] = Model.rotateY(orientedQuads[2]);
77+
}
78+
79+
public static boolean intersect(Ray ray, String facing) {
80+
boolean hit = false;
81+
ray.t = Double.POSITIVE_INFINITY;
82+
83+
Quad[] quads = orientedQuads[getOrientationIndex(facing)];
84+
for (int i = 0; i < quads.length; ++i) {
85+
Quad quad = quads[i];
86+
if (quad.intersect(ray)) {
87+
float[] color = tex[i].getColor(ray.u, ray.v);
88+
if (color[3] > Ray.EPSILON) {
89+
ray.color.set(color);
90+
ray.t = ray.tNext;
91+
ray.n.set(quad.n);
92+
hit = true;
93+
}
94+
}
95+
}
96+
97+
if (hit) {
98+
ray.distance += ray.t;
99+
ray.o.scaleAdd(ray.t, ray.d);
100+
}
101+
return hit;
102+
}
103+
104+
private static int getOrientationIndex(String facing) {
105+
switch (facing) {
106+
case "north":
107+
return 0;
108+
case "east":
109+
return 1;
110+
case "south":
111+
return 2;
112+
case "west":
113+
return 3;
114+
default:
115+
return 0;
116+
}
117+
}
118+
}

chunky/src/java/se/llbit/chunky/resources/Texture.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ public class Texture {
770770
public static final Texture bambooSmallLeaves = new Texture();
771771
public static final Texture bambooLargeLeaves = new Texture();
772772
public static final Texture bambooSingleLeaf = new Texture();
773+
public static final Texture stonecutterBottom = new Texture();
774+
public static final Texture stonecutterTop = new Texture();
775+
public static final Texture stonecutterSide = new Texture();
776+
public static final Texture stonecutterSaw = new Texture();
773777

774778
// [1.15]
775779
public static final Texture honeyBlockTop = new Texture();

chunky/src/java/se/llbit/chunky/resources/TexturePackLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,6 +3345,11 @@ public class TexturePackLoader {
33453345
addSimpleTexture("assets/minecraft/textures/block/bamboo_large_leaves", Texture.bambooLargeLeaves);
33463346
addSimpleTexture("assets/minecraft/textures/block/bamboo_singleleaf", Texture.bambooSingleLeaf);
33473347

3348+
addSimpleTexture("assets/minecraft/textures/block/stonecutter_bottom", Texture.stonecutterBottom);
3349+
addSimpleTexture("assets/minecraft/textures/block/stonecutter_top", Texture.stonecutterTop);
3350+
addSimpleTexture("assets/minecraft/textures/block/stonecutter_side", Texture.stonecutterSide);
3351+
addSimpleTexture("assets/minecraft/textures/block/stonecutter_saw", Texture.stonecutterSaw);
3352+
33483353
addSimpleTexture("assets/minecraft/textures/block/honey_block_top", Texture.honeyBlockTop);
33493354
addSimpleTexture("assets/minecraft/textures/block/honey_block_side", Texture.honeyBlockSide);
33503355
addSimpleTexture("assets/minecraft/textures/block/honey_block_bottom", Texture.honeyBlockBottom);

0 commit comments

Comments
 (0)