Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,27 @@ public ChainConveyorRenderer(Context context) {

@Override
protected void renderSafe(ChainConveyorBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
int light, int overlay) {
// Defensive: if the BE has no level or blockstate yet, bail out early.
if (be == null)
return;
Level level = be.getLevel();
if (level == null)
return;
BlockState state = be.getBlockState();
if (state == null)
return;

super.renderSafe(be, partialTicks, ms, buffer, light, overlay);
BlockPos pos = be.getBlockPos();

renderChains(be, ms, buffer, light, overlay);

if (VisualizationManager.supportsVisualization(be.getLevel()))
if (VisualizationManager.supportsVisualization(level))
return;

CachedBuffers.partial(AllPartialModels.CHAIN_CONVEYOR_WHEEL, be.getBlockState())
// use the validated state variable
CachedBuffers.partial(AllPartialModels.CHAIN_CONVEYOR_WHEEL, state)
.light(light)
.overlay(overlay)
.renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped()));
Expand Down Expand Up @@ -100,10 +111,22 @@ private void renderBox(ChainConveyorBlockEntity be, PoseStack ms, MultiBufferSou
physicsData.modelKey = key;
}

//More Safety Checks
ResourceLocation modelKey = physicsData.modelKey;
if (modelKey == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Tropheus said this is the only check that should be necessary and the others should be removed. Do we need a similar check in the ChainConveyorVisual?

Also can we move it up in the method to skip the expensive light lookups if we're going to early out anyway?

return;

var rigModel = AllPartialModels.PACKAGE_RIGGING.get(modelKey);
var boxModel = AllPartialModels.PACKAGES.get(modelKey);

// If either partial model is missing, skip rendering this package to avoid cache loader nulls.
if (rigModel == null || boxModel == null)
return;

SuperByteBuffer rigBuffer =
CachedBuffers.partial(AllPartialModels.PACKAGE_RIGGING.get(physicsData.modelKey), blockState);
CachedBuffers.partial(rigModel, blockState);
SuperByteBuffer boxBuffer =
CachedBuffers.partial(AllPartialModels.PACKAGES.get(physicsData.modelKey), blockState);
CachedBuffers.partial(boxModel, blockState);

Vec3 dangleDiff = VecHelper.rotate(targetPosition.add(0, 0.5, 0)
.subtract(position), -yaw, Axis.Y);
Expand Down Expand Up @@ -153,20 +176,25 @@ private void renderChains(ChainConveyorBlockEntity be, PoseStack ms, MultiBuffer
.length());

Level level = be.getLevel();
if (level == null)
continue;
BlockPos tilePos = be.getBlockPos();
Vec3 startOffset = stats.start()
.subtract(Vec3.atCenterOf(tilePos));

if (!VisualizationManager.supportsVisualization(be.getLevel())) {
SuperByteBuffer guard =
CachedBuffers.partial(AllPartialModels.CHAIN_CONVEYOR_GUARD, be.getBlockState());
guard.center();
guard.rotateYDegrees((float) yaw);

guard.uncenter();
guard.light(light)
.overlay(overlay)
.renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped()));
if (!VisualizationManager.supportsVisualization(level)) {
BlockState state = be.getBlockState();
if (state != null) {
SuperByteBuffer guard =
CachedBuffers.partial(AllPartialModels.CHAIN_CONVEYOR_GUARD, state);
guard.center();
guard.rotateYDegrees((float) yaw);

guard.uncenter();
guard.light(light)
.overlay(overlay)
.renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped()));
}
}

ms.pushPose();
Expand Down