Skip to content

Commit

Permalink
[1.20.4] Snapshot ModelDataManager in RenderChunkRegion instead of ex…
Browse files Browse the repository at this point in the history
…posing original ModelDataManager owned by ClientLevel (#433)
  • Loading branch information
XFactHD authored Jan 8, 2024
1 parent 7e140db commit 6f06b00
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
private final BlockStatePredictionHandler blockStatePredictionHandler = new BlockStatePredictionHandler();
private static final Set<Item> MARKER_PARTICLE_ITEMS = Set.of(Items.BARRIER, Items.LIGHT);
+ private final it.unimi.dsi.fastutil.ints.Int2ObjectMap<net.neoforged.neoforge.entity.PartEntity<?>> partEntities = new it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<>();
+ private final net.neoforged.neoforge.client.model.data.ModelDataManager modelDataManager = new net.neoforged.neoforge.client.model.data.ModelDataManager(this);
+ private final net.neoforged.neoforge.client.model.data.ModelDataManager.Active modelDataManager = new net.neoforged.neoforge.client.model.data.ModelDataManager.Active(this);

public void handleBlockChangedAck(int p_233652_) {
this.blockStatePredictionHandler.endPredictionsUpTo(p_233652_, this);
Expand Down Expand Up @@ -114,7 +114,7 @@
+ }
+
+ @Override
+ public net.neoforged.neoforge.client.model.data.ModelDataManager getModelDataManager() {
+ public net.neoforged.neoforge.client.model.data.ModelDataManager.Active getModelDataManager() {
+ return modelDataManager;
+ }
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
posestack$pose1.normal(),
1.0F
);
+ net.neoforged.neoforge.client.model.data.ModelData modelData = level.getModelDataManager().getAt(blockpos2);
+ net.neoforged.neoforge.client.model.data.ModelData modelData = level.getModelDataManager().getAtOrEmpty(blockpos2);
this.minecraft
.getBlockRenderer()
- .renderBreakingTexture(this.level.getBlockState(blockpos2), blockpos2, this.level, p_109600_, vertexconsumer1);
+ .renderBreakingTexture(this.level.getBlockState(blockpos2), blockpos2, this.level, p_109600_, vertexconsumer1, modelData == null ? net.neoforged.neoforge.client.model.data.ModelData.EMPTY : modelData);
+ .renderBreakingTexture(this.level.getBlockState(blockpos2), blockpos2, this.level, p_109600_, vertexconsumer1, modelData);
p_109600_.popPose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
+ }
+
+ public TextureAtlasSprite getTexture(BlockState p_110883_, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) {
+ var data = level.getModelDataManager().getAt(pos);
+ var data = level.getModelDataManager().getAtOrEmpty(pos);
+ BakedModel model = this.getBlockModel(p_110883_);
+ return model.getParticleIcon(model.getModelData(level, pos, p_110883_, data == null ? net.neoforged.neoforge.client.model.data.ModelData.EMPTY : data));
+ return model.getParticleIcon(model.getModelData(level, pos, p_110883_, data));
}

public BakedModel getBlockModel(BlockState p_110894_) {
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
--- a/net/minecraft/client/renderer/chunk/RenderChunkRegion.java
+++ b/net/minecraft/client/renderer/chunk/RenderChunkRegion.java
@@ -74,4 +_,14 @@
@@ -20,12 +_,19 @@
private final int centerZ;
protected final RenderChunk[][] chunks;
protected final Level level;
+ @Nullable
+ private final net.neoforged.neoforge.client.model.data.ModelDataManager.Snapshot modelDataManager;

+ @Deprecated
RenderChunkRegion(Level p_200456_, int p_200457_, int p_200458_, RenderChunk[][] p_200459_) {
+ this(p_200456_, p_200457_, p_200458_, p_200459_, null);
+ }
+ RenderChunkRegion(Level p_200456_, int p_200457_, int p_200458_, RenderChunk[][] p_200459_, @Nullable net.neoforged.neoforge.client.model.data.ModelDataManager.Snapshot modelDataManager) {
this.level = p_200456_;
this.centerX = p_200457_;
this.centerZ = p_200458_;
this.chunks = p_200459_;
+ this.modelDataManager = modelDataManager;
}

@Override
@@ -73,5 +_,16 @@
@Override
public int getHeight() {
return this.level.getHeight();
}
+ }
+
+ @Override
+ public float getShade(float normalX, float normalY, float normalZ, boolean shade) {
+ return this.level.getShade(normalX, normalY, normalZ, shade);
+ }
+
+ @Override
+ public net.neoforged.neoforge.client.model.data.ModelDataManager getModelDataManager() {
+ return level.getModelDataManager();
+ }
+ @Nullable
+ public net.neoforged.neoforge.client.model.data.ModelDataManager.Snapshot getModelDataManager() {
+ return modelDataManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/net/minecraft/client/renderer/chunk/RenderRegionCache.java
+++ b/net/minecraft/client/renderer/chunk/RenderRegionCache.java
@@ -44,7 +_,10 @@
}
}

