跳到主要内容

33块实体渲染器

代码

新建一个GemPolishingBlockEntityRenderer类:

public class GemPolishingBlockEntityRenderer implements BlockEntityRenderer<GemPolishingStationBlockEntity> {
public GemPolishingBlockEntityRenderer(BlockEntityRendererFactory.Context context) {

}

@Override
public void render(GemPolishingStationBlockEntity entity, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light, int overlay) {
ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
ItemStack stack = entity.getRenderStack();
matrices.push();
matrices.translate(0.5f, 0.75f, 0.5f);
matrices.scale(0.35f, 0.35f, 0.35f);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(270));

itemRenderer.renderItem(stack, ModelTransformationMode.GUI, getLightLevel(entity.getWorld(),
entity.getPos()), OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), 1);
matrices.pop();
}

private int getLightLevel(World world, BlockPos pos) {
int bLight = world.getLightLevel(LightType.BLOCK, pos);
int sLight = world.getLightLevel(LightType.SKY, pos);
return LightmapTextureManager.pack(bLight, sLight);
}
}

修改原来的GemPolishingStationBlockEntity:

public ItemStack getRenderStack() {
if(this.getStack(OUTPUT_SLOT).isEmpty()) {
return this.getStack(INPUT_SLOT);
} else {
return this.getStack(OUTPUT_SLOT);
}
}

@Override
public void markDirty() {
world.updateListeners(pos, getCachedState(), getCachedState(), 3);
super.markDirty();
}

@Nullable
@Override
public Packet<ClientPlayPacketListener> toUpdatePacket() {
return BlockEntityUpdateS2CPacket.create(this);
}

@Override
public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}

效果

此时我们的抛光机上面就有了图案

image-20240825182317390