From f8616ae3c1b74573995b616df84265c5fb79fb8b Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 23 Jun 2023 22:44:28 -0700 Subject: [PATCH 1/4] Preliminary Render Data v2 --- .../build.gradle | 7 ++ .../data/v1/RenderAttachedBlockView.java | 46 ++++++++++++ .../data/v1/RenderAttachmentBlockEntity.java | 41 ++++++++++ .../rendering/data/BlockEntityMixin.java | 43 +++++++++++ .../mixin/rendering/data}/WorldViewMixin.java | 7 +- .../icon.png | Bin ...c-rendering-data-attachment-v1.mixins.json | 0 .../src/main/resources/fabric.mod.json | 14 ++-- .../fabric/api/block/v1/FabricBlock.java | 10 +-- fabric-render-data-v2/build.gradle | 8 ++ .../client/RenderDataMapConsumer.java | 8 +- .../ChunkRendererRegionBuilderMixin.java | 59 ++++++++------- .../client/ChunkRendererRegionMixin.java | 26 ++++--- .../fabric-render-data-v2.client.mixins.json | 2 +- .../renderdata/v2/RenderDataBlockEntity.java | 61 +++++++++++++++ .../renderdata/v2/RenderDataBlockView.java | 60 +++++++++++++++ .../mixin/renderdata}/BlockEntityMixin.java | 10 +-- .../renderdata/BlockRenderViewMixin.java | 27 +++++++ .../assets/fabric-render-data-v2/icon.png | Bin 0 -> 1579 bytes .../fabric-render-data-v2.accesswidener | 0 .../fabric-render-data-v2.mixins.json | 12 +++ .../src/main/resources/fabric.mod.json | 38 ++++++++++ fabric-renderer-api-v1/build.gradle | 2 +- .../test/renderer/simple/FrameBlock.java | 6 +- .../renderer/simple/FrameBlockEntity.java | 6 +- .../simple/client/FrameBakedModel.java | 15 ++-- .../build.gradle | 8 -- .../data/v1/RenderAttachedBlockView.java | 70 ------------------ .../data/v1/RenderAttachmentBlockEntity.java | 46 ------------ gradle.properties | 1 + settings.gradle | 4 +- 31 files changed, 426 insertions(+), 211 deletions(-) create mode 100644 deprecated/fabric-rendering-data-attachment-v1/build.gradle create mode 100644 deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java create mode 100644 deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java create mode 100644 deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/BlockEntityMixin.java rename {fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment => deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data}/WorldViewMixin.java (82%) rename {fabric-rendering-data-attachment-v1 => deprecated/fabric-rendering-data-attachment-v1}/src/main/resources/assets/fabric-rendering-data-attachment-v1/icon.png (100%) rename {fabric-rendering-data-attachment-v1 => deprecated/fabric-rendering-data-attachment-v1}/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json (100%) rename {fabric-rendering-data-attachment-v1 => deprecated/fabric-rendering-data-attachment-v1}/src/main/resources/fabric.mod.json (68%) create mode 100644 fabric-render-data-v2/build.gradle rename fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/impl/rendering/data/attachment/RenderDataObjectConsumer.java => fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java (71%) rename {fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment => fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata}/client/ChunkRendererRegionBuilderMixin.java (63%) rename {fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment => fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata}/client/ChunkRendererRegionMixin.java (50%) rename fabric-rendering-data-attachment-v1/src/client/resources/fabric-rendering-data-attachment-v1.client.mixins.json => fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json (72%) create mode 100644 fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java create mode 100644 fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java rename {fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment => fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata}/BlockEntityMixin.java (72%) create mode 100644 fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java create mode 100644 fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2/icon.png rename fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.accesswidener => fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener (100%) create mode 100644 fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json create mode 100644 fabric-render-data-v2/src/main/resources/fabric.mod.json delete mode 100644 fabric-rendering-data-attachment-v1/build.gradle delete mode 100644 fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java delete mode 100644 fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java diff --git a/deprecated/fabric-rendering-data-attachment-v1/build.gradle b/deprecated/fabric-rendering-data-attachment-v1/build.gradle new file mode 100644 index 0000000000..e535ab02ba --- /dev/null +++ b/deprecated/fabric-rendering-data-attachment-v1/build.gradle @@ -0,0 +1,7 @@ +archivesBaseName = "fabric-rendering-data-attachment-v1" +version = getSubprojectVersion(project) + +moduleDependencies(project, [ + 'fabric-api-base', + 'fabric-render-data-v2' +]) diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java new file mode 100644 index 0000000000..a18355e329 --- /dev/null +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.rendering.data.v1; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; +import net.minecraft.world.WorldView; + +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockView; + +/** + * This interface is guaranteed to be implemented on all {@link WorldView} instances. + * It is likely to be implemented on a {@link BlockRenderView} instance, but this is + * not guaranteed. + * + * @deprecated Use {@link RenderDataBlockView} instead. + */ +@Deprecated +public interface RenderAttachedBlockView extends BlockRenderView { + /** + * This method will call {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)} by default. + * + * @deprecated Use {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)} instead. + */ + @Deprecated + @Nullable + default Object getBlockEntityRenderAttachment(BlockPos pos) { + return getBlockEntityRenderData(pos); + } +} diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java new file mode 100644 index 0000000000..0b7c52b825 --- /dev/null +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.rendering.data.v1; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.block.entity.BlockEntity; + +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockEntity; + +/** + * This interface is guaranteed to be implemented on all {@link BlockEntity} instances. + * + * @deprecated Use {@link RenderDataBlockEntity} instead. + */ +@Deprecated +@FunctionalInterface +public interface RenderAttachmentBlockEntity { + /** + * This method will be automatically called if {@link RenderDataBlockEntity#getRenderData()} is not overridden. + * + * @deprecated Use {@link RenderDataBlockEntity#getRenderData()} instead. + */ + @Deprecated + @Nullable + Object getRenderAttachmentData(); +} diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/BlockEntityMixin.java b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/BlockEntityMixin.java new file mode 100644 index 0000000000..befa65abbf --- /dev/null +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/BlockEntityMixin.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.rendering.data; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.block.entity.BlockEntity; + +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockEntity; +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; + +@Mixin(BlockEntity.class) +public class BlockEntityMixin implements RenderAttachmentBlockEntity, RenderDataBlockEntity { + @Override + @Nullable + public Object getRenderAttachmentData() { + return null; + } + + /** + * Instead of returning null by default in v2, proxy to v1 method instead. + */ + @Override + @Nullable + public Object getRenderData() { + return getRenderAttachmentData(); + } +} diff --git a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/WorldViewMixin.java b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/WorldViewMixin.java similarity index 82% rename from fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/WorldViewMixin.java rename to deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/WorldViewMixin.java index 317cc7df8a..bbd04fcfdc 100644 --- a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/WorldViewMixin.java +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/WorldViewMixin.java @@ -14,15 +14,14 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.rendering.data.attachment; +package net.fabricmc.fabric.mixin.rendering.data; import org.spongepowered.asm.mixin.Mixin; -import net.minecraft.world.BlockRenderView; import net.minecraft.world.WorldView; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; -/** Make {@link BlockRenderView} implement {@link RenderAttachedBlockView}. */ @Mixin(WorldView.class) -public interface WorldViewMixin extends RenderAttachedBlockView { } +public interface WorldViewMixin extends RenderAttachedBlockView { +} diff --git a/fabric-rendering-data-attachment-v1/src/main/resources/assets/fabric-rendering-data-attachment-v1/icon.png b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/assets/fabric-rendering-data-attachment-v1/icon.png similarity index 100% rename from fabric-rendering-data-attachment-v1/src/main/resources/assets/fabric-rendering-data-attachment-v1/icon.png rename to deprecated/fabric-rendering-data-attachment-v1/src/main/resources/assets/fabric-rendering-data-attachment-v1/icon.png diff --git a/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json similarity index 100% rename from fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json rename to deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json diff --git a/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json similarity index 68% rename from fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json rename to deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json index 03fcd46275..e51711d9b9 100644 --- a/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json @@ -17,18 +17,14 @@ ], "depends": { "fabricloader": ">=0.4.0", - "fabric-api-base": "*" + "fabric-api-base": "*", + "fabric-render-data-v2": "*" }, "description": "Thread-safe hooks for block entity data use during terrain rendering.", "mixins": [ - "fabric-rendering-data-attachment-v1.mixins.json", - { - "config": "fabric-rendering-data-attachment-v1.client.mixins.json", - "environment": "client" - } + "fabric-rendering-data-attachment-v1.mixins.json" ], "custom": { - "fabric-api:module-lifecycle": "stable" - }, - "accessWidener": "fabric-rendering-data-attachment-v1.accesswidener" + "fabric-api:module-lifecycle": "deprecated" + } } diff --git a/fabric-block-api-v1/src/main/java/net/fabricmc/fabric/api/block/v1/FabricBlock.java b/fabric-block-api-v1/src/main/java/net/fabricmc/fabric/api/block/v1/FabricBlock.java index 5240b08f44..6304c434a5 100644 --- a/fabric-block-api-v1/src/main/java/net/fabricmc/fabric/api/block/v1/FabricBlock.java +++ b/fabric-block-api-v1/src/main/java/net/fabricmc/fabric/api/block/v1/FabricBlock.java @@ -56,11 +56,12 @@ public interface FabricBlock { *

This can be called on the server, where block entity data can be safely accessed, * and on the client, possibly in a meshing thread, where block entity data is not safe to access! * Here is an example of how data from a block entity can be handled safely. - * The block entity needs to implement {@code RenderAttachmentBlockEntity} for this to work. + * The block entity should override {@code RenderDataBlockEntity#getBlockEntityRenderData} to return + * the necessary data. Refer to the documentation of {@code RenderDataBlockEntity} for more information. *

{@code @Override
 	 * public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) {
 	 *     if (renderView instanceof ServerWorld serverWorld) {
-	 *         // Server side, ok to use block entity directly!
+	 *         // Server side; ok to use block entity directly!
 	 *         BlockEntity blockEntity = serverWorld.getBlockEntity(pos);
 	 *
 	 *         if (blockEntity instanceof ...) {
@@ -68,9 +69,8 @@ public interface FabricBlock {
 	 *             return ...;
 	 *         }
 	 *     } else {
-	 *         // Client side, need to use the render attachment!
-	 *         RenderAttachedBlockView attachmentView = (RenderAttachedBlockView) renderView;
-	 *         Object data = attachmentView.getBlockEntityRenderAttachment(pos);
+	 *         // Client side; need to use the block entity render data!
+	 *         Object data = renderView.getBlockEntityRenderData(pos);
 	 *
 	 *         // Check if data is not null and of the correct type, and use that to determine the appearance
 	 *         if (data instanceof ...) {
diff --git a/fabric-render-data-v2/build.gradle b/fabric-render-data-v2/build.gradle
new file mode 100644
index 0000000000..1a43486d1e
--- /dev/null
+++ b/fabric-render-data-v2/build.gradle
@@ -0,0 +1,8 @@
+archivesBaseName = "fabric-render-data-v2"
+version = getSubprojectVersion(project)
+
+moduleDependencies(project, ['fabric-api-base'])
+
+loom {
+	accessWidenerPath = file("src/main/resources/fabric-render-data-v2.accesswidener")
+}
diff --git a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/impl/rendering/data/attachment/RenderDataObjectConsumer.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java
similarity index 71%
rename from fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/impl/rendering/data/attachment/RenderDataObjectConsumer.java
rename to fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java
index 32c50114a0..5ea85d450e 100644
--- a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/impl/rendering/data/attachment/RenderDataObjectConsumer.java
+++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java
@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-package net.fabricmc.fabric.impl.rendering.data.attachment;
+package net.fabricmc.fabric.impl.renderdata.client;
 
-import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
 
-public interface RenderDataObjectConsumer {
-	void fabric_acceptRenderDataObjects(Long2ObjectOpenHashMap renderDataObjects);
+public interface RenderDataMapConsumer {
+	void fabric$acceptRenderDataMap(Long2ObjectMap renderDataMap);
 }
diff --git a/fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionBuilderMixin.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java
similarity index 63%
rename from fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionBuilderMixin.java
rename to fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java
index eb759c7898..0e4fc767ac 100644
--- a/fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionBuilderMixin.java
+++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java
@@ -14,52 +14,58 @@
  * limitations under the License.
  */
 
-package net.fabricmc.fabric.mixin.rendering.data.attachment.client;
+package net.fabricmc.fabric.mixin.renderdata.client;
 
 import java.util.ConcurrentModificationException;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
-import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
 import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
 
 import net.minecraft.block.entity.BlockEntity;
-import net.minecraft.client.render.chunk.ChunkRendererRegionBuilder;
 import net.minecraft.client.render.chunk.ChunkRendererRegion;
+import net.minecraft.client.render.chunk.ChunkRendererRegionBuilder;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.World;
 import net.minecraft.world.chunk.WorldChunk;
 
-import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
-import net.fabricmc.fabric.impl.rendering.data.attachment.RenderDataObjectConsumer;
+import net.fabricmc.fabric.impl.renderdata.client.RenderDataMapConsumer;
 
 @Mixin(ChunkRendererRegionBuilder.class)
 public abstract class ChunkRendererRegionBuilderMixin {
 	private static final AtomicInteger ERROR_COUNTER = new AtomicInteger();
 	private static final Logger LOGGER = LoggerFactory.getLogger(ChunkRendererRegionBuilderMixin.class);
 
-	@Inject(at = @At("RETURN"), method = "build", locals = LocalCapture.CAPTURE_FAILHARD)
-	private void create(World world, BlockPos startPos, BlockPos endPos, int chunkRadius, CallbackInfoReturnable info, int i, int j, int k, int l, ChunkRendererRegionBuilder.ClientChunk[][] chunkData) {
+	@Inject(method = "build(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;I)Lnet/minecraft/client/render/chunk/ChunkRendererRegion;", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
+	private void fabric$createDataMap(World world, BlockPos startPos, BlockPos endPos, int offset, CallbackInfoReturnable cir, int startX, int startZ, int endX, int endZ, ChunkRendererRegionBuilder.ClientChunk[][] chunksXZ) {
+		ChunkRendererRegion rendererRegion = cir.getReturnValue();
+
+		if (rendererRegion == null) {
+			return;
+		}
+
 		// instantiated lazily - avoids allocation for chunks without any data objects - which is most of them!
 		Long2ObjectOpenHashMap map = null;
 
-		for (ChunkRendererRegionBuilder.ClientChunk[] chunkDataOuter : chunkData) {
-			for (ChunkRendererRegionBuilder.ClientChunk data : chunkDataOuter) {
+		for (ChunkRendererRegionBuilder.ClientChunk[] chunksZ : chunksXZ) {
+			for (ChunkRendererRegionBuilder.ClientChunk chunk : chunksZ) {
 				// Hash maps in chunks should generally not be modified outside of client thread
 				// but does happen in practice, due to mods or inconsistent vanilla behaviors, causing
-				// CMEs when we iterate the map.  (Vanilla does not iterate these maps when it builds
+				// CMEs when we iterate the map. (Vanilla does not iterate these maps when it builds
 				// the chunk cache and does not suffer from this problem.)
 				//
-				// We handle this simply by retrying until it works.  Ugly but effective.
-				for (;;) {
+				// We handle this simply by retrying until it works. Ugly but effective.
+				while (true) {
 					try {
-						map = mapChunk(data.getChunk(), startPos, endPos, map);
+						map = fabric$mapChunk(chunk.getChunk(), startPos, endPos, map);
 						break;
 					} catch (ConcurrentModificationException e) {
 						final int count = ERROR_COUNTER.incrementAndGet();
@@ -76,35 +82,34 @@ private void create(World world, BlockPos startPos, BlockPos endPos, int chunkRa
 			}
 		}
 
-		ChunkRendererRegion rendererRegion = info.getReturnValue();
-
-		if (map != null && rendererRegion != null) {
-			((RenderDataObjectConsumer) rendererRegion).fabric_acceptRenderDataObjects(map);
+		if (map != null) {
+			((RenderDataMapConsumer) rendererRegion).fabric$acceptRenderDataMap(map);
 		}
 	}
 
-	private static Long2ObjectOpenHashMap mapChunk(WorldChunk chunk, BlockPos posFrom, BlockPos posTo, Long2ObjectOpenHashMap map) {
+	@Unique
+	private static Long2ObjectOpenHashMap fabric$mapChunk(WorldChunk chunk, BlockPos posFrom, BlockPos posTo, Long2ObjectOpenHashMap map) {
 		final int xMin = posFrom.getX();
 		final int xMax = posTo.getX();
-		final int zMin = posFrom.getZ();
-		final int zMax = posTo.getZ();
 		final int yMin = posFrom.getY();
 		final int yMax = posTo.getY();
+		final int zMin = posFrom.getZ();
+		final int zMax = posTo.getZ();
 
 		for (Map.Entry entry : chunk.getBlockEntities().entrySet()) {
-			final BlockPos entPos = entry.getKey();
+			final BlockPos pos = entry.getKey();
 
-			if (entPos.getX() >= xMin && entPos.getX() <= xMax
-					&& entPos.getY() >= yMin && entPos.getY() <= yMax
-					&& entPos.getZ() >= zMin && entPos.getZ() <= zMax) {
-				final Object o = ((RenderAttachmentBlockEntity) entry.getValue()).getRenderAttachmentData();
+			if (pos.getX() >= xMin && pos.getX() <= xMax
+					&& pos.getY() >= yMin && pos.getY() <= yMax
+					&& pos.getZ() >= zMin && pos.getZ() <= zMax) {
+				final Object data = entry.getValue().getRenderData();
 
-				if (o != null) {
+				if (data != null) {
 					if (map == null) {
 						map = new Long2ObjectOpenHashMap<>();
 					}
 
-					map.put(entPos.asLong(), o);
+					map.put(pos.asLong(), data);
 				}
 			}
 		}
diff --git a/fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionMixin.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java
similarity index 50%
rename from fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionMixin.java
rename to fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java
index 71a1b49864..5cca7f7563 100644
--- a/fabric-rendering-data-attachment-v1/src/client/java/net/fabricmc/fabric/mixin/rendering/data/attachment/client/ChunkRendererRegionMixin.java
+++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java
@@ -14,29 +14,33 @@
  * limitations under the License.
  */
 
-package net.fabricmc.fabric.mixin.rendering.data.attachment.client;
+package net.fabricmc.fabric.mixin.renderdata.client;
 
-import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
 
 import net.minecraft.client.render.chunk.ChunkRendererRegion;
 import net.minecraft.util.math.BlockPos;
+import net.minecraft.world.BlockRenderView;
 
-import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
-import net.fabricmc.fabric.impl.rendering.data.attachment.RenderDataObjectConsumer;
+import net.fabricmc.fabric.impl.renderdata.client.RenderDataMapConsumer;
 
 @Mixin(ChunkRendererRegion.class)
-public abstract class ChunkRendererRegionMixin implements RenderAttachedBlockView, RenderDataObjectConsumer {
-	private Long2ObjectOpenHashMap fabric_renderDataObjects;
+public abstract class ChunkRendererRegionMixin implements BlockRenderView, RenderDataMapConsumer {
+	@Unique
+	private Long2ObjectMap fabric$renderDataMap;
 
 	@Override
-	public Object getBlockEntityRenderAttachment(BlockPos pos) {
-		return fabric_renderDataObjects == null ? null : fabric_renderDataObjects.get(pos.asLong());
+	public Object getBlockEntityRenderData(BlockPos pos) {
+		return fabric$renderDataMap == null ? null : fabric$renderDataMap.get(pos.asLong());
 	}
 
-	// Called in MixinChunkRendererRegionBuilder
+	/**
+	 * Called in {@link ChunkRendererRegionBuilderMixin}.
+	 */
 	@Override
-	public void fabric_acceptRenderDataObjects(Long2ObjectOpenHashMap renderDataObjects) {
-		this.fabric_renderDataObjects = renderDataObjects;
+	public void fabric$acceptRenderDataMap(Long2ObjectMap renderDataMap) {
+		this.fabric$renderDataMap = renderDataMap;
 	}
 }
diff --git a/fabric-rendering-data-attachment-v1/src/client/resources/fabric-rendering-data-attachment-v1.client.mixins.json b/fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json
similarity index 72%
rename from fabric-rendering-data-attachment-v1/src/client/resources/fabric-rendering-data-attachment-v1.client.mixins.json
rename to fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json
index 1acdfb76b2..cda8ad1dd0 100644
--- a/fabric-rendering-data-attachment-v1/src/client/resources/fabric-rendering-data-attachment-v1.client.mixins.json
+++ b/fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json
@@ -1,6 +1,6 @@
 {
   "required": true,
-  "package": "net.fabricmc.fabric.mixin.rendering.data.attachment.client",
+  "package": "net.fabricmc.fabric.mixin.renderdata.client",
   "compatibilityLevel": "JAVA_16",
   "client": [
     "ChunkRendererRegionMixin",
diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java
new file mode 100644
index 0000000000..575a2db5f5
--- /dev/null
+++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, 2017, 2018, 2019 FabricMC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.fabricmc.fabric.api.renderdata.v2;
+
+import org.jetbrains.annotations.Nullable;
+
+import net.minecraft.block.entity.BlockEntity;
+import net.minecraft.util.math.BlockPos;
+
+/**
+ * Extensions that allow {@link BlockEntity} subclasses to provide render data.
+ *
+ * 

Block entity render data is arbitrary data that is safe to access and use in a client-side + * multithreaded environment, such as chunk building. This includes, but is not limited to, + * access and use from inside models ({@code FabricBakedModel#emitBlockQuads}), block color + * providers ({@code BlockColorProvider#getColor}), and block appearance computation + * ({@code FabricBlock#getAppearance}). + * + *

Implementation Tips + * + *

The simplest form of render data is a value or object that is immutable. If only one such value + * must serve as render data, then it can be returned directly. An example of this would be returning + * an {@code Integer} that represents some internal state of a block entity. If more than one value + * must be used as render data, it can be packaged into an object that cannot be modified externally, + * such as a record. It is also possible to make render data a mutable object, but it must be ensured + * that changes to the internal state of this object are atomic and safe. + * + *

Note: This interface is automatically implemented on all {@link BlockEntity} instances via Mixin and interface injection. + * + * @see RenderDataBlockView + */ +public interface RenderDataBlockEntity { + /** + * Gets the render data provided by this block entity. The returned object must be safe to + * use in a multithreaded environment. + * + *

Note: This method should not be called directly, unless the result is used to implement + * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)}. Otherwise, use + * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)} to access render data instead. + * + * @return the render data + */ + @Nullable + default Object getRenderData() { + return null; + } +} diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java new file mode 100644 index 0000000000..71ce858264 --- /dev/null +++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.renderdata.v2; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; + +/** + * Extensions that allow {@link BlockRenderView} subclasses to provide access to block entity render + * data in a thread-safe and consistent way. + * + *

Thread-safety and consistency are especially important in the main use case of this module, + * which is chunk building. In this context, {@link BlockRenderView#getBlockEntity(BlockPos)} should + * still work as expected, but this method should not be used because accessing a {@link BlockEntity} + * directly to get data may not be thread-safe or consistent. It may not be thread-safe since it may + * lead to non-atomic modification of the internal state of the {@link BlockEntity} instance. It may + * not be consistent since the internal state of the {@link BlockEntity} instance is not guaranteed + * to remain the same during chunk building, unlike other data of the {@link BlockRenderView}, such + * as block states. However, accessing and using render data through + * {@link #getBlockEntityRenderData(BlockPos)} is guaranteed to be thread-safe and consistent. + * + *

Note: This interface is automatically implemented on all {@link BlockRenderView} instances via Mixin and interface injection. + * + * @see RenderDataBlockEntity + */ +public interface RenderDataBlockView { + /** + * Retrieves block entity render data for a given block position. Always use this method + * instead of {@link RenderDataBlockEntity#getRenderData()} to ensure thread safety and + * data consistency. + * + *

Callers of this method should always check the returned object's class (for example, + * using {@code instanceof}) before casting. This prevents unexpected class cast exceptions. + * + * @param pos position of the block entity + * @return the render data provided by the block entity, or null if there is no block entity at this position + */ + @Nullable + default Object getBlockEntityRenderData(BlockPos pos) { + BlockEntity blockEntity = ((BlockRenderView) this).getBlockEntity(pos); + return blockEntity == null ? null : blockEntity.getRenderData(); + } +} diff --git a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/BlockEntityMixin.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java similarity index 72% rename from fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/BlockEntityMixin.java rename to fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java index e1c8f7395e..90e444f7dd 100644 --- a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/mixin/rendering/data/attachment/BlockEntityMixin.java +++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java @@ -14,18 +14,14 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.rendering.data.attachment; +package net.fabricmc.fabric.mixin.renderdata; import org.spongepowered.asm.mixin.Mixin; import net.minecraft.block.entity.BlockEntity; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockEntity; @Mixin(BlockEntity.class) -public class BlockEntityMixin implements RenderAttachmentBlockEntity { - @Override - public Object getRenderAttachmentData() { - return null; - } +public abstract class BlockEntityMixin implements RenderDataBlockEntity { } diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java new file mode 100644 index 0000000000..a65eabb629 --- /dev/null +++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.renderdata; + +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.world.BlockRenderView; + +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockView; + +@Mixin(BlockRenderView.class) +public interface BlockRenderViewMixin extends RenderDataBlockView { +} diff --git a/fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2/icon.png b/fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2931efbf610873c0084debb8690902b0103d27fe GIT binary patch literal 1579 zcmbVMTWB0r7@iGm)TAXsYw<=rnU=;v=W=GRbL=!tc4Brl6GO7t2vVJ$IlDV#XU;e? z+r2ymsZdMQqAyaFLLUo;RumtE8Z@?uf_*4nP^4;o6fOFoSkN+o1$K?f2nE9_*b5G-l)AV)k5Qhb^- zU{V4ZnTKgnmXdpcB*Kg!W(1hvM2N&RO30x1u~eI9meGQGe@_?PDQq%q1CiV$8~M7 z?MQ_mOdqCh^a65Sv|ntwSXjV5se1;VK1|Kr8G7TQoQL&*ctt{L{fClG}xPK5k^yK3%T69N6J=>3jBqc zDNvZsrJ-yOXI^^mWf1cmY^XST)CVzIGjvEPENowmy}ax zvJ8_(Cf#+H-dBlH53`_u-~6BVAMz|(g?jCVdBWNZ(+A}(pFV7>S3QgPiQcMaflkIC z-3Ti|VT~{au*vq0ts9O&m$p&Gl=L6+q6_m$IcVq}o~+Pl{g>1esQp4%wp~|*zk1n` zZ7T6Toc4`y88s}riCP|ZXrJ?FLz@^KTcyqLjey zu95Yz%F&S{<0~f)Iomek?+hQ%MhCu%T^zsg>C_L`1`Br`xNY&))k9yTQb$JC>)w_f zpU(^tu^Q)y%W~lVz`jz;_ jF?g&s@Y=Qe&c#kW|JbvqK0Y=Rw)4XDoVqsk_>;c_`@;F@ literal 0 HcmV?d00001 diff --git a/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.accesswidener b/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener similarity index 100% rename from fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.accesswidener rename to fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener diff --git a/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json b/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json new file mode 100644 index 0000000000..609c9327e7 --- /dev/null +++ b/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "net.fabricmc.fabric.mixin.renderdata", + "compatibilityLevel": "JAVA_16", + "mixins": [ + "BlockEntityMixin", + "BlockRenderViewMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/fabric-render-data-v2/src/main/resources/fabric.mod.json b/fabric-render-data-v2/src/main/resources/fabric.mod.json new file mode 100644 index 0000000000..1b6c54b5f3 --- /dev/null +++ b/fabric-render-data-v2/src/main/resources/fabric.mod.json @@ -0,0 +1,38 @@ +{ + "schemaVersion": 1, + "id": "fabric-render-data-v2", + "name": "Fabric Render Data (v2)", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/fabric-render-data-v2/icon.png", + "contact": { + "homepage": "https://fabricmc.net", + "irc": "irc://irc.esper.net:6667/fabric", + "issues": "https://github.com/FabricMC/fabric/issues", + "sources": "https://github.com/FabricMC/fabric" + }, + "authors": [ + "FabricMC" + ], + "depends": { + "fabricloader": ">=0.4.0", + "fabric-api-base": "*" + }, + "description": "Hooks for accessing and using block entity data in client-side multithreaded environments.", + "mixins": [ + "fabric-render-data-v2.mixins.json", + { + "config": "fabric-render-data-v2.client.mixins.json", + "environment": "client" + } + ], + "custom": { + "fabric-api:module-lifecycle": "stable", + "loom:injected_interfaces": { + "net/minecraft/class_2586": ["net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity"], + "net/minecraft/class_1920": ["net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView"] + } + }, + "accessWidener": "fabric-render-data-v2.accesswidener" +} diff --git a/fabric-renderer-api-v1/build.gradle b/fabric-renderer-api-v1/build.gradle index f8b1366eb8..b8eb11580a 100644 --- a/fabric-renderer-api-v1/build.gradle +++ b/fabric-renderer-api-v1/build.gradle @@ -8,7 +8,7 @@ testDependencies(project, [ ':fabric-blockrenderlayer-v1', ':fabric-models-v0', ':fabric-object-builder-api-v1', + ':fabric-render-data-v2', ':fabric-renderer-indigo', - ':fabric-rendering-data-attachment-v1', ':fabric-resource-loader-v0' ]) diff --git a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlock.java b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlock.java index 74e5dfafe4..c09b14f752 100644 --- a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlock.java +++ b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlock.java @@ -36,7 +36,7 @@ import net.fabricmc.fabric.api.block.v1.FabricBlock; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockView; // Need to implement FabricBlock manually because this is a testmod for another Fabric module, otherwise it would be injected. public final class FrameBlock extends Block implements BlockEntityProvider, FabricBlock { @@ -106,8 +106,8 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { // but the goal here is just to test the behavior with the pillar's connected textures. ;-) @Override public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) { - // For this specific block, the render attachment works on both the client and the server, so let's use that. - if (((RenderAttachedBlockView) renderView).getBlockEntityRenderAttachment(pos) instanceof Block mimickedBlock) { + // For this specific block, the render data works on both the client and the server, so let's use that. + if (((RenderDataBlockView) renderView).getBlockEntityRenderData(pos) instanceof Block mimickedBlock) { return mimickedBlock.getDefaultState(); } diff --git a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlockEntity.java b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlockEntity.java index 5ed12957e8..abf5a444a3 100644 --- a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlockEntity.java +++ b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple/FrameBlockEntity.java @@ -29,9 +29,9 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockEntity; -public final class FrameBlockEntity extends BlockEntity implements RenderAttachmentBlockEntity { +public final class FrameBlockEntity extends BlockEntity implements RenderDataBlockEntity { @Nullable private Block block = null; @@ -86,7 +86,7 @@ public void setBlock(@Nullable Block block) { @Nullable @Override - public Block getRenderAttachmentData() { + public Block getRenderData() { return this.block; } diff --git a/fabric-renderer-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/renderer/simple/client/FrameBakedModel.java b/fabric-renderer-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/renderer/simple/client/FrameBakedModel.java index 388361a9d9..87293a3c37 100644 --- a/fabric-renderer-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/renderer/simple/client/FrameBakedModel.java +++ b/fabric-renderer-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/renderer/simple/client/FrameBakedModel.java @@ -37,6 +37,7 @@ import net.minecraft.util.math.random.Random; import net.minecraft.world.BlockRenderView; +import net.fabricmc.fabric.api.renderdata.v2.RenderDataBlockView; import net.fabricmc.fabric.api.renderer.v1.RendererAccess; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; @@ -44,7 +45,6 @@ import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; final class FrameBakedModel implements BakedModel { private final Mesh frameMesh; @@ -112,17 +112,12 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos // Emit our frame mesh this.frameMesh.outputTo(context.getEmitter()); - RenderAttachedBlockView renderAttachedBlockView = (RenderAttachedBlockView) blockView; - - // We cannot access the block entity from here. We should instead use the immutable render attachments provided by the block entity. - @Nullable - Block data = (Block) renderAttachedBlockView.getBlockEntityRenderAttachment(pos); - - if (data == null) { - return; // No inner block to render + // We should not access the block entity from here. We should instead use the immutable render data provided by the block entity. + if (!(((RenderDataBlockView) blockView).getBlockEntityRenderData(pos) instanceof Block mimickedBlock)) { + return; // No inner block to render, or data of wrong type } - BlockState innerState = data.getDefaultState(); + BlockState innerState = mimickedBlock.getDefaultState(); // Now, we emit a transparent scaled-down version of the inner model // Try both emissive and non-emissive versions of the translucent material diff --git a/fabric-rendering-data-attachment-v1/build.gradle b/fabric-rendering-data-attachment-v1/build.gradle deleted file mode 100644 index 329d2499e7..0000000000 --- a/fabric-rendering-data-attachment-v1/build.gradle +++ /dev/null @@ -1,8 +0,0 @@ -archivesBaseName = "fabric-rendering-data-attachment-v1" -version = getSubprojectVersion(project) - -moduleDependencies(project, ['fabric-api-base']) - -loom { - accessWidenerPath = file("src/main/resources/fabric-rendering-data-attachment-v1.accesswidener") -} diff --git a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java b/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java deleted file mode 100644 index dbfd88d370..0000000000 --- a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.api.rendering.data.v1; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.World; - -/** - * {@link BlockRenderView}-extending interface to be used by {@code FabricBakedModel} - * for dynamic model customization. It ensures thread safety and exploits data cached in render - * chunks for performance and data consistency. This interface is guaranteed to be implemented on - * every {@link BlockRenderView} subclass, and as such any {@link BlockRenderView} - * can be safely cast to {@link RenderAttachedBlockView}. - * - *

There are differences from regular {@link World} access that consumers must understand: - * - *

BlockEntity implementations that provide data for model customization should implement - * {@link RenderAttachmentBlockEntity} which will be queried on the main thread when a render - * chunk is enqueued for rebuild. The model should retrieve the results by casting the - * {@link BlockRenderView} to this class and then calling {@link #getBlockEntityRenderAttachment(BlockPos)}. - * While {@link #getBlockEntity(net.minecraft.util.math.BlockPos)} is not disabled, it - * is not thread-safe for use on render threads. Models that violate this guidance are - * responsible for any necessary synchronization or collision detection. - * - *

{@link #getBlockState(net.minecraft.util.math.BlockPos)} and {@link #getFluidState(net.minecraft.util.math.BlockPos)} - * will always reflect the state cached with the render chunk. Block and fluid states - * can thus be different from main-thread world state due to lag between block update - * application from network packets and render chunk rebuilds. Use of {link #getCachedRenderData()} - * will ensure consistency of model state with the rest of the chunk being rendered. - * - *

Models should avoid using {@link BlockRenderView#getBlockEntity(BlockPos)} - * to ensure thread safety because this view may be accessed outside the main client thread. - * Models that require Block Entity data should implement {@link RenderAttachmentBlockEntity} - * on their block entity class, cast the {@link BlockRenderView} to {@link RenderAttachedBlockView} - * and then use {@link #getBlockEntityRenderAttachment(BlockPos)} to retrieve the data. When called from the - * main thread, that method will simply retrieve the data directly. - */ -public interface RenderAttachedBlockView extends BlockRenderView { - /** - * For models associated with Block Entities that implement {@link RenderAttachmentBlockEntity} - * this will be the most recent value provided by that implementation for the given block position. - * - *

Null in all other cases, or if the result from the implementation was null. - * - * @param pos Position of the block for the block model. - */ - @Nullable - default Object getBlockEntityRenderAttachment(BlockPos pos) { - BlockEntity be = this.getBlockEntity(pos); - return be == null ? null : ((RenderAttachmentBlockEntity) be).getRenderAttachmentData(); - } -} diff --git a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java b/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java deleted file mode 100644 index b96c0bfc94..0000000000 --- a/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachmentBlockEntity.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.api.rendering.data.v1; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.world.BlockRenderView; - -/** - * Interface for {@link BlockEntity}s which provide dynamic model state data. - * - *

Dynamic model state data is separate from BlockState, and will be - * cached during render chunk building on the main thread (safely) and accessible - * during chunk rendering on non-main threads. - * - *

To access the dynamic data, cast the {@link BlockRenderView} to {@link RenderAttachedBlockView}, - * and then call {@link #getRenderAttachmentData()} with the correct position. - * - *

Due to chunk meshing happening on non-main threads, please ensure that all accesses to the passed model data are - * thread-safe. This can be achieved by, for example, passing a pre-generated - * immutable object, or ensuring all gets performed on the passed object are atomic - * and well-checked for unusual states. - */ -@FunctionalInterface -public interface RenderAttachmentBlockEntity { - /** - * @return The model state data provided by this block entity. Can be null. - */ - @Nullable - Object getRenderAttachmentData(); -} diff --git a/gradle.properties b/gradle.properties index 333898d266..a40b7dbad8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,6 +45,7 @@ fabric-object-builder-api-v1-version=7.0.6 fabric-particles-v1-version=1.0.26 fabric-recipe-api-v1-version=1.0.11 fabric-registry-sync-v0-version=2.2.3 +fabric-render-data-v2-version=1.0.0 fabric-renderer-api-v1-version=2.4.0 fabric-renderer-indigo-version=1.4.0 fabric-renderer-registries-v1-version=3.2.41 diff --git a/settings.gradle b/settings.gradle index daeff6014f..1e40d11084 100644 --- a/settings.gradle +++ b/settings.gradle @@ -39,11 +39,10 @@ include 'fabric-object-builder-api-v1' include 'fabric-particles-v1' include 'fabric-recipe-api-v1' include 'fabric-registry-sync-v0' +include 'fabric-render-data-v2' include 'fabric-renderer-api-v1' include 'fabric-renderer-indigo' - include 'fabric-rendering-v1' -include 'fabric-rendering-data-attachment-v1' include 'fabric-rendering-fluids-v1' include 'fabric-resource-conditions-api-v1' include 'fabric-resource-loader-v0' @@ -63,5 +62,6 @@ include 'deprecated:fabric-events-lifecycle-v0' include 'deprecated:fabric-keybindings-v0' include 'deprecated:fabric-networking-v0' include 'deprecated:fabric-renderer-registries-v1' +include 'deprecated:fabric-rendering-data-attachment-v1' include 'deprecated:fabric-rendering-v0' include 'deprecated:fabric-loot-tables-v1' From edca3cde1ffd445818ac2e8722bf2bd2072e8d3a Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 24 Jun 2023 09:35:04 -0700 Subject: [PATCH 2/4] Fixes and improvements - Fix mixins of v1 - Use `fabric_` instead of `fabric$`; remove prefix completely in some cases - Improve javadoc - Remove dependencies on `fabric-api-base` - Bump `fabricloader` dependency of v2 - Attempt to fix checkstyle --- .../build.gradle | 5 +---- .../data/v1/RenderAttachedBlockView.java | 4 ++-- ...c-rendering-data-attachment-v1.mixins.json | 2 +- .../src/main/resources/fabric.mod.json | 1 - fabric-render-data-v2/build.gradle | 2 -- .../client/RenderDataMapConsumer.java | 2 +- .../ChunkRendererRegionBuilderMixin.java | 10 ++++----- .../client/ChunkRendererRegionMixin.java | 8 +++---- .../renderdata/v2/RenderDataBlockEntity.java | 22 +++++++++++++------ .../renderdata/v2/RenderDataBlockView.java | 7 +++--- .../src/main/resources/fabric.mod.json | 3 +-- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/deprecated/fabric-rendering-data-attachment-v1/build.gradle b/deprecated/fabric-rendering-data-attachment-v1/build.gradle index e535ab02ba..be9278dbc9 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/build.gradle +++ b/deprecated/fabric-rendering-data-attachment-v1/build.gradle @@ -1,7 +1,4 @@ archivesBaseName = "fabric-rendering-data-attachment-v1" version = getSubprojectVersion(project) -moduleDependencies(project, [ - 'fabric-api-base', - 'fabric-render-data-v2' -]) +moduleDependencies(project, ['fabric-render-data-v2']) diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java index a18355e329..40091889e0 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1/RenderAttachedBlockView.java @@ -26,8 +26,8 @@ /** * This interface is guaranteed to be implemented on all {@link WorldView} instances. - * It is likely to be implemented on a {@link BlockRenderView} instance, but this is - * not guaranteed. + * It is likely to be implemented on any given {@link BlockRenderView} instance, but + * this is not guaranteed. * * @deprecated Use {@link RenderDataBlockView} instead. */ diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json index 3e4c81bc9d..582372a7a2 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "net.fabricmc.fabric.mixin.rendering.data.attachment", + "package": "net.fabricmc.fabric.mixin.rendering.data", "compatibilityLevel": "JAVA_16", "mixins": [ "BlockEntityMixin", diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json index e51711d9b9..119e22d6f4 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json @@ -17,7 +17,6 @@ ], "depends": { "fabricloader": ">=0.4.0", - "fabric-api-base": "*", "fabric-render-data-v2": "*" }, "description": "Thread-safe hooks for block entity data use during terrain rendering.", diff --git a/fabric-render-data-v2/build.gradle b/fabric-render-data-v2/build.gradle index 1a43486d1e..4d4316d270 100644 --- a/fabric-render-data-v2/build.gradle +++ b/fabric-render-data-v2/build.gradle @@ -1,8 +1,6 @@ archivesBaseName = "fabric-render-data-v2" version = getSubprojectVersion(project) -moduleDependencies(project, ['fabric-api-base']) - loom { accessWidenerPath = file("src/main/resources/fabric-render-data-v2.accesswidener") } diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java index 5ea85d450e..e4e7679595 100644 --- a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java +++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java @@ -19,5 +19,5 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; public interface RenderDataMapConsumer { - void fabric$acceptRenderDataMap(Long2ObjectMap renderDataMap); + void fabric_acceptRenderDataMap(Long2ObjectMap renderDataMap); } diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java index 0e4fc767ac..56b9a7748d 100644 --- a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java +++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java @@ -44,8 +44,8 @@ public abstract class ChunkRendererRegionBuilderMixin { private static final AtomicInteger ERROR_COUNTER = new AtomicInteger(); private static final Logger LOGGER = LoggerFactory.getLogger(ChunkRendererRegionBuilderMixin.class); - @Inject(method = "build(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;I)Lnet/minecraft/client/render/chunk/ChunkRendererRegion;", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - private void fabric$createDataMap(World world, BlockPos startPos, BlockPos endPos, int offset, CallbackInfoReturnable cir, int startX, int startZ, int endX, int endZ, ChunkRendererRegionBuilder.ClientChunk[][] chunksXZ) { + @Inject(method = "build", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) + private void createDataMap(World world, BlockPos startPos, BlockPos endPos, int offset, CallbackInfoReturnable cir, int startX, int startZ, int endX, int endZ, ChunkRendererRegionBuilder.ClientChunk[][] chunksXZ) { ChunkRendererRegion rendererRegion = cir.getReturnValue(); if (rendererRegion == null) { @@ -65,7 +65,7 @@ public abstract class ChunkRendererRegionBuilderMixin { // We handle this simply by retrying until it works. Ugly but effective. while (true) { try { - map = fabric$mapChunk(chunk.getChunk(), startPos, endPos, map); + map = mapChunk(chunk.getChunk(), startPos, endPos, map); break; } catch (ConcurrentModificationException e) { final int count = ERROR_COUNTER.incrementAndGet(); @@ -83,12 +83,12 @@ public abstract class ChunkRendererRegionBuilderMixin { } if (map != null) { - ((RenderDataMapConsumer) rendererRegion).fabric$acceptRenderDataMap(map); + ((RenderDataMapConsumer) rendererRegion).fabric_acceptRenderDataMap(map); } } @Unique - private static Long2ObjectOpenHashMap fabric$mapChunk(WorldChunk chunk, BlockPos posFrom, BlockPos posTo, Long2ObjectOpenHashMap map) { + private static Long2ObjectOpenHashMap mapChunk(WorldChunk chunk, BlockPos posFrom, BlockPos posTo, Long2ObjectOpenHashMap map) { final int xMin = posFrom.getX(); final int xMax = posTo.getX(); final int yMin = posFrom.getY(); diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java index 5cca7f7563..4ef0e0fb6c 100644 --- a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java +++ b/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java @@ -29,18 +29,18 @@ @Mixin(ChunkRendererRegion.class) public abstract class ChunkRendererRegionMixin implements BlockRenderView, RenderDataMapConsumer { @Unique - private Long2ObjectMap fabric$renderDataMap; + private Long2ObjectMap fabric_renderDataMap; @Override public Object getBlockEntityRenderData(BlockPos pos) { - return fabric$renderDataMap == null ? null : fabric$renderDataMap.get(pos.asLong()); + return fabric_renderDataMap == null ? null : fabric_renderDataMap.get(pos.asLong()); } /** * Called in {@link ChunkRendererRegionBuilderMixin}. */ @Override - public void fabric$acceptRenderDataMap(Long2ObjectMap renderDataMap) { - this.fabric$renderDataMap = renderDataMap; + public void fabric_acceptRenderDataMap(Long2ObjectMap renderDataMap) { + this.fabric_renderDataMap = renderDataMap; } } diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java index 575a2db5f5..163195c68f 100644 --- a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java +++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java @@ -20,17 +20,24 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; /** * Extensions that allow {@link BlockEntity} subclasses to provide render data. * *

Block entity render data is arbitrary data that is safe to access and use in a client-side - * multithreaded environment, such as chunk building. This includes, but is not limited to, - * access and use from inside models ({@code FabricBakedModel#emitBlockQuads}), block color - * providers ({@code BlockColorProvider#getColor}), and block appearance computation + * multithreaded environment. In these environments, accessing and using a {@link BlockEntity} + * directly via {@link BlockView#getBlockEntity(BlockPos)} may not be thread-safe since the + * {@link BlockEntity} might be modified on a different thread or because accessing the internal + * state of the {@link BlockEntity} could modify it in a non-atomic way (such as through lazy + * computation). + * + *

The most common such environment is chunk building. Places to use render data include, but are + * not limited to, block models ({@code FabricBakedModel#emitBlockQuads}), block color providers + * ({@code BlockColorProvider#getColor}), and block appearance computation * ({@code FabricBlock#getAppearance}). * - *

Implementation Tips + *

Implementation Tips

* *

The simplest form of render data is a value or object that is immutable. If only one such value * must serve as render data, then it can be returned directly. An example of this would be returning @@ -48,9 +55,10 @@ public interface RenderDataBlockEntity { * Gets the render data provided by this block entity. The returned object must be safe to * use in a multithreaded environment. * - *

Note: This method should not be called directly, unless the result is used to implement - * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)}. Otherwise, use - * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)} to access render data instead. + *

Note: This method should not be called directly; use + * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)} instead. Only call this + * method when the result is used to implement + * {@link RenderDataBlockView#getBlockEntityRenderData(BlockPos)}. * * @return the render data */ diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java index 71ce858264..593a427b91 100644 --- a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java +++ b/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java @@ -43,10 +43,11 @@ public interface RenderDataBlockView { /** * Retrieves block entity render data for a given block position. Always use this method - * instead of {@link RenderDataBlockEntity#getRenderData()} to ensure thread safety and - * data consistency. + * instead of {@link BlockRenderView#getBlockEntity(BlockPos)} or + * {@link RenderDataBlockEntity#getRenderData()} to ensure thread safety and data + * consistency. * - *

Callers of this method should always check the returned object's class (for example, + *

Callers of this method should always check the returned object's class (usually * using {@code instanceof}) before casting. This prevents unexpected class cast exceptions. * * @param pos position of the block entity diff --git a/fabric-render-data-v2/src/main/resources/fabric.mod.json b/fabric-render-data-v2/src/main/resources/fabric.mod.json index 1b6c54b5f3..1f5f60ea9a 100644 --- a/fabric-render-data-v2/src/main/resources/fabric.mod.json +++ b/fabric-render-data-v2/src/main/resources/fabric.mod.json @@ -16,8 +16,7 @@ "FabricMC" ], "depends": { - "fabricloader": ">=0.4.0", - "fabric-api-base": "*" + "fabricloader": ">=0.14.21" }, "description": "Hooks for accessing and using block entity data in client-side multithreaded environments.", "mixins": [ From cdb46bfa8af7ea5782b3346dbf70774d1425d0e8 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 24 Jun 2023 15:38:30 -0700 Subject: [PATCH 3/4] Rename module to include `api` - Clarify required checks after calling `RenderDataBlockView#getBlockEntityRenderData` --- .../build.gradle | 2 +- .../src/main/resources/fabric.mod.json | 2 +- .../build.gradle | 4 ++-- .../renderdata/client/RenderDataMapConsumer.java | 0 .../client/ChunkRendererRegionBuilderMixin.java | 0 .../renderdata/client/ChunkRendererRegionMixin.java | 0 .../fabric-render-data-api-v2.client.mixins.json | 0 .../api/renderdata/v2/RenderDataBlockEntity.java | 0 .../api/renderdata/v2/RenderDataBlockView.java | 8 ++++++-- .../fabric/mixin/renderdata/BlockEntityMixin.java | 0 .../mixin/renderdata/BlockRenderViewMixin.java | 0 .../assets/fabric-render-data-api-v2}/icon.png | Bin .../fabric-render-data-api-v2.accesswidener | 0 .../resources/fabric-render-data-api-v2.mixins.json | 0 .../src/main/resources/fabric.mod.json | 12 ++++++------ fabric-renderer-api-v1/build.gradle | 2 +- gradle.properties | 2 +- settings.gradle | 2 +- 18 files changed, 19 insertions(+), 15 deletions(-) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/build.gradle (61%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java (100%) rename fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json => fabric-render-data-api-v2/src/client/resources/fabric-render-data-api-v2.client.mixins.json (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java (84%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java (100%) rename {fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2 => fabric-render-data-api-v2/src/main/resources/assets/fabric-render-data-api-v2}/icon.png (100%) rename fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener => fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.accesswidener (100%) rename fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json => fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json (100%) rename {fabric-render-data-v2 => fabric-render-data-api-v2}/src/main/resources/fabric.mod.json (74%) diff --git a/deprecated/fabric-rendering-data-attachment-v1/build.gradle b/deprecated/fabric-rendering-data-attachment-v1/build.gradle index be9278dbc9..886022f45d 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/build.gradle +++ b/deprecated/fabric-rendering-data-attachment-v1/build.gradle @@ -1,4 +1,4 @@ archivesBaseName = "fabric-rendering-data-attachment-v1" version = getSubprojectVersion(project) -moduleDependencies(project, ['fabric-render-data-v2']) +moduleDependencies(project, ['fabric-render-data-api-v2']) diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json index 119e22d6f4..5cfddc0a53 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric.mod.json @@ -17,7 +17,7 @@ ], "depends": { "fabricloader": ">=0.4.0", - "fabric-render-data-v2": "*" + "fabric-render-data-api-v2": "*" }, "description": "Thread-safe hooks for block entity data use during terrain rendering.", "mixins": [ diff --git a/fabric-render-data-v2/build.gradle b/fabric-render-data-api-v2/build.gradle similarity index 61% rename from fabric-render-data-v2/build.gradle rename to fabric-render-data-api-v2/build.gradle index 4d4316d270..d18a9aac58 100644 --- a/fabric-render-data-v2/build.gradle +++ b/fabric-render-data-api-v2/build.gradle @@ -1,6 +1,6 @@ -archivesBaseName = "fabric-render-data-v2" +archivesBaseName = "fabric-render-data-api-v2" version = getSubprojectVersion(project) loom { - accessWidenerPath = file("src/main/resources/fabric-render-data-v2.accesswidener") + accessWidenerPath = file("src/main/resources/fabric-render-data-api-v2.accesswidener") } diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java b/fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java similarity index 100% rename from fabric-render-data-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java rename to fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/impl/renderdata/client/RenderDataMapConsumer.java diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java b/fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java similarity index 100% rename from fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java rename to fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionBuilderMixin.java diff --git a/fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java b/fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java similarity index 100% rename from fabric-render-data-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java rename to fabric-render-data-api-v2/src/client/java/net/fabricmc/fabric/mixin/renderdata/client/ChunkRendererRegionMixin.java diff --git a/fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json b/fabric-render-data-api-v2/src/client/resources/fabric-render-data-api-v2.client.mixins.json similarity index 100% rename from fabric-render-data-v2/src/client/resources/fabric-render-data-v2.client.mixins.json rename to fabric-render-data-api-v2/src/client/resources/fabric-render-data-api-v2.client.mixins.json diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java b/fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java similarity index 100% rename from fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java rename to fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockEntity.java diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java b/fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java similarity index 84% rename from fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java rename to fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java index 593a427b91..d8359ea591 100644 --- a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java +++ b/fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView.java @@ -47,8 +47,12 @@ public interface RenderDataBlockView { * {@link RenderDataBlockEntity#getRenderData()} to ensure thread safety and data * consistency. * - *

Callers of this method should always check the returned object's class (usually - * using {@code instanceof}) before casting. This prevents unexpected class cast exceptions. + *

Users of this method are required to always check the returned object before using + * it. Users must check if it is null and if it is of the correct type to avoid null pointer + * and class cast exceptions, as the returned data is not guaranteed to be what the user expects. + * A simple way to implement these checks is to use {@code instanceof}, since it always returns + * false if the object is null. If the {@code instanceof} returns false, a fallback path should + * be used. * * @param pos position of the block entity * @return the render data provided by the block entity, or null if there is no block entity at this position diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java b/fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java similarity index 100% rename from fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java rename to fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockEntityMixin.java diff --git a/fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java b/fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java similarity index 100% rename from fabric-render-data-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java rename to fabric-render-data-api-v2/src/main/java/net/fabricmc/fabric/mixin/renderdata/BlockRenderViewMixin.java diff --git a/fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2/icon.png b/fabric-render-data-api-v2/src/main/resources/assets/fabric-render-data-api-v2/icon.png similarity index 100% rename from fabric-render-data-v2/src/main/resources/assets/fabric-render-data-v2/icon.png rename to fabric-render-data-api-v2/src/main/resources/assets/fabric-render-data-api-v2/icon.png diff --git a/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener b/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.accesswidener similarity index 100% rename from fabric-render-data-v2/src/main/resources/fabric-render-data-v2.accesswidener rename to fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.accesswidener diff --git a/fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json b/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json similarity index 100% rename from fabric-render-data-v2/src/main/resources/fabric-render-data-v2.mixins.json rename to fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json diff --git a/fabric-render-data-v2/src/main/resources/fabric.mod.json b/fabric-render-data-api-v2/src/main/resources/fabric.mod.json similarity index 74% rename from fabric-render-data-v2/src/main/resources/fabric.mod.json rename to fabric-render-data-api-v2/src/main/resources/fabric.mod.json index 1f5f60ea9a..796bd96883 100644 --- a/fabric-render-data-v2/src/main/resources/fabric.mod.json +++ b/fabric-render-data-api-v2/src/main/resources/fabric.mod.json @@ -1,11 +1,11 @@ { "schemaVersion": 1, - "id": "fabric-render-data-v2", - "name": "Fabric Render Data (v2)", + "id": "fabric-render-data-api-v2", + "name": "Fabric Render Data API (v2)", "version": "${version}", "environment": "*", "license": "Apache-2.0", - "icon": "assets/fabric-render-data-v2/icon.png", + "icon": "assets/fabric-render-data-api-v2/icon.png", "contact": { "homepage": "https://fabricmc.net", "irc": "irc://irc.esper.net:6667/fabric", @@ -20,9 +20,9 @@ }, "description": "Hooks for accessing and using block entity data in client-side multithreaded environments.", "mixins": [ - "fabric-render-data-v2.mixins.json", + "fabric-render-data-api-v2.mixins.json", { - "config": "fabric-render-data-v2.client.mixins.json", + "config": "fabric-render-data-api-v2.client.mixins.json", "environment": "client" } ], @@ -33,5 +33,5 @@ "net/minecraft/class_1920": ["net/fabricmc/fabric/api/renderdata/v2/RenderDataBlockView"] } }, - "accessWidener": "fabric-render-data-v2.accesswidener" + "accessWidener": "fabric-render-data-api-v2.accesswidener" } diff --git a/fabric-renderer-api-v1/build.gradle b/fabric-renderer-api-v1/build.gradle index b8eb11580a..efa97066fd 100644 --- a/fabric-renderer-api-v1/build.gradle +++ b/fabric-renderer-api-v1/build.gradle @@ -8,7 +8,7 @@ testDependencies(project, [ ':fabric-blockrenderlayer-v1', ':fabric-models-v0', ':fabric-object-builder-api-v1', - ':fabric-render-data-v2', + ':fabric-render-data-api-v2', ':fabric-renderer-indigo', ':fabric-resource-loader-v0' ]) diff --git a/gradle.properties b/gradle.properties index a40b7dbad8..f860a30c8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,7 +45,7 @@ fabric-object-builder-api-v1-version=7.0.6 fabric-particles-v1-version=1.0.26 fabric-recipe-api-v1-version=1.0.11 fabric-registry-sync-v0-version=2.2.3 -fabric-render-data-v2-version=1.0.0 +fabric-render-data-api-v2-version=1.0.0 fabric-renderer-api-v1-version=2.4.0 fabric-renderer-indigo-version=1.4.0 fabric-renderer-registries-v1-version=3.2.41 diff --git a/settings.gradle b/settings.gradle index 1e40d11084..6e5fbd1936 100644 --- a/settings.gradle +++ b/settings.gradle @@ -39,7 +39,7 @@ include 'fabric-object-builder-api-v1' include 'fabric-particles-v1' include 'fabric-recipe-api-v1' include 'fabric-registry-sync-v0' -include 'fabric-render-data-v2' +include 'fabric-render-data-api-v2' include 'fabric-renderer-api-v1' include 'fabric-renderer-indigo' include 'fabric-rendering-v1' From 629abcf98ffac57c8debe1fa32bfd5bb93e3f09b Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Tue, 27 Jun 2023 11:51:52 -0700 Subject: [PATCH 4/4] Bump mixin compatibility level --- .../resources/fabric-rendering-data-attachment-v1.mixins.json | 2 +- .../src/main/resources/fabric-render-data-api-v2.mixins.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json index 582372a7a2..9c09ede3c4 100644 --- a/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json +++ b/deprecated/fabric-rendering-data-attachment-v1/src/main/resources/fabric-rendering-data-attachment-v1.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.fabricmc.fabric.mixin.rendering.data", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "mixins": [ "BlockEntityMixin", "WorldViewMixin" diff --git a/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json b/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json index 609c9327e7..7447f9ee4e 100644 --- a/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json +++ b/fabric-render-data-api-v2/src/main/resources/fabric-render-data-api-v2.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "net.fabricmc.fabric.mixin.renderdata", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "mixins": [ "BlockEntityMixin", "BlockRenderViewMixin"