- return new RenderChunkRegion(p_200466_, i, j, arenderchunk);
+ int sectionMinY = SectionPos.blockToSectionCoord(p_200467_.getY() - p_200469_);
+ int sectionMaxY = SectionPos.blockToSectionCoord(p_200468_.getY() + p_200469_);
+ var modelDataManager = p_200466_.getModelDataManager().snapshotSectionRegion(i, sectionMinY, j, k, sectionMaxY, l);
+ return new RenderChunkRegion(p_200466_, i, j, arenderchunk, modelDataManager);
}
}

Original file line number Diff line number Diff line change
@@ -1,88 +1,27 @@
--- a/net/minecraft/client/renderer/chunk/SectionRenderDispatcher.java
+++ b/net/minecraft/client/renderer/chunk/SectionRenderDispatcher.java
@@ -76,7 +_,7 @@
final LevelRenderer renderer;
private Vec3 camera = Vec3.ZERO;

- public SectionRenderDispatcher(ClientLevel p_295274_, LevelRenderer p_295323_, Executor p_295234_, RenderBuffers p_307511_) {
+ public SectionRenderDispatcher(ClientLevel p_295274_, LevelRenderer p_295323_, Executor p_295234_, RenderBuffers p_307511_) { // TODO 1.20.3 PORTING: reevaluate the patch (where does it go now?)
this.level = p_295274_;
this.renderer = p_295323_;
this.fixedBuffers = p_307511_.fixedBufferPack();
@@ -404,7 +_,7 @@
return false;
} else {
this.lastResortTransparencyTask = new SectionRenderDispatcher.RenderSection.ResortTransparencyTask(
- this.getDistToPlayerSqr(), sectionrenderdispatcher$compiledsection
+ SectionPos.of(getOrigin()), this.getDistToPlayerSqr(), sectionrenderdispatcher$compiledsection
);
p_294363_.schedule(this.lastResortTransparencyTask);
return true;
@@ -440,7 +_,7 @@
}

this.lastRebuildTask = new SectionRenderDispatcher.RenderSection.RebuildTask(
- this.getDistToPlayerSqr(), renderchunkregion, !flag1 || this.initialCompilationCancelCount.get() > 2
+ SectionPos.of(getOrigin()), this.getDistToPlayerSqr(), renderchunkregion, !flag1 || this.initialCompilationCancelCount.get() > 2
);
return this.lastRebuildTask;
}
@@ -481,10 +_,22 @@
protected final double distAtCreation;
protected final AtomicBoolean isCancelled = new AtomicBoolean(false);
protected final boolean isHighPriority;
+ protected final java.util.Map<net.minecraft.core.BlockPos, net.neoforged.neoforge.client.model.data.ModelData> modelData;

+ @Deprecated
public CompileTask(double p_294428_, boolean p_295051_) {
+ this(null, p_294428_, p_295051_);
+ }
+
+ public CompileTask(@Nullable SectionPos sectionPos, double p_294428_, boolean p_295051_) {
this.distAtCreation = p_294428_;
this.isHighPriority = p_295051_;
+
+ if (sectionPos == null || Minecraft.getInstance().level == null || Minecraft.getInstance().level.getModelDataManager() == null) {
+ this.modelData = java.util.Collections.emptyMap();
+ } else {
+ this.modelData = Minecraft.getInstance().level.getModelDataManager().getAt(sectionPos);
+ }
}

