Skip to content

Commit c5a37b9

Browse files
committed
Move waterlogged to the Block class.
1 parent 3d99f0a commit c5a37b9

File tree

8 files changed

+44
-41
lines changed

8 files changed

+44
-41
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public abstract class Block extends Material {
3232
*/
3333
public boolean invisible = false;
3434

35+
protected boolean waterlogged = false;
36+
3537
public Block(String name, Texture texture) {
3638
super(name, texture);
3739
}
@@ -176,4 +178,12 @@ public Block applyWaterlogging() {
176178
this.waterlogged = true;
177179
return this;
178180
}
181+
182+
public boolean isWaterlogged() {
183+
return waterlogged;
184+
}
185+
186+
public boolean isWaterFilled() {
187+
return waterlogged || isWater();
188+
}
179189
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ public OctreeFinalizationState(Octree worldTree, Octree waterTree,
2525

2626
@Override
2727
public Material getMaterial() {
28-
return worldTree.getMaterial(x, y, z, getPalette());
28+
return worldTree.getBlock(x, y, z, getPalette());
2929
}
3030

3131
@Override
3232
public Material getMaterial(int rx, int ry, int rz) {
33-
return worldTree
34-
.getMaterial(x + rx, y + ry, z + rz, getPalette());
33+
return worldTree.getBlock(x + rx, y + ry, z + rz, getPalette());
3534
}
3635

3736
@Override

chunky/src/java/se/llbit/chunky/entity/BeaconBeam.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public void loadDataFromOctree(Octree octree, BlockPalette palette, Vector3i ori
8989
//Start i at 1 so the first beacon block is not checked. This would cause the base beam color to always be white.
9090
//Stop iterating if the we get outside octree.
9191
for (int i = 1; i < height && octree.isInside(new Vector3((position.x - origin.x), (position.y + i - origin.y), (position.z - origin.z))); i++) {
92-
Material blockMaterial = octree.getMaterial((int)(position.x - origin.x), (int)(position.y + i - origin.y), (int)(position.z - origin.z), palette);
93-
int color = getColorFromBlock((Block)blockMaterial);
92+
Block block = octree.getBlock((int)(position.x - origin.x), (int)(position.y + i - origin.y), (int)(position.z - origin.z), palette);
93+
int color = getColorFromBlock(block);
9494
if(color != -1) {
9595
if (!foundFirst) {
9696
this.materials.put(i, new BeaconBeamMaterial(color));
@@ -111,12 +111,12 @@ public void loadDataFromOctree(Octree octree, BlockPalette palette, Vector3i ori
111111
}
112112
}
113113

114-
private int getColorFromBlock(Block blockMaterial) {
115-
if(blockMaterial instanceof Beacon) {
114+
private int getColorFromBlock(Block block) {
115+
if(block instanceof Beacon) {
116116
return BeaconBeamMaterial.DEFAULT_COLOR;
117117
}
118118
Pattern stainedGlassPattern = Pattern.compile("(minecraft:)?(.+?)_stained_glass(_pane)?");
119-
Matcher matcher = stainedGlassPattern.matcher(blockMaterial.name);
119+
Matcher matcher = stainedGlassPattern.matcher(block.name);
120120
if (matcher.find()) {
121121
String prefix = matcher.group(2);
122122
switch (prefix) {

chunky/src/java/se/llbit/chunky/renderer/scene/OctreeFinalizer.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package se.llbit.chunky.renderer.scene;
1818

19+
import se.llbit.chunky.block.Block;
1920
import se.llbit.chunky.block.minecraft.Lava;
2021
import se.llbit.chunky.block.minecraft.Water;
2122
import se.llbit.chunky.chunk.BlockPalette;
@@ -65,12 +66,12 @@ private static void hideBlocks(Octree worldTree, BlockPalette palette, int x,
6566
int y = cy - origin.y;
6667
if (cy > yMin && cy < yMax - 1) {
6768
boolean isHidden =
68-
worldTree.getMaterial(x - 1, y, z, palette).opaque
69-
&& worldTree.getMaterial(x + 1, y, z, palette).opaque
70-
&& worldTree.getMaterial(x, y, z - 1, palette).opaque
71-
&& worldTree.getMaterial(x, y, z + 1, palette).opaque
72-
&& worldTree.getMaterial(x, y - 1, z, palette).opaque
73-
&& worldTree.getMaterial(x, y + 1, z, palette).opaque;
69+
worldTree.getBlock(x - 1, y, z, palette).opaque
70+
&& worldTree.getBlock(x + 1, y, z, palette).opaque
71+
&& worldTree.getBlock(x, y, z - 1, palette).opaque
72+
&& worldTree.getBlock(x, y, z + 1, palette).opaque
73+
&& worldTree.getBlock(x, y - 1, z, palette).opaque
74+
&& worldTree.getBlock(x, y + 1, z, palette).opaque;
7475
if (isHidden) {
7576
worldTree.set(BlockPalette.ANY_ID, x, y, z);
7677
}
@@ -80,11 +81,11 @@ private static void hideBlocks(Octree worldTree, BlockPalette palette, int x,
8081
private static void processBlock(Octree worldTree, Octree waterTree, BlockPalette palette,
8182
Set<ChunkPosition> loadedChunks, int x, int cy, int z, Vector3i origin) {
8283
int y = cy - origin.y;
83-
Material mat = worldTree.getMaterial(x, y, z, palette);
84-
Material wmat = waterTree.getMaterial(x, y, z, palette);
84+
Block mat = worldTree.getBlock(x, y, z, palette);
85+
Block wmat = waterTree.getBlock(x, y, z, palette);
8586

8687
if (wmat instanceof Water) {
87-
Material above = waterTree.getMaterial(x, y + 1, z, palette);
88+
Block above = waterTree.getBlock(x, y + 1, z, palette);
8889
int level0 = 8 - ((Water) wmat).level;
8990
if (!above.isWaterFilled()) {
9091
int cornerSW = level0;
@@ -141,7 +142,7 @@ private static void processBlock(Octree worldTree, Octree waterTree, BlockPalett
141142
waterTree.set(palette.getWaterId(0, 1 << Water.FULL_BLOCK), x, y, z);
142143
}
143144
} else if (mat instanceof Lava) {
144-
Material above = worldTree.getMaterial(x, y + 1, z, palette);
145+
Material above = worldTree.getBlock(x, y + 1, z, palette);
145146
if (!(above instanceof Lava)) {
146147
Lava lava = (Lava) mat;
147148

@@ -201,14 +202,14 @@ private static int waterLevelAt(Octree worldTree, Octree waterTree, BlockPalette
201202
return baseLevel;
202203
}
203204

204-
Material corner = waterTree.getMaterial(x, cy, z, palette);
205+
Block corner = waterTree.getBlock(x, cy, z, palette);
205206
if (corner.isWater()) {
206-
Material above = waterTree.getMaterial(x, cy + 1, z, palette);
207+
Block above = waterTree.getBlock(x, cy + 1, z, palette);
207208
boolean isFullBlock = above.isWaterFilled();
208209
return isFullBlock ? 8 : 8 - ((Water) corner).level;
209210
} else if (corner.isWaterlogged()) {
210211
return 8;
211-
} else if (!worldTree.getMaterial(x, cy, z, palette).solid) {
212+
} else if (!worldTree.getBlock(x, cy, z, palette).solid) {
212213
return 0;
213214
}
214215
return baseLevel;
@@ -221,9 +222,9 @@ private static int lavaLevelAt(Octree octree, BlockPalette palette,
221222
return baseLevel;
222223
}
223224

224-
Material corner = octree.getMaterial(x, cy, z, palette);
225+
Block corner = octree.getBlock(x, cy, z, palette);
225226
if (corner instanceof Lava) {
226-
Material above = octree.getMaterial(x, cy + 1, z, palette);
227+
Block above = octree.getBlock(x, cy + 1, z, palette);
227228
boolean isFullBlock = above instanceof Lava;
228229
return isFullBlock ? 8 : 8 - ((Lava) corner).level;
229230
} else if (!corner.solid) {

chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ public Vector3 calcCenterCamera() {
15691569
int zcenter = (zmax + zmin) / 2;
15701570
int ycenter = (yMax + yMin) / 2;
15711571
for (int y = Math.min(ycenter+127, yMax); y >= Math.max(ycenter-128, yMin); --y) {
1572-
Material block = worldOctree.getMaterial(xcenter - origin.x, y - origin.y, zcenter - origin.z,
1572+
Material block = worldOctree.getBlock(xcenter - origin.x, y - origin.y, zcenter - origin.z,
15731573
palette);
15741574
if (!(block instanceof Air)) {
15751575
return new Vector3(xcenter, y + 5, zcenter);
@@ -2544,7 +2544,7 @@ public boolean isInWater(Ray ray) {
25442544
int x = (int) QuickMath.floor(ray.o.x);
25452545
int y = (int) QuickMath.floor(ray.o.y);
25462546
int z = (int) QuickMath.floor(ray.o.z);
2547-
Material block = waterOctree.getMaterial(x, y, z, palette);
2547+
Block block = waterOctree.getBlock(x, y, z, palette);
25482548
return block.isWater()
25492549
&& ((ray.o.y - y) < 0.875 || ((Water) block).isFullBlock());
25502550
}

chunky/src/java/se/llbit/chunky/world/Material.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ public abstract class Material {
8787

8888
public boolean refractive = false;
8989

90-
protected boolean waterlogged = false;
91-
9290
public Material(String name, Texture texture) {
9391
this.name = name;
9492
this.texture = texture;
@@ -131,14 +129,6 @@ public boolean isWater() {
131129
return false;
132130
}
133131

134-
public boolean isWaterlogged() {
135-
return waterlogged;
136-
}
137-
138-
public boolean isWaterFilled() {
139-
return waterlogged || isWater();
140-
}
141-
142132
public boolean isSameMaterial(Material other) {
143133
return other == this;
144134
}

chunky/src/java/se/llbit/math/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static EmitterPosition create(int x, int y, int z, int block, Scene scene
4545
}
4646

4747
public static EmitterPosition create(int x, int y, int z, Scene scene) {
48-
return new EmitterPosition(x, y, z, (Block) scene.getWorldOctree().getMaterial(x, y, z, scene.getPalette()));
48+
return new EmitterPosition(x, y, z, scene.getWorldOctree().getBlock(x, y, z, scene.getPalette()));
4949
}
5050

5151
public void sample(Vector3 loc, Random rand) {

chunky/src/java/se/llbit/math/Octree.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public class Octree {
5858

5959
public interface OctreeImplementation {
6060
void set(int type, int x, int y, int z);
61-
Material getMaterial(int x, int y, int z, BlockPalette palette);
61+
@Deprecated(forRemoval = true) Material getMaterial(int x, int y, int z, BlockPalette palette);
62+
default Block getBlock(int x, int y, int z, BlockPalette palette) {
63+
return (Block) getMaterial(x, y, z, palette);
64+
}
6265
void store(DataOutputStream output) throws IOException;
6366
int getDepth();
6467
long nodeCount();
@@ -287,18 +290,18 @@ public synchronized void set(int type, int x, int y, int z) {
287290
}
288291

289292
/**
290-
* Get the material at the given position (relative to the octree origin).
293+
* Get the block at the given position (relative to the octree origin).
291294
* @param x x position
292295
* @param y y position
293296
* @param z z position
294297
* @param palette Block palette
295-
* @return Material at the given position or {@link Air#INSTANCE} if the position is outside of this octree
298+
* @return Block at the given position or {@link Air#INSTANCE} if the position is outside of this octree
296299
*/
297-
public Material getMaterial(int x, int y, int z, BlockPalette palette) {
300+
public Block getBlock(int x, int y, int z, BlockPalette palette) {
298301
int size = (1 << implementation.getDepth());
299302
if(x < 0 || y < 0 || z < 0 || x >= size || y >= size || z >= size)
300303
return Air.INSTANCE;
301-
return implementation.getMaterial(x, y, z, palette);
304+
return implementation.getBlock(x, y, z, palette);
302305
}
303306

304307
/**

0 commit comments

Comments
 (0)