Skip to content

Commit 1fc1ff3

Browse files
committed
Merge branch '21.1/enh/blackboards' into 21.1/main
2 parents 4dba056 + 60726e4 commit 1fc1ff3

File tree

46 files changed

+760
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+760
-648
lines changed

core/src/main/java/dev/compactmods/gander/core/camera/SceneCamera.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.client.Camera;
44

55
import net.minecraft.core.Direction;
6+
import net.minecraft.util.Mth;
67
import net.minecraft.world.phys.Vec3;
78

89
import org.joml.Quaternionf;
@@ -26,7 +27,11 @@ public SceneCamera() {
2627
this.recalcLook();
2728
}
2829

29-
public Vector3f getLookFrom() {
30+
public Vector2f cameraRotation() {
31+
return new Vector2f(cameraRotation);
32+
}
33+
34+
public Vector3f getLookFrom() {
3035
return new Vector3f(lookFrom);
3136
}
3237

@@ -85,21 +90,23 @@ public void lookDirection(Direction direction) {
8590
break;
8691

8792
case DOWN:
88-
this.cameraRotation.set(Math.PI / 2, Math.PI);
93+
this.cameraRotation.set(-Mth.HALF_PI - 0.001, Math.PI);
8994
break;
9095

9196
case NORTH:
92-
this.cameraRotation.set(0, Math.PI);
97+
this.cameraRotation.set(-Math.PI, Math.PI);
9398
break;
9499

95100
case SOUTH:
96-
this.cameraRotation.set(Math.PI / 2, -Math.PI);
101+
this.cameraRotation.set(0, Math.PI);
97102
break;
98103

99104
case WEST:
105+
this.cameraRotation.set(-Mth.PI, Mth.HALF_PI);
100106
break;
101107

102108
case EAST:
109+
this.cameraRotation.set(-Mth.PI, -Mth.HALF_PI);
103110
break;
104111
}
105112

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dev.compactmods.gander.core.math;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.SectionPos;
5+
import net.minecraft.util.Mth;
6+
import net.minecraft.util.RandomSource;
7+
import net.minecraft.world.level.ChunkPos;
8+
import net.minecraft.world.level.Level;
9+
import net.minecraft.world.phys.AABB;
10+
11+
import java.util.Set;
12+
import java.util.function.Consumer;
13+
import java.util.stream.Collectors;
14+
import java.util.stream.Stream;
15+
16+
public class WorldMath {
17+
18+
public static ChunkPos minCornerChunk(AABB aabb) {
19+
var mn = BlockPos.containing(aabb.minX, aabb.minY, aabb.minZ);
20+
return new ChunkPos(mn);
21+
}
22+
23+
public static ChunkPos maxCornerChunk(AABB aabb) {
24+
var mx = BlockPos.containing(aabb.maxX, aabb.maxY, aabb.maxZ);
25+
return new ChunkPos(mx);
26+
}
27+
28+
public static AABB chunkAABB(Level level, ChunkPos chunkPos) {
29+
var minBlock = new BlockPos(chunkPos.getMinBlockX(), level.getMinBuildHeight(), chunkPos.getMinBlockZ());
30+
var maxBlock = new BlockPos(chunkPos.getMaxBlockX(), level.getMaxBuildHeight(), chunkPos.getMaxBlockZ());
31+
return AABB.encapsulatingFullBlocks(minBlock, maxBlock);
32+
}
33+
34+
public static AABB sectionABB(SectionPos sectionPos) {
35+
var minBlock = new BlockPos(sectionPos.minBlockX(), sectionPos.minBlockY(), sectionPos.minBlockZ());
36+
var maxBlock = new BlockPos(sectionPos.maxBlockX(), sectionPos.maxBlockY(), sectionPos.maxBlockZ());
37+
return AABB.encapsulatingFullBlocks(minBlock, maxBlock);
38+
}
39+
40+
public static BlockPos randomPosInAABB(RandomSource random, AABB aabb) {
41+
int rx = random.nextIntBetweenInclusive(Mth.floor(aabb.minX), Mth.floor(aabb.maxX));
42+
int ry = random.nextIntBetweenInclusive(Mth.floor(aabb.minY), Mth.floor(aabb.maxY));
43+
int ra = random.nextIntBetweenInclusive(Mth.floor(aabb.minZ), Mth.floor(aabb.maxZ));
44+
return new BlockPos(rx, ry, ra);
45+
}
46+
47+
public static Stream<ChunkPos> chunkPositions(AABB aabb) {
48+
return ChunkPos.rangeClosed(minCornerChunk(aabb), maxCornerChunk(aabb));
49+
}
50+
51+
public static Stream<SectionPos> sectionPositions(Level level, AABB area) {
52+
final var minChunk = WorldMath.minCornerChunk(area);
53+
final var maxChunk = WorldMath.maxCornerChunk(area);
54+
return ChunkPos.rangeClosed(minChunk, maxChunk)
55+
.mapMulti((ChunkPos cp, Consumer<SectionPos> nums) -> {
56+
for (int y = level.getMinSection(); y <= level.getMaxSection(); ++y)
57+
nums.accept(SectionPos.of(cp, y));
58+
});
59+
}
60+
}

gradle.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@
22
# This is required to provide enough memory for the Minecraft decompilation process.
33
org.gradle.jvmargs = -Xmx3G
44
org.gradle.daemon = false
5-
6-
#read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings
7-
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
8-
neogradle.subsystems.parchment.minecraftVersion=1.21.1
9-
neogradle.subsystems.parchment.mappingsVersion=2024.11.17

levels/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ repositories {
3838
mavenLocal()
3939
}
4040

41+
dependencies {
42+
implementation(project(":core"))
43+
}
44+
4145
tasks.withType<ProcessResources> {
4246
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
4347
}

levels/src/main/java/dev/compactmods/gander/level/VirtualLevel.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import java.util.function.Consumer;
55
import java.util.function.Supplier;
66

7+
import net.minecraft.util.Mth;
8+
import net.minecraft.world.phys.AABB;
79
import net.neoforged.neoforge.client.model.data.ModelData;
810
import net.neoforged.neoforge.client.model.data.ModelDataManager;
911

1012
import org.jetbrains.annotations.NotNull;
1113
import org.jetbrains.annotations.Nullable;
1214

15+
import dev.compactmods.gander.core.math.WorldMath;
1316
import dev.compactmods.gander.level.block.VirtualBlockSystem;
1417
import dev.compactmods.gander.level.chunk.VirtualChunkSource;
1518
import dev.compactmods.gander.level.entity.VirtualEntitySystem;
@@ -46,7 +49,6 @@
4649
import net.minecraft.world.level.dimension.DimensionType;
4750
import net.minecraft.world.level.entity.LevelEntityGetter;
4851
import net.minecraft.world.level.gameevent.GameEvent;
49-
import net.minecraft.world.level.levelgen.structure.BoundingBox;
5052
import net.minecraft.world.level.lighting.LevelLightEngine;
5153
import net.minecraft.world.level.material.Fluid;
5254
import net.minecraft.world.level.material.FluidState;
@@ -66,7 +68,7 @@ public class VirtualLevel extends Level implements WorldGenLevel, TickingLevel {
6668
private final VirtualChunkSource chunkSource;
6769
private final VirtualBlockSystem blocks;
6870
private final Scoreboard scoreboard;
69-
private BoundingBox bounds;
71+
private AABB bounds;
7072
private VirtualEntitySystem entities;
7173
private final Holder<Biome> biome;
7274
private final Consumer<VirtualLevel> onBlockUpdate;
@@ -95,7 +97,7 @@ private VirtualLevel(WritableLevelData pLevelData, ResourceKey<Level> pDimension
9597
this.chunkSource = new VirtualChunkSource(this);
9698
this.blocks = new VirtualBlockSystem(this);
9799
this.scoreboard = new Scoreboard();
98-
this.bounds = BoundingBox.fromCorners(BlockPos.ZERO, BlockPos.ZERO);
100+
this.bounds = AABB.INFINITE;
99101
this.entities = new VirtualEntitySystem();
100102
this.biome = pRegistryAccess.registryOrThrow(Registries.BIOME).getHolderOrThrow(Biomes.PLAINS);
101103
this.modelDataManager = new ModelDataManager(this);
@@ -187,33 +189,30 @@ public void removeBlockEntity(final BlockPos pPos) {
187189
@Nullable
188190
@Override
189191
public BlockEntity getBlockEntity(BlockPos pPos) {
190-
if (!bounds.isInside(pPos))
192+
if (!bounds.contains(Vec3.atCenterOf(pPos)))
191193
return null;
192194

193195
return blocks.blockAndFluidStorage().getBlockEntity(pPos);
194196
}
195197

196198
@Override
197199
public BlockState getBlockState(BlockPos pPos) {
198-
if (!bounds.isInside(pPos))
200+
if (!bounds.contains(Vec3.atCenterOf(pPos)))
199201
return Blocks.AIR.defaultBlockState();
200202

201203
return blocks.blockAndFluidStorage().getBlockState(pPos);
202204
}
203205

204206
@Override
205207
public @NotNull FluidState getFluidState(BlockPos pos) {
206-
if (!bounds.isInside(pos))
208+
if (!bounds.contains(Vec3.atCenterOf(pos)))
207209
return Fluids.EMPTY.defaultFluidState();
208210

209211
return blocks.blockAndFluidStorage().getFluidState(pos);
210212
}
211213

212214
public void animateTick() {
213-
animateBlockTick(new BlockPos(
214-
random.nextIntBetweenInclusive(bounds.minX(), bounds.maxX()),
215-
random.nextIntBetweenInclusive(bounds.minY(), bounds.maxY()),
216-
random.nextIntBetweenInclusive(bounds.minZ(), bounds.maxZ())));
215+
animateBlockTick(WorldMath.randomPosInAABB(random, bounds));
217216
}
218217

219218
@Override
@@ -387,7 +386,7 @@ public ServerLevel getLevel() {
387386
return null;
388387
}
389388

390-
public void setBounds(BoundingBox bounds) {
389+
public void setBounds(AABB bounds) {
391390
this.bounds = bounds;
392391
}
393392

@@ -413,15 +412,15 @@ public void blockUpdated(BlockPos pPos, Block pBlock) {
413412

414413
@Override
415414
public int getMaxBuildHeight() {
416-
return bounds.maxY() + 1;
415+
return Mth.ceil(bounds.maxY) + 1;
417416
}
418417

419418
@Override
420419
public int getMinBuildHeight() {
421-
return bounds.minY();
420+
return Mth.floor(bounds.minY);
422421
}
423422

424-
public BoundingBox getBounds() {
423+
public AABB getBounds() {
425424
return bounds;
426425
}
427426

levels/src/main/java/dev/compactmods/gander/level/block/VirtualBlockAndTintGetter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.compactmods.gander.level.block;
22

3-
import dev.compactmods.gander.level.light.VirtualLightEngine;
43
import net.minecraft.client.Minecraft;
54
import net.minecraft.core.BlockPos;
65
import net.minecraft.core.Direction;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package dev.compactmods.gander.render;
2+
3+
public record RenderBoundaries(int width, int height) {
4+
}

rendering/src/main/java/dev/compactmods/gander/render/RenderTypes.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
1010

1111
import java.util.Map;
12-
import java.util.Set;
1312
import java.util.function.Function;
1413
import java.util.stream.Collectors;
1514

16-
// TODO 1.17: use custom shaders instead of vanilla ones
1715
public class RenderTypes extends RenderStateShard {
1816

1917
public static final Map<RenderLevelStageEvent.Stage, RenderType> GEOMETRY_STAGES
Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,20 @@
11
package dev.compactmods.gander.render.geometry;
22

3-
import com.mojang.blaze3d.vertex.MeshData;
4-
5-
import com.mojang.blaze3d.vertex.VertexBuffer;
6-
import com.mojang.blaze3d.vertex.VertexSorting;
7-
import net.minecraft.client.renderer.RenderType;
8-
9-
import net.minecraft.client.renderer.SectionBufferBuilderPack;
10-
import net.minecraft.world.level.BlockAndTintGetter;
3+
import net.minecraft.core.SectionPos;
114
import net.minecraft.world.level.Level;
12-
import net.minecraft.world.level.levelgen.structure.BoundingBox;
5+
6+
import net.minecraft.world.phys.AABB;
137

148
import org.joml.Vector3f;
159

1610
import java.util.Map;
1711

18-
public final class BakedLevel {
19-
private final Level originalLevel;
20-
private final SectionBufferBuilderPack blockBuilders;
21-
private final SectionBufferBuilderPack fluidBuilders;
22-
private final Map<RenderType, VertexBuffer> blockBuffers;
23-
private final Map<RenderType, VertexBuffer> fluidBuffers;
24-
private final Map<RenderType, MeshData.SortState> blockSortStates;
25-
private final Map<RenderType, MeshData.SortState> fluidSortStates;
26-
private final BoundingBox blockBoundaries;
27-
28-
public BakedLevel(Level originalLevel,
29-
SectionBufferBuilderPack blockBuilders,
30-
SectionBufferBuilderPack fluidBuilders,
31-
Map<RenderType, VertexBuffer> blockBuffers,
32-
Map<RenderType, VertexBuffer> fluidBuffers,
33-
Map<RenderType, MeshData.SortState> blockSortStates,
34-
Map<RenderType, MeshData.SortState> fluidSortStates,
35-
BoundingBox blockBoundaries) {
36-
this.originalLevel = originalLevel;
37-
this.blockBuilders = blockBuilders;
38-
this.fluidBuilders = fluidBuilders;
39-
this.blockBuffers = blockBuffers;
40-
this.fluidBuffers = fluidBuffers;
41-
this.blockSortStates = blockSortStates;
42-
this.fluidSortStates = fluidSortStates;
43-
this.blockBoundaries = blockBoundaries;
44-
}
45-
46-
public void resortTranslucency(Vector3f cameraPosition) {
47-
// FIXME - This is broken somehow, causes a black screen
48-
var vertexSorting = VertexSorting.byDistance(cameraPosition.x, cameraPosition.y, cameraPosition.z);
49-
resortTranslucency(vertexSorting, blockBuilders, blockBuffers, blockSortStates);
50-
resortTranslucency(vertexSorting, fluidBuilders, fluidBuffers, fluidSortStates);
51-
}
52-
53-
private void resortTranslucency(
54-
VertexSorting vertexSorting,
55-
SectionBufferBuilderPack pack,
56-
Map<RenderType, VertexBuffer> buffers,
57-
Map<RenderType, MeshData.SortState> sortStates) {
12+
public record BakedLevel(Level originalLevel,
13+
AABB blockBoundaries,
14+
Map<SectionPos, BakedLevelSection> sections) {
5815

59-
sortStates.forEach((type, state) -> {
60-
var result = state.buildSortedIndexBuffer(pack.buffer(type), vertexSorting);
61-
if (result == null)
62-
return;
63-
64-
var buffer = buffers.get(type);
65-
buffer.uploadIndexBuffer(result);
66-
VertexBuffer.unbind();
67-
});
68-
}
69-
70-
public Level originalLevel() {
71-
return originalLevel;
72-
}
73-
74-
public Map<RenderType, VertexBuffer> blockRenderBuffers() {
75-
return blockBuffers;
76-
}
77-
78-
public Map<RenderType, VertexBuffer> fluidRenderBuffers() {
79-
return fluidBuffers;
80-
}
8116

82-
public BoundingBox blockBoundaries() {
83-
return blockBoundaries;
17+
public void resortTranslucency(Vector3f vector3f) {
18+
sections.values().forEach(s -> s.resortTranslucency(vector3f));
8419
}
8520
}

0 commit comments

Comments
 (0)