public abstract CompletableFuture<SectionRenderDispatcher.SectionTaskResult> doTask(SectionBufferBuilderPack p_294622_);
@@ -496,6 +_,10 @@
public int compareTo(SectionRenderDispatcher.RenderSection.CompileTask p_296186_) {
return Doubles.compare(this.distAtCreation, p_296186_.distAtCreation);
}
+
+ public net.neoforged.neoforge.client.model.data.ModelData getModelData(BlockPos pos) {
+ return modelData.getOrDefault(pos, net.neoforged.neoforge.client.model.data.ModelData.EMPTY);
+ }
}

@OnlyIn(Dist.CLIENT)
@@ -503,8 +_,13 @@
@@ -502,10 +_,13 @@
class RebuildTask extends SectionRenderDispatcher.RenderSection.CompileTask {
@Nullable
protected RenderChunkRegion region;
+ private final net.neoforged.neoforge.client.model.data.ModelDataManager.Snapshot modelData;

+ @Deprecated
public RebuildTask(double p_294400_, @Nullable RenderChunkRegion p_294382_, boolean p_295207_) {
- super(p_294400_, p_295207_);
+ this(null, p_294400_, p_294382_, p_295207_);
+ }
+
+ public RebuildTask(@Nullable SectionPos pos, double p_294400_, @Nullable RenderChunkRegion p_294382_, boolean p_295207_) {
+ super(pos, p_294400_, p_295207_);
super(p_294400_, p_295207_);
this.region = p_294382_;
+ var manager = p_294382_ != null ? p_294382_.getModelDataManager() : null;
+ this.modelData = manager != null ? manager : net.neoforged.neoforge.client.model.data.ModelDataManager.Snapshot.EMPTY;
}

@@ -609,7 +_,10 @@
@Override
@@ -609,7 +_,11 @@
}

if (blockstate.getRenderShape() != RenderShape.INVISIBLE) {
- RenderType rendertype2 = ItemBlockRenderTypes.getChunkRenderType(blockstate);
+ var model = blockrenderdispatcher.getBlockModel(blockstate);
+ var modelData = model.getModelData(renderchunkregion, blockpos2, blockstate, getModelData(blockpos2));
+ var modelData = this.modelData.getAtOrEmpty(blockpos2);
+ modelData = model.getModelData(renderchunkregion, blockpos2, blockstate, modelData);
+ randomsource.setSeed(blockstate.getSeed(blockpos2));
+ for (RenderType rendertype2 : model.getRenderTypes(blockstate, randomsource, modelData)) {
BufferBuilder bufferbuilder2 = p_294319_.builder(rendertype2);
Expand Down Expand Up @@ -111,18 +50,3 @@
}
}
}
@@ -681,8 +_,13 @@
class ResortTransparencyTask extends SectionRenderDispatcher.RenderSection.CompileTask {
private final SectionRenderDispatcher.CompiledSection compiledSection;

+ @Deprecated
public ResortTransparencyTask(double p_294102_, SectionRenderDispatcher.CompiledSection p_294601_) {
- super(p_294102_, true);
+ this(null, p_294102_, p_294601_);
+ }
+
+ public ResortTransparencyTask(@Nullable SectionPos pos, double p_294102_, SectionRenderDispatcher.CompiledSection p_294601_) {
+ super(pos, p_294102_, true);
this.compiledSection = p_294601_;
}

8 changes: 7 additions & 1 deletion patches/net/minecraft/world/level/Level.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
this.neighborChanged(blockstate, blockpos, p_46719_, p_46718_, false);
}
}
@@ -1070,6 +_,18 @@
@@ -1070,6 +_,24 @@
@Override
public BiomeManager getBiomeManager() {
return this.biomeManager;
Expand All @@ -235,6 +235,12 @@
+ if (value > maxEntityRadius)
+ maxEntityRadius = value;
+ return maxEntityRadius;
+ }
+
+ @Override
+ @Nullable
+ public net.neoforged.neoforge.client.model.data.ModelDataManager.Active getModelDataManager() {
+ return null;
}

public final boolean isDebug() {
Loading

0 comments on commit 6f06b00

Please sign in to comment.