Skip to content

Commit 2807fc5

Browse files
committed
Add the campfire
1 parent a6b02c1 commit 2807fc5

File tree

6 files changed

+310
-2
lines changed

6 files changed

+310
-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
@@ -1498,8 +1498,7 @@ private Block blockFromTag(String name) {
14981498
return new SweetBerryBush(age);
14991499
}
15001500
case "campfire":
1501-
// TODO
1502-
return new UnknownBlock(name);
1501+
return new Campfire(getFacing(tag, "north"), isLit(tag));
15031502
case "cut_sandstone_slab":
15041503
return slab(tag, Texture.sandstoneCut, Texture.sandstoneTop);
15051504
case "cut_red_sandstone_slab":
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package se.llbit.chunky.block;
2+
3+
import se.llbit.chunky.model.CampfireModel;
4+
import se.llbit.chunky.model.StonecutterModel;
5+
import se.llbit.chunky.renderer.scene.Scene;
6+
import se.llbit.chunky.resources.Texture;
7+
import se.llbit.math.Ray;
8+
9+
public class Campfire extends MinecraftBlockTranslucent {
10+
private final String facing;
11+
public final boolean isLit;
12+
13+
public Campfire(String facing, boolean lit) {
14+
super("campfire", Texture.campfireLog);
15+
localIntersect = true;
16+
this.facing = facing;
17+
this.isLit = lit;
18+
// TODO the fire is 1/16th higher than a block, so this must be an entity
19+
}
20+
21+
@Override
22+
public boolean intersect(Ray ray, Scene scene) {
23+
return CampfireModel.intersect(ray, facing, isLit);
24+
}
25+
}

