mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Small Cleanups (#2767)
* ServerLoginNetworking javadoc fix
* Improve Rendering Data Attachment javadocs. Fixes #863
* Deprecate `NbtType`. Fixes #1401
* Remove redundancy
(cherry picked from commit afca2f3e33
)
This commit is contained in:
parent
b6b6abb47f
commit
6e0787e663
6 changed files with 27 additions and 20 deletions
fabric-api-base/src/main/java/net/fabricmc/fabric/api/util
fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1
fabric-renderer-api-v1/src
client/java/net/fabricmc/fabric/api/renderer/v1/model
testmod/java/net/fabricmc/fabric/test/renderer/simple
fabric-rendering-data-attachment-v1/src/main/java/net/fabricmc/fabric/api/rendering/data/v1
|
@ -26,7 +26,9 @@ import net.minecraft.nbt.NbtElement;
|
|||
*
|
||||
* @see NbtCompound#contains(String, int)
|
||||
* @see net.minecraft.nbt.NbtTypes#byId(int)
|
||||
* @deprecated Use the constants in {@link NbtElement} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class NbtType {
|
||||
public static final int END = 0;
|
||||
public static final int BYTE = 1;
|
||||
|
|
|
@ -168,7 +168,7 @@ public final class ServerLoginNetworking {
|
|||
* <pre>{@code
|
||||
* ServerLoginNetworking.registerGlobalReceiver(CHECK_CHANNEL, (server, handler, understood, buf, synchronizer, responseSender) -> {
|
||||
* if (!understood) {
|
||||
* handler.disconnect(new LiteralText("Only accept clients that can check!"));
|
||||
* handler.disconnect(Text.literal("Only accept clients that can check!"));
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
|
@ -179,7 +179,7 @@ public final class ServerLoginNetworking {
|
|||
* LoginInfoChecker checker = LoginInfoChecker.get(server);
|
||||
*
|
||||
* if (!checker.check(handler.getConnectionInfo(), checkMessage)) {
|
||||
* handler.disconnect(new LiteralText("Invalid credentials!"));
|
||||
* handler.disconnect(Text.literal("Invalid credentials!"));
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
|
|
|
@ -85,9 +85,8 @@ public interface FabricBakedModel {
|
|||
* it will probably be easier to use {@link RenderContext#fallbackConsumer} which handles
|
||||
* re-seeding per face automatically.
|
||||
*
|
||||
* @param blockView Access to world state. Using {@link net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView#getBlockEntityRenderAttachment(BlockPos)} to
|
||||
* retrieve block entity state unless thread safety can be guaranteed.
|
||||
* param safeBlockEntityAccessor Thread-safe access to block entity data
|
||||
* @param blockView Access to world state. Cast to {@code RenderAttachedBlockView} to
|
||||
* retrieve block entity data unless thread safety can be guaranteed.
|
||||
* @param state Block state for model being rendered.
|
||||
* @param pos Position of block for model being rendered.
|
||||
* @param randomSupplier Random object seeded per vanilla conventions. Call multiple times to re-seed.
|
||||
|
|
|
@ -22,14 +22,14 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
|
||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity;
|
||||
import net.fabricmc.fabric.api.util.NbtType;
|
||||
import net.fabricmc.fabric.test.renderer.WorldRenderExtensions;
|
||||
|
||||
public final class FrameBlockEntity extends BlockEntity implements RenderAttachmentBlockEntity {
|
||||
|
@ -44,7 +44,7 @@ public final class FrameBlockEntity extends BlockEntity implements RenderAttachm
|
|||
public void readNbt(NbtCompound tag) {
|
||||
super.readNbt(tag);
|
||||
|
||||
if (tag.contains("block", NbtType.STRING)) {
|
||||
if (tag.contains("block", NbtElement.STRING_TYPE)) {
|
||||
this.block = Registry.BLOCK.get(new Identifier(tag.getString("block")));
|
||||
} else {
|
||||
this.block = null;
|
||||
|
|
|
@ -21,17 +21,21 @@ 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;
|
||||
|
||||
/**
|
||||
* BlockView-extending interface to be used by {@link net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel} for dynamic model
|
||||
* customization. It ensures thread safety and exploits data cached in render
|
||||
* chunks for performance and data consistency.
|
||||
* {@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}.
|
||||
*
|
||||
* <p>There are differences from BlockView consumers must understand:
|
||||
* <p>There are differences from regular {@link World} access that consumers must understand:
|
||||
*
|
||||
* <p>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 via {@link #getBlockEntityRenderAttachment(BlockPos)}.
|
||||
* 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.
|
||||
|
@ -45,12 +49,10 @@ import net.minecraft.world.BlockRenderView;
|
|||
* <p>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}
|
||||
* and then use {@link #getBlockEntityRenderAttachment(BlockPos)} to retrieve it. When called from the
|
||||
* 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.
|
||||
*
|
||||
* <p>This interface is guaranteed to be implemented on every {@link BlockRenderView} subclass.
|
||||
*/
|
||||
// XXX can not link net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
|
||||
public interface RenderAttachedBlockView extends BlockRenderView {
|
||||
/**
|
||||
* For models associated with Block Entities that implement {@link RenderAttachmentBlockEntity}
|
||||
|
@ -62,7 +64,7 @@ public interface RenderAttachedBlockView extends BlockRenderView {
|
|||
*/
|
||||
@Nullable
|
||||
default Object getBlockEntityRenderAttachment(BlockPos pos) {
|
||||
BlockEntity be = ((BlockRenderView) this).getBlockEntity(pos);
|
||||
BlockEntity be = this.getBlockEntity(pos);
|
||||
return be == null ? null : ((RenderAttachmentBlockEntity) be).getRenderAttachmentData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ 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.
|
||||
|
@ -27,7 +28,10 @@ import net.minecraft.block.entity.BlockEntity;
|
|||
* cached during render chunk building on the main thread (safely) and accessible
|
||||
* during chunk rendering on non-main threads.
|
||||
*
|
||||
* <p>For this reason, please ensure that all accesses to the passed model data are
|
||||
* <p>To access the dynamic data, cast the {@link BlockRenderView} to {@link RenderAttachedBlockView},
|
||||
* and then call {@link #getRenderAttachmentData()} with the correct position.
|
||||
*
|
||||
* <p>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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue