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