chunky/src/java/se/llbit/chunky/chunk/BlockPalette.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import se.llbit.chunky.block.Block;
44
import se.llbit.chunky.block.BlockSpec;
5+
import se.llbit.chunky.block.Campfire;
56
import se.llbit.chunky.block.RedstoneLamp;
67
import se.llbit.nbt.CompoundTag;
78
import se.llbit.nbt.StringTag;
@@ -164,6 +165,11 @@ public Block get(int id) {
164165
materialProperties.put("minecraft:tall_seagrass", block -> {
165166
block.waterlogged = true;
166167
});
168+
materialProperties.put("minecraft:campfire", block -> {
169+
if (block instanceof Campfire && ((Campfire)block).isLit) {
170+
block.emittance = 1.0f;
171+
}
172+
});
167173
// TODO: handle glass panes (multiple different block names).
168174
/*STAINED_GLASS.ior = 1.52f;
169175
GLASSPANE.ior = 1.52f;
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
package se.llbit.chunky.model;
2+
3+
import se.llbit.chunky.resources.Texture;
4+
import se.llbit.math.*;
5+
6+
public class CampfireModel {
7+
private static final Texture log = Texture.campfireLog;
8+
private static final Texture litlog = Texture.campfireLogLit;
9+
private static final Texture fire = Texture.campfireFire;
10+
11+
private static final Texture[] tex = new Texture[]{
12+
log, log, log, log, log, log, log, log, log, log, log, log, log, log, log,
13+
log, log, log, log, log, log, log, log, log, log, log, log, log,
14+
};
15+
16+
private static final Texture[] texLit = new Texture[]{
17+
log, log, log, litlog, log, log, log, litlog, log, log, litlog, litlog, log, log, litlog,
18+
log, log, log, log, litlog, log, log, litlog, litlog, litlog, log, log, log, fire, fire, fire, fire
19+
};
20+
21+
private static final Quad[] quads = new Quad[]{
22+
new Quad(
23+
new Vector3(5 / 16.0, 4 / 16.0, 16 / 16.0),
24+
new Vector3(5 / 16.0, 4 / 16.0, 0 / 16.0),
25+
new Vector3(1 / 16.0, 4 / 16.0, 16 / 16.0),
26+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
27+
),
28+
new Quad(
29+
new Vector3(5 / 16.0, 0 / 16.0, 0 / 16.0),
30+
new Vector3(5 / 16.0, 0 / 16.0, 16 / 16.0),
31+
new Vector3(1 / 16.0, 0 / 16.0, 0 / 16.0),
32+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
33+
),
34+
new Quad(
35+
new Vector3(1 / 16.0, 4 / 16.0, 16 / 16.0),
36+
new Vector3(1 / 16.0, 4 / 16.0, 0 / 16.0),
37+
new Vector3(1 / 16.0, 0 / 16.0, 16 / 16.0),
38+
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 12 / 16.0)
39+
),
40+
new Quad(
41+
new Vector3(5 / 16.0, 4 / 16.0, 0 / 16.0),
42+
new Vector3(5 / 16.0, 4 / 16.0, 16 / 16.0),
43+
new Vector3(5 / 16.0, 0 / 16.0, 0 / 16.0),
44+
new Vector4(16 / 16.0, 0 / 16.0, 15 / 16.0, 11 / 16.0)
45+
),
46+
new Quad(
47+
new Vector3(1 / 16.0, 4 / 16.0, 0 / 16.0),
48+
new Vector3(5 / 16.0, 4 / 16.0, 0 / 16.0),
49+
new Vector3(1 / 16.0, 0 / 16.0, 0 / 16.0),
50+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
51+
),
52+
new Quad(
53+
new Vector3(5 / 16.0, 4 / 16.0, 16 / 16.0),
54+
new Vector3(1 / 16.0, 4 / 16.0, 16 / 16.0),
55+
new Vector3(5 / 16.0, 0 / 16.0, 16 / 16.0),
56+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
57+
),
58+
new Quad(
59+
new Vector3(16 / 16.0, 7 / 16.0, 11 / 16.0),
60+
new Vector3(0 / 16.0, 7 / 16.0, 11 / 16.0),
61+
new Vector3(16 / 16.0, 7 / 16.0, 15 / 16.0),
62+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
63+
),
64+
new Quad(
65+
new Vector3(0 / 16.0, 3 / 16.0, 11 / 16.0),
66+
new Vector3(16 / 16.0, 3 / 16.0, 11 / 16.0),
67+
new Vector3(0 / 16.0, 3 / 16.0, 15 / 16.0),
68+
new Vector4(0 / 16.0, 16 / 16.0, 8 / 16.0, 12 / 16.0)
69+
),
70+
new Quad(
71+
new Vector3(0 / 16.0, 7 / 16.0, 15 / 16.0),
72+
new Vector3(0 / 16.0, 7 / 16.0, 11 / 16.0),
73+
new Vector3(0 / 16.0, 3 / 16.0, 15 / 16.0),
74+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
75+
),
76+
new Quad(
77+
new Vector3(16 / 16.0, 7 / 16.0, 11 / 16.0),
78+
new Vector3(16 / 16.0, 7 / 16.0, 15 / 16.0),
79+
new Vector3(16 / 16.0, 3 / 16.0, 11 / 16.0),
80+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
81+
),
82+
new Quad(
83+
new Vector3(0 / 16.0, 7 / 16.0, 11 / 16.0),
84+
new Vector3(16 / 16.0, 7 / 16.0, 11 / 16.0),
85+
new Vector3(0 / 16.0, 3 / 16.0, 11 / 16.0),
86+
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 12 / 16.0)
87+
),
88+
new Quad(
89+
new Vector3(16 / 16.0, 7 / 16.0, 15 / 16.0),
90+
new Vector3(0 / 16.0, 7 / 16.0, 15 / 16.0),
91+
new Vector3(16 / 16.0, 3 / 16.0, 15 / 16.0),
92+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 12 / 16.0)
93+
),
94+
new Quad(
95+
new Vector3(15 / 16.0, 4 / 16.0, 16 / 16.0),
96+
new Vector3(15 / 16.0, 4 / 16.0, 0 / 16.0),
97+
new Vector3(11 / 16.0, 4 / 16.0, 16 / 16.0),
98+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
99+
),
100+
new Quad(
101+
new Vector3(15 / 16.0, 0 / 16.0, 0 / 16.0),
102+
new Vector3(15 / 16.0, 0 / 16.0, 16 / 16.0),
103+
new Vector3(11 / 16.0, 0 / 16.0, 0 / 16.0),
104+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
105+
),
106+
new Quad(
107+
new Vector3(11 / 16.0, 4 / 16.0, 16 / 16.0),
108+
new Vector3(11 / 16.0, 4 / 16.0, 0 / 16.0),
109+
new Vector3(11 / 16.0, 0 / 16.0, 16 / 16.0),
110+
new Vector4(0 / 16.0, 16 / 16.0, 15 / 16.0, 11 / 16.0)
111+
),
112+
new Quad(
113+
new Vector3(15 / 16.0, 4 / 16.0, 0 / 16.0),
114+
new Vector3(15 / 16.0, 4 / 16.0, 16 / 16.0),
115+
new Vector3(15 / 16.0, 0 / 16.0, 0 / 16.0),
116+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 12 / 16.0)
117+
),
118+
new Quad(
119+
new Vector3(11 / 16.0, 4 / 16.0, 0 / 16.0),
120+
new Vector3(15 / 16.0, 4 / 16.0, 0 / 16.0),
121+
new Vector3(11 / 16.0, 0 / 16.0, 0 / 16.0),
122+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
123+
),
124+
new Quad(
125+
new Vector3(15 / 16.0, 4 / 16.0, 16 / 16.0),
126+
new Vector3(11 / 16.0, 4 / 16.0, 16 / 16.0),
127+
new Vector3(15 / 16.0, 0 / 16.0, 16 / 16.0),
128+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
129+
),
130+
new Quad(
131+
new Vector3(16 / 16.0, 7 / 16.0, 1 / 16.0),
132+
new Vector3(0 / 16.0, 7 / 16.0, 1 / 16.0),
133+
new Vector3(16 / 16.0, 7 / 16.0, 5 / 16.0),
134+
new Vector4(0 / 16.0, 16 / 16.0, 12 / 16.0, 16 / 16.0)
135+
),
136+
new Quad(
137+
new Vector3(0 / 16.0, 3 / 16.0, 1 / 16.0),
138+
new Vector3(16 / 16.0, 3 / 16.0, 1 / 16.0),
139+
new Vector3(0 / 16.0, 3 / 16.0, 5 / 16.0),
140+
new Vector4(0 / 16.0, 16 / 16.0, 8 / 16.0, 12 / 16.0)
141+
),
142+
new Quad(
143+
new Vector3(0 / 16.0, 7 / 16.0, 5 / 16.0),
144+
new Vector3(0 / 16.0, 7 / 16.0, 1 / 16.0),
145+
new Vector3(0 / 16.0, 3 / 16.0, 5 / 16.0),
146+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
147+
),
148+
new Quad(
149+
new Vector3(16 / 16.0, 7 / 16.0, 1 / 16.0),
150+
new Vector3(16 / 16.0, 7 / 16.0, 5 / 16.0),
151+
new Vector3(16 / 16.0, 3 / 16.0, 1 / 16.0),
152+
new Vector4(4 / 16.0, 0 / 16.0, 12 / 16.0, 8 / 16.0)
153+
),
154+
new Quad(
155+
new Vector3(0 / 16.0, 7 / 16.0, 1 / 16.0),
156+
new Vector3(16 / 16.0, 7 / 16.0, 1 / 16.0),
157+
new Vector3(0 / 16.0, 3 / 16.0, 1 / 16.0),
158+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 12 / 16.0)
159+
),
160+
new Quad(
161+
new Vector3(16 / 16.0, 7 / 16.0, 5 / 16.0),
162+
new Vector3(0 / 16.0, 7 / 16.0, 5 / 16.0),
163+
new Vector3(16 / 16.0, 3 / 16.0, 5 / 16.0),
164+
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 12 / 16.0)
165+
),
166+
new Quad(
167+
new Vector3(11 / 16.0, 1 / 16.0, 16 / 16.0),
168+
new Vector3(11 / 16.0, 1 / 16.0, 0 / 16.0),
169+
new Vector3(5 / 16.0, 1 / 16.0, 16 / 16.0),
170+
new Vector4(0 / 16.0, 16 / 16.0, 2 / 16.0, 8 / 16.0)
171+
),
172+
new Quad(
173+
new Vector3(11 / 16.0, 0 / 16.0, 0 / 16.0),
174+
new Vector3(11 / 16.0, 0 / 16.0, 16 / 16.0),
175+
new Vector3(5 / 16.0, 0 / 16.0, 0 / 16.0),
176+
new Vector4(0 / 16.0, 16 / 16.0, 2 / 16.0, 8 / 16.0)
177+
),
178+
new Quad(
179+
new Vector3(5 / 16.0, 1 / 16.0, 0 / 16.0),
180+
new Vector3(11 / 16.0, 1 / 16.0, 0 / 16.0),
181+
new Vector3(5 / 16.0, 0 / 16.0, 0 / 16.0),
182+
new Vector4(6 / 16.0, 0 / 16.0, 1 / 16.0, 0 / 16.0)
183+
),
184+
new Quad(
185+
new Vector3(11 / 16.0, 1 / 16.0, 16 / 16.0),
186+
new Vector3(5 / 16.0, 1 / 16.0, 16 / 16.0),
187+
new Vector3(11 / 16.0, 0 / 16.0, 16 / 16.0),
188+
new Vector4(16 / 16.0, 10 / 16.0, 1 / 16.0, 0 / 16.0)
189+
),
190+
rotateFire(new Quad(
191+
new Vector3(0.8 / 16.0, 17 / 16.0, 8 / 16.0),
192+
new Vector3(15.2 / 16.0, 17 / 16.0, 8 / 16.0),
193+
new Vector3(0.8 / 16.0, 1 / 16.0, 8 / 16.0),
194+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
195+
)),
196+
rotateFire(new Quad(
197+
new Vector3(15.2 / 16.0, 17 / 16.0, 8 / 16.0),
198+
new Vector3(0.8 / 16.0, 17 / 16.0, 8 / 16.0),
199+
new Vector3(15.2 / 16.0, 1 / 16.0, 8 / 16.0),
200+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
201+
)),
202+
rotateFire(new Quad(
203+
new Vector3(8 / 16.0, 17 / 16.0, 15.2 / 16.0),
204+
new Vector3(8 / 16.0, 17 / 16.0, 0.8 / 16.0),
205+
new Vector3(8 / 16.0, 1 / 16.0, 15.2 / 16.0),
206+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
207+
)),
208+
rotateFire(new Quad(
209+
new Vector3(8 / 16.0, 17 / 16.0, 0.8 / 16.0),
210+
new Vector3(8 / 16.0, 17 / 16.0, 15.2 / 16.0),
211+
new Vector3(8 / 16.0, 1 / 16.0, 0.8 / 16.0),
212+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
213+
))
214+
};
215+
216+
static final Quad[][] orientedQuads = new Quad[4][];
217+
218+
static {
219+
orientedQuads[0] = quads;
220+
orientedQuads[1] = Model.rotateY(orientedQuads[0]);
221+
orientedQuads[2] = Model.rotateY(orientedQuads[1]);
222+
orientedQuads[3] = Model.rotateY(orientedQuads[2]);
223+
}
224+
225+
public static boolean intersect(Ray ray, String facing, boolean lit) {
226+
boolean hit = false;
227+
ray.t = Double.POSITIVE_INFINITY;
228+
229+
Quad[] quads = orientedQuads[getOrientationIndex(facing)];
230+
int n = lit ? quads.length : quads.length - 4;
231+
Texture[] textures = lit ? texLit : tex;
232+
for (int i = 0; i < n; ++i) {
233+
Quad quad = quads[i];
234+
if (quad.intersect(ray)) {
235+
float[] color = textures[i].getColor(ray.u, ray.v);
236+
if (color[3] > Ray.EPSILON) {
237+
ray.color.set(color);
238+
ray.t = ray.tNext;
239+
ray.n.set(quad.n);
240+
hit = true;
241+
}
242+
}
243+
}
244+
245+
if (hit) {
246+
ray.distance += ray.t;
247+
ray.o.scaleAdd(ray.t, ray.d);
248+
}
249+
return hit;
250+
}
251+
252+
private static int getOrientationIndex(String facing) {
253+
switch (facing) {
254+
case "north":
255+
return 0;
256+
case "east":
257+
return 1;
258+
case "south":
259+
return 2;
260+
case "west":
261+
return 3;
262+
default:
263+
return 0;
264+
}
265+
}
266+
267+
private static Quad rotateFire(Quad quad) {
268+
double rotatedWidth = 14.4 * Math.cos(Math.toRadians(45));
269+
return new Quad(quad, Transform.NONE.rotateY(Math.toRadians(45)));
270+
}
271+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ public class Texture {
777777
public static final Texture grindstonePivot = new Texture();
778778
public static final Texture grindstoneRound = new Texture();
779779
public static final Texture grindstoneSide = new Texture();
780+
public static final Texture campfireLog = new Texture();
781+
public static final Texture campfireLogLit = new Texture();
782+
public static final Texture campfireFire = new Texture();
780783

781784
// [1.15]
782785
public static final Texture honeyBlockTop = new Texture();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,10 @@ public class TexturePackLoader {
33543354
addSimpleTexture("assets/minecraft/textures/block/grindstone_round", Texture.grindstoneRound);
33553355
addSimpleTexture("assets/minecraft/textures/block/grindstone_side", Texture.grindstoneSide);
33563356

3357+
addSimpleTexture("assets/minecraft/textures/block/campfire_log", Texture.campfireLog);
3358+
addSimpleTexture("assets/minecraft/textures/block/campfire_log_lit", Texture.campfireLogLit);
3359+
addSimpleTexture("assets/minecraft/textures/block/campfire_fire", Texture.campfireFire);
3360+
33573361
addSimpleTexture("assets/minecraft/textures/block/honey_block_top", Texture.honeyBlockTop);
33583362
addSimpleTexture("assets/minecraft/textures/block/honey_block_side", Texture.honeyBlockSide);
33593363
addSimpleTexture("assets/minecraft/textures/block/honey_block_bottom", Texture.honeyBlockBottom);

0 commit comments

Comments
 